/* CareClock styles
   Design system: tokens follow the U.S. Web Design System (USWDS, public domain) color/spacing scale and
   NHS digital service patterns for older users. Public Sans typeface (SIL OFL 1.1), self-hosted.
   Rules for older eyes and hands: base text 18-25px (user setting), WCAG 2.2 AA contrast or better,
   44px+ touch targets, status = icon + word (never color alone), visible focus, no motion if reduced. */

@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/public-sans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/public-sans-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/public-sans-vietnamese.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

:root {
  color-scheme: light;
  /* USWDS-derived palette */
  --ink: #1b1b1b;
  --ink-2: #3d4551;
  --ink-3: #565c65;
  --bg: #ffffff;
  --bg-2: #f0f0f0;
  --bg-3: #e6e6e6;
  --line: #dfe1e2;
  --line-2: #a9aeb1;
  --brand: #005ea2;
  --brand-dark: #1a4480;
  --brand-darker: #162e51;
  --brand-light: #d9e8f6;
  --brand-ink: #ffffff;
  --link: #005ea2;
  --focus: #2491ff;
  --ok: #00a91c;
  --ok-dark: #008817;
  --ok-text: #216e1f;
  --ok-bg: #ecf3ec;
  --warn: #ffbe2e;
  --warn-dark: #e5a000;
  --warn-text: #6b4e00;
  --warn-bg: #faf3d1;
  --bad: #d54309;
  --bad-dark: #b50909;
  --bad-text: #b50909;
  --bad-bg: #f4e3db;
  --info: #00bde3;
  --info-bg: #e7f6f8;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #a9aeb1;
  --appbar: #162e51;
  --appbar-ink: #ffffff;
  --r: 4px;
  --r-lg: 8px;
  --nav-h: 4.1rem;
  font-size: 21px;
}
:root[data-size='m'] { font-size: 18px; }
:root[data-size='l'] { font-size: 21px; }
:root[data-size='xl'] { font-size: 25px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='contrast']) {
    color-scheme: dark;
    --ink: #f0f0f0; --ink-2: #dfe1e2; --ink-3: #c6cace;
    --bg: #121416; --bg-2: #1c1f23; --bg-3: #262a2f;
    --line: #33383e; --line-2: #6f757b;
    --brand: #73b3e7; --brand-dark: #4f97d1; --brand-darker: #0b1a2e; --brand-light: #13304f; --brand-ink: #0b1220; --link: #8cc3ef;
    --ok-text: #70e17b; --ok-bg: #10291a; --warn-text: #ffd479; --warn-bg: #2e2508; --bad-text: #ff8d7b; --bad-bg: #331811; --info-bg: #0d2a30;
    --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c2a; --axis: #4a4f55;
    --appbar: #0b1a2e;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --ink: #f0f0f0; --ink-2: #dfe1e2; --ink-3: #c6cace;
  --bg: #121416; --bg-2: #1c1f23; --bg-3: #262a2f;
  --line: #33383e; --line-2: #6f757b;
  --brand: #73b3e7; --brand-dark: #4f97d1; --brand-darker: #0b1a2e; --brand-light: #13304f; --brand-ink: #0b1220; --link: #8cc3ef;
  --ok-text: #70e17b; --ok-bg: #10291a; --warn-text: #ffd479; --warn-bg: #2e2508; --bad-text: #ff8d7b; --bad-bg: #331811; --info-bg: #0d2a30;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c2a; --axis: #4a4f55;
  --appbar: #0b1a2e;
}
/* high contrast for low vision: black, white, yellow; thick outlines */
:root[data-theme='contrast'] {
  color-scheme: dark;
  --ink: #fff; --ink-2: #fff; --ink-3: #fff;
  --bg: #000; --bg-2: #000; --bg-3: #000;
  --line: #fff; --line-2: #fff;
  --brand: #ffe000; --brand-dark: #ffe000; --brand-darker: #000; --brand-light: #000; --brand-ink: #000; --link: #ffe000;
  --focus: #ffe000;
  --ok-text: #7dff8a; --ok-bg: #000; --warn-text: #ffe000; --warn-bg: #000; --bad-text: #ff8d7b; --bad-bg: #000; --info-bg: #000;
  --series-1: #ffe000; --series-2: #00e5ff; --grid: #555; --axis: #fff;
  --appbar: #000;
}
:root[data-theme='contrast'] .appbar { border-bottom: 2px solid #fff; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', 'PingFang SC', 'Microsoft YaHei', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1.5rem);
}
body.is-locked { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
main { max-width: 42rem; margin: 0 auto; padding: 1.25rem 16px 1rem; outline: none; overflow-wrap: break-word; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.5rem; }
a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 0.5rem; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.center-v { align-items: center; }
.stack { display: grid; gap: 0.5rem; margin: 0.75rem 0; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; z-index: 50; background: var(--brand); color: var(--brand-ink); padding: 0.5rem 1rem; font-weight: 700; }
.skip:focus { left: 0; }
:focus-visible { outline: 0.25rem solid var(--focus); outline-offset: 0; }
h1[tabindex='-1']:focus { outline: none; }
.ico { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.22em; }
.ico.big { width: 3rem; height: 3rem; }
.good { color: var(--ok-text); }
.warn-text { color: var(--warn-text); font-weight: 600; }

/* ---------- app bar ---------- */
.appbar { background: var(--appbar); color: var(--appbar-ink); position: sticky; top: 0; z-index: 15; padding-top: env(safe-area-inset-top); }
.appbar-inner { max-width: 42rem; margin: 0 auto; padding: 0 16px; min-height: 3.1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: 0.55rem; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand img { width: 1.6rem; height: 1.6rem; border-radius: 6px; }
.appbar-clock { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.05rem; }

/* ---------- buttons (USWDS-style) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  min-height: 2.75rem; padding: 0.55rem 1.1rem;
  font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.15; text-align: center; text-decoration: none;
  color: var(--brand); background: var(--bg); border: 2px solid var(--brand); border-radius: var(--r);
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:hover { color: var(--brand-dark); border-color: var(--brand-dark); background: var(--brand-light); }
.btn:active { background: var(--bg-3); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--brand-ink); }
.btn.danger { color: var(--bad-text); border-color: var(--bad-text); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.big { min-height: 3.25rem; width: 100%; font-size: 1.05rem; }
.btn.sm { min-height: 2.5rem; padding: 0.35rem 0.8rem; font-size: 0.9rem; }
.btn.icon { width: 2.75rem; padding: 0; }
.btn.icon.sm { width: 2.5rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-2); border-color: transparent; }
.btn.take { min-height: 3.25rem; font-size: 1.1rem; padding-inline: 1.4rem; }
.btn.listening { background: var(--bad-bg); }
.help-btn { width: 100%; min-height: 3.4rem; margin-top: 2rem; color: var(--bad-text); border-color: var(--bad-text); font-size: 1.1rem; }
.help-btn:hover { background: var(--bad-bg); color: var(--bad-text); border-color: var(--bad-text); }

/* ---------- containers ---------- */
.card { display: block; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 1rem; margin: 0 0 1rem; color: inherit; }
a.card { text-decoration: none; }
a.card:hover { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin: 0.25rem 0 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--line); }
.page-head h1 { margin: 0; }
.hello { margin: 0.25rem 0 1.25rem; }
.hello h1 { font-size: 1.9rem; margin-bottom: 0.2rem; }
.date { color: var(--ink-3); font-size: 1.05rem; margin: 0; }

/* alerts: USWDS pattern, thick left rule + tinted background */
.banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem 0.75rem;
  padding: 0.85rem 1rem; margin: 0 0 0.75rem; border-left: 0.5rem solid; border-radius: 0;
  font-weight: 600; color: var(--ink); text-decoration: none; background: var(--bg-2);
}
.banner > span { min-width: 0; }
.banner > .btn { grid-column: 2 / -1; justify-self: start; }
@media (min-width: 40rem) { .banner > .btn { grid-column: auto; } }
.banner > .ico:first-child { width: 1.5rem; height: 1.5rem; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); }
.banner.warn > .ico:first-child { color: var(--warn-text); }
.banner.info { background: var(--info-bg); border-color: var(--info); }
.banner.bad { background: var(--bad-bg); border-color: var(--bad); }
.banner.bad > .ico:first-child { color: var(--bad-text); }
a.banner:hover > span { text-decoration: underline; }

