/* ============================================================================
 * styles.css  —  O-Ring Calculator
 * ========================================================================== */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1f2a37;
  --muted: #6b7785;
  --line: #dbe2ea;
  --brand: #0b5cab;
  --brand-dark: #08487f;
  --accent: #0e8a6b;
  --warn: #b9470b;
  --err: #c0392b;
  --ok: #0e8a6b;
  --shadow: 0 1px 3px rgba(16, 32, 56, .08), 0 6px 18px rgba(16, 32, 56, .06);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, "Noto Sans", "Microsoft YaHei", "Malgun Gothic", "Hiragino Sans", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }

/* ---- Top bar ---- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(180deg, var(--brand-dark), var(--brand));
  color: #fff; box-shadow: var(--shadow);
}
.tb-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.tb-brand { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tb-lang { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: #eaf2fb; }
.tb-lang select {
  border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff;
  border-radius: 8px; padding: 5px 8px; font-size: .85rem; cursor: pointer;
}
.tb-lang select option { color: #1f2a37; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; color: var(--brand-dark);
  border: 0; border-radius: 8px; padding: 7px 14px; font-weight: 600; font-size: .85rem;
  cursor: pointer; transition: transform .08s ease, box-shadow .15s ease;
}
.tb-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.tb-mail { background: #ffe7b3; color: #7a4b00; }

/* ---- Layout ---- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 22px 18px 60px; }
.page-head { margin: 6px 0 18px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.5rem; }
.page-head p { margin: 0; color: var(--muted); }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--brand); }

/* ---- Home cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); transition: transform .1s ease, border-color .15s;
  display: flex; flex-direction: column; gap: 6px;
}
.card:hover { transform: translateY(-3px); border-color: var(--brand); }
.card h3 { margin: 0; font-size: 1.05rem; color: var(--brand-dark); }
.card p { margin: 0; color: var(--muted); font-size: .9rem; }
.card .go { margin-top: auto; font-weight: 600; color: var(--brand); font-size: .9rem; }
.card.os h3 { color: #0b5cab; } .card.is h3 { color: #0e8a6b; }
.card.as h3 { color: #8a5cf6; } .card.qs h3 { color: #c0700b; } .card.ors h3 { color: #b03060; }

/* ---- Two-column form/result ---- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }

/* ---- Form ---- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: .95rem; color: var(--ink); background: #fff;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11,92,171,.12); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 12px; font-size: .85rem; cursor: pointer; color: var(--ink); }
.seg button.active { background: var(--brand); color: #fff; }
.btns { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  border: 0; border-radius: 9px; padding: 10px 16px; font-weight: 600; cursor: pointer; font-size: .92rem;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #eef2f7; color: var(--ink); }
.btn.ghost:hover { background: #e2e8f0; }

/* ---- Results ---- */
.results .item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.results .item:last-child { border-bottom: 0; }
.results .k { color: var(--muted); font-size: .9rem; }
.results .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.result-bad { color: var(--err); }
.result-ok { color: var(--ok); }
.messages { margin-top: 12px; }
.msg { padding: 9px 12px; border-radius: 8px; font-size: .88rem; margin-bottom: 6px; }
.msg.error { background: #fdecea; color: var(--err); border: 1px solid #f5c6c0; }
.msg.info { background: #eaf4fb; color: var(--brand-dark); border: 1px solid #cfe4f6; }
.rec { margin-top: 14px; background: #f3f8f5; border: 1px solid #cfe7dc; border-radius: 10px; padding: 12px 14px; }
.rec h3 { margin: 0 0 8px; font-size: .95rem; color: var(--accent); }
.rec ul { margin: 0; padding-left: 18px; font-size: .85rem; color: #2f4a40; }
.rec li { margin-bottom: 3px; }
.foot { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 26px; }
.disclaimer { font-size: .8rem; color: var(--muted); background: #fffbe9; border: 1px solid #f3e6b0; border-radius: 8px; padding: 10px 12px; margin-top: 14px; }
.small { font-size: .8rem; color: var(--muted); }

/* ---- Groove reference table ---- */
.ref-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.ref-table th, .ref-table td { border: 1px solid var(--line); padding: 5px 7px; text-align: right; }
.ref-table th { background: #eef3f8; text-align: center; color: var(--brand-dark); }
.ref-table td:first-child { text-align: center; font-weight: 600; }

/* ---- Groove / O-ring cross-section diagram ---- */
.diagram { margin: 10px 0 4px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.groove-svg { width: 100%; height: auto; display: block; }
body.theme-dark .diagram { background: #0f1822; border-color: #2c3a48; }

/* ---- Saved designs table ---- */
.saved-tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.saved-tbl th, .saved-tbl td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: middle; }
.saved-tbl th { color: var(--brand-dark); font-size: .82rem; }
.saved-tbl .muted { color: var(--muted); font-size: .82rem; }
.saved-tbl .acts { white-space: nowrap; text-align: right; }
.btn.sm { padding: 6px 10px; font-size: .82rem; }
body.theme-dark .saved-tbl th, body.theme-dark .saved-tbl td { border-color: #2c3a48; }

/* ---- Theme toggle & dark theme ---- */
.tb-btn.theme { background: #dfe7f1; color: var(--brand-dark); font-size: 1rem; line-height: 1; padding: 6px 10px; }
body.theme-dark {
  --bg: #0f1620; --panel: #16202c; --ink: #e6edf3; --muted: #9fb0c0;
  --line: #27323e; --brand: #3b9eff; --brand-dark: #1f6fc4; --accent: #36c79a;
  --warn: #e8923c; --err: #ff6b5e; --ok: #36c79a;
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 6px 18px rgba(0,0,0,.4);
}
body.theme-dark .field input, body.theme-dark .field select { background: #0f1822; color: #e6edf3; border-color: #2c3a48; }
body.theme-dark .seg { border-color: #2c3a48; }
body.theme-dark .seg button { background: #0f1822; color: #e6edf3; }
body.theme-dark .seg button.active { background: var(--brand); color: #06121f; }
body.theme-dark .btn.ghost { background: #223040; color: #e6edf3; }
body.theme-dark .btn.ghost:hover { background: #2c3d4f; }
body.theme-dark .rec { background: #14241d; border-color: #1f4a38; }
body.theme-dark .rec ul { color: #bfe6d6; }
body.theme-dark .rec h3 { color: var(--accent); }
body.theme-dark .msg.info { background: #10283f; color: #bfe0ff; border-color: #1d4a6e; }
body.theme-dark .disclaimer { background: #2a2410; border-color: #5a4d18; color: #e8dca0; }
body.theme-dark .results .k { color: var(--muted); }

/* ---- Chemical compatibility matrix ---- */
.compat-tbl { border-collapse: collapse; font-size: .82rem; min-width: 720px; }
.compat-tbl th, .compat-tbl td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.compat-tbl thead th { background: #eef3f8; color: var(--brand-dark); position: sticky; top: 0; }
.compat-tbl th.rk { text-align: left; background: #eef3f8; font-weight: 600; white-space: nowrap; }
.compat-tbl td { font-weight: 700; }
.compat-tbl td.cA { background: #d6f0e0; color: #14633f; }
.compat-tbl td.cB { background: #fdf3d6; color: #8a6400; }
.compat-tbl td.cC { background: #fde2dc; color: #a4321f; }
.compat-tbl td.cN { background: #eef1f4; color: #8895a3; }
.compat-legend { margin: 14px 0 4px; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: .85rem; color: var(--ink); }
.compat-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.compat-legend .sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.12); }
.compat-legend .sw.cA { background: #d6f0e0; }
.compat-legend .sw.cB { background: #fdf3d6; }
.compat-legend .sw.cC { background: #fde2dc; }
.compat-legend .sw.cN { background: #eef1f4; }
body.theme-dark .compat-tbl th, body.theme-dark .compat-tbl td { border-color: #2c3a48; }
body.theme-dark .compat-tbl thead th, body.theme-dark .compat-tbl th.rk { background: #1b2735; color: #9fd0ff; }
body.theme-dark .compat-tbl td.cA { background: #123026; color: #6fe0b0; }
body.theme-dark .compat-tbl td.cB { background: #2f2a13; color: #e8d27a; }
body.theme-dark .compat-tbl td.cC { background: #321a16; color: #ff9d8c; }
body.theme-dark .compat-tbl td.cN { background: #1c2630; color: #8fa1b3; }
body.theme-dark .compat-legend .sw.cA { background: #123026; }
body.theme-dark .compat-legend .sw.cB { background: #2f2a13; }
body.theme-dark .compat-legend .sw.cC { background: #321a16; }
body.theme-dark .compat-legend .sw.cN { background: #1c2630; }

/* ---- Print / PDF report ---- */
.print-area { display: none; }
@media print {
  body { background: #fff; color: #000; }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { display: block; position: absolute; left: 0; top: 0; width: 100%; padding: 0 6mm; color: #000; }
  body.theme-dark { --ink:#000; --muted:#333; --line:#999; --panel:#fff; }
  .print-area h1 { font-size: 18pt; margin: 0 0 4pt; color: #06243f; }
  .print-area .p-brand { font-size: 11pt; color: #0b5cab; font-weight: 700; margin-bottom: 10pt; }
  .print-area .p-meta { font-size: 9pt; color: #555; margin-bottom: 12pt; }
  .print-area table { width: 100%; border-collapse: collapse; margin-bottom: 12pt; }
  .print-area th, .print-area td { border: 1px solid #999; padding: 5pt 8pt; text-align: left; font-size: 10pt; }
  .print-area th { background: #eef3f8; }
  .print-area .p-sec { font-size: 12pt; font-weight: 700; margin: 12pt 0 4pt; color: #06243f; }
  .print-area .p-rec li { font-size: 9.5pt; }
  /* Compact groove dimension reference table (7 columns) */
  .print-area table.p-ref { font-size: 7.5pt; margin-bottom: 10pt; }
  .print-area table.p-ref th, .print-area table.p-ref td { padding: 3pt 4pt; text-align: right; }
  .print-area table.p-ref th { background: #eef3f8; text-align: center; font-weight: 600; }
  .print-area table.p-ref td:first-child { text-align: center; font-weight: 600; }
  .print-area ul { margin: 4pt 0; padding-left: 16pt; }
  .print-area ul li { font-size: 9.5pt; }
  .print-area .p-disc { font-size: 8pt; color: #555; border-top: 1px solid #999; margin-top: 14pt; padding-top: 6pt; }
  .print-area .p-err { color: #b00; font-size: 9.5pt; }
  .print-area .p-ok { color: #080; font-size: 9.5pt; }
}

/* ---- Precision selector (units row) ---- */
.prec-wrap { display: flex; flex-direction: column; gap: 3px; }
.prec-wrap select { width: 64px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font-size: .85rem; }
body.theme-dark .prec-wrap select { background: #1b2735; color: #e6edf5; border-color: #2c3e50; }

/* ---- Candidate chips (quick search) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-block; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; color: var(--muted); background: var(--panel); }
.chip-on { border-color: var(--brand); color: var(--brand); font-weight: 700; background: #eef5fc; }
body.theme-dark .chip { background: #1b2735; color: #9fb0c0; border-color: #2c3e50; }
body.theme-dark .chip-on { background: #16314d; color: #8ec5ff; border-color: #2f6fb0; }

/* ---- Comparison table ---- */
.cmp-tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.cmp-tbl th, .cmp-tbl td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.cmp-tbl th { background: var(--brand); color: #fff; }
.cmp-tbl td.lbl { font-weight: 600; color: var(--ink); background: #f7f9fc; white-space: nowrap; }
body.theme-dark .cmp-tbl th { background: #16314d; }
body.theme-dark .cmp-tbl td.lbl { background: #15212e; color: #cfe0f0; }

/* ---- Report header / signature (print + meta) ---- */
.p-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.p-logo { max-height: 42px; }
.p-brand { font-weight: 700; font-size: 1.1rem; }
.p-company { color: var(--muted); font-size: .9rem; }
.p-sign { display: flex; align-items: flex-end; gap: 10px; margin: 22pt 0 8pt; font-size: 9.5pt; }
.p-sign-line { flex: 1; border-bottom: 1px solid #888; height: 1px; }
.p-notes { font-size: 9.5pt; color: #333; white-space: pre-wrap; }

/* ---- Report meta config (collapsible) ---- */
.rep-meta { margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fafcfe; }
.rep-meta summary { cursor: pointer; font-weight: 600; color: var(--brand); font-size: .9rem; }
.rm-row { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.rm-row label { font-size: .8rem; color: var(--muted); }
.rm-row input, .rm-row textarea { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; width: 100%; box-sizing: border-box; }
body.theme-dark .rep-meta { background: #15212e; border-color: #2c3e50; }
body.theme-dark .rm-row input, body.theme-dark .rm-row textarea { background: #1b2735; color: #e6edf5; border-color: #2c3e50; }


