/* ---------- tokens ---------- */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #16202a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #ccfbf1;
  --sys: #dc2626;
  --dia: #2563eb;
  --warn-bg: #fef3c7;
  --err-bg: #fee2e2;
  --err: #991b1b;
  --ok-bg: #dcfce7;
  --ok: #166534;
  --c-normal: #16a34a;
  --c-elevated: #ca8a04;
  --c-stage1: #ea580c;
  --c-stage2: #dc2626;
  --c-severe: #7f1d1d;
  --radius: 14px;
  --tap: 52px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #8b98a8;
    --line: #2a313c;
    --accent: #2dd4bf;
    --accent-ink: #042f2e;
    --accent-soft: #134e4a;
    --sys: #f87171;
    --dia: #60a5fa;
    --warn-bg: #3b2f0b;
    --err-bg: #3b1212;
    --err: #fca5a5;
    --ok-bg: #0f2e1a;
    --ok: #86efac;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
h1:focus { outline: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  min-height: 44px;
}
/* iOS Safari renders date/time inputs wider than their box unless reset. */
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; display: block; text-align: left; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
label > input, label > select, label > textarea { margin-top: .25rem; color: var(--text); font-size: 1rem; }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .75rem; margin: 0 0 .75rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .25rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .5rem 1rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600;
  touch-action: manipulation;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; margin-top: .5rem; }
.btn.icon { width: 48px; padding: 0; font-size: 1.6rem; }
.btn.del { color: var(--err); font-size: 1.1rem; }
.grow { flex: 1; }
.link { background: none; border: 0; color: var(--accent); padding: .35rem 0; cursor: pointer; font-weight: 600; }
.login .link { padding-top: .75rem; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.brand.big { font-size: 2rem; text-align: center; margin-bottom: 1rem; }
.topnav { display: none; gap: .25rem; flex: 1; }
.topnav a { padding: .4rem .75rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; }
.topnav a.active { background: var(--accent-soft); color: var(--text); }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; }
.person-select { margin-left: auto; width: auto; min-height: 36px; padding: .3rem .5rem; }
.gear { font-size: 1.45rem; line-height: 1; text-decoration: none; color: var(--muted); padding: .25rem .35rem; }
.gear.active { color: var(--accent); }

