/*
  Design plan
  - One thing per screen: a title, one primary button, everything else is quiet.
  - Grouped lists with hairlines instead of a box around every idea.
  - 60-30-10: pale grey page, white panels, one deep green for actions and the active tab.
  - Status uses words plus a small dot, never colour alone. Status colours are separate from the accent.
  - 17px text, 48px+ touch targets, system fonts (no font CDN: a health app should not tell one who is using it).
*/
:root {
  --bg: #F4F5F6; --surface: #FFFFFF; --ink: #15181B; --muted: #5B636B; --line: #E3E6E9; --field: #767E86;
  --accent: #0B6E5E; --accent-ink: #FFFFFF; --accent-soft: #E3F1EE;
  --good: #1E7B4D; --caution: #9A5806; --caution-soft: #FCEFD9; --alert: #B3261E; --alert-soft: #FBE4E1;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --bar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1113; --surface: #171B1E; --ink: #ECEFF1; --muted: #9AA4AD; --line: #272D32; --field: #7C868F;
    --accent: #4FC3A9; --accent-ink: #08201B; --accent-soft: #14312B;
    --good: #5CD08F; --caution: #F2B14C; --caution-soft: #3A2A10; --alert: #FF9087; --alert-soft: #3C1A17;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 1.0625rem/1.45 var(--font); -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.9rem; line-height: 1.12; letter-spacing: -0.02em; font-weight: 750; text-wrap: balance; }
h2 { font-size: 1.2rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1rem; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
main:focus { outline: none; }
pre { margin: 0; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }

/* frame */
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--bar) + 40px + env(safe-area-inset-bottom)); }
.wrap.signed-out { padding-bottom: 32px; }
.top { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.wordmark { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.03em; }
.iconbtn { display: inline-grid; place-items: center; min-width: 48px; min-height: 48px; border: 0; background: none; color: var(--ink); cursor: pointer; border-radius: 12px; }
.screen { display: flex; flex-direction: column; gap: 28px; padding-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.lede { color: var(--muted); }
.sub { color: var(--muted); font-size: .94rem; }
.small { font-size: .85rem; }

/* tab bar */
nav.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabbar .inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
nav.tabbar button { position: relative; border: 0; background: none; min-height: var(--bar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .75rem; font-weight: 600; cursor: pointer; }
nav.tabbar button[aria-current="page"] { color: var(--accent); }
nav.tabbar button[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* grouped lists */
.group { display: flex; flex-direction: column; gap: 10px; }
.group-title { padding: 0 4px; }
.panel { background: var(--surface); border-radius: 14px; overflow: hidden; }
.panel.pad { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { padding: 14px 16px; min-height: 56px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.rows > li:first-child { border-top: 0; }
.line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.line > :first-child { min-width: 0; overflow-wrap: anywhere; }
.value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-size: 2rem; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
button.rowbtn { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; min-height: 56px; cursor: pointer; }
button.rowbtn:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.rows > li.link-row { padding: 0; }

/* buttons and fields */
.btn { min-height: 48px; padding: 12px 20px; border: 1px solid var(--field); background: var(--surface); border-radius: 12px; font-weight: 650; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.quiet { border-color: transparent; background: none; color: var(--accent); padding-inline: 8px; }
.btn.alertbtn { border-color: var(--alert); color: var(--alert); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: space-between; }
.grow { flex: 1; min-width: 150px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, label.q { font-weight: 650; font-size: .96rem; }
input[type="text"], input[type="url"], input[type="number"], input[type="date"], input[type="time"], select, textarea { width: 100%; min-height: 48px; border: 1px solid var(--field); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
input[inputmode="decimal"] { font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }
textarea { min-height: 150px; resize: vertical; }
input[type="range"] { width: 100%; min-height: 48px; accent-color: var(--accent); }
.scale { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); }
.chips, .segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { min-height: 44px; padding: 8px 16px; border: 1px solid var(--field); background: var(--surface); border-radius: 999px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"], .chip[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: flex; gap: 12px; align-items: center; min-height: 48px; }
.check input { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }
.fieldset { border: 0; margin: 0; padding: 0; }
.fieldset legend { font-weight: 650; padding: 0 0 4px; }

/* status words with a dot */
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 650; color: var(--muted); }
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tag.good { color: var(--good); } .tag.caution { color: var(--caution); } .tag.alert { color: var(--alert); } .tag.info { color: var(--accent); }
.callout { padding: 14px 16px; border-radius: 12px; background: var(--caution-soft); color: var(--ink); }
.callout.alert { background: var(--alert-soft); }
.callout.info { background: var(--accent-soft); }
.callout strong { font-weight: 700; }
.quote { padding: 10px 12px; border-radius: 10px; background: var(--bg); color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.link { all: unset; color: var(--accent); cursor: pointer; font-weight: 600; font-size: .9rem; padding: 10px 6px; min-height: 44px; display: inline-flex; align-items: center; }
.link:focus-visible { outline: 3px solid var(--accent); }
details > summary { cursor: pointer; font-weight: 650; min-height: 48px; display: flex; align-items: center; }
details > .stack { padding-bottom: 8px; }
pre.text, details pre { white-space: pre-wrap; overflow-wrap: anywhere; font: .88rem/1.5 var(--mono); background: var(--bg); padding: 12px; border-radius: 10px; max-height: 360px; overflow: auto; }
pre.preview { font: .94rem/1.5 var(--font); white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); padding: 12px; border-radius: 10px; }
.q-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.q-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--bg); border-radius: 10px; padding: 4px 4px 4px 12px; }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-line { stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); }
.chart-dot.last { stroke: var(--surface); stroke-width: 2; }
.chart-text { fill: var(--muted); font-size: 10px; font-family: var(--font); }

/* feedback */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--bar) + 12px + env(safe-area-inset-bottom)); z-index: 40; max-width: 528px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px 6px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); min-height: 52px; }
.toast .link { color: var(--bg); text-decoration: underline; }
.wrap.signed-out ~ .toast { bottom: 16px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); }
@media (prefers-reduced-motion: no-preference) { .spinner { animation: spin .8s linear infinite; } .btn, .chip { transition: background .12s, border-color .12s; } }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 14px; align-items: center; padding: 32px 4px; color: var(--muted); }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty strong { color: var(--ink); }

