/* Layout: a verdict line, then test results (left) beside the plan and the
   what-if tool (right), then history full width. One column on phones with
   a docked plan summary. Behind it all, the pool (js/water.js): panels are
   frosted glass on the water, and type set straight on the water is white.
   Dark first (night water); a light theme (day) follows the system. */
:root {
  --bg: #071820;             /* night water; the shader draws over it */
  --panel: rgb(10 24 31 / .78);   /* frosted glass on the water */
  --panel-solid: #0c1c24;    /* dialogs and anything off the water */
  --field: rgb(4 14 19 / .55);
  --field-line: #2c4a56;     /* input borders: stronger than dividers */
  --sec: #173540;            /* selected control */
  --line: rgb(160 220 235 / .14);
  --line-2: rgb(160 220 235 / .08);
  --track: rgb(160 220 235 / .11);
  --ink: #e8f6f9;
  --muted: #a9c4cc;
  --dim: #7d99a2;
  --faint: #2f4a55;
  --aqua: #6fd3dc;           /* brand accent and target zones */
  --on-aqua: #04191d;
  --chart: #8fdde3;
  --zone: rgb(111 211 220 / .45);
  --band: rgb(111 211 220 / .12);
  --warn: #f2a541;           /* out of range, only */
  --bad: #f07a6e;
  --glass-edge: rgb(160 220 235 / .16);
  --shadow: 0 30px 60px -30px rgb(0 0 0 / .8);
  --on-water-warn: #ffc56e;  /* "Not yet." on the water */

  --font: "Chivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 12px;
  --r-sm: 6px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #2f8399; --panel: rgb(246 251 252 / .8); --panel-solid: #f6fbfc; --field: rgb(255 255 255 / .75); --field-line: #b2c8cf; --sec: #dcecf0;
    --line: rgb(13 50 64 / .14); --line-2: rgb(13 50 64 / .08); --track: rgb(13 50 64 / .1);
    --ink: #0b2a35; --muted: #3f5f6a; --dim: #5a7781; --faint: #b6ccd3;
    --aqua: #0b7285; --on-aqua: #ffffff; --chart: #0b7285; --zone: rgb(11 114 133 / .35); --band: rgb(11 114 133 / .1);
    --warn: #b05600; --bad: #c2373f; --glass-edge: rgb(255 255 255 / .6); --shadow: 0 30px 60px -30px rgb(0 30 45 / .6);
    --on-water-warn: #ffd38a;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #2f8399; --panel: rgb(246 251 252 / .8); --panel-solid: #f6fbfc; --field: rgb(255 255 255 / .75); --field-line: #b2c8cf; --sec: #dcecf0;
  --line: rgb(13 50 64 / .14); --line-2: rgb(13 50 64 / .08); --track: rgb(13 50 64 / .1);
  --ink: #0b2a35; --muted: #3f5f6a; --dim: #5a7781; --faint: #b6ccd3;
  --aqua: #0b7285; --on-aqua: #ffffff; --chart: #0b7285; --zone: rgb(11 114 133 / .35); --band: rgb(11 114 133 / .1);
  --warn: #b05600; --bad: #c2373f; --glass-edge: rgb(255 255 255 / .6); --shadow: 0 30px 60px -30px rgb(0 30 45 / .6);
  --on-water-warn: #ffd38a;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums lining-nums;
  padding-bottom: 72px;
}
@media (min-width: 980px) { body { padding-bottom: 0; } }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.015em; }
h3 { font-size: 15px; font-weight: 500; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--aqua); outline-offset: 2px; border-radius: 4px; }
.meta { color: var(--muted); font-size: 13px; }

.wrap {
  max-width: 1400px; margin: 0 auto;
  padding-left: max(32px, env(safe-area-inset-left, 0px));
  padding-right: max(32px, env(safe-area-inset-right, 0px));
  padding-bottom: 40px;
}