.content { max-width: 880px; margin: 0 auto; padding: 1rem 1rem calc(84px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .45rem 0 .5rem; font-size: .72rem; font-weight: 600;
  color: var(--muted); text-decoration: none;
}
.tabbar a.active { color: var(--accent); }
.tabbar .ti { font-size: 1.15rem; line-height: 1; }

@media (min-width: 760px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  .content { padding-bottom: 2rem; }
  .who, .person-select { margin-left: 0; }
  .gear { display: none; }
}

.banner {
  position: sticky; top: 0; z-index: 20;
  background: var(--warn-bg); padding: .6rem 1rem; text-align: center; font-size: .9rem;
}
.splash { min-height: 60vh; display: grid; place-items: center; gap: 1rem; text-align: center; }
.spinner {
  width: 32px; height: 32px; margin: 2rem auto;
  border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.card.tight { padding: .75rem 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.alert { background: var(--err-bg); color: var(--err); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.pill { font-size: .8rem; font-weight: 700; padding: .15rem .55rem; border-radius: 99px; background: var(--bg); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.grid2, .grid3 { display: grid; gap: 0 .75rem; grid-template-columns: 1fr; }
.grid2 > *, .grid3 > * { min-width: 0; }
.grid3 { grid-template-columns: 1fr 1fr; }
@media (min-width: 520px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-actions { display: inline-flex; gap: .25rem; margin-left: auto; }
.plain { list-style: none; padding: 0; margin: 0 0 .5rem; }
.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 380px; }

/* ---------- today ---------- */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.day-title { text-align: center; }

.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 519px) { .steppers { grid-template-columns: 1fr; } }   /* phones: one big stepper per row */
.stepper label { text-align: center; margin-bottom: .3rem; font-weight: 600; }
.stepper-row {
  display: grid; grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg);
}
@media (max-width: 519px) { .stepper-row { grid-template-columns: 72px minmax(0, 1fr) 72px; } }
.stepper input {
  border: 0; border-radius: 0; background: transparent; text-align: center; width: 100%;
  font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; padding: .3rem 0; min-height: 68px;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; background: var(--accent-soft); }
.step {
  border: 0; background: var(--surface); font-size: 1.9rem; font-weight: 600; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.step:active { background: var(--accent-soft); }
.stepper.sys input { color: var(--sys); }
.stepper.dia input { color: var(--dia); }
.reading-form > .stepper.pulse { max-width: 340px; margin: 0 auto .75rem; }

.when-summary {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem; width: 100%;
  margin-top: .9rem; padding: .7rem .9rem; min-height: 48px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; text-align: left;
}
.grid3.when { margin-top: .9rem; }
.when-actions { display: flex; justify-content: flex-end; gap: 1.25rem; margin-top: -.25rem; }
.extras { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: .6rem 0; min-height: 44px; }
.extras .check { margin: 0; }
.notes { margin-top: .25rem; }
.reading-form .actions { margin-top: .5rem; }
.reading-form .actions .btn.primary { min-height: 52px; font-size: 1.05rem; }
.card.done { opacity: .8; }

.dose { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.dose:first-of-type { border-top: 0; }
.dose-info { flex: 1; min-width: 0; }
.dose-name { font-weight: 650; }
.dose-actions { display: flex; flex-direction: column; gap: .3rem; align-items: stretch; }
.dose.taken .dose-name::before { content: "\2713  "; color: var(--ok); }
.dose.taken .status { color: var(--ok); }
.dose.skipped .dose-name { text-decoration: line-through; color: var(--muted); }

.readings { list-style: none; margin: 0; padding: 0; }
.readings li { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.readings li:first-child { border-top: 0; }
.readings li.editing { display: block; }
.readings .time { width: 4.6rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.readings .bp { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; padding-left: .55rem; border-left: 4px solid currentColor; }
.readings .bp { color: var(--text); }
.readings .note { flex-basis: 100%; padding-left: 5.35rem; font-size: .9rem; color: var(--muted); }
.date-h { font-size: .95rem; color: var(--muted); }
.bp.c-normal { border-left-color: var(--c-normal) !important; }
.bp.c-elevated { border-left-color: var(--c-elevated) !important; }
.bp.c-stage1 { border-left-color: var(--c-stage1) !important; }
.bp.c-stage2 { border-left-color: var(--c-stage2) !important; }
.bp.c-severe { border-left-color: var(--c-severe) !important; }

/* ---------- stats ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: .45rem .8rem; min-height: 40px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.range { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; margin-bottom: 1rem; }
.range-custom { display: flex; gap: .5rem; }
.range-custom label { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; display: flex; flex-direction: column; }
.tile .lbl { font-size: .8rem; color: var(--muted); }
.tile .val { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.chart { margin: 0; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: .7; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .sys { fill: none; stroke: var(--sys); stroke-width: 2; }
.chart .dia { fill: none; stroke: var(--dia); stroke-width: 2; }
.chart .sys-dot { fill: var(--sys); }
.chart .dia-dot { fill: var(--dia); }
.chart figcaption { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; font-size: .8rem; color: var(--muted); margin-top: .4rem; }
.key { display: inline-block; width: 14px; height: 3px; margin-right: -.6rem; vertical-align: middle; }
.sys-key { background: var(--sys); } .dia-key { background: var(--dia); }
.ref-key { border-top: 2px dashed var(--muted); height: 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data td:last-child { white-space: normal; }
table.data th { font-size: .78rem; color: var(--muted); font-weight: 650; }
table.data .n { text-align: right; }
table.data tr.strong td { font-weight: 700; }
table.data.compact td, table.data.compact th { padding: .25rem .4rem; }

.cats { display: grid; gap: .45rem; }
.cat-row { display: grid; grid-template-columns: minmax(9rem, 13rem) 1fr auto; gap: .6rem; align-items: center; font-size: .88rem; }
.cat-bar { height: 12px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.cat-fill { display: block; height: 100%; border-radius: 99px; }
.cat-fill.c-normal { background: var(--c-normal); }
.cat-fill.c-elevated { background: var(--c-elevated); }
.cat-fill.c-stage1 { background: var(--c-stage1); }
.cat-fill.c-stage2 { background: var(--c-stage2); }
.cat-fill.c-severe { background: var(--c-severe); }
.cat-val { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- settings ---------- */
.regimen { display: flex; gap: .75rem; align-items: flex-start; padding: .7rem 0; border-top: 1px solid var(--line); }
.regimen.ended { opacity: .55; }
.regimen-form { border-top: 1px solid var(--line); margin-top: .75rem; padding-top: .5rem; }
.slot-pick { display: flex; align-items: center; gap: 1rem; min-height: 48px; }
.slot-pick .check { margin: 0; min-width: 7rem; }
.slot-pick .qty { display: flex; align-items: center; gap: .5rem; margin: 0; }
.slot-pick .qty input { width: 5rem; margin: 0; }

/* ---------- report ---------- */
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.report section { margin-top: 1.25rem; }
.report h2 { font-size: 1rem; border-bottom: 2px solid var(--text); padding-bottom: .2rem; }
.report-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.report-head .big { font-size: 1.3rem; font-weight: 700; }
.report-head .right { text-align: right; }
.report footer { margin-top: 1.5rem; }

#blazor-error-ui {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--warn-bg); padding: .75rem 1rem;
}

/* ---------- print ---------- */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --line: #bbb;
    --sys: #c00; --dia: #0040c0;
  }
  @page { margin: 14mm; }
  body { font-size: 11pt; background: #fff; }
  .no-print, .topbar, .tabbar, .banner, #blazor-error-ui { display: none !important; }
  .content { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; }
  .report section { margin-top: 12pt; }
  .avoid-break, table.data tr, .tile { break-inside: avoid; }
  .table-wrap { overflow: visible; }
  table.data { font-size: 9.5pt; }
  .tiles.print-tiles { grid-template-columns: repeat(4, 1fr); }
  .tile { border: 1px solid #bbb; padding: 6pt 8pt; }
  .tile .val { font-size: 15pt; }
  .chart svg { max-height: 220px; }
  .cat-bar, .cat-fill, .key { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
}