.overlay { position: fixed; inset: 0; background: rgba(8, 14, 20, .6); display: grid; place-items: center; padding: 16px; z-index: 60; }
.dialog { background: var(--surface); border-radius: 16px; padding: 22px; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 14px; }

footer { color: var(--muted); font-size: .8rem; padding: 28px 4px 8px; }

/* hide patient data when the tab is not visible (task switchers, screen sharing) */
html.obscured #shell, html.obscured nav.tabbar { filter: blur(18px); pointer-events: none; user-select: none; }
html.obscured::after { content: "CareBridge is hidden while you are away"; position: fixed; inset: 0; display: grid; place-items: center; font-weight: 700; }
@media print { #shell, nav.tabbar { display: none; } html::after { content: "Printing is turned off to protect your health information."; } }

/* details rows, two-column fields */
.rowdetails > summary { list-style: none; cursor: pointer; padding: 14px 16px; min-height: 56px; display: flex; align-items: center; }
.rowdetails > summary::-webkit-details-marker { display: none; }
.rowdetails > summary > .stack { width: 100%; gap: 4px; }
.rowdetails > summary:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.rowdetails .body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
details.panel > summary { padding: 0; }
details.panel[open] > summary { margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel.pad > h2 { margin-bottom: 2px; }
.rows .btn { align-self: flex-start; }
.rows select { margin-top: 4px; }
.panel.pad > .btn.primary.block, .panel.pad > .btn.block { margin-top: 4px; }
p .link { display: inline; min-height: 0; padding: 0 4px; }
.rows li > .link { margin: -8px 0 -10px; align-self: flex-start; }

/* long-form pages (privacy, terms, accessibility) */
.prose { gap: 14px; padding-top: 8px; }
.prose h2 { margin-top: 14px; }
.prose ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 8px; }
.prose a, footer a { color: var(--accent); text-underline-offset: 3px; }
a.wordmark { color: var(--ink); text-decoration: none; }
footer a { display: inline-block; padding: 12px 6px; }
footer .sep { color: var(--line); }
.footnav { display: flex; flex-wrap: wrap; gap: 0 12px; }
.footnav a { padding: 12px 4px; }
footer p { margin-bottom: 4px; }

/* Windows high contrast and other forced-colour modes */
@media (forced-colors: active) {
  .chip[aria-pressed="true"], .chip[aria-current="true"] { border: 4px solid CanvasText; }
  .btn.primary { border: 2px solid ButtonText; }
  nav.tabbar button[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 3px; }
  .chart-line { stroke: CanvasText; }
  .chart-dot { fill: CanvasText; }
}
