:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #5b6675;
  --line: #e2e8f0;
  --brand: #1f3a5f;
  --brand2: #aec6e0;
  --accent: #2f7ff0;
  --accent2: #e8553a;
  --chip: #eef3f9;
  --ok: #1a7f37;
  --bad: #c2142a;
  --shadow: 0 1px 3px rgba(15, 30, 55, 0.08), 0 6px 18px rgba(15, 30, 55, 0.06);
}

/* Dark theme (parity with reference; applied via [data-theme="dark"]) */
[data-theme="dark"] {
  --bg: #0f1620;
  --panel: #16202c;
  --ink: #e6edf5;
  --muted: #93a2b5;
  --line: #283545;
  --brand: #4a7bb5;
  --brand2: #6f93ba;
  --accent: #4f9bff;
  --accent2: #ff7a5c;
  --chip: #1e2a3a;
  --ok: #4ccb6e;
  --bad: #ff6b7d;
}
[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
[data-theme="dark"] .sidebar { background: var(--panel); border-right-color: var(--line); }
[data-theme="dark"] .sidebar .nav-mod.active { background: var(--brand); color: #fff; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #0f1822; color: var(--ink); border-color: var(--line);
}
[data-theme="dark"] input:focus, [data-theme="dark"] select:focus { outline-color: var(--accent); border-color: var(--accent); }
[data-theme="dark"] .result, [data-theme="dark"] .rc-out, [data-theme="dark"] .mawp-tbl, [data-theme="dark"] .lc-tbl { background: var(--panel); }
[data-theme="dark"] .foot { background: var(--panel); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  font-size: 13px; line-height: 1.5;
  display: flex; flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 18px;
  background: linear-gradient(90deg, var(--brand), #2c5282);
  color: #fff; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand-cn { font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand-en { font-size: 12px; color: var(--brand2); opacity: .9; }
.brand-en small { opacity: .8; }
.top-ctrls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.top-sel, .top-btn {
  border: 1px solid rgba(255, 255, 255, .5); background: transparent; color: #fff;
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.top-sel { padding: 5px 8px; }
.top-btn:hover, .top-sel:hover { background: #fff; color: var(--brand); }
.top-btn.primary { background: #fff; color: var(--brand); font-weight: 700; }
.lang-btns { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.lang-btn {
  border: 1px solid rgba(255, 255, 255, .5); background: transparent; color: #fff;
  padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: 11px; line-height: 1.3;
  white-space: nowrap;
}
.lang-btn:hover { background: #fff; color: var(--brand); }
.lang-btn.active { background: #fff; color: var(--brand); font-weight: 700; }

.unit-btns { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.unit-btn {
  border: 1px solid rgba(255, 255, 255, .5); background: transparent; color: #fff;
  padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: 11px; line-height: 1.3;
  white-space: nowrap;
}
.unit-btn:hover { background: #fff; color: var(--brand); }
.unit-btn.active { background: #fff; color: var(--brand); font-weight: 700; }

/* ---------- layout: sidebar + panel ---------- */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 252px; flex: 0 0 252px; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 8px 6px;
}
.sidebar .grp {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 12px 8px 4px; font-weight: 700;
}
.sidebar .nav-mod {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--ink); padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.sidebar .nav-mod:hover { background: var(--chip); }
.sidebar .nav-mod.active { background: var(--brand); color: #fff; font-weight: 600; }
.panel { flex: 1; overflow-y: auto; padding: 18px 26px 40px; min-width: 0; }

.mod { display: none; }
.mod.active { display: block; }
.mod h2 { font-size: 20px; margin: 0 0 4px; color: var(--ink); }
.mod .desc { color: var(--muted); margin: 6px 0 16px; max-width: 820px; line-height: 1.55; }

/* ---------- input grid & fields ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 10px 18px; margin-bottom: 16px;
}
label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
label > span:first-child { font-weight: 500; color: var(--ink); }
input, select, textarea {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  background: #fbfdff; color: var(--ink); width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.uom { font-size: 11px; color: var(--muted); margin-top: -2px; }
label.chk { flex-direction: row; align-items: center; gap: 8px; }
label.chk input { width: auto; }
label.chk > span { font-weight: 500; color: var(--ink); }

/* ---------- actions / buttons ---------- */
.actions { display: flex; gap: 10px; margin: 8px 0 16px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 6px; padding: 9px 20px; cursor: pointer;
  font-size: 13px; font-weight: 600; background: var(--chip); color: var(--ink);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #16305a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- result card ---------- */
.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.result:empty { display: none; }
.result h3 { margin: 0 0 10px; font-size: 15px; }
.res-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px;
}
.res-row .k { color: var(--muted); }
.res-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.res-row .v small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.verdict { font-size: 16px; font-weight: 700; margin: 6px 0 12px; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.formula {
  margin-top: 12px; background: var(--chip); border: 1px solid var(--line);
  border-left: 3px solid var(--brand); border-radius: 8px; padding: 10px 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12.5px; color: var(--ink); white-space: pre-wrap; word-break: break-word;
}
.note {
  margin-top: 10px; font-size: 12px; color: var(--muted);
  border-left: 3px solid var(--line); padding-left: 10px; line-height: 1.5;
}
.subhead { font-weight: 600; color: var(--muted); margin: 12px 0 4px; font-size: 13px; }

/* ---------- tables ---------- */
.rc-out, .mawp-tbl, .lc-tbl, .lc-out {
  width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 13px;
}
.rc-out th, .rc-out td,
.mawp-tbl th, .mawp-tbl td,
.lc-tbl th, .lc-tbl td,
.lc-out th, .lc-out td { border: 1px solid var(--line); padding: 5px 8px; text-align: center; }
.rc-out th, .mawp-tbl th, .lc-tbl th, .lc-out th {
  color: var(--muted); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: .03em; background: var(--chip);
}
.rc-out td:first-child, .mawp-tbl td:first-child, .lc-tbl td:first-child, .lc-out td:first-child {
  text-align: left; font-weight: 600;
}
.rc-out tr.bad td, .lc-out tr.bad td { color: var(--bad); }
.rc-out tr.bad, .lc-out tr.bad { background: #fff6f6; }
.rc-out tr.best td { background: #fff7e6; }
.lc-tbl .lc-name, .lc-tbl .lc-cat, .lc-tbl input { width: 100%; box-sizing: border-box; }
.lc-tbl input { width: 78px; }
.lc-tbl .lc-cat { min-width: 120px; }
.mawp-tbl .mawp-name { width: 100%; }
.mawp-tbl .mawp-val { width: 130px; }

/* ---------- dynamic nozzle / wc rows ---------- */
.mo-rows { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 14px; }
.mo-row {
  display: grid; grid-template-columns: 32px repeat(7, minmax(96px, 1fr)) 32px;
  align-items: end; gap: 8px 10px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.mo-row .mo-idx { font-weight: 600; color: var(--muted); align-self: center; text-align: center; }
.wc-rows { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 8px; }
.wc-row { display: grid; grid-template-columns: 1fr 1fr 1fr 34px; gap: 8px; align-items: center; }
.wc-row input { width: 100%; }
.btn-mini {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--bad); font-size: 18px; line-height: 1; cursor: pointer; align-self: end;
}
.btn-mini:hover { background: #fff0f1; }

/* ---------- FEA checklist ---------- */
.fe-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 8px 0 14px; }
.fe-item { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.35; cursor: pointer; }
.fe-item input { margin-top: 2px; flex: none; width: auto; }

/* ---------- footer ---------- */
.foot {
  padding: 14px 24px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--panel);
}

/* ---------- responsive ---------- */
@media (max-width: 880px) {
  .sidebar { width: 200px; flex-basis: 200px; }
}
@media (max-width: 680px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-basis: auto; max-height: 200px; border-right: 0; border-bottom: 1px solid var(--line); }
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .mo-row { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .mo-row .mo-idx, .mo-row .btn-mini { grid-column: span 1; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .sidebar, .actions, .desc { display: none !important; }
  body { background: #fff; display: block; }
  .layout { display: block; }
  .panel { overflow: visible; padding: 0; }
  .mod { display: block !important; }
  .result { box-shadow: none; border: 1px solid #999; }
  body.printing-summary .topbar,
  body.printing-summary .sidebar,
  body.printing-summary .layout { display: none !important; }
  body.printing-summary #print-root { display: block !important; }
}

/* ---------- top bar extras ---------- */
.top-link { text-decoration: none; }
.top-sep { width: 1px; height: 22px; background: rgba(255,255,255,.4); margin: 0 2px; }
.top-break { flex-basis: 100%; height: 0; }
.side-search {
  width: 100%; margin: 4px 0 8px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
  background: #fbfdff; color: var(--ink);
}
.sidebar .grp.hidden, .sidebar .nav-mod.hidden { display: none; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 22, 32, .55);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; z-index: 1000; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  display: none; width: min(760px, 96vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
  color: var(--ink); max-height: 86vh; flex-direction: column;
}
.modal.open { display: flex; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  font-size: 15px; font-weight: 700;
}
.modal-x {
  border: 0; background: transparent; color: var(--muted); font-size: 22px;
  line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-x:hover { color: var(--bad); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); text-align: right; }
.ta { width: 100%; min-height: 110px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
.muted { color: var(--muted); font-size: 12px; margin: 0 0 10px; }

/* unit converter */
.uc-row { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 10px; align-items: end; margin-bottom: 12px; }
.uc-row .uc-lab { font-weight: 600; align-self: center; }
.uc-col { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.uc-sub { font-size: 12px; color: var(--muted); margin: 4px 0 14px; }

/* history / clause tables */
.tbl-mini { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl-mini th, .tbl-mini td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.tbl-mini th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.hist-item { cursor: pointer; }
.hist-item:hover { background: var(--chip); }
.tag-ok { color: var(--ok); font-weight: 600; }
.tag-bad { color: var(--bad); font-weight: 600; }

/* sweep chart */
.sweep-svg { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.sweep-axis { stroke: #aab; stroke-width: 1; }
.sweep-line { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.sweep-dot { fill: var(--accent); }
.sweep-lbl { fill: var(--muted); font-size: 11px; }

/* sketch */
.sketch-svg { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.sk-pipe { stroke: #2c5282; stroke-width: 3; fill: none; }
.sk-dim { stroke: #e8553a; stroke-width: 1; }
.sk-txt { fill: #33415c; font-size: 11px; }
.sk-noz { stroke: #33415c; stroke-width: 2; }

/* dark overrides */
[data-theme="dark"] .modal { background: var(--panel); color: var(--ink); }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.6); }
[data-theme="dark"] .sweep-svg, [data-theme="dark"] .sketch-svg { background: #0f1822; }
[data-theme="dark"] .sweep-lbl, [data-theme="dark"] .sk-txt { fill: #cdd7e3; }
[data-theme="dark"] .side-search { background: #0f1822; }

/* B16.5 card + charts */
.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-top: 16px; background: #fff; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: #1f3a5f; }
.chart-wrap { margin-top: 12px; }
.chart-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chart-legend { font-size: 11px; color: var(--muted); margin-top: 4px; }
[data-theme="dark"] .card { background: var(--panel); border-color: #2c3a4d; }
[data-theme="dark"] .card h3 { color: #cfe0f0; }

