:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #1b2430; --muted: #5d6b7c; --line: #d9e0e8;
  --accent: #1f5fbf; --accent-ink: #ffffff; --accent-soft: #e6effc;
  --ok: #17803d; --warn-bg: #fff4d6; --warn-ink: #7a5200; --bad-bg: #fde4e4; --bad-ink: #9b1c1c;
  --field: #ffffff; --calc: #f0f4f9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171e; --card: #1b222c; --ink: #e6ebf2; --muted: #98a6b8; --line: #303b49;
    --accent: #6aa3f5; --accent-ink: #0d1520; --accent-soft: #22324a;
    --ok: #55c27f; --warn-bg: #3b3115; --warn-ink: #f1cf7a; --bad-bg: #432024; --bad-ink: #f4a3a3;
    --field: #141a22; --calc: #212a36;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 20px 6px; max-width: 1280px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; gap: 8px; }
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.small { padding: 3px 9px; font-size: 12.5px; }
button.x { padding: 1px 8px; color: var(--muted); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 0 20px; max-width: 1280px; margin: 8px auto 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: transparent; padding: 8px 14px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.tabs button small { font-size: 11px; opacity: .85; }
.tabs button.on { background: var(--card); border-color: var(--line); color: var(--ink); font-weight: 600; margin-bottom: -1px; }

main { max-width: 1280px; margin: 0 auto; padding: 16px 20px 60px; }
[hidden] { display: none !important; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }
.result { position: sticky; top: 12px; }
@media (max-width: 1000px) { .result { position: static; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 13px; margin: 16px 0 6px; padding-top: 10px; border-top: 1px dashed var(--line); color: var(--ink); }
.card h3:first-of-type { border-top: 0; padding-top: 0; margin-top: 4px; }
.n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 12px; }
.grid.w2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.f { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.f > span i { font-style: normal; color: var(--muted); opacity: .85; }
.f input, .f select, .f textarea { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; width: 100%; }
.f input:focus, .f select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.f.span2 { grid-column: span 2; }
.out { background: var(--calc); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-height: 31px; color: var(--ink); font-variant-numeric: tabular-nums; display: flex; align-items: center; }
.out.strong { font-weight: 700; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.sub-grp { margin-top: 6px; }

.msgs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.msg { border-radius: 8px; padding: 7px 10px; font-size: 12.5px; background: var(--warn-bg); color: var(--warn-ink); }
.msg.bad { background: var(--bad-bg); color: var(--bad-ink); }
.msg.info { background: var(--accent-soft); color: var(--ink); }

table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th, table.t td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.t td.r, table.t th.r { text-align: right; }
table.t input { font: inherit; width: 100%; min-width: 70px; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }
table.res td:first-child { width: 42%; }
table.res td:nth-child(2) { text-align: right; white-space: nowrap; }
table.res td:nth-child(3) { color: var(--muted); font-size: 11.5px; }
table.res tr.sec td { padding-top: 12px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; border-bottom: 0; }
table.res tr.big td { font-size: 17px; font-weight: 700; background: var(--accent-soft); border-bottom: 0; }
table.res tr.big td:nth-child(2) { color: var(--accent); }
.datatbl { overflow: auto; max-height: 360px; border: 1px solid var(--line); border-radius: 8px; }
.datatbl table th { position: sticky; top: 0; background: var(--card); }

svg.chart { width: 100%; height: auto; display: block; margin-top: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
svg.chart text { fill: var(--muted); font: 11px system-ui, sans-serif; }
svg.chart .ax { stroke: var(--line); }
svg.chart .ln { stroke: var(--accent); stroke-width: 1.6; fill: none; }
svg.chart .ex { stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: 5 4; fill: none; opacity: .8; }
svg.chart .pt { fill: var(--ink); }
svg.chart .zero { fill: none; stroke: var(--bad-ink); stroke-width: 1.6; }
details { margin: 8px 0; }
summary { cursor: pointer; font-weight: 600; }
.notes p, .notes li { max-width: 80ch; }
.notes code { background: var(--calc); padding: 1px 5px; border-radius: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }

@media print {
  body { background: #fff; color: #000; }
  .top-actions, .tabs, button, .row, .noprint { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .result { position: static; }
  .card { break-inside: avoid; border-color: #999; }
  .panel[hidden] { display: none !important; }
  input, select { border: 0 !important; background: transparent !important; padding: 0 !important; appearance: none; }
}

/* section 4 distance grid: narrow "effective distance", wide "chamber distance beyond reference plane" */
.grid.isq4 { grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.7fr) minmax(0, 1fr); }
.f.span-all { grid-column: 1 / -1; }
@media (max-width: 700px) { .grid.isq4 { grid-template-columns: 1fr 1fr; } }
table.t input[readonly] { background: var(--calc); }
table.t tr.pick { cursor: pointer; }
table.t tr.pick:hover td { background: var(--accent-soft); }
table.t tr.sel td { background: var(--accent-soft); font-weight: 600; }

/* estimated HVL (from the HVL estimation tab): tinted field + label */
:root { --est: #e0f3ea; --est-ink: #0f5a3a; --c-linear: #c2410c; --c-loglin: #1f6feb; --c-spline: #15803d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --est: #17382c; --est-ink: #7fdcab; --c-linear: #fb923c; --c-loglin: #5b9dff; --c-spline: #4ade80; } }
.f input.est, .out.est { background: var(--est); border-color: var(--est-ink); }
.f > span i.estl { color: var(--est-ink); font-weight: 700; opacity: 1; background: var(--est); border-radius: 8px; padding: 0 6px; }
.tabs button:disabled { opacity: .4; cursor: not-allowed; }
.tabs button:disabled:hover { border-color: transparent; }
table.t select { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 5px; padding: 4px 4px; max-width: 100%; }
table.t input[type="checkbox"] { min-width: 0; width: auto; }
table.t input:disabled { background: var(--calc); }

/* HVL estimation tab */
.hv-layout { display: grid; gap: 16px; align-items: start; grid-template-columns: minmax(270px, 310px) minmax(0, 1fr) minmax(330px, 380px); }
@media (max-width: 1180px) { .hv-layout { grid-template-columns: minmax(270px, 320px) minmax(0, 1fr); } .hv-layout > :nth-child(3) { grid-column: 1 / -1; } }
@media (max-width: 760px) { .hv-layout { grid-template-columns: minmax(0, 1fr); } }
.hv-layout .card { margin-bottom: 0; min-width: 0; }
.hv-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.hv-head h2 { margin: 0; }
.hv-drop { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; padding: 12px; margin: 10px 0 4px; border: 1.5px dashed var(--line); border-radius: 10px; cursor: pointer; color: var(--muted); font-size: 13px; position: relative; }
.hv-drop b { color: var(--accent); }
.hv-drop small { font-size: 11.5px; }
.hv-drop.over, .hv-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.hv-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
#hv_file_status:empty { display: none; }
.hv-entry { width: 100%; border-collapse: collapse; margin: 4px 0 8px; }
.hv-entry th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; padding: 0 4px 4px; }
.hv-entry td { padding: 2px 3px; }
.hv-entry input { width: 100%; font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.hv-entry input.invalid { border-color: var(--bad-ink); background: var(--bad-bg); }
.hv-entry .idx { color: var(--muted); font-size: 12px; text-align: right; width: 1.6em; }
.hv-entry .del { width: 26px; height: 26px; border: none; background: transparent; color: var(--muted); padding: 0; }
.hv-entry .del:hover { background: var(--bad-bg); color: var(--bad-ink); }
.hv-i0 { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px 10px; margin: 10px 0 0; }
.hv-i0 legend { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.hv-radio { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.hv-radio input[type="text"] { flex: 1; font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; min-width: 0; }
.hv-radio input:disabled { background: var(--calc); }
.hv-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hv-seg button { border: 0; border-radius: 0; padding: 4px 12px; }
.hv-seg button + button { border-left: 1px solid var(--line); }
.hv-seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.hv-chart { position: relative; width: 100%; }
.hv-chart svg { display: block; width: 100%; height: auto; font-size: 12px; }
.hv-chart .grid line { stroke: var(--line); }
.hv-chart .frame { fill: none; stroke: var(--line); }
.hv-chart .tick, .hv-chart .axis, .hv-chart .empty, .hv-chart .ref-label { fill: var(--muted); font-size: 11.5px; }
.hv-chart .axis { font-size: 12.5px; }
.hv-chart .ref { stroke: var(--muted); stroke-dasharray: 5 4; opacity: .7; }
.hv-chart .curve { fill: none; stroke-width: 2; }
.hv-chart .err { stroke: var(--ink); stroke-width: 1.2; opacity: .55; }
.hv-chart .pt { fill: var(--ink); stroke: var(--card); stroke-width: 1.5; }
.hv-chart .marker { fill: var(--card); stroke-width: 2.2; }
.hv-chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; pointer-events: none; }
.hv-chart .hit { fill: transparent; cursor: crosshair; }
.curve.s-linear, .marker.s-linear { stroke: var(--c-linear); }
.curve.s-loglin, .marker.s-loglin { stroke: var(--c-loglin); }
.curve.s-spline, .marker.s-spline { stroke: var(--c-spline); }
.hv-tip { position: absolute; pointer-events: none; z-index: 2; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 14px rgb(0 0 0 / .12); font-variant-numeric: tabular-nums; }
.hv-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 6px; font-size: 13px; }
.hv-legend label, .hv-legend .key { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.hv-legend .key { cursor: default; color: var(--muted); }
.hv-legend .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.hv-sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.hv-legend .hv-sw { margin-right: 0; }
.hv-sw.s-linear { background: var(--c-linear); } .hv-sw.s-loglin { background: var(--c-loglin); } .hv-sw.s-spline { background: var(--c-spline); }
.hv-eval { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.hv-eval th, .hv-eval td { padding: 6px 5px; border-bottom: 1px solid var(--line); text-align: right; font-size: 13px; }
.hv-eval th:first-child, .hv-eval tbody th { text-align: left; font-weight: normal; white-space: normal; }
.hv-eval thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
.hv-results td { font-weight: 600; }
.hv-results tr.avg-row th, .hv-results tr.avg-row td { border-top: 2px solid var(--line); }
.hv-results tr.avg-row th { font-weight: 600; }
.hv-results tr.cv-row th, .hv-results tr.cv-row td, .hv-results tr.spread th, .hv-results tr.spread td { color: var(--muted); font-weight: normal; font-size: 12px; }
.hv-avg th, .hv-avg td { padding: 3px 6px; font-size: 12.5px; }
.hv-notes { margin: 14px 0 0; font-size: 12px; }
.hv-notes dt { font-weight: 600; margin-top: 6px; }
.hv-notes dd { margin: 0 0 0 20px; color: var(--muted); }
@media print { .hv-drop, .hv-seg, .hv-legend input { display: none !important; } .hv-layout { display: block; } .hv-layout .card { margin-bottom: 12px; } }

/* tab header colours: green = dose sheets, orange = configuration, blue = estimation tools */
:root { --tab-g: #e3f4e8; --tab-g-on: #c9ebd4; --tab-o: #fdebd6; --tab-o-on: #f9d9b3; --tab-b: #e2edfc; --tab-b-on: #c8dcf8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tab-g: #1c3427; --tab-g-on: #25492f; --tab-o: #3a2c18; --tab-o-on: #4d3a1d; --tab-b: #1d2c46; --tab-b-on: #26406a; } }
.tabs button[data-tab="lo"], .tabs button[data-tab="me"] { background: var(--tab-g); }
.tabs button[data-tab="eq"], .tabs button[data-tab="xu"] { background: var(--tab-o); }
.tabs button[data-tab="ee"], .tabs button[data-tab="hv"], .tabs button[data-tab="is"] { background: var(--tab-b); }
.tabs button[data-tab="lo"].on, .tabs button[data-tab="me"].on { background: var(--tab-g-on); }
.tabs button[data-tab="eq"].on, .tabs button[data-tab="xu"].on { background: var(--tab-o-on); }
.tabs button[data-tab="ee"].on, .tabs button[data-tab="hv"].on, .tabs button[data-tab="is"].on { background: var(--tab-b-on); }

h1 .aid { display: inline-block; margin-left: 8px; padding: 1px 9px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-ink); font-size: 12px; font-weight: 600; vertical-align: middle; }
.aid a { color: inherit; text-decoration: underline; }