/* ---- controls -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--dim); }
.btn-primary { background: var(--aqua); border-color: var(--aqua); color: var(--on-aqua); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--aqua); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-danger-solid, .btn-danger-solid:hover { background: var(--bad); border-color: var(--bad); color: var(--panel-solid); }
.tb { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0; border: 0; background: none; color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tb:hover { color: var(--aqua); }
.tb[aria-pressed="true"] { color: var(--aqua); }
.tb-danger { color: var(--bad); }
.link-btn { border: 0; background: none; color: var(--aqua); font-weight: 500; cursor: pointer; padding: 4px 0; font-size: 13px; }
.link-danger { color: var(--bad); }
.icon-btn { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 8px; }

/* text toggle: quiet, underlined when on */
.tt { display: inline-flex; gap: 14px; }
.tt button { border: 0; background: none; padding: 6px 0; color: var(--dim); font-size: 13px; font-weight: 500; cursor: pointer; }
.tt button[aria-pressed="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--aqua); }
/* segmented control, for the history range and dialogs */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--dim); padding: 0 12px; height: 32px; font-size: 13px; font-weight: 500; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--sec); color: var(--ink); }
.seg-wide { display: flex; flex-wrap: wrap; }
.seg-wide button { flex: 1 1 auto; height: 38px; }

