/* Pool Math — phone-first layout: one column of cards, bottom tab bar.
   Palette: pool tile and water; semantic colors only for status chips. */
:root {
  --bg: #eaf3f5;
  --surface: #ffffff;
  --sunk: #f3f8f9;
  --ink: #0f2a33;
  --muted: #587480;
  --line: #d2e2e6;
  --accent: #0a6f8c;
  --accent-ink: #ffffff;
  --accent-soft: #dcf0f5;
  --good: #1d8656;
  --good-soft: #def3e8;
  --warn: #a8670f;
  --warn-soft: #fbefd9;
  --bad: #be3a26;
  --bad-soft: #fbe3de;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #06171c;
    --surface: #0d242b;
    --sunk: #0a1d23;
    --ink: #dcedf1;
    --muted: #8fb0b9;
    --line: #1d3b44;
    --accent: #48c0da;
    --accent-ink: #04161b;
    --accent-soft: #0f3540;
    --good: #5ccb92;
    --good-soft: #10352a;
    --warn: #e7b453;
    --warn-soft: #3a2c0f;
    --bad: #f2866f;
    --bad-soft: #3d1c16;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--bg);
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
header.top h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
header.top .pool { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.sync { font-size: 0.75rem; padding: 2px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }

main { padding: 0 16px 24px; max-width: 640px; margin: 0 auto; display: grid; gap: 14px; }
section.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 12px; min-width: 0; }
.card h2 { margin: 0; font-size: 1.05rem; }
.card h2 small { color: var(--muted); font-weight: 400; font-size: 0.85rem; margin-left: 6px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Test grid: label | now | goal | status */
.tests { display: grid; grid-template-columns: 4.2rem 1fr 1fr 4.6rem; gap: 6px 8px; align-items: center; }
.tests .hd { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tests .lbl { font-weight: 600; }
.tests .lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 0.7rem; line-height: 1.1; }
input.v, select, input.t {
  width: 100%; min-width: 0; padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--sunk);
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1rem;
}
select, input.t { font-family: var(--font); }
input.v.goal { background: transparent; border-style: dashed; }
input.v:focus, select:focus, input.t:focus { border-color: var(--accent); outline: none; }
.chip { justify-self: start; font-size: 0.72rem; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.chip.ok { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.none { background: transparent; color: var(--muted); }

label.f { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); min-width: 0; }
label.f > span { color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* CSI meter */
.csi { display: grid; gap: 6px; }
.csi .bar { position: relative; height: 10px; border-radius: 99px;
  background: linear-gradient(90deg, var(--bad) 0%, var(--warn) 25%, var(--good) 40%, var(--good) 60%, var(--warn) 75%, var(--bad) 100%); opacity: 0.85; }
.csi .mark { position: absolute; top: -4px; width: 4px; height: 18px; border-radius: 2px; background: var(--ink); transform: translateX(-2px); }
.csi .mark.goal { background: transparent; border: 2px solid var(--ink); width: 8px; transform: translateX(-4px); }
.csi .scale { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); font-family: var(--mono); }

/* Doses */
.doses { display: grid; gap: 10px; }
.dose { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; background: var(--sunk); }
.dose .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.dose .what { font-weight: 600; }
.dose .amt { font-family: var(--mono); font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.dose .alt { font-size: 0.85rem; color: var(--muted); }
.dose .alt b { font-family: var(--mono); color: var(--ink); font-weight: 600; }
.dose label.added { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.dose label.added input { width: 18px; height: 18px; accent-color: var(--accent); }
.empty { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); font-weight: 600; }
.btn.danger { background: var(--bad); color: var(--surface); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; }
textarea { width: 100%; min-height: 64px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--sunk); resize: vertical; }

/* Log */
.trend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.spark { border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: var(--sunk); min-width: 0; }
.spark .k { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.spark .v { font-family: var(--mono); font-weight: 700; font-size: 1.1rem; }
.spark svg { width: 100%; height: 36px; display: block; }
.spark svg path.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark svg path.area { fill: var(--accent-soft); stroke: none; }
.spark svg circle { fill: var(--accent); }
.entries { display: grid; gap: 10px; }
.entry { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 6px; }
.entry:first-child { border-top: 0; padding-top: 0; }
.entry .when { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.entry .vals { display: flex; flex-wrap: wrap; gap: 4px 12px; font-family: var(--mono); font-size: 0.88rem; }
.entry .vals span b { font-family: var(--font); font-weight: 600; color: var(--muted); font-size: 0.75rem; margin-right: 3px; }
.entry .added, .entry .note { font-size: 0.85rem; color: var(--muted); }
.entry .acts { display: flex; gap: 8px; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 0.85rem; }
.linkbtn.danger { color: var(--bad); }

.result { background: var(--accent-soft); border-radius: 12px; padding: 12px; font-size: 0.95rem; }
.result ul { margin: 0; padding-left: 18px; }

/* Tab bar */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}
nav.tabs button { background: none; border: 0; padding: 6px 0; display: grid; justify-items: center; gap: 2px; color: var(--muted); font-size: 0.72rem; font-weight: 600; cursor: pointer; }
nav.tabs button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button[aria-selected="true"] { color: var(--accent); }

/* Login */
.login { min-height: 80vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 2rem; }
.err { color: var(--bad); font-size: 0.9rem; min-height: 1.2em; }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-weight: 600; font-size: 0.9rem; z-index: 20; }

@media (max-width: 380px) {
  .tests { grid-template-columns: 3.6rem 1fr 1fr 4.2rem; gap: 6px; }
  .three { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }
}

[hidden] { display: none !important; }
