:root {
  color-scheme: light;
  --bg: #fcfcfb;
  --surface: #ffffff;
  --surface-2: #f3f2ef;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #73726c;
  --border: #d9d8d3;
  --grid: #e6e5e0;
  --accent: #2e7d32;
  --accent-text: #ffffff;
  --accent-soft: #e3f1e4;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #5c4300;
  /* Chart series: categorical slots 1-3, validated as a colour-blind-safe set. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #252523;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --border: #3a3a37;
    --grid: #2c2c2a;
    --accent: #66bb6a;
    --accent-text: #0b1f0c;
    --accent-soft: #1f3320;
    --danger: #f2b8b5;
    --warn-bg: #3d3100;
    --warn-text: #ffe08a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #252523;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #9a998f;
  --border: #3a3a37;
  --grid: #2c2c2a;
  --accent: #66bb6a;
  --accent-text: #0b1f0c;
  --accent-soft: #1f3320;
  --danger: #f2b8b5;
  --warn-bg: #3d3100;
  --warn-text: #ffe08a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 720px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.5rem; margin: 8px 0 16px; }
h3 { font-size: 1rem; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--text-2); }
.small { font-size: 0.85rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto; padding: 12px 16px 0;
}

.banner {
  max-width: 688px; margin: 8px auto 0; padding: 10px 14px;
  border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-text);
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
@media (max-width: 720px) { .banner { margin: 8px 16px 0; } }

/* Bottom tab bar */
.tabs {
  position: fixed; inset: auto 0 0 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  appearance: none; border: 0; background: none; color: var(--text-2);
  font: inherit; font-weight: 600; padding: 16px 4px; cursor: pointer;
}
.tabs button[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* Controls */
.btn {
  appearance: none; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  min-height: 44px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-small { padding: 6px 14px; min-height: 36px; font-size: 0.9rem; }
.btn-block { width: 100%; }
.icon-btn {
  appearance: none; border: 0; background: none; color: var(--text-2); font: inherit;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; min-height: 40px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="date"], input[type="number"], input:not([type]) {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[aria-invalid="true"] { border-color: var(--danger); }
.field { margin-bottom: 16px; }
.field-error { color: var(--danger); font-size: 0.85rem; margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > .grow { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  appearance: none; font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 14px; min-height: 40px;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.segmented button { appearance: none; border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; padding: 10px 4px; cursor: pointer; }
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); }

.list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--border); }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list .main { flex: 1; min-width: 0; }
.list .main button { all: unset; cursor: pointer; display: block; width: 100%; }
.list .primary { font-weight: 600; overflow-wrap: anywhere; }
.list .secondary { color: var(--text-2); font-size: 0.9rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.success { color: var(--accent); font-weight: 600; }

/* Chart */
.readout { min-height: 52px; margin-bottom: 4px; }
.readout .date { font-weight: 600; }
.readout .values { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.readout .values span { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; touch-action: pan-y; user-select: none; }
/* Focus ring only when the chart was reached by keyboard, not after a tap. */
.chart-wrap svg:focus { outline: none; }
.chart-wrap svg.kbd:focus { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart-wrap svg { display: block; width: 100%; height: 300px; overflow: visible; }
.chart-empty { height: 300px; display: grid; place-items: center; color: var(--text-2); text-align: center; }
.axis-text { fill: var(--text-3); font-size: 11px; }
.label-text { fill: var(--text); font-size: 12px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.crosshair { stroke: var(--text-2); stroke-width: 1; }
.series-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.marker { stroke: var(--surface); }
.s0 { stroke: var(--series-1); } .f0 { fill: var(--series-1); } .b0 { background: var(--series-1); }
.s1 { stroke: var(--series-2); } .f1 { fill: var(--series-2); } .b1 { background: var(--series-2); }
.s2 { stroke: var(--series-3); } .f2 { fill: var(--series-3); } .b2 { background: var(--series-3); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; font-weight: 600; margin: 16px 0 8px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { font-size: 1.2rem; margin: 0 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
