:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f8f7f3;
  --ink: #17232d;
  --ink-2: #4f5d68;
  --ink-3: #82909a;
  --line: #e4e0d6;
  --brand: #1e3a4c;
  --brand-ink: #ffffff;
  --brand-soft: #e4ecf1;
  --accent: #d0741c;
  --good: #2f7d57;
  --ok: #c7861a;
  --low: #c24a2c;
  --track: #ece8df;
  --a-yellow-bg: #fff6d6; --a-yellow-edge: #e8c233;
  --a-amber-bg:  #ffead1; --a-amber-edge:  #e8891a;
  --a-red-bg:    #fde2dc; --a-red-edge:    #d23b24;
  --shadow: 0 1px 2px rgba(20, 30, 40, .05), 0 4px 16px rgba(20, 30, 40, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161b;
    --surface: #182129;
    --surface-2: #1d2730;
    --ink: #e7ecef;
    --ink-2: #a8b4bd;
    --ink-3: #7a8893;
    --line: #2a3640;
    --brand: #7fb3d1;
    --brand-ink: #0d151b;
    --brand-soft: #1f3342;
    --accent: #eb9a4c;
    --good: #5cc08c;
    --ok: #e5a93f;
    --low: #f07a5c;
    --track: #25303a;
    --a-yellow-bg: #332c12; --a-yellow-edge: #d9b52e;
    --a-amber-bg:  #3a2711; --a-amber-edge:  #eb9a4c;
    --a-red-bg:    #3d1a14; --a-red-edge:    #f07a5c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10161b; --surface: #182129; --surface-2: #1d2730;
  --ink: #e7ecef; --ink-2: #a8b4bd; --ink-3: #7a8893; --line: #2a3640;
  --brand: #7fb3d1; --brand-ink: #0d151b; --brand-soft: #1f3342; --accent: #eb9a4c;
  --good: #5cc08c; --ok: #e5a93f; --low: #f07a5c; --track: #25303a;
  --a-yellow-bg: #332c12; --a-yellow-edge: #d9b52e;
  --a-amber-bg: #3a2711; --a-amber-edge: #eb9a4c;
  --a-red-bg: #3d1a14; --a-red-edge: #f07a5c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--brand); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--ink-2); }
.fine { color: var(--ink-3); font-size: .82rem; margin-top: 10px; }

/* header */
.top {
  background: var(--brand);
  color: var(--brand-ink);
  padding: calc(14px + env(safe-area-inset-top)) 0 14px;
  position: sticky; top: 0; z-index: 10;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 24px; background: var(--accent);
  clip-path: path("M11 0 L22 4.5 V11 C22 18 17 22.5 11 24 C5 22.5 0 18 0 11 V4.5 Z");
}
.place-chip {
  background: rgba(255, 255, 255, .14); color: inherit; border: 0; border-radius: 999px;
  padding: 5px 12px; font-size: .85rem; font-weight: 600; cursor: pointer; letter-spacing: .02em;
}
.place-chip:hover { background: rgba(255, 255, 255, .24); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .top { background: #14202a; color: var(--ink); }
  :root:not([data-theme="light"]) .place-chip { background: rgba(255, 255, 255, .08); }
}

main { padding-top: 16px; }
.view { display: grid; gap: 12px; }

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card > * + * { margin-top: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head + * { margin-top: 12px; }
.pill { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.empty { color: var(--ink-2); text-align: center; }

.welcome { background: var(--brand-soft); border-color: transparent; }
.welcome h2 { font-size: 1.3rem; }

/* score */
.eyebrow { color: var(--ink-2); font-size: .9rem; font-weight: 500; }
.score-num { font-size: 3.2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; margin-top: 2px; font-variant-numeric: tabular-nums; }
.score-unit { font-size: 1.3rem; font-weight: 600; letter-spacing: 0; color: var(--ink-2); }
.score-note { color: var(--ink-2); margin-top: 6px; }
.score[data-level="low"] .score-num { color: var(--low); }
.score[data-level="ok"] .score-num { color: var(--ok); }
.score[data-level="good"] .score-num { color: var(--good); }
.meters { display: grid; gap: 14px; margin-top: 18px !important; }
.meter-top { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
.meter-val { color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.bar { position: relative; height: 10px; background: var(--track); border-radius: 999px; overflow: visible; }
.fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--low); transition: width .4s ease; max-width: 100%; }
.meter[data-level="ok"] .fill { background: var(--ok); }
.meter[data-level="good"] .fill { background: var(--good); }
.goal { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-3); border-radius: 1px; opacity: .6; }
.g3 { left: calc(3 / 14 * 100%); }
.g14 { right: 0; }
.legend { font-size: .78rem; color: var(--ink-3); display: flex; align-items: center; gap: 8px; margin-top: 14px !important; }
.goal-key { display: inline-block; width: 2px; height: 14px; background: var(--ink-3); opacity: .6; border-radius: 1px; flex: none; }

/* alerts */
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alert a {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: 10px; text-decoration: none; color: var(--ink);
  border-left: 4px solid var(--a-yellow-edge); background: var(--a-yellow-bg);
}
.alert.amber a { border-color: var(--a-amber-edge); background: var(--a-amber-bg); }
.alert.red a { border-color: var(--a-red-edge); background: var(--a-red-bg); }
.alert span { color: var(--ink-2); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.all-clear { color: var(--good); font-weight: 600; display: flex; gap: 8px; align-items: baseline; }

/* rows */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; padding-top: 2px; }
.row-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; display: grid; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: .82rem; color: var(--ink-3); }
.row-sub.soon { color: var(--ok); font-weight: 600; }
.row-sub.expired { color: var(--low); font-weight: 600; }
.qty { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: .9rem; white-space: nowrap; }
.nudge { display: flex; gap: 4px; }
.nudge button {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-size: 1.1rem; line-height: 1; display: grid; place-items: center;
}
.nudge button:hover { border-color: var(--ink-3); }

/* presets */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 6px 12px; font-size: .85rem; cursor: pointer; font-weight: 500;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* kit checklist */
.checks { list-style: none; margin: 0; padding: 0; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; cursor: pointer; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.box {
  flex: none; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--ink-3); margin-top: 1px;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check input:checked + .box { background: var(--good); border-color: var(--good); }
.check input:checked + .box::after {
  content: ""; width: 10px; height: 6px; border: 2.5px solid #fff; border-top: 0; border-right: 0;
  transform: translateY(-1px) rotate(-45deg);
}
.check input:checked ~ span:last-child { color: var(--ink-2); }
.check input:focus-visible + .box { outline: 3px solid var(--accent); outline-offset: 2px; }

/* numbers */
.numbers { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.numbers a {
  display: grid; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
}
.numbers strong { font-variant-numeric: tabular-nums; }
.numbers span { font-size: .8rem; color: var(--ink-2); }

/* forms */
.form { display: grid; gap: 14px; }
.form > * + * { margin-top: 0; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: .9rem; }
input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.hint { font-size: .8rem; color: var(--ink-3); }
.hint.err { color: var(--low); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.steppers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.step { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.step button { border: 0; background: none; width: 36px; font-size: 1.2rem; cursor: pointer; flex: none; }
.step input { border: 0; border-radius: 0; text-align: center; padding: 8px 0; min-width: 0; -moz-appearance: textfield; background: none; }
.step input::-webkit-inner-spin-button, .step input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row.end .grow { flex: 1; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--brand); font-weight: 600; cursor: pointer; font-size: .9rem; }
.link-btn:disabled { opacity: .5; }
.link-btn.danger { color: var(--low); }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  background: none; border: 0; display: grid; justify-items: center; gap: 2px; padding: 6px 0;
  font-size: .75rem; font-weight: 600; color: var(--ink-3); cursor: pointer; border-radius: 10px;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--brand); }
.tabs button.on svg { fill: var(--brand-soft); }
@media (min-width: 700px) {
  .tabs { left: 50%; right: auto; transform: translateX(-50%); bottom: 16px; width: 420px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 6px; }
  body { padding-bottom: 110px; }
}

/* dialog */
dialog {
  width: min(520px, calc(100vw - 24px)); border: 0; border-radius: 18px; padding: 20px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 18, 24, .5); }
@media (max-width: 520px) {
  dialog { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .row2 { grid-template-columns: 1fr; }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; font-weight: 500;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
@media (min-width: 700px) { .toast { bottom: 100px; } }

@media (max-width: 380px) {
  .numbers { grid-template-columns: 1fr; }
  .steppers { grid-template-columns: 1fr; }
}
