:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-2: #eaf0f2;
  --ink: #10242c;
  --ink-2: #4b626b;
  --line: #d6e0e4;
  --accent: #0b7f8f;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --bad: #b3261e;
  --manual: #0b7f8f;
  --icp: #7a4cc2;
  --aquawiz: #d0661f;
  --tuya: #2f6fd1;
  --band: rgba(31, 138, 76, 0.12);
  --radius: 14px;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071a21;
    --surface: #0d2630;
    --surface-2: #12313d;
    --ink: #e5f1f4;
    --ink-2: #93aeb7;
    --line: #1f4250;
    --accent: #3fc1cf;
    --accent-ink: #04232a;
    --ok: #4cc983;
    --warn: #f0a341;
    --bad: #ff7b72;
    --manual: #3fc1cf;
    --icp: #b48cff;
    --aquawiz: #ff9a57;
    --tuya: #6aa5ff;
    --band: rgba(76, 201, 131, 0.14);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand { display: flex; flex-direction: column; }
.title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sub { font-size: 13px; color: var(--ink-2); }
.icon-btn {
  border: 0; background: var(--surface); color: var(--ink-2);
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  border: 1px solid var(--line);
}

main { padding: 4px 16px 24px; max-width: 720px; margin: 0 auto; }
h2 { font-size: 15px; font-weight: 650; color: var(--ink-2); margin: 22px 2px 10px; text-transform: uppercase; letter-spacing: 0.04em; }
h2:first-child { margin-top: 8px; }
p.muted, .muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.reading {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: left; width: 100%; cursor: pointer; position: relative;
  border-left: 4px solid var(--line);
}
.reading.ok { border-left-color: var(--ok); }
.reading.low, .reading.high { border-left-color: var(--warn); }
.reading.none { border-left-color: var(--line); }
.reading .name { font-size: 13px; color: var(--ink-2); }
.reading .val { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.reading .val small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.reading .meta { font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.reading.stale .val { opacity: 0.55; }
.flag { font-size: 11px; font-weight: 650; padding: 1px 6px; border-radius: 99px; }
.flag.low, .flag.high { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.flag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

.src { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-2); }
.dot.manual { background: var(--manual); } .dot.icp { background: var(--icp); }
.dot.aquawiz { background: var(--aquawiz); } .dot.tuya { background: var(--tuya); }

/* Home: alkalinity hero, temperature light */
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
.hero { margin-top: 10px; padding: 10px 12px; }
.hero-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-head .meta { font-size: 11px; }
.hero-top { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.reading .val.big { font-size: 30px; line-height: 1.1; margin: 0; white-space: nowrap; }
.reading .val.big small { font-size: 13px; }
.hero-stats { display: grid; gap: 2px; text-align: right; flex: none; }
.hero-stats div { display: flex; flex-direction: column; line-height: 1.15; }
.hero-stats b { font-size: 13px; font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: 10px; color: var(--ink-2); }
.spark { flex: 1; min-width: 0; height: 44px; display: block; }
.spark path { fill: none; stroke: var(--aquawiz); stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark .band { fill: var(--band); }
.spark .mid, .chart .mid { stroke: var(--ink-2); stroke-opacity: 0.35; stroke-width: 1; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.spark .sp, .chart .sp { stroke: var(--warn); stroke-opacity: 0.6; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.chart .sp-label { fill: var(--warn); font-size: 10px; opacity: 0.8; }
.statusbar {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 10px; padding: 10px 12px; cursor: pointer; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.statusbar .light { width: 14px; height: 14px; border-radius: 50%; background: var(--line); flex: none; }
.statusbar.ok .light { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent); }
.statusbar.low .light, .statusbar.high .light { background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 22%, transparent); }
.statusbar.low, .statusbar.high { border-color: var(--warn); }
.statusbar .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sb-name { font-weight: 650; }
.sb-sub { font-size: 12px; color: var(--ink-2); }
.statusbar.low .sb-sub, .statusbar.high .sb-sub { color: var(--warn); font-weight: 650; }
.sb-val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Kalk reactor */
.card.kalk { margin-top: 10px; padding: 10px 12px; border-left: 4px solid var(--line); }
.card.kalk.ok { border-left-color: var(--ok); } .card.kalk.high { border-left-color: var(--warn); }
.flag.none { background: var(--surface-2); color: var(--ink-2); }
.kalk-row { display: flex; align-items: center; gap: 12px; margin-top: 2px; cursor: pointer; }
.kalk .val.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kalk .val.big small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.kalk-facts { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: right; }
.kalk-facts div { display: flex; flex-direction: column; line-height: 1.2; }
.kalk-facts span { font-size: 10px; color: var(--ink-2); }
.kalk-facts b { font-size: 13px; font-variant-numeric: tabular-nums; }
.kalk-tip { margin: 4px 0 0; font-size: 12px; }
.kalk-cond { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.kalk-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.kalk-btns.two { grid-template-columns: 1fr 1fr; }
.kalk-btns .btn { padding: 6px 4px; min-height: 34px; font-size: 13px; white-space: nowrap; }
.kalk-log { display: flex; gap: 8px; margin-top: 10px; }
.kalk-log[hidden] { display: none; }
.kalk-log .btn { white-space: nowrap; }
.kalk-log input { min-height: 36px; padding: 6px 10px; }
.chart .dose.cal { stroke: #8a5cd6; stroke-dasharray: 2 3; stroke-width: 1.5; opacity: 0.9; }
.chart .dose.kalk { stroke: var(--tuya); stroke-dasharray: none; stroke-width: 1.5; opacity: 0.8; }

/* Doser heads */
.card.doser { padding: 10px 12px; }
.list.heads li { padding: 8px 0; }
.list.heads li.off { opacity: 0.5; }
.head-ml { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Suggestions */
.card.advice { margin-top: 10px; padding: 10px 12px; }
.adv { border-top: 1px solid var(--line); }
.adv:first-of-type { border-top: 0; }
.adv summary { display: flex; gap: 8px; align-items: center; padding: 8px 0; cursor: pointer; list-style: none; font-size: 14px; font-weight: 600; }
.adv summary::-webkit-details-marker { display: none; }
.adv p { margin: 0 0 8px 16px; }
.adv-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line); }
.adv-dot.change, .adv-dot.action { background: var(--warn); }
.adv-dot.ok { background: var(--ok); } .adv-dot.test, .adv-dot.watch { background: var(--tuya); }
.adv-conf { font-size: 10px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.adv-more > summary { padding: 6px 0; cursor: pointer; }
.adv-more .adv summary { font-weight: 500; }
.adv-foot { margin: 6px 0 0; font-size: 11px; }

/* Dosing prompts */
.adv-pair { display: block; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.adv-act { display: flex; gap: 8px; margin: 0 0 8px 16px; }
.adv-act:empty { display: none; }
.adv-review { margin: 0 0 10px 16px; }
.adv-review:empty { display: none; }
.pv { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; }
.pv-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pv-table td { padding: 4px 2px; }
.pv-table td:nth-child(2), .pv-table td:nth-child(3) { text-align: right; }
.pv-table tr.chg td:nth-child(3) { color: var(--accent); font-weight: 700; }
.pv-table tr.tot td { font-weight: 700; }

/* AquaWiz calibrate link */
.cal-link { margin-left: 8px; font-size: 11px; font-weight: 650; color: var(--accent); text-decoration: none; padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; }

a { color: var(--accent); }
code.topic { font: 600 14px ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 4px 8px; border-radius: 8px; user-select: all; }

/* Bottles */
.list li.bottle { align-items: flex-start; gap: 12px; }
.btl { flex: none; width: 34px; text-align: center; padding-top: 2px; }
.btl svg { display: block; margin: 0 auto; }
.btl span { display: block; font-size: 11px; color: var(--ink-2); margin-top: 3px; }
.b-liquid { fill: var(--accent); opacity: 0.55; }
.b-glass { fill: none; stroke: var(--ink-2); stroke-width: 1.2; }
.b-cap { stroke: var(--ink-2); stroke-width: 2; }
.bottle-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.b-name b { display: block; font-size: 15px; }
.b-name span, .b-days span { display: block; font-size: 12px; color: var(--ink-2); }
.b-days { text-align: right; white-space: nowrap; }
.b-days b { font-size: 20px; font-variant-numeric: tabular-nums; }
.b-track { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.b-fill { height: 100%; border-radius: 4px; }
.b-btns { display: flex; gap: 8px; margin-top: 8px; }
.b-btns .btn { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.b-ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin: 4px 0 0 46px; }
.ldot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.warn-t { color: var(--warn); font-weight: 650; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }

/* Buttons and forms */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; min-height: 44px;
}
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: 0.5; }
.btn.block { width: 100%; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.tests { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.test-in { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.test-in label { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; }
.test-in input { border: 0; padding: 4px 0; min-height: 36px; font-size: 20px; font-weight: 650; background: transparent; }
.test-in input:focus { outline: none; }
.test-in:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 99px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-2); font-size: 11px; }
.chart .axis { stroke: var(--line); }
.chart .line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; opacity: 0.6; }
.chart .line.auto { stroke: var(--aquawiz); opacity: 0.9; stroke-width: 1.6; stroke-linejoin: round; }
.chart .line.auto.tuya { stroke: var(--tuya); }
.chart .band { fill: var(--band); }
.chart .dose { stroke: var(--warn); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--ink-2); }

/* App shortcuts */
.apps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.app {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 6px; font-size: 13px; text-align: center;
}
.app .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 750; color: #fff; font-size: 15px; }

/* Journal */
.entry .when { font-size: 12px; color: var(--ink-2); }
.cat { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; cursor: pointer;
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs button.active { color: var(--accent); font-weight: 650; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 12px; z-index: 20; font-size: 14px;
  max-width: 560px; margin: 0 auto;
}
.toast.err { background: var(--bad); color: #fff; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
table.readings { width: 100%; border-collapse: collapse; font-size: 14px; }
table.readings td { padding: 8px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.readings td:last-child { text-align: right; }