select, input[type="number"], input[type="text"], input[type="datetime-local"], input[type="file"] {
  border: 1px solid var(--field-line); border-radius: var(--r-sm); background: var(--field); height: 34px; padding: 0 10px; font-size: 14px; min-width: 0;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 28px;
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23999' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- the water ------------------------------------------------------ */
.water { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; opacity: 0; transition: opacity .6s; }
.water.on { opacity: 1; }
.wrap { position: relative; z-index: 1; }
/* type set straight on the water */
.top, .intro, .verdict, .hist-head, .hist-foot, .foot { --ink: #fff; --muted: rgb(255 255 255 / .9); --dim: rgb(255 255 255 / .78); --line: rgb(255 255 255 / .32); --aqua: #fff; color: var(--ink); text-shadow: 0 1px 14px rgb(0 40 55 / .55); }
.top .btn, .theme-btn, .hist-head .seg { background: rgb(255 255 255 / .1); border-color: rgb(255 255 255 / .4); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.hist-head .seg button[aria-pressed="true"] { background: rgb(255 255 255 / .25); }
.top .btn:hover, .theme-btn:hover { border-color: #fff; }
.hist-foot .tb-danger { color: #ffd2ca; }
#sampleHist { margin-bottom: 16px; background: var(--panel-solid); color: var(--ink); text-shadow: none; }

/* ---- header ---------------------------------------------------------- */
.top { display: flex; align-items: center; gap: 16px; height: 72px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 21px; font-weight: 800; letter-spacing: -.025em; }
.tagline { margin-right: auto; padding-left: 14px; border-left: 1px solid var(--line); font-size: 13px; color: var(--muted); white-space: nowrap; }
.pool-label { color: var(--muted); }
.pool-chip svg { color: var(--muted); }
.theme-btn { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: var(--r-sm); background: none; color: var(--muted); cursor: pointer; }
.theme-btn:hover { color: var(--ink); border-color: var(--dim); }

/* ---- intro (first visit, while the sample readings are shown) --------- */
.intro { padding: 36px 0 4px; max-width: 900px; }
.intro h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.intro p { margin-top: 10px; font-size: 16px; line-height: 1.5; color: var(--muted); max-width: 72ch; }
.intro + .verdict { padding-top: 22px; }

/* ---- verdict --------------------------------------------------------- */
.verdict { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; align-items: baseline; padding: 32px 0 26px; }
.verdict-word { grid-column: span 4; font-size: 60px; font-weight: 800; letter-spacing: -.035em; line-height: 1; white-space: nowrap; }
.verdict[data-v="notYet"] .verdict-word, .verdict[data-v="wait"] .verdict-word { color: var(--on-water-warn); }
.verdict-text { grid-column: span 8; font-size: 20px; line-height: 1.35; color: var(--muted); max-width: 64ch; }
.verdict-text strong { color: var(--ink); font-weight: 700; }

/* ---- main grid ------------------------------------------------------- */
.calc { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; align-items: stretch; padding-bottom: 48px; }
.readings-panel { grid-column: span 4; }
.side { grid-column: span 8; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.plan-panel { flex: 1; }
.panel, .log-sheet {
  background: var(--panel); border: 1px solid var(--glass-edge); border-radius: 16px; padding: 26px 28px; min-width: 0;
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: inset 0 1px 0 var(--glass-edge), var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 34px; flex-wrap: wrap; }
.sample-note { font-size: 13px; color: var(--ink); background: var(--band); border-radius: var(--r-sm); padding: 8px 12px; margin-top: 12px; }

/* ---- readings -------------------------------------------------------- */
#readingsSub { margin: 4px 0 6px; }
.readings { display: grid; }
.reading { display: grid; grid-template-columns: 96px 72px minmax(0, 1fr); gap: 0 18px; align-items: center; min-height: 50px; border-bottom: 1px solid var(--line-2); }
.r-label { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.r-abbr { font-size: 14px; font-weight: 500; }
.r-name { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-status, .r-age { display: none; }
.r-value { position: relative; }
.r-input { width: 100%; height: 36px; text-align: right; font-size: 18px; font-weight: 500; padding: 0 10px; border: 1px solid var(--field-line); border-radius: var(--r-sm); background: var(--field); }
.r-input:hover { border-color: var(--dim); }
.r-input:focus { border-color: var(--aqua); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--aqua) 25%, transparent); }
.reading.is-off .r-input, .reading.is-off .r-calc { color: var(--warn); }
.r-unit { display: none; }
.r-calc { height: 36px; display: flex; align-items: center; justify-content: flex-end; padding-right: 11px; font-size: 18px; font-weight: 500; border: 1px dashed var(--field-line); border-radius: var(--r-sm); }

.r-bar { position: relative; height: 38px; min-width: 0; }
.bar-track { position: absolute; left: 0; right: 0; top: 9px; height: 8px; border-radius: 4px; background: var(--track); }
.bar-zone { position: absolute; top: 9px; height: 8px; background: var(--zone); }
.bar-mark { position: absolute; top: 5px; width: 3px; height: 16px; margin-left: -1.5px; border-radius: 2px; background: var(--ink); pointer-events: none; }
.reading.is-off .bar-mark { background: var(--warn); top: 2px; height: 22px; }
.bar-edge { position: absolute; top: 25px; transform: translateX(-50%); font-size: 12px; line-height: 1; color: var(--dim); white-space: nowrap; pointer-events: none; }
.r-range { position: absolute; left: 0; right: 0; top: 0; height: 26px; width: 100%; margin: 0; background: none; -webkit-appearance: none; appearance: none; cursor: pointer; opacity: 0; }
.r-range::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; }
.r-range::-moz-range-thumb { width: 24px; height: 24px; border: 0; }
.r-bar:focus-within .bar-mark { box-shadow: 0 0 0 3px var(--aqua); }

.r-goal { grid-column: 1 / -1; display: none; gap: 6px 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); padding: 0 0 10px; }
.readings.show-goals .r-goal { display: flex; }
.r-goal label { display: inline-flex; align-items: center; gap: 6px; }
.goal-input { width: 4.4em; height: 28px; font-size: 13px; text-align: right; }
.goal-auto { font-size: 12px; border: 0; background: none; color: var(--aqua); cursor: pointer; padding: 0; text-decoration: underline; }
.r-hint { color: var(--dim); }

.quick-summary { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 13px; color: var(--muted); padding: 10px 0 0; }
.quick-summary b { color: var(--ink); font-weight: 500; }
.guide-line { padding-top: 12px; }
.readings-foot { display: flex; align-items: center; gap: 18px; padding-top: 16px; flex-wrap: wrap; }
.readings-foot .btn-primary { margin-left: auto; }
.track-more { display: contents; }

/* ---- plan ------------------------------------------------------------ */
.pool-spec { display: flex; align-items: stretch; width: 100%; margin: 14px 0 22px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; color: var(--ink); text-align: left; cursor: pointer; }
.pool-spec > span { display: flex; flex-direction: column; gap: 4px; padding: 10px 16px; }
.pool-spec > span + span { border-left: 1px solid var(--line); }
.pool-spec small { font-size: 12px; color: var(--muted); }
.pool-spec b { font-size: 15px; font-weight: 500; white-space: nowrap; }
.pool-spec .ps-edit { flex-direction: row; align-items: center; gap: 6px; margin-left: auto; font-size: 13px; font-weight: 500; color: var(--muted); }
.pool-spec:hover { border-color: var(--aqua); }
.pool-spec:hover .ps-edit { color: var(--aqua); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 32px 48px; }
.step { display: flex; flex-direction: column; min-width: 0; }
.step-h { display: flex; align-items: baseline; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.step-n { font-size: 15px; font-weight: 700; color: var(--aqua); }
.step-title { font-size: 15px; font-weight: 500; }
.step-when { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.step-dose { display: flex; align-items: baseline; gap: 10px; margin-top: 28px; }
.step-dose b { font-size: 96px; font-weight: 500; line-height: .82; letter-spacing: -.045em; }
.step-dose span { font-size: 22px; font-weight: 500; color: var(--muted); }
.step-prod { font-size: 14px; font-weight: 500; margin-top: 20px; }
.step-prod span { color: var(--muted); font-weight: 400; }
.step-note { font-size: 14px; color: var(--muted); margin-top: 4px; max-width: 52ch; }
.step-fx { font-size: 14px; margin-top: 14px; }
.step-fx s { text-decoration: none; color: var(--dim); }
.step-fx b { font-weight: 400; color: var(--muted); }
.step-how { margin-top: 14px; font-size: 14px; color: var(--muted); }
.step-how summary { cursor: pointer; width: fit-content; color: var(--aqua); font-weight: 500; font-size: 13px; }
.step-how ul { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 8px; }
.step-how b { color: var(--ink); font-weight: 500; }
.step-how p { margin-top: 10px; }
.step-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: auto; padding-top: 16px; }
.mini-select { height: 30px; font-size: 13px; background-color: transparent; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--aqua); margin: 0; }
.step-done { margin-left: auto; }
.step.done .step-dose, .step.done .step-prod, .step.done .step-note, .step.done .step-fx { opacity: .45; }
.step.done .step-n::after { content: " ✓"; }
.balanced { display: grid; gap: 6px; grid-column: 1 / -1; }
.balanced strong { font-size: 28px; font-weight: 700; letter-spacing: -.02em; color: var(--aqua); }
.balanced span { color: var(--muted); }
.alert { grid-column: 1 / -1; font-size: 14px; color: var(--muted); border-left: 0; padding: 12px 14px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.alert strong { color: var(--warn); font-weight: 500; }

/* ---- what if --------------------------------------------------------- */
.whatif { padding: 18px 28px; }
.whatif-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.whatif-row h3 { margin-right: 6px; white-space: nowrap; }
.whatif-row select, .whatif-row input { height: 32px; font-size: 13px; background-color: transparent; }
.amount-input { display: inline-flex; gap: 6px; }
#wiAmount { width: 64px; text-align: right; }
.whatif-out { margin-top: 12px; justify-content: space-between; }
.wi-result { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 15px; }
.wi-result span { color: var(--muted); }
.wi-result s { text-decoration: none; color: var(--dim); }
.wi-result b { font-weight: 500; color: var(--ink); }
.wi-empty { color: var(--muted); font-size: 13px; }

/* ---- history --------------------------------------------------------- */
.hist-head { display: flex; align-items: baseline; gap: 12px 18px; flex-wrap: wrap; padding-bottom: 20px; }
.hist-head h2 { font-size: 26px; }
.hist-head .meta { margin-right: auto; }
.hist-head .seg { align-self: center; }
.empty { color: var(--muted); padding: 24px; border: 1px dashed var(--line); border-radius: var(--r); text-align: center; }

.stats { display: flex; flex-wrap: wrap; gap: 8px 32px; padding: 0 0 22px; }
.stat { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stat-label { order: 2; font-size: 13px; color: var(--muted); }
.stat b { order: 1; font-size: 20px; font-weight: 500; }
.stat-sub { order: 3; font-size: 12px; color: var(--dim); }

.charts { display: grid; gap: 22px 32px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.chart { min-width: 0; }
.chart-main { grid-column: 1 / -1; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; padding-bottom: 8px; }
.chart-name { font-size: 14px; font-weight: 500; }
.chart-name span { font-weight: 400; color: var(--muted); }
.chart-last { font-size: 12px; color: var(--muted); }
.chart-plot { position: relative; }
.chart-plot svg { display: block; max-width: 100%; height: auto; touch-action: pan-y; overflow: visible; }
.c-grid { stroke: var(--line-2); stroke-width: 1; }
.c-tick { fill: var(--dim); font: 400 11px var(--font); }
.c-band { fill: var(--band); }
.c-min { stroke: var(--dim); stroke-width: 1; stroke-dasharray: 3 4; }
.c-min-label { fill: var(--muted); }
.c-area { fill: none; }
.c-line { fill: none; stroke: var(--chart); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.c-warn { fill: none; stroke: var(--warn); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--chart); stroke: var(--panel-solid); stroke-width: 1.5; }
.c-last { fill: var(--ink); font: 500 12px var(--font); }
.c-event { fill: var(--aqua); opacity: .8; }
.c-cross { stroke: var(--dim); stroke-width: 1; }
.c-tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--ink); color: var(--panel-solid); padding: 5px 9px; border-radius: var(--r-sm); font-size: 12px; display: grid; pointer-events: none; white-space: nowrap; z-index: 2; }
.c-tip strong { font-weight: 500; }
.c-tip span { opacity: .75; }

.tl-title { font-size: 15px; font-weight: 500; margin: 32px 0 4px; }
.timeline { display: grid; }
.tl-day { display: grid; }
.tl-date { font-size: 13px; font-weight: 500; color: var(--ink); padding: 14px 0 4px; border-bottom: 1px solid var(--line); }
.tl-row { display: grid; grid-template-columns: 5.6em minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.tl-time { color: var(--dim); font-size: 12px; white-space: nowrap; }
.tl-body { display: flex; flex-wrap: wrap; gap: 4px 16px; min-width: 0; color: var(--muted); }
.tl-add .tl-body { color: var(--ink); }
.tl-add .tl-time::before { content: "▲ "; color: var(--aqua); font-size: 10px; }
.tl-val b { color: var(--ink); font-weight: 500; margin-left: 2px; }
.tl-note { flex-basis: 100%; color: var(--dim); font-size: 13px; }
.tl-actions { display: flex; gap: 2px; }
.tl-btn { border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.tl-btn:hover { color: var(--aqua); }
.hist-foot { display: flex; gap: 22px; align-items: center; padding-top: 14px; }
#clearHistWrap { margin-left: auto; }

.foot { color: var(--dim); font-size: 12px; max-width: 90ch; padding-top: 40px; }

/* ---- dock (phones) ---------------------------------------------------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.dock-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-size: 14px; font-weight: 500;
}
@media (min-width: 980px) { .dock { display: none; } }

/* ---- dialogs --------------------------------------------------------- */
dialog { border: 1px solid var(--line); border-radius: var(--r); padding: 0; background: var(--panel-solid); color: var(--ink); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.dialog-body { display: grid; gap: 16px; padding: 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.dialog-foot-group { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: grid; gap: 6px; font-size: 13px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field legend { color: var(--muted); font-weight: 500; padding: 0; }
.field em { font-style: normal; font-weight: 400; }
.field input:not([type="checkbox"]), .field select { width: 100%; height: 38px; }
fieldset.field:has(.check) { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; }
fieldset.field:has(.check) legend { flex-basis: 100%; margin-bottom: 6px; }
.field .check { font-size: 14px; }
.field .amount-input { display: flex; }
.field .amount-input input { flex: 1; }
.field .amount-input select { width: auto; }
.unit-tag { align-self: center; color: var(--muted); }
.estimator { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; }
.estimator summary { cursor: pointer; font-weight: 500; color: var(--aqua); font-size: 13px; }
.est-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.est-out { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 15px; font-weight: 500; }
.td-help { font-size: 13px; color: var(--muted); font-weight: 400; }
.td-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 14px; margin-top: 4px; }
.td-row { display: grid; grid-template-columns: 20px 3.6em minmax(0, 1fr) 2.6em; gap: 8px; align-items: center; font-size: 14px; color: var(--ink); }
.td-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--aqua); }
.td-name { font-weight: 500; }
.td-unit { color: var(--muted); font-size: 12px; }
.field .td-val { height: 32px; }
textarea { width: 100%; border: 1px solid var(--field-line); border-radius: var(--r-sm); background: var(--field); padding: 8px 10px; font-size: 13px; color: var(--ink); resize: vertical; }
.im-preview { font-size: 13px; min-height: 1.4em; }

.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); display: flex; gap: 12px; align-items: center; background: var(--ink); color: var(--panel-solid); padding: 9px 16px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: var(--aqua); font-weight: 700; cursor: pointer; padding: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- phones ---------------------------------------------------------- */
@media (max-width: 979px) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .top { height: 60px; gap: 10px; }
  .brand { font-size: 19px; }
  .pool-chip { height: 32px; padding: 0 10px; }
  .pool-label, .pool-more { display: none; }
  .tagline { display: none; }
  .brand { margin-right: auto; }
  .intro { padding: 22px 0 0; }
  .intro h1 { font-size: 22px; }
  .intro p { font-size: 15px; }
  .verdict { display: block; padding: 22px 0 20px; }
  .verdict-word { font-size: 44px; }
  .verdict-text { margin-top: 10px; font-size: 18px; }
  .calc { display: flex; flex-direction: column; gap: 14px; padding-bottom: 36px; }
  .side { gap: 14px; }
  .panel, .log-sheet { padding: 20px 18px; }
  .reading { grid-template-columns: 82px 64px minmax(0, 1fr); gap: 0 14px; }
  .steps { grid-template-columns: 1fr; gap: 28px; }
  .step-dose { margin-top: 22px; }
  .step-dose b { font-size: 84px; }
  .whatif { padding: 18px; }
  .whatif-row h3 { width: 100%; }
  #wiProduct { flex: 1 1 140px; }
  .wi-of { display: none; }
  .pool-spec > span { padding: 9px 12px; }
  .pool-spec .ps-edit { padding: 9px 12px; }
  .pool-spec .ps-edit { font-size: 0; gap: 0; }
  .pool-spec .ps-edit svg { width: 14px; height: 14px; }
  .hist-head h2 { font-size: 22px; }
  .hist-head .meta { flex-basis: 100%; order: 2; }
  .hist-head .seg { order: 3; }
  .charts { grid-template-columns: 1fr; }
  .tl-row { grid-template-columns: 4.6em minmax(0, 1fr) auto; gap: 8px; }
}
