:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #1c2321;
  --muted: #5d6965;
  --line: #d9dfdb;
  --brand: #0f6e6e;
  --brand-ink: #ffffff;
  --brand-soft: #e1f0ef;
  --ok: #1d7a45;
  --ok-soft: #e3f3e8;
  --watch: #8a5a00;
  --watch-soft: #fdf1d8;
  --alert: #b3261e;
  --alert-soft: #fce4e1;
  --info-soft: #e6eef8;
  --s1: #0f6e6e;
  --s2: #c2652a;
  --band: rgba(29, 122, 69, 0.08);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #1a201e;
    --surface-2: #232b28;
    --text: #e7ece9;
    --muted: #9aa7a2;
    --line: #2f3936;
    --brand: #4fb3ae;
    --brand-ink: #08201f;
    --brand-soft: #173533;
    --ok: #5cc98a;
    --ok-soft: #173326;
    --watch: #f0b84a;
    --watch-soft: #3a2d10;
    --alert: #ff8a80;
    --alert-soft: #43201d;
    --info-soft: #1c2a3a;
    --s1: #4fb3ae;
    --s2: #f09a5f;
    --band: rgba(92, 201, 138, 0.10);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}
body.patient { font-size: 19px; }
a { color: var(--brand); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.6rem; }
h2.inline { display: inline; margin: 0; }
code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.req { color: var(--alert); }

/* ---------- chrome */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; gap: 0.45rem; align-items: center; }
.brand-mark { font-size: 1.2rem; }
.signout { margin: 0; }
.topbar .linkbtn { color: var(--brand-ink); opacity: 0.9; }
.mainnav {
  display: flex; gap: 0.25rem; overflow-x: auto; padding: 0.4rem 0.75rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.mainnav a {
  padding: 0.45rem 0.75rem; border-radius: 999px; text-decoration: none; color: var(--text);
  white-space: nowrap; font-size: 0.95rem;
}
.mainnav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 1rem 1rem 3rem; }

/* ---------- cards, flashes, badges */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 420px; margin: 2rem auto; }
details.card > summary { cursor: pointer; list-style: revert; }
details.card[open] > summary { margin-bottom: 0.8rem; }
.flash { border-radius: 10px; padding: 0.75rem 0.9rem; margin: 0 0 0.8rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); border-color: var(--ok); }
.flash-info { background: var(--info-soft); }
.flash-error { background: var(--alert-soft); border-color: var(--alert); }
.flash-watch { background: var(--watch-soft); border-color: var(--watch); }
.flash-alert {
  background: var(--alert-soft); border: 2px solid var(--alert); font-size: 1.1em; padding: 1rem;
}
.flash-alert strong { color: var(--alert); font-size: 1.15em; }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 0.1rem 0.5rem; border-radius: 999px; vertical-align: middle; }
.badge-alert { background: var(--alert); color: #fff; }
.badge-watch { background: var(--watch-soft); color: var(--watch); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; padding: 0.6rem 1rem; border-radius: 10px; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); text-decoration: none;
  min-height: 44px;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.big { font-size: 1.15em; min-height: 56px; }
.btn.small { padding: 0.35rem 0.7rem; min-height: 36px; font-size: 0.9rem; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--alert); }
.stack { display: grid; gap: 0.9rem; }
label { display: grid; gap: 0.3rem; font-weight: 600; }
label.check { display: flex; gap: 0.6rem; align-items: flex-start; font-weight: 400; }
label.check input { width: 1.3em; height: 1.3em; margin-top: 0.15em; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.7rem; width: 100%; min-height: 44px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input.num { max-width: 12rem; font-size: 1.3em; }
input.code { max-width: 10rem; font-size: 1.4em; letter-spacing: 0.15em; text-align: center; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 600; margin-bottom: 0.4rem; padding: 0; }
.field.has-error input, .field.has-error textarea { border-color: var(--alert); }
.field.has-error legend, .field.has-error label { color: var(--alert); }
.err { color: var(--alert); margin: 0.3rem 0 0; font-size: 0.95rem; }
details.field summary { cursor: pointer; color: var(--brand); }
details.field[open] summary { margin-bottom: 0.5rem; }

.pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pill { display: block; font-weight: 400; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0.5rem 1rem;
  border: 2px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.pill input:checked + span { border-color: var(--brand); background: var(--brand-soft); font-weight: 700; }
.pill input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 1px; }
.checks .pill input:checked + span::before { content: "✓ "; margin-right: 0.25rem; }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem 1rem; align-items: end; }
.grid-form .span2 { grid-column: 1 / -1; }
.grid-form > .btn { justify-self: start; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; }
.narrow-form { max-width: 420px; }
.small-form { margin-top: 0.5rem; min-width: 220px; }
.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters label { min-width: 12rem; }

/* ---------- patient home */
.hello { font-size: 2rem; margin-bottom: 0; }
.today { margin-top: 0.1rem; }
.bigbuttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.8rem; margin: 1rem 0 1.5rem; }
.bigbtn {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem;
  min-height: 120px; padding: 0.9rem 0.6rem; border-radius: 18px; text-align: center; text-decoration: none;
  background: var(--surface); border: 2px solid var(--line); color: var(--text); box-shadow: var(--shadow);
}
.bigbtn:active { transform: scale(0.98); }
.bigbtn .ico { font-size: 2.2rem; line-height: 1; }
.bigbtn .lbl { font-weight: 700; font-size: 1.1rem; }
.bigbtn .tick { font-size: 0.85rem; color: var(--ok); font-weight: 700; }
.bigbtn.done { border-color: var(--ok); background: var(--ok-soft); }
.back { margin: 0 0 0.25rem; }

