:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b2330;
  --muted: #5b6676;
  --line: #d9dee6;
  --accent: #0b5cad;
  --accent-ink: #ffffff;
  --accent-bg: #e8f1fb;
  --pass: #1a7f37;
  --pass-bg: #e6f4ea;
  --fail: #b42318;
  --fail-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --info: #3b5b86;
  --info-bg: #e8eff9;
  --s1: #0b5cad;   /* chart series */
  --s2: #c2410c;
  --s3: #1b2330;
  --band: rgba(11, 92, 173, 0.10);
  --cold: #2563eb;  /* temperature cases in charts */
  --hot: #c2410c;
  --band-ok: rgba(26, 127, 55, 0.13);
  --band-neutral: rgba(91, 102, 118, 0.08);
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --panel: #1a2029; --ink: #e6e9ee; --muted: #9aa5b4; --line: #2e3744;
    --accent: #5aa2f0; --accent-ink: #0b1220; --accent-bg: #172536;
    --pass: #56c271; --pass-bg: #16301f; --fail: #ff7b72; --fail-bg: #3a1a19;
    --warn: #e3b341; --warn-bg: #362b10; --info: #8fb4e8; --info-bg: #19263a;
    --s1: #5aa2f0; --s2: #f08a4b; --s3: #e6e9ee; --band: rgba(90, 162, 240, 0.14);
    --cold: #7fb2ff; --hot: #f08a4b; --band-ok: rgba(86, 194, 113, 0.16); --band-neutral: rgba(154, 165, 180, 0.10);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; align-items: baseline; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { margin: 0; font-size: 18px; }
header .sub { color: var(--muted); font-size: 13px; }
nav { display: flex; gap: 4px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 0; z-index: 5; }
nav button { border: 0; background: none; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
nav button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
main { padding: 16px 20px 60px; max-width: 1400px; margin: 0 auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; scroll-margin-top: 56px; }
.card h2 { margin: 0 0 10px; font-size: 15px; }
.card h3 { margin: 16px 0 8px; font-size: 14px; }
.card > .lead { margin: -4px 0 10px; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.field .unit { color: var(--muted); font-size: 11px; }
.help { display: inline-block; margin-left: 4px; color: var(--accent); cursor: help; font-style: normal; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; min-width: 0; }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); border-style: dashed; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 16px; height: 16px; }
.missing { border-color: var(--warn) !important; background: var(--warn-bg) !important; }
.invalid { border-color: var(--fail) !important; background: var(--fail-bg) !important; }
button.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.btn.small { padding: 3px 9px; font-size: 12px; }
button.btn:disabled { opacity: 0.6; cursor: progress; }
button.icon { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; }

details { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 10px; }
details > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
details.plain { border: 0; margin: 0; padding: 0; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.edit td { padding: 3px 4px; }
table.edit th { white-space: normal; min-width: 70px; }
table.edit input:not([type=checkbox]), table.edit select { width: 100%; min-width: 70px; }
table.edit td.name input { min-width: 150px; }
table.edit td.type select { min-width: 140px; }
.toolbar .intro { flex: 1 1 320px; }
table.edit td.center { text-align: center; }
tr.total td { font-weight: 600; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.badge.pass, .badge.complete, .badge.computed { color: var(--pass); background: var(--pass-bg); }
.badge.fail { color: var(--fail); background: var(--fail-bg); }
.badge.warn, .badge.needed, .badge.stale { color: var(--warn); background: var(--warn-bg); }
.badge.info, .badge.optional { color: var(--info); background: var(--info-bg); }
.badge.unused, .badge.pending { color: var(--muted); background: var(--bg); border: 1px solid var(--line); }

.alert { border-radius: 6px; padding: 8px 12px; margin: 6px 0; font-size: 13px; }
.alert.warn { background: var(--warn-bg); border-left: 3px solid var(--warn); }
.alert.fail { background: var(--fail-bg); border-left: 3px solid var(--fail); }
.alert.info { background: var(--info-bg); border-left: 3px solid var(--info); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert a { color: inherit; }
.formula { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.rationale { background: var(--info-bg); border-radius: 6px; padding: 8px 12px; margin: 8px 0; }
.sentence { font-size: 14px; margin: 4px 0 10px; }

/* ---------- workflow map (live, compact) */
.wf { display: flex; gap: 6px; align-items: stretch; overflow-x: auto; padding-bottom: 4px; }
.wf-step { flex: 1 1 112px; border: 1px solid var(--line); border-top: 4px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--panel); cursor: pointer; font-size: 12px; min-width: 112px; }
.wf-step:hover { background: var(--accent-bg); }
.wf-step .n { color: var(--muted); font-weight: 700; }
.wf-step .t { font-weight: 600; font-size: 12.5px; }
.wf-step .e { color: var(--muted); font-size: 11px; margin: 2px 0 4px; }
.wf-step.complete, .wf-step.computed { border-top-color: var(--pass); }
.wf-step.needed, .wf-step.stale { border-top-color: var(--warn); }
.wf-step.optional { border-top-color: var(--info); }
.wf-step.unused, .wf-step.pending { opacity: .65; }
.wf-step.result { background: var(--bg); }
.wf-arrow { align-self: center; color: var(--muted); flex: 0 0 auto; }

.stage.unused .stage-body { display: none; }
.stage.unused { opacity: .8; }

/* ---------- stepper (step-by-step calculator) */
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; position: sticky; top: 41px; z-index: 4; background: var(--bg); padding: 6px 0; }
.step { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; text-align: left; flex: 1 1 130px; min-width: 130px;
        border: 1px solid var(--line); border-left: 4px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 10px;
        cursor: pointer; font: inherit; color: var(--ink); }
.step .n { grid-row: span 2; font-weight: 800; color: var(--muted); font-size: 16px; }
.step .t { font-weight: 600; font-size: 13px; }
.step .e { font-size: 11px; color: var(--muted); }
.step:hover { background: var(--accent-bg); }
.step.active { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--accent-bg); }
.step.complete, .step.computed { border-left-color: var(--pass); }
.step.needed, .step.stale { border-left-color: var(--warn); }
.step.needed .e, .step.stale .e { color: var(--warn); font-weight: 600; }
.step.optional { border-left-color: var(--info); }
.step.unused, .step.pending { opacity: .6; }
.toolbar.nav { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.recommend { background: var(--pass-bg); border-left: 3px solid var(--pass); border-radius: 6px; padding: 8px 12px; margin: 6px 0 10px; font-size: 13px; }
tr.recommended td { background: var(--pass-bg); }
tr.recommended td:first-child { font-weight: 700; }

/* ---------- workflow diagram (documentation) */
.flow { display: flex; flex-direction: column; gap: 0; }
.flow-node { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.flow-node.result { border-color: var(--accent); }
.flow-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.flow-node.result .flow-head { background: var(--accent-bg); }
.flow-head .n { font-weight: 800; color: var(--accent); }
.flow-head .t { font-weight: 700; }
.flow-head .e { color: var(--muted); font-size: 12px; }
.flow-body { display: grid; grid-template-columns: 1fr 24px 1fr 24px 1fr; gap: 0; padding: 8px 12px; font-size: 12.5px; }
.flow-body .col h4 { margin: 0 0 3px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.flow-body .to { align-self: center; text-align: center; color: var(--muted); }
.flow-link { text-align: center; color: var(--muted); line-height: 1; padding: 3px 0; font-size: 16px; }
.flow-side { border: 1px dashed var(--accent); border-radius: 8px; padding: 8px 12px; margin: 6px 0; font-size: 12.5px; background: var(--accent-bg); }
@media (max-width: 760px) {
  .flow-body { grid-template-columns: 1fr; }
  .flow-body .to { transform: rotate(90deg); }
}

/* ---------- report */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.report-head { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 16px; font-size: 12.5px; margin-bottom: 10px; }
.report-head div span { color: var(--muted); display: block; font-size: 11px; }
.report-sheet h3 { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.report-sheet h3:first-of-type { margin-top: 8px; border-top: 0; padding-top: 0; }
.report-sheet h4 { margin: 12px 0 4px; font-size: 12.5px; color: var(--ink); }
.sheet-wrap { margin-bottom: 8px; }
.sheet-table { font-size: 12px; }
.sheet-table th { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.sheet-table td { border: 1px solid var(--line); }
.sheet-table tr.total td { font-weight: 700; background: var(--accent-bg); }
.sheet-table tr.recommended td { background: var(--pass-bg); }
.sheet-table tr.warn td { background: var(--warn-bg); }
.sheet-table tr.fail td { background: var(--fail-bg); }
.sheet-input { background: #fff4b8; color: #1b2330; }
.sheet-calc { background: #dff0ff; color: #1b2330; }
.sheet-output { background: #dff3dc; color: #1b2330; font-weight: 700; }
.sheet-pass { background: var(--pass-bg); color: var(--ink); }

/* ---------- interactive charts (viz.js) */
.viz { position: relative; max-width: 900px; }
.viz-svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.viz-svg text { fill: var(--muted); font-size: 11px; }
.viz-svg .viz-axis-label { fill: var(--ink); font-size: 12px; }
.viz-svg .viz-label { font-size: 11px; }
.viz-svg .viz-label.strong { font-weight: 600; }
.viz-grid line { stroke: var(--line); stroke-dasharray: 2 3; }
.viz-frame { fill: none; stroke: var(--line); }
.viz-cross { stroke: var(--muted); stroke-dasharray: 3 3; pointer-events: none; }
.viz-pin { stroke: var(--accent); stroke-width: 1.5; pointer-events: none; }
.viz-dot, .viz-marker { stroke: var(--panel); stroke-width: 1.5; pointer-events: none; }
.viz-hit { cursor: crosshair; }
.viz-hit.pick { cursor: pointer; }
.viz-row-bg { fill: var(--accent-bg); }
.viz-svg .viz-row-label.strong { fill: var(--ink); font-weight: 600; }
.viz-tip { position: absolute; z-index: 3; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
           box-shadow: 0 4px 14px rgba(0, 0, 0, .14); padding: 6px 9px; font-size: 12px; min-width: 170px; max-width: 340px; }
.viz-tip .h { font-weight: 600; margin-bottom: 3px; }
.viz-tip .h.mark { color: var(--accent); white-space: normal; }
.viz-tip .r { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.viz-tip .r b { margin-left: auto; padding-left: 10px; font-variant-numeric: tabular-nums; font-weight: 600; }
.viz-tip .note { color: var(--muted); margin-top: 4px; font-size: 11px; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 4px; }
.viz-key { font: inherit; font-size: 12px; color: var(--ink); background: none; border: 1px solid transparent; border-radius: 4px; padding: 1px 6px;
           cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.viz-key:hover { border-color: var(--line); }
.viz-key.off { opacity: .45; text-decoration: line-through; }
.viz-key.static { cursor: default; color: var(--muted); }
.viz-key.static:hover { border-color: transparent; }
.viz-notes { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 12px; margin: 2px 0 0 6px; }
.viz-swatch { display: inline-block; width: 20px; height: 0; border-top: 2px solid; }
.viz-swatch.band { height: 10px; border: 0; border-radius: 2px; opacity: .8; }
.viz-swatch.marker { width: 9px; height: 9px; border: 0; border-radius: 50%; }

/* ---------- visual analysis card */
.viz-controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; vertical-align: middle; }
.seg button { font: inherit; font-size: 12.5px; border: 0; border-right: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 10px; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.viz-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.viz-tabs button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--muted); padding: 7px 11px; cursor: pointer; border-bottom: 2px solid transparent; }
.viz-tabs button:hover { color: var(--ink); }
.viz-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.viz-panel.off { display: none; }
.viz-panel h4 { margin: 12px 0 4px; font-size: 13px; }
.viz-panel .how { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; max-width: 900px; }
.viz-panel .table-wrap { max-width: 900px; margin-top: 8px; }
.viz-readout { background: var(--accent-bg); border-radius: 6px; padding: 7px 11px; margin: 8px 0 0; font-size: 13px; max-width: 900px; }
.viz-readout .ok { color: var(--pass); font-weight: 600; }
.viz-readout .bad, .viz-panel .bad { color: var(--fail); font-weight: 600; }
.viz-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 6px 18px; }
.viz-pair .viz { max-width: none; }
.print-viz-circuit { break-inside: auto; }
.print-viz-circuit > h3 { margin-top: 4px; }
.print-viz-panel { break-inside: avoid; margin: 10px 0 14px; }
.print-viz-panel > h4 { margin: 0 0 4px; font-size: 13px; }

/* ---------- documentation */
.docs { display: grid; grid-template-columns: 210px 1fr; gap: 16px; align-items: start; }
.toc { position: sticky; top: 56px; display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 13px; }
.toc a { color: var(--accent); text-decoration: none; }
.docs article { min-width: 0; }
table.eq th { width: 210px; color: var(--ink); font-size: 13px; }
ol.steps li, ol.refs li { margin-bottom: 6px; }
dl.glossary { display: grid; grid-template-columns: 220px 1fr; gap: 6px 14px; margin: 0; }
dl.glossary dt { font-weight: 600; }
dl.glossary dd { margin: 0; }
@media (max-width: 860px) { .docs { grid-template-columns: 1fr; } .toc { position: static; } dl.glossary { grid-template-columns: 1fr; } }

.hidden { display: none !important; }
.spinner { color: var(--muted); }
.print-only { display: none; }

@media print {
  nav, .toolbar, .stepper, .wf-wrap, .no-print, button { display: none !important; }
  .stage:not([data-step="results"]) { display: none !important; }
  .print-only { display: block; }
  .viz-screen { display: none !important; }
  body.print-summary .report-full-only { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .card { break-inside: avoid; border-color: #bbb; }
  .report-sheet { break-inside: auto; }
  .report-sheet .sheet-circuit { break-inside: auto; }
  .report-sheet h3, .report-sheet h4 { break-after: avoid; }
  .sheet-table th, .sheet-table td { padding: 3px 5px; }
  .report-visuals { break-inside: auto; }
  [data-viz] { break-inside: auto; }
  .viz-panel.off { display: block !important; }
  .viz-panel.no-print { display: none !important; }  /* same specificity as the line above, later: wins (un-run sensitivity) */
  .viz-panel { break-inside: avoid; }
  .print-viz-panel { break-inside: avoid; page-break-inside: avoid; }
  .print-viz-panel .how, .print-viz-panel .viz-readout { font-size: 11.5px; }
  .viz-tip, .viz-cross, .viz-pin { display: none !important; }
  .viz-legend .viz-key { display: inline-flex !important; }  /* legend entries are buttons on screen */
}