/* today summary */
.summary { margin: 0 0 1.5rem; padding: 1rem 0 0; border-top: 1px solid var(--line); }
.summary-count { font-size: 1.15rem; margin-bottom: 0.6rem; }
.summary-count strong { font-size: 2.4rem; line-height: 1; margin-right: 0.15rem; }
.segbar { display: flex; gap: 3px; height: 0.9rem; }
.segbar span { flex: 1 1 0; min-width: 0; border-radius: 2px; background: var(--bg-3); border: 1px solid var(--line-2); }
.segbar.dense { gap: 1px; }
.segbar.dense span { border: 0; border-radius: 0; }
.segbar .s-taken, .sw.s-taken { background: var(--ok); border-color: var(--ok-dark); }
.segbar .s-skipped, .sw.s-skipped { background: var(--line-2); border-color: var(--ink-3); }
.segbar .s-due, .sw.s-due { background: var(--warn); border-color: var(--warn-dark); }
.segbar .s-late, .sw.s-late, .segbar .s-missed { background: var(--bad); border-color: var(--bad-dark); }
.segbar-legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin: 0.5rem 0 0; font-size: 0.875rem; color: var(--ink-2); }
.sw { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; border: 1px solid var(--line-2); background: var(--bg-3); margin-right: 0.35rem; vertical-align: -0.05rem; }
.summary-line { margin: 0.75rem 0 0; font-weight: 700; font-size: 1.1rem; display: flex; gap: 0.5rem; align-items: flex-start; }
.summary-line > .ico { margin-top: 0.15em; }
.summary-line .muted { font-weight: 600; white-space: nowrap; }