/* ---------- observation list */
.obslist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.obs {
  display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.7rem 0.8rem;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px;
}
.obs.flag-watch { border-left-color: var(--watch); }
.obs.flag-alert { border-left-color: var(--alert); }
.obs .ico { font-size: 1.4rem; line-height: 1.2; }
.obs .body { flex: 1; min-width: 0; }
.obs .note { font-size: 0.95em; margin-top: 0.2rem; white-space: normal; overflow-wrap: anywhere; }
.obs .when { font-size: 0.85rem; }
.obs form { margin: 0; }

/* ---------- dashboard */
.pagehead h1 { margin-bottom: 0; }
.pagehead p { margin-top: 0.2rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tile {
  display: grid; gap: 0.2rem; padding: 0.8rem 0.9rem; border-radius: 12px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--brand);
}
.tile.flag-watch { border-top-color: var(--watch); }
.tile.flag-alert { border-top-color: var(--alert); }
.tile-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.tile-value { font-weight: 700; font-size: 1.05rem; }
.tile-when { font-size: 0.8rem; color: var(--muted); }
.tile-when.stale { color: var(--watch); }
.stat-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin: 0; }
.stat b { font-size: 1.3rem; }
.stat.warn b { color: var(--watch); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 1rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .band { fill: var(--band); }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1, .chart .dot.s1 { stroke: var(--s1); }
.chart .line.s2, .chart .dot.s2 { stroke: var(--s2); }
.chart .dot { fill: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--muted); }
.legend .key::before { content: ""; display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin-right: 0.35em; vertical-align: -0.05em; }
.legend .key.s1::before { background: var(--s1); }
.legend .key.s2::before { background: var(--s2); }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }

/* ---------- tables */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.out td { background: var(--watch-soft); }
table.data td.actions { display: grid; gap: 0.35rem; justify-items: start; }
table.data td.actions form { margin: 0; }
table.data.small td { font-size: 0.85rem; }

.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0 0 1rem; }
.chips a { padding: 0.3rem 0.75rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--text); font-size: 0.9rem; background: var(--surface); }
.chips a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- supplements */
.suplist { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
.suplist li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.85rem; }
.sup-main { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.sup-meta { margin-top: 0.25rem; }
.sup-actions { display: flex; gap: 1rem; align-items: center; margin-top: 0.5rem; flex-wrap: wrap; }
.sup-actions form { margin: 0; }

/* ---------- reviews */
.reviewlist { list-style: none; padding: 0; margin: 0 0 1rem; }
.reviewlist .card.latest { border-left: 4px solid var(--brand); }
.reviewlist p { margin: 0.5rem 0 0; }
.review-title { font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.latest-review { border-left: 4px solid var(--brand); }
a.review-link { display: grid; gap: 0.2rem; text-decoration: none; color: var(--text); }
a.review-link > span:last-child { color: var(--brand); font-weight: 600; }
.review { max-width: 820px; }
.prose { line-height: 1.6; }
.prose h2 { font-size: 1.25rem; margin: 1.6rem 0 0.5rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.prose h3 { font-size: 1.05rem; margin: 1.2rem 0 0.4rem; }
.prose h4 { font-size: 1rem; margin: 1rem 0 0.3rem; }
.prose p, .prose ul, .prose ol { margin: 0.5rem 0; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.25rem 0; }
.prose li > ul, .prose li > ol { margin: 0.2rem 0; }
.prose blockquote { margin: 0.8rem 0; padding: 0.3rem 0 0.3rem 0.9rem; border-left: 3px solid var(--line); color: var(--muted); }
.prose pre { background: var(--surface-2); padding: 0.7rem; border-radius: 8px; overflow-x: auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.prose .tablewrap { margin: 0.8rem 0; }
.prose .ref { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }
.disclaimer { border-top: 1px solid var(--line); padding-top: 0.8rem; margin-top: 1.5rem; }

/* ---------- ask */
.askbtn {
  display: flex; align-items: center; gap: 0.8rem; margin: 1rem 0 0; padding: 0.9rem 1rem; border-radius: 18px;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; box-shadow: var(--shadow); flex-wrap: wrap;
}
.askbtn .ico { font-size: 2rem; line-height: 1; }
.askbtn .small { opacity: 0.9; }
.askbtn .badge { margin-left: auto; }
.attention { border-left: 4px solid var(--watch); }
.threadlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.thread { display: grid; gap: 0.3rem; padding: 0.8rem 0.9rem; border-radius: 10px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); }
.thread.new { border-color: var(--brand); border-width: 2px; }
.chat { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.7rem; }
.msg { padding: 0.8rem 0.95rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); max-width: 46rem; }
.msg.mine { background: var(--brand-soft); border-color: transparent; justify-self: end; }
.msg.claude { border-left: 4px solid var(--brand); }
.msg .who { font-weight: 700; margin-bottom: 0.3rem; }
.msg .text { overflow-wrap: anywhere; }
.msg .prose h2 { border-top: 0; padding-top: 0; margin-top: 0.8rem; font-size: 1.1rem; }
.attachment { display: inline-block; margin: 0.4rem 0.6rem 0 0; padding: 0.35rem 0.7rem; border-radius: 8px; background: var(--surface-2); text-decoration: none; }

/* ---------- account */
.steps { padding-left: 1.2rem; display: grid; gap: 0.6rem; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 1.15rem; letter-spacing: 0.06em; background: var(--surface-2); padding: 0.5rem 0.7rem; border-radius: 8px; margin: 0.35rem 0; word-break: break-all; }

@media (max-width: 640px) {
  .grid-form { grid-template-columns: 1fr; }
  .wrap { padding: 0.75rem 0.75rem 3rem; }
  h1 { font-size: 1.4rem; }
  body.patient h1 { font-size: 1.6rem; }
  .charts { grid-template-columns: 1fr; }
}