/* ---------- dose schedule ---------- */
.period-group { margin-bottom: 1.5rem; }
.period { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.5rem; font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.dose-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden; }
.dose {
  display: grid; grid-template-columns: 1fr; gap: 0.6rem;
  padding: 0.9rem 1rem 1rem; border-left: 0.4rem solid transparent; background: var(--bg);
}
.dose + .dose { border-top: 1px solid var(--line); }
.dose.s-taken { border-left-color: var(--ok); }
.dose.s-skipped { border-left-color: var(--line-2); }
.dose.s-due { border-left-color: var(--warn); background: var(--warn-bg); }
.dose.s-late { border-left-color: var(--bad); background: var(--bad-bg); }
.dose.s-taken .pill-art, .dose.s-skipped .pill-art { opacity: 0.6; }
.dose.s-taken .dose-name, .dose.s-skipped .dose-name { color: var(--ink-3); }
.dose-when { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.dose-time { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.dose-last { color: var(--ink-3); font-size: 0.9rem; }
.dose-what { display: flex; gap: 0.9rem; align-items: flex-start; }
.dose-name { font-size: 1.35rem; margin: 0 0 0.15rem; }
.dose-strength { font-weight: 500; color: var(--ink-3); }
.dose-amt { margin: 0; display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.dose-note { margin: 0.35rem 0 0; color: var(--ink-2); font-size: 0.95rem; }
.dose-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.dose-actions .take { flex: 1; }
@media (min-width: 40rem) {
  .dose { grid-template-columns: 7.5rem 1fr auto; align-items: center; gap: 1rem; }
  .dose-when { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  .dose-actions { flex-direction: column; align-items: stretch; min-width: 8.5rem; }
}
.pill-art { display: block; flex: none; border-radius: var(--r-lg); object-fit: cover; }

.status { display: inline-flex; align-items: center; gap: 0.3em; padding: 0.1rem 0.5rem; border-radius: 2px; font-size: 0.85rem; font-weight: 700; white-space: nowrap; border: 1px solid; }
.status .ico { width: 1em; height: 1em; }
.status.s-taken { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-dark); }
.status.s-due { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-dark); }
.status.s-late, .status.s-missed { background: var(--bad-bg); color: var(--bad-text); border-color: var(--bad); }
.status.s-skipped, .status.s-upcoming { background: var(--bg-2); color: var(--ink-2); border-color: var(--line-2); }
.chip { display: inline-flex; align-items: center; gap: 0.3em; padding: 0.05rem 0.5rem; border-radius: 2px; background: var(--bg-2); border: 1px solid var(--line); font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }

.empty { padding: 2rem 0; }
.empty .ico.big { color: var(--brand); margin-bottom: 0.75rem; }
.empty p { color: var(--ink-2); max-width: 30em; margin: 0 0 1.25rem; }
.empty .row { justify-content: flex-start; }

/* ---------- medicines ---------- */
.med-card { display: flex; gap: 1rem; align-items: center; }
.med-card h3 { margin-bottom: 0.15rem; font-size: 1.2rem; }
.med-card p { margin: 0; }
.med-card > .ico:last-child { color: var(--ink-3); }
.safety h2 { display: flex; align-items: center; gap: 0.45rem; }
.finding { border-left: 0.5rem solid var(--warn); background: var(--warn-bg); padding: 0.85rem 1rem; margin: 0.85rem 0; }
.finding.strong { border-color: var(--bad); background: var(--bad-bg); }
.finding-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.finding blockquote { margin: 0.5rem 0; padding: 0.6rem 0.8rem; background: var(--bg); border: 1px solid var(--line); font-size: 0.92rem; color: var(--ink-2); }
.flags { padding-left: 1.2em; }
.flags li { margin-bottom: 0.4rem; }
.disclaimer { color: var(--ink-2); font-size: 0.875rem; margin: 1rem 0 0; display: flex; gap: 0.45rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.checking { display: flex; gap: 0.45rem; align-items: center; font-weight: 700; }
.checking .ico { animation: pulse 1s infinite alternate; }
.fda-box { display: flex; gap: 0.7rem; padding: 0.8rem 1rem; margin: 0.75rem 0 0; border-left: 0.5rem solid var(--info); background: var(--info-bg); }
.fda-box p { margin: 0.3rem 0 0; }
.scan-btn { margin-top: 0.5rem; padding-left: 0; }
.prn-warn { margin: 0; white-space: normal; }
.dlg-head { display: flex; gap: 0.85rem; align-items: center; margin-bottom: 0.5rem; }
.dlg-head h2 { margin-bottom: 0.15rem; }
.dlg-head p { margin: 0; }
.fda-box.muted { border-color: var(--line-2); background: var(--bg-2); }

/* ---------- forms ---------- */
fieldset.card { border: 1px solid var(--line-2); }
legend { font-weight: 700; font-size: 1.15rem; padding: 0 0.35rem; }
label, .label { display: block; font-weight: 600; margin: 1rem 0 0.35rem; }
input, select, textarea {
  font: inherit; font-size: 1rem; width: 100%; min-height: 2.75rem; padding: 0.5rem 0.7rem;
  color: var(--ink); background: var(--bg); border: 2px solid var(--ink-3); border-radius: 0;
}
input:focus, select:focus, textarea:focus { outline: 0.25rem solid var(--focus); outline-offset: 0; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
.row > input { width: auto; }
.row input.grow { width: 100%; min-width: 0; flex: 1 1 10rem; }
.row label input { width: 100%; }
.grid2, .grid3 { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 30rem) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.time-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.time-row input { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0; }
.swatch { margin: 0; position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; cursor: pointer; }
.swatch::before { content: ''; display: block; width: 2.6rem; height: 2.6rem; border-radius: 50%; background: var(--c); border: 2px solid var(--ink-3); }
.swatch:has(input:checked)::before { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--brand); }
.swatch:has(input:focus-visible)::before { outline: 0.25rem solid var(--focus); outline-offset: 6px; }
/* segmented choice (radio tiles) */
.seg { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.seg label { margin: 0; flex: 1; position: relative; }
.seg label input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.seg label span, .seg > button {
  display: flex; align-items: center; justify-content: center; gap: 0.45em; min-height: 2.75rem; padding: 0.35rem 0.8rem;
  border: 2px solid var(--line-2); border-radius: var(--r); background: var(--bg); font: inherit; font-weight: 700; color: var(--ink); cursor: pointer; text-align: center;
}
.seg > button { flex: 1; }
.seg label input:checked + span, .seg > button[aria-selected='true'] { background: var(--brand-light); border-color: var(--brand); color: var(--ink); box-shadow: inset 0 0 0 1px var(--brand); }
.seg label input:focus-visible + span { outline: 0.25rem solid var(--focus); }
.tabs { border-bottom: 1px solid var(--line); padding-bottom: 0.75rem; }
.big-tabs > button { min-height: 3rem; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.35rem; }
.day { margin: 0; position: relative; }
.day input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.day span { display: flex; align-items: center; justify-content: center; min-height: 2.75rem; border: 2px solid var(--line-2); border-radius: var(--r); font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.day input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.day input:focus-visible + span { outline: 0.25rem solid var(--focus); }
.form-error { color: var(--bad-text); font-weight: 700; padding: 0.75rem 1rem; border-left: 0.5rem solid var(--bad); background: var(--bad-bg); }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--bg); padding: 0.75rem 0; z-index: 2; border-top: 1px solid var(--line); }
.sticky-actions .btn.big { width: auto; }
@media (max-height: 720px) { .sticky-actions { position: static; border-top: 0; } }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.check { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0; font-weight: 500; }
.check input { width: 1.6rem; height: 1.6rem; min-height: 0; flex: none; margin-top: 0.05em; accent-color: var(--brand); }

/* option tiles (language, size, theme) */
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.5rem; margin: 0.75rem 0; }
.choices.big { grid-template-columns: repeat(auto-fill, minmax(min(10rem, 45%), 1fr)); margin: 1rem 0 1.5rem; }
.choice {
  display: flex; align-items: center; gap: 0.6rem; min-height: 3rem; padding: 0.5rem 0.8rem; text-align: left;
  font: inherit; font-weight: 600; color: var(--ink); background: var(--bg); border: 2px solid var(--line-2); border-radius: var(--r); cursor: pointer;
}
.choice::before { content: ''; flex: none; width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 2px solid var(--ink-3); background: var(--bg); }
.choice.on { border-color: var(--brand); background: var(--brand-light); }
.choice.on::before { border-color: var(--brand); background: var(--brand); box-shadow: inset 0 0 0 3px var(--bg); }
.choices.big .choice { min-height: 3.5rem; font-size: 1.1rem; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0; padding: 0.75rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle > span { display: grid; gap: 0.1rem; }
.toggle input[role='switch'] {
  appearance: none; -webkit-appearance: none; width: 3.3rem; height: 1.9rem; min-height: 0; padding: 0; flex: none;
  border-radius: 99px; background: var(--bg-3); border: 2px solid var(--ink-3); position: relative; cursor: pointer;
}
.toggle input[role='switch']::after { content: ''; position: absolute; top: 2px; left: 2px; width: 1.35rem; height: 1.35rem; border-radius: 50%; background: var(--ink-3); transition: transform 0.15s; }
.toggle input[role='switch']:checked { background: var(--brand); border-color: var(--brand); }
.toggle input[role='switch']:checked::after { transform: translateX(1.4rem); background: var(--brand-ink); }

.link-list { border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden; margin-bottom: 1.25rem; }
.link-row { display: flex; align-items: center; gap: 1rem; padding: 1rem; color: var(--ink); text-decoration: none; background: var(--bg); width: 100%; border: 0; font: inherit; text-align: left; cursor: pointer; }
.link-row + .link-row { border-top: 1px solid var(--line); }
.link-row:hover { background: var(--bg-2); }
.link-row:hover strong { text-decoration: underline; }
.link-row > .ico:first-child { width: 1.5rem; height: 1.5rem; color: var(--brand); }
.link-row > .ico:last-child { color: var(--ink-3); }
.link-row .grow { display: grid; }

/* ---------- history ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 1.25rem; border: 1px solid var(--line-2); border-radius: var(--r-lg); overflow: hidden; }
.tile { padding: 0.85rem 1rem; }
.tile + .tile { border-left: 1px solid var(--line); }
.tile-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-2); margin: 0; }
.tile-value { font-size: 2.1rem; font-weight: 800; margin: 0.15rem 0 0; line-height: 1.05; letter-spacing: -0.02em; white-space: nowrap; }
.tile-sub { font-size: 0.8rem; color: var(--ink-3); margin: 0.25rem 0 0; }
@media (max-width: 26rem) { .tile-value { font-size: 1.45rem; } .tile { padding: 0.65rem; } .tile-label { font-size: 0.78rem; } }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.3rem; max-width: 26rem; }
.cal-h { text-align: center; font-size: 0.75rem; font-weight: 700; color: var(--ink-2); }
.cal {
  aspect-ratio: 1; min-width: 0; min-height: 0; overflow: hidden; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15em; padding: 0;
  border-radius: var(--r); border: 1px solid var(--line); background: var(--bg-2); font: inherit; font-size: 0.85rem; font-weight: 700; color: var(--ink); cursor: pointer;
}
.cal .ico { width: 0.8em; height: 0.8em; }
.cal.b-full { background: var(--ok-bg); border-color: var(--ok); }
.cal.b-full .ico { color: var(--ok-text); }
.cal.b-most { background: var(--warn-bg); border-color: var(--warn-dark); }
.cal.b-most .ico { color: var(--warn-text); }
.cal.b-low { background: var(--bad-bg); border-color: var(--bad); }
.cal.b-low .ico { color: var(--bad-text); }
.cal.sel { outline: 0.2rem solid var(--ink); outline-offset: 1px; }
.cal.mini { width: 1.6em; display: inline-flex; vertical-align: middle; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; margin-top: 0.75rem; font-size: 0.875rem; color: var(--ink-2); }
.leg { display: inline-flex; align-items: center; gap: 0.4em; }
.key { display: inline-block; width: 1.4em; height: 3px; border-radius: 2px; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.key.band { height: 0.9em; width: 0.9em; background: var(--ok-bg); border: 1px solid var(--ok); }
.day-list, .per-med, .qs { list-style: none; margin: 0; padding: 0; }
.day-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.4rem 0.75rem; padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
.day-list .dl-main { min-width: 0; }
.day-list .fix { grid-column: 1 / -1; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.per-med li { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.pm-pct { font-weight: 700; min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
.meter { display: block; height: 0.6rem; background: var(--bg-3); border-radius: 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); }
.meter.thin { width: 30%; min-width: 4rem; }
.meter.b-full > span { background: var(--ok); }
.meter.b-most > span { background: var(--warn); }
.meter.b-low > span { background: var(--bad); }
.share-preview { white-space: pre-wrap; font: inherit; font-size: 0.9rem; background: var(--bg-2); padding: 0.8rem; border-left: 0.3rem solid var(--line-2); }

/* ---------- charts ---------- */
.chart { position: relative; margin: 0.75rem 0; max-width: 34rem; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis { stroke: var(--axis); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .tick { fill: var(--ink-2); font-size: 0.64rem; font-variant-numeric: tabular-nums; font-family: inherit; }
.chart .end-label { fill: var(--ink); font-size: 0.68rem; font-weight: 700; font-family: inherit; }
.chart .bar { fill: var(--series-1); }
.chart .bar-zero { fill: var(--bad); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart .dot.s1 { fill: var(--series-1); }
.chart .dot.s2 { fill: var(--series-2); }
.chart .band { fill: var(--ok-bg); }
.chart .hit { fill: transparent; cursor: crosshair; outline: none; }
.chart .hit:focus-visible { fill: var(--brand-light); opacity: 0.6; }
.chart .xhair { stroke: var(--ink-2); stroke-width: 1; vector-effect: non-scaling-stroke; opacity: 0; pointer-events: none; }
.chart .xhair.on { opacity: 0.6; }
.chart .tip { position: absolute; top: -0.5rem; background: var(--ink); color: var(--bg); padding: 0.3rem 0.65rem; border-radius: var(--r); font-size: 0.85rem; font-weight: 600; pointer-events: none; white-space: nowrap; z-index: 3; }

.latest { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; font-size: 1.05rem; }
.table { width: 100%; border-collapse: collapse; margin-top: 0.85rem; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 0.5rem 0.45rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 0.8rem; color: var(--ink-2); border-bottom: 2px solid var(--ink-3); }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.table-wrap:focus-visible { outline-offset: 2px; }
@media (max-width: 34rem) {
  .table.stack-sm thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.stack-sm tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.3rem 0.75rem; padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
  .table.stack-sm td { border: 0; padding: 0; min-width: 0; }
  .table.stack-sm .status { white-space: normal; }
  .table.stack-sm td:last-child { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
  .table.stack-sm td.num { font-size: 1.05rem; font-weight: 700; }
}
.appt { display: flex; gap: 1rem; }
.appt-date { display: grid; place-items: center; align-content: center; min-width: 3.6rem; height: 3.8rem; border: 2px solid var(--brand); border-radius: var(--r); color: var(--brand); text-transform: uppercase; font-size: 0.75rem; font-weight: 800; }
.appt-date strong { font-size: 1.45rem; line-height: 1; color: var(--ink); }
.qs li { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.qs li .check { flex: 1; }
.qs li.done span { text-decoration: line-through; color: var(--ink-3); }

/* ---------- emergency card + report ---------- */
.ice-card { background: var(--bg); border: 3px solid var(--bad-dark); border-radius: var(--r-lg); overflow: hidden; margin-bottom: 1rem; padding-bottom: 0.85rem; }
.ice-card h3, .ice-card ul { margin-left: 1rem; margin-right: 1rem; }
.ice-card h3 { margin-top: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.9rem; color: var(--ink-2); }
.ice-head { background: var(--bad-dark); color: #fff; padding: 0.6rem 1rem; font-weight: 800; letter-spacing: 0.06em; display: flex; gap: 0.5em; align-items: center; text-transform: uppercase; }
.ice-body { display: flex; gap: 1rem; padding: 1rem; flex-wrap: wrap; }
.ice-info { flex: 1; min-width: 12rem; }
.ice-info h2 { font-size: 1.55rem; }
.ice-info dl { margin: 0; }
.kv { display: grid; grid-template-columns: 8em minmax(0, 1fr); gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
@media (max-width: 30rem) { .kv { grid-template-columns: minmax(0, 1fr); gap: 0; } }
.kv dt { font-weight: 700; color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; }
.ice-qr { margin: 0; text-align: center; width: 10rem; }
.ice-qr svg { width: 100%; height: auto; background: #fff; padding: 2px; border: 1px solid var(--line); }
.ice-qr figcaption { font-size: 0.8rem; color: var(--ink-2); margin-top: 0.3rem; }
.ice-meds { padding-left: 1.2em; }
.ice-meds li { margin-bottom: 0.3rem; }
.report { background: var(--bg); border: 1px solid var(--line-2); padding: 1.25rem; }
.report header { border-bottom: 3px solid var(--ink); margin-bottom: 1rem; padding-bottom: 0.6rem; }
.report h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; }
.report section { margin-bottom: 1.25rem; }
.big-num { font-size: 2.4rem; font-weight: 800; margin: 0; }
.cols { columns: 2 14em; padding-left: 1.2em; }
.plain { list-style: none; padding: 0; }

/* ---------- legal pages ---------- */
.legal { max-width: 38rem; }
.legal h2 { margin-top: 1.75rem; font-size: 1.2rem; }
.legal h3 { margin-top: 1.1rem; font-size: 1.02rem; }
.legal ul { padding-left: 1.25rem; }
.legal li { margin-bottom: 0.35rem; }
.legal .updated { color: var(--ink-3); font-size: 0.9rem; }
.legal .summary-box { background: var(--brand-light); border-left: 0.5rem solid var(--brand); padding: 0.85rem 1rem; margin: 1rem 0; }
.legal .summary-box ul { margin: 0.25rem 0 0; }
.legal table { border-collapse: collapse; width: 100%; font-size: 0.9rem; margin: 0.75rem 0; }
.legal th, .legal td { border: 1px solid var(--line-2); padding: 0.45rem 0.55rem; text-align: left; vertical-align: top; }
.lang-note { background: var(--bg-2); border-left: 0.3rem solid var(--line-2); padding: 0.6rem 0.85rem; font-size: 0.9rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin: 2rem 0 0; padding-top: 1rem; border-top: 1px solid var(--line); font-size: 0.9rem; }

/* ---------- dialog / toast / nav ---------- */
dialog {
  width: min(34rem, calc(100% - 2rem)); max-height: calc(100% - 2rem); overflow: auto;
  border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 1.5rem 1.25rem 1.25rem; background: var(--bg); color: var(--ink);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.small { width: min(26rem, calc(100% - 2rem)); }
dialog h2 { padding-right: 2.75rem; }
.dialog-x { position: absolute; top: 0.6rem; right: 0.6rem; width: 2.75rem; height: 2.75rem; border: none; background: transparent; color: var(--ink); cursor: pointer; display: grid; place-items: center; border-radius: var(--r); }
.dialog-x:hover { background: var(--bg-2); }
:root[data-theme='contrast'] dialog { border: 3px solid #fff; }
dialog.alert { border-top: 0.5rem solid var(--warn); }
.alert-head { text-align: center; margin-bottom: 0.85rem; }
.alert-head h2 { padding: 0; font-size: 1.55rem; margin-top: 0.45rem; }
.alert-head .ico { color: var(--warn-text); }
.ring { animation: ring 1.2s ease-in-out infinite; transform-origin: 50% 10%; }
.alert-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0.6rem 0.85rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.alert-row > .btn, .alert-row > .status { grid-column: 1 / -1; }
.alert-row > .btn { width: 100%; min-height: 3.1rem; }
@media (min-width: 36rem) {
  .alert-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .alert-row > .btn, .alert-row > .status { grid-column: auto; width: auto; }
}

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 0.75rem);
  width: max-content; max-width: calc(100% - 2rem); display: flex; align-items: center; gap: 0.85rem;
  background: var(--ink); color: var(--bg); padding: 0.75rem 1rem; border-radius: var(--r); font-weight: 600; z-index: 20; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
#toast[hidden] { display: none; }
#toast .btn { color: var(--bg); border-color: currentColor; background: transparent; min-height: 2.2rem; }

#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--bg); border-top: 1px solid var(--line-2); padding-bottom: env(safe-area-inset-bottom); }
#nav:empty { display: none; }
#nav ul { display: flex; list-style: none; margin: 0 auto; padding: 0; max-width: 42rem; }
#nav li { flex: 1; }
#nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; min-height: var(--nav-h); color: var(--ink-2); text-decoration: none; font-size: 0.72rem; font-weight: 700; padding: 0.3rem 0.1rem; text-align: center; }
#nav a .ico { width: 1.55rem; height: 1.55rem; }
#nav a:hover { color: var(--brand); }
#nav a[aria-current='page'] { color: var(--brand); }
#nav a[aria-current='page']::before { content: ''; position: absolute; top: -1px; left: 20%; right: 20%; height: 0.25rem; background: var(--brand); }
.nav-locked { max-width: 42rem; margin: 0 auto; padding: 0.5rem 16px; display: flex; justify-content: center; }

/* ---------- onboarding ---------- */
.onboarding { padding-top: 0.5rem; max-width: 34rem; }
.ob-top { display: flex; min-height: 2.75rem; margin-bottom: 0.5rem; }
.ob-logo { width: 3.5rem; height: 3.5rem; margin: 0.5rem 0 0.75rem; display: block; }
.lead { font-size: 1.15rem; color: var(--ink-2); }
.onboarding input { font-size: 1.25rem; }
.ob-dots { display: flex; gap: 0.35rem; margin-bottom: 1rem; }
.ob-dots span { flex: 1; height: 0.3rem; background: var(--bg-3); }
.ob-dots span.on { background: var(--brand); }
.ob-points { list-style: none; padding: 1rem 0 0; margin-top: 1.5rem; border-top: 1px solid var(--line); }
.ob-points li { display: flex; gap: 0.65rem; padding: 0.45rem 0; color: var(--ink-2); }
.ob-points .ico { color: var(--brand); margin-top: 0.15em; }
.ob-legal { font-size: 0.9rem; color: var(--ink-2); margin-top: 1rem; }
.ob-demo { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.linklike { background: none; border: 0; padding: 0.4rem 0; min-height: 2.75rem; font: inherit; font-weight: 700; color: var(--link); text-decoration: underline; text-underline-offset: 0.15em; cursor: pointer; text-align: left; }
.pin-input { text-align: center; font-size: 1.6rem; letter-spacing: 0.4em; }
.frame-block { max-width: 30rem; margin: 3rem auto; padding: 1.5rem; font-size: 1.1rem; }

@keyframes ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(8deg); } 60% { transform: rotate(0); } }
@keyframes pulse { from { opacity: 0.4; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (forced-colors: active) { .segbar span, .sw, .cal { forced-color-adjust: none; } }

@media print {
  :root { font-size: 11pt; color-scheme: light; --ink: #000; --ink-2: #222; --ink-3: #444; --bg: #fff; --bg-2: #fff; --line: #bbb; --line-2: #888; }
  body { padding: 0; background: #fff; }
  main { max-width: none; padding: 0; }
  .appbar, #nav, #toast, dialog, .no-print, .skip, .help-btn, .footer-links { display: none !important; }
  .card, .report, .ice-card { break-inside: avoid; }
  .report { border: none; padding: 0; }
  .table-wrap { overflow: visible !important; }
  .chart .tip, .chart .xhair { display: none !important; }
  .page-head { border: 0; margin-bottom: 0.5rem; }
  .ice-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
}
