:root {
  /* COLOR = the direction/state of a VALUE, never a category, never branding,
     never "nice". Attach color only to a delta, a status dot, or an out-of-range
     value — never to chrome (no colored borders, fills, glyphs, or chips). One
     channel per signal. In-range facts get ZERO color. At most one --warn and
     one --good above the fold. --accent is interaction-only (links/focus/active). */
  /* SURFACE SCALE — Radix-dark-gray-style stepping (Linear). Each step is a
     genuinely perceptible jump so cards/rows/sections stay distinct even at
     reduced screen brightness, where near-black grays otherwise collapse. */
  --bg: #0d0f12;       /* page canvas */
  --panel: #131720;    /* cards, nav-active, metric cells — clearly above bg */
  --surface: #1a1f29;  /* elevated: inputs, primary action card, tooltips, drawer */
  --raised: #212736;   /* hover/active states, the one-up nudge */
  --line: #252c38;     /* default border — reads at lower brightness */
  --line-strong: #353e4f; /* section rules / dividers that must pop */
  /* TEXT RAMP — calm AND high-contrast (Linear/Stripe). --faint is STRUCTURE
     ONLY (borders, rings, disabled) and must NEVER set readable text. */
  --text: #f1f3f8;     /* primary near-white ~14:1 — titles, numerals, hero */
  --muted: #9aa3b2;    /* the readable FLOOR ~5.8:1 — body, payoff, meta */
  --label: #aeb4c2;    /* brightest non-primary — small uppercase micro-labels */
  --faint: #6b7587;    /* chrome + faint structure; lifted to read when dimmed */
  --accent: #6cb6f5;   /* interaction only: links, focus, CTAs */
  --good: #4ec291;     /* improving / back-in-range — vivid, full strength */
  --warn: #f0675a;     /* out of range / act now — the loudest, fully saturated */
  --amber: #e0a44a;    /* watch / borderline / recheck-due / stale */

  /* ONE coherent modular type ladder (~1.25). Hierarchy = visual weight, and
     visual weight tracks information importance. Weight (400/600/700) does the
     fine-grain work — no two readable tiers sit within a couple px doing
     different jobs. The big jump (20→32) is spent only on the brief. */
  --t-hero: 32px;    /* THE BRIEF only — the page's dominant element */
  --t-3xl: 26px;     /* vital display numerals only */
  --t-primary: 20px; /* the single #1-action title only */
  --t-xl: 17px;      /* secondary metric values (last-night/screen grids) */
  --t-lg: 16px;      /* lead / feed titles / prose / payoff */
  --t-md: 14px;      /* body, watch rows, demoted alert, meta */
  --t-sm: 12px;      /* labels, eyebrows, pills, deltas, chrome */
  --t-section: 12px; /* (alias — section labels use --t-sm size now) */

  /* spacing — multiples of 4 */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s6: 24px;
  --s7: 28px;

  --ls: .06em;    /* one letter-spacing for all uppercase micro-labels */

  --chat-w: 400px;  /* docked chat sidebar width (drawer + reflow padding) */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: var(--t-md)/1.45 -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

/* keyboard focus — ONE visible ring for every interactive element. Non-input
   controls reset their background/border, which suppresses the UA default ring
   on dark; this restores a consistent, on-brand focus indicator everywhere.
   (Inputs signal focus via their border-color swap, so they're excluded.) */
a:focus-visible, button:focus-visible, select:focus-visible,
summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px;
}

/* one treatment for every uppercase micro-label */
.label, .block .label, .smetric .label, .strip-name, .domain, .lab-table th,
.schart-label, .pattern .ptitle, h2 {
  font-size: var(--t-sm); text-transform: uppercase; letter-spacing: var(--ls);
}

/* ---- header / nav ---- */
header {
  display: flex; justify-content: space-between; align-items: baseline;
  max-width: 1180px; margin: 0 auto; padding: var(--s4) 20px var(--s1); gap: var(--s4);
}
.brand { font-weight: 600; letter-spacing: .02em; }
.tabs { display: flex; gap: 2px; margin-right: auto; }
.tabs a { color: var(--muted); text-decoration: none; font-size: var(--t-sm); padding: 3px 10px; border: 1px solid transparent; }
.tabs a.on { color: var(--text); background: var(--panel); border-color: var(--line); }
.tabs a:hover { color: var(--text); }
.hdr-right { display: flex; gap: var(--s3); align-items: baseline; }
.meta { color: var(--muted); font-size: var(--t-sm); display: inline-flex; align-items: center; gap: 5px; transition: color .3s; }
.meta .ico { width: 13px; height: 13px; }
.meta.just-synced { color: var(--good); }
.sync-spin { display: inline-flex; animation: spin 1s linear infinite; }
.sync-spin .ico { width: 13px; height: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
/* accordion / disclosure content eases in on open. The resting state is fully
   visible, so the reveal only enhances — content never depends on it to show. */
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
/* content eases in only when a disclosure is actually opened (JS adds .reveal-open
   on the `toggle` event) — a background re-render that recreates an already-open
   <details> won't replay it. Resting state stays fully visible. */
details.reveal-open > summary ~ * { animation: reveal .22s ease-out; }
/* tab switch: a quick opacity fade of the newly shown page. No translate — the
   DOM is already mounted, so a slide would falsely imply content is arriving. */
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
.page.page-in { animation: page-in 140ms ease-out; }
@media (prefers-reduced-motion: reduce) {
  details.reveal-open > summary ~ *, .page.page-in { animation: none; }
  .box-collapse > summary::before, .screen-wrap > summary::before, .chat-mcp > summary::before { transition: none; }
}
.sync-err { color: var(--warn); }
/* data-freshness status: a dot + label reflecting DATA recency (newest night),
   kept distinct from "checked Xm ago" (when we last pulled + analyzed). */
.fresh { display: inline-flex; align-items: center; gap: 5px; font-size: var(--t-sm); font-weight: 600; cursor: help; }
.fresh-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.fresh-current { color: var(--good); } .fresh-current .fresh-dot { background: var(--good); box-shadow: 0 0 0 3px rgba(78,194,145,.18); }
.fresh-behind { color: var(--amber); } .fresh-behind .fresh-dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(224,164,74,.18); }
.fresh-stale { color: var(--warn); } .fresh-stale .fresh-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(240,103,90,.18); }
.fresh-idle { color: var(--muted); }
.fresh-checked { color: var(--muted); font-size: var(--t-sm); }
.fresh-checked::before { content: "· "; color: var(--faint); }
/* per-module breakdown shown on hover of the status (reuses #tip) */
.fresh-tip-row { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; font-size: var(--t-sm); }
.fresh-tip-row .fresh { font-weight: 400; cursor: default; }
.fresh-tip-row .ico { width: 13px; height: 13px; color: var(--faint); flex-shrink: 0; }
.fresh-tip-name { color: var(--text); font-weight: 600; white-space: nowrap; }
.fresh-tip-rec { color: var(--muted); }
#refresh { background: none; border: 1px solid var(--line); color: var(--muted); font: inherit; font-size: var(--t-sm); font-weight: 550; padding: 4px 10px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
#refresh .ico { width: 13px; height: 13px; }
#refresh:hover:not(:disabled) { color: var(--text); border-color: var(--raised); }
#refresh:disabled { color: var(--muted); cursor: default; }

.page { display: none; }
.page.on { display: block; }

main { max-width: 1180px; margin: 0 auto; padding: var(--s2) 20px 40px; }

/* ---- section headings ---- */
h2 { font-weight: 600; color: var(--muted); }
.h2sub { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: var(--t-sm); }

/* small tracked uppercase labels need MORE luminance, not less → --label */
.eyebrow, .t-label, .schart-label, #strips .strips-label { color: var(--label); }
.eyebrow { color: var(--label); font-size: var(--t-sm); font-weight: 600; text-transform: uppercase; letter-spacing: var(--ls); }

/* pill / tag — legible category label with a real container edge */
.tag { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: 5px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07); color: var(--label);
  font-size: var(--t-sm); line-height: 1; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.tag.warn { background: rgba(240,103,90,.13); border-color: transparent; color: #f3a79e; }

/* staleness caveat — a quiet line, not an emergency box (the fact is in the brief) */
.alert { display: flex; gap: var(--s2); align-items: center; font-size: var(--t-md); color: var(--muted); }
.alert::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); flex-shrink: 0; }
.alert .ico { display: none; }
.alert .a-title { color: var(--muted); font-weight: 400; font-size: var(--t-md); }
.alert .a-cta { color: var(--accent); text-decoration: none; margin-left: 4px; }
.alert .a-cta:hover { text-decoration: underline; }
.alert .a-cta .ico { display: none; }
/* labeled section header — bold tracked title + count + a rule that runs right */
.sec-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.sec-label { color: var(--text); font-size: var(--t-section); font-weight: 700; text-transform: uppercase; letter-spacing: .09em; white-space: nowrap; }
.sec-sub { color: var(--muted); font-size: var(--t-sm); white-space: nowrap; }
.sec-rule { flex: 1; height: 1px; background: var(--line-strong); }
#alerts:empty, #actionplan:empty { display: none; }
#alerts { margin-top: var(--s3); }   /* tight under the brief — a caveat */
#actionplan, #vitals, #synth, #watch { margin-top: 40px; }
#actionplan .hero-action { margin-top: 0; }
#actionplan .feed { margin-top: var(--s2); }

/* inline SVG icon — one stroke weight across the whole set */
.ico { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.5; fill: none;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
/* vendored brand marks are filled single-path logos, not line glyphs */
.ico-brand { stroke: none; fill: currentColor; }
/* brand marks carry their brand color — a deliberate exception to the otherwise
   monochrome system; near-black brands (Apple, Peloton) are lightened so they
   stay legible on the dark canvas. Services without a real mark stay grey. */
.ico-b-peloton { color: #e01a2b; }
.ico-b-strava { color: #fc4c02; }
.ico-b-garmin { color: #1a9fe0; }
.ico-b-fitbit { color: #00b0b9; }
.ico-b-apple_health { color: #e2e5ec; }
.ico-b-google_health { color: #4285f4; }
.ico-b-headspace { color: #f47d31; }
.ico-b-anthropic { color: #d97757; }
.ico-b-openai { color: #74aa9c; }
.eyebrow .ico, .good .ico, .warn .ico, .muted .ico, .t-arrow .ico, .stale-note .ico { width: 13px; height: 13px; vertical-align: -2px; }

/* ---- THE BRIEF — the page's dominant element (visual weight = importance) ---- */
#briefing { margin-top: 40px; margin-bottom: 8px; }
.brief-date { color: var(--muted); font-size: var(--t-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px; }
.brief-body { font-size: var(--t-hero); font-weight: 600; line-height: 1.3; color: var(--text); max-width: 700px; letter-spacing: -.01em; }
.brief-body strong { font-weight: 700; }   /* risk terms carry inline emphasis */
.stale-note { color: var(--amber); font-size: var(--t-sm); margin-top: var(--s2); }
.stale-note a { color: var(--accent); text-decoration: none; }


/* ---- vitals: boxed 3-up, big values, color only on the arrow ---- */
#vitals { margin-top: var(--s6); }
/* flat hairline grid — the NUMBERS carry the weight, not a box */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; background: none; border: 0; }
.tile { background: none; padding: 0 24px; border-left: 1px solid var(--line); }
.tile:first-child { padding-left: 0; border-left: 0; }
.t-label { color: var(--label); font-size: var(--t-sm); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.t-value { font-size: var(--t-3xl); font-weight: 650; color: var(--text); margin-top: var(--s1); display: flex; align-items: center; gap: 6px; }
.t-arrow .ico { width: 18px; height: 18px; }
.t-arrow { display: inline-flex; }
.t-arrow.good, .good { color: var(--good); }
.t-arrow.warn { color: var(--warn); }
.t-arrow.amber { color: var(--amber); }
.t-value.v-amber { color: var(--amber); }
.t-sub { color: var(--muted); font-size: var(--t-sm); margin-top: 2px; }
.vitals-foot { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s3); }
.vitals-foot .good { color: var(--good); }
.vitals-foot .muted { color: var(--muted); }

/* ---- cardiovascular synthesis: prose, no rail, no box ---- */
#synth:empty { display: none; }
#synth { margin-top: var(--s6); }
.synth-b { color: var(--muted); margin-top: var(--s2); line-height: 1.55; max-width: 640px; font-size: var(--t-lg); }
.synth-claims { margin-top: var(--s2); color: var(--muted); font-size: var(--t-sm); }
.synth-claims .mid { color: var(--muted); margin: 0 7px; }
.claim { color: var(--muted); }

/* ---- watchlist ---- */
#watch:empty { display: none; }
#watch { margin-top: var(--s6); }
#watch .eyebrow { margin-bottom: var(--s1); }
.watch-row { display: flex; gap: var(--s3); padding: 4px 0; border-bottom: 1px solid var(--line); font-size: var(--t-md); }
.watch-what { flex: 1; color: var(--text); }
.watch-when { color: var(--muted); }
.watch-cost { color: var(--muted); min-width: 90px; text-align: right; }
@media (max-width: 760px) { .tiles { grid-template-columns: 1fr; gap: var(--s3); } .tile { border-left: 0; padding-left: 0; } }

/* ---- banner (sleep page only now) ---- */
#banner:empty, #verdict:empty { display: none; }
.banner { margin-top: var(--s4); padding: var(--s3); border-left: 3px solid var(--warn); background: #1c1416; }
.banner.info { border-left-color: var(--amber); background: var(--panel); }
.banner .btitle { font-weight: 600; }
.banner .baction { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); }
.verdict { margin-top: var(--s3); font-size: var(--t-lg); line-height: 1.5; color: var(--text); }

/* ---- actions / insights: flat hairline rows ---- */
#actions, #insights { margin-top: 0; }
.insight {
  display: grid; grid-template-columns: 12px 1fr auto; gap: var(--s3);
  padding: 16px 0; border-bottom: 1px solid var(--line); background: none;
  align-items: start;
}
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(240,103,90,.18); }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px rgba(78,194,145,.18); }
.dot.quiet { background: none; box-shadow: inset 0 0 0 1.5px #6b7283; }
.insight .body .title { color: var(--text); font-weight: 600; font-size: var(--t-lg); }
.payoff { color: var(--muted); font-size: var(--t-md); margin-top: 4px; line-height: 1.5; }
.insight .side { align-self: start; margin-top: 4px; }
.insight .side svg { display: block; }
.delta { color: var(--muted); font-size: var(--t-sm); }

/* the #1 action earns primacy through elevation + position + CTA — NOT a bigger
   title. Same title size as the feed; the surface lift + CTA carry the emphasis. */
.insight.is-primary { background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 20px; margin-bottom: var(--s3); }
.insight.is-primary .payoff { margin-top: 5px; }

/* the why explanation — a full-width block under the row, toggled inline */
.more-body { color: var(--muted); font-size: var(--t-md); line-height: 1.55; max-width: 720px;
  margin-top: 10px; }
.more-body[hidden] { display: none; }

/* footer controls — Why this + Mark done sit together, always same place */
.row-foot { display: flex; align-items: center; gap: var(--s4); margin-top: 12px; }
.why-btn { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0;
  font: inherit; font-size: var(--t-sm); font-weight: 600; color: var(--accent); cursor: pointer; }
.why-btn:hover { text-decoration: underline; }
.why-btn .ico { width: 13px; height: 13px; transition: transform .12s; }
.why-btn.open .ico { transform: rotate(180deg); }
.row-cta { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-sm); font-weight: 650;
  color: #0e1014; background: var(--accent); border: 0; border-radius: 8px; padding: 7px 13px; text-decoration: none; }
.row-cta:hover { filter: brightness(1.08); }
.row-cta .ico { width: 14px; height: 14px; }

/* domain badge = legible pill with a leading domain icon (beaker, moon, …) */
.domain { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px 0 6px; border-radius: 6px;
  background: #21262f; color: var(--label);
  font-size: var(--t-sm); line-height: 1; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; }
.domain .ico { width: 13px; height: 13px; color: var(--muted); }
.insight .title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
#inbox-suggest { margin-top: var(--s4); }

/* tooltip / learn-as-you-go — underline only on hover, so values don't read
   as spell-check errors; the affordance appears when you reach for it */
[data-tip] { cursor: help; text-decoration: none; }
[data-tip]:hover { text-decoration: underline dotted var(--faint); text-underline-offset: 3px; }
#tip {
  position: fixed; display: none; z-index: 50; max-width: 320px;
  background: #181b22; border: 1px solid var(--faint); padding: var(--s2) var(--s3);
  font-size: var(--t-sm); line-height: 1.45; box-shadow: 0 4px 16px rgba(0,0,0,.5);
  pointer-events: none;
}
#tip .tip-t { font-weight: 600; color: var(--text); }
#tip .tip-d { color: var(--muted); margin-top: 3px; }
#tip .tip-m { color: var(--muted); margin-top: var(--s1); }
#tip .tip-stale { color: var(--amber); margin-top: var(--s1); }
.done-btn { background: none; border: 1px solid var(--line); color: var(--muted); font: inherit; font-size: var(--t-sm); font-weight: 550; padding: 5px 11px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.done-btn:hover { color: var(--text); border-color: var(--raised); }
.is-primary .done-btn { position: static; }
.insight.is-done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.insight.is-done .payoff { color: var(--muted); }

/* chips: text tokens, no borders — color only on true flags */
.chip { display: inline-block; font-size: var(--t-sm); margin-left: 7px; color: var(--muted); vertical-align: 1px; }
.chip.improved { color: var(--good); }
.chip.regressed, .chip.flag { color: var(--warn); }
.chip.recheck { color: var(--amber); }
.chip.new, .chip.stale { color: var(--label); }
/* stale actions stay fully legible (the data, not the advice, is old — the
   NEEDS-ATTENTION alert already flags that). Only DONE gets a strikethrough. */

/* ---- jump-to: a near-invisible footer index ---- */
#strips { margin-top: var(--s7); border-top: 1px solid var(--line-strong); padding-top: var(--s4); }
#strips .strips-label { color: var(--muted); margin-bottom: var(--s2); display: block; font-size: var(--t-sm); text-transform: uppercase; letter-spacing: var(--ls); }
.strip { display: inline-flex; gap: var(--s2); align-items: baseline; margin-right: var(--s6); text-decoration: none; color: var(--muted); font-size: var(--t-md); }
.strip:hover { color: var(--text); }
.strip-name { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: 5px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07); color: var(--label);
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: var(--t-sm); }
.strip-body { color: var(--muted); }
.strip-go { color: var(--muted); display: inline-flex; }
.warn-txt { color: var(--warn); }
.empty { color: var(--muted); margin-top: var(--s4); }

/* ---- metric grid (shared: last-night, screens, labs status) ---- */
.metrics { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); margin-top: var(--s2); }
.metrics.c8 { grid-template-columns: repeat(8, 1fr); }
.metrics.c7 { grid-template-columns: repeat(7, 1fr); }
.metrics.c3 { grid-template-columns: repeat(3, 1fr); }
.metric { background: var(--panel); padding: var(--s2) 10px; }
.metric .label { color: var(--muted); }
.metric .value { font-size: var(--t-xl); font-weight: 600; margin-top: 2px; }
.metric .value.f-mid { color: var(--amber); }
.metric .bdelta, .metric .snote { font-size: var(--t-sm); margin-top: 2px; }
.bdelta.up { color: var(--good); }
.bdelta.down { color: var(--warn); }
.bdelta.flat { color: var(--muted); }
.metric .snote { color: var(--muted); }
.metric svg { margin-top: var(--s1); }
#lastnight, #labs-status { margin-top: var(--s4); }
#lastnight h2 { margin-bottom: var(--s1); }

/* traffic lights */
.tl { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 6px 2px 0; }
.tl-ok { background: var(--good); }
.tl-mid { background: var(--amber); }
.tl-high { background: var(--warn); }

/* ---- pattern ---- */
#pattern:empty { display: none; }
.pattern { margin-top: var(--s4); padding: var(--s2) var(--s3); border: 1px solid var(--amber); background: var(--panel); }
.pattern .ptitle { color: var(--amber); }
.pattern .pbody { margin-top: var(--s1); }
.pattern .pdays { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); }

/* ---- collapsibles (one disclosure treatment) ---- */
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
/* "Why this" — reads as an interactive link, accent + chevron */
details.more { margin-top: 10px; }
details.more > summary { color: var(--accent); font-size: var(--t-sm); font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px; }
details.more > summary:hover { text-decoration: underline; }
details.more > summary .ico { width: 13px; height: 13px; transition: transform .12s; }
details.more[open] > summary .ico { transform: rotate(180deg); }
.more-body { color: var(--muted); font-size: var(--t-md); line-height: 1.5; margin-top: 6px; max-width: 720px; }

/* "Show N more" / "Acted on" — a real bordered button control */
details.more-insights { margin-top: var(--s3); }
details.more-insights > summary { display: inline-block; }
.more-btn { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-sm); font-weight: 550;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; }
.more-btn:hover { color: var(--text); border-color: var(--raised); }
.more-btn .ico { width: 13px; height: 13px; transition: transform .12s; }
details.more-insights[open] .more-btn .ico { transform: rotate(180deg); }

/* boxed collapsible (charts, screens, labs table) */
.box-collapse { margin-top: var(--s4); border: 1px solid var(--line); background: var(--panel); padding: var(--s2) var(--s3); }
.box-collapse > summary { display: flex; align-items: baseline; gap: var(--s3); }
.box-collapse > summary h2 { display: inline; }
.box-collapse > summary::before { content: "›"; display: inline-block; margin-right: var(--s2); color: var(--muted); font-size: 17px; line-height: 1; font-weight: 600; transition: transform .2s ease; }
.box-collapse[open] > summary::before { transform: rotate(90deg); }

/* ---- screens ---- */
#screens:empty { display: none; }
.screen-wrap { margin-top: var(--s4); border: 1px solid var(--line); background: var(--panel); padding: var(--s2) var(--s3); }
.screen-wrap > summary::before { content: "›"; display: inline-block; margin-right: var(--s2); color: var(--muted); font-size: 17px; line-height: 1; font-weight: 600; transition: transform .2s ease; }
.screen-wrap[open] > summary::before { transform: rotate(90deg); }
.screen-wrap > summary h2 { display: inline; }
.screen-wrap h2 .dot { display: inline-block; }
.sverdict-inline { display: block; color: var(--muted); margin: var(--s1) 0 0 14px; }
.screen { margin-top: var(--s2); }
.sverdict { color: var(--text); }
.saction { color: var(--muted); }
.schart-label { color: var(--muted); margin-top: var(--s3); display: block; }
.sevidence { list-style: none; padding: var(--s1) 0 0; color: var(--muted); font-size: var(--t-sm); }
.sevidence li { margin-top: var(--s1); padding-left: 10px; border-left: 2px solid var(--line); }

/* ---- charts ---- */
.range { display: inline-flex; }
.range button { background: none; border: 1px solid var(--line); color: var(--muted); font: inherit; font-size: var(--t-sm); padding: 2px 8px; cursor: pointer; }
.range button + button { border-left: none; }
.range button.on { color: var(--text); background: var(--panel); }
.charts { margin-top: var(--s1); }
.chart-block { margin-top: var(--s4); }
.chart { height: 240px; margin-top: var(--s1); }
.chart.short { height: 180px; }
#notes { list-style: none; padding: var(--s1) 0 0; color: var(--muted); font-size: var(--t-sm); }
#notes li { margin-top: 2px; }

/* ---- tables (labs markers + retest) ---- */
.lab-table { width: 100%; border-collapse: collapse; margin-top: var(--s2); }
.lab-table th { text-align: left; color: var(--muted); padding: var(--s1) var(--s2) var(--s1) 0; border-bottom: 1px solid var(--line); }
.lab-table td { padding: var(--s1) var(--s2) var(--s1) 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lab-table .num { white-space: nowrap; }
.lab-table .muted { color: var(--muted); font-size: var(--t-sm); }

#labs-retest { margin-top: var(--s4); }
.rt-v { font-size: var(--t-sm); text-transform: uppercase; letter-spacing: var(--ls); white-space: nowrap; width: 1%; color: var(--muted); }
.rt-skip-v { color: var(--muted); }
.rt-policy { color: var(--muted); font-size: var(--t-sm); margin-top: 2px; }

/* draw-event cards */
.draw-card { border: 1px solid var(--line); background: var(--panel); padding: var(--s3); margin-top: var(--s2); }
.draw-card.urgent { border-left: 3px solid var(--warn); }
.draw-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.draw-title { font-weight: 600; }
.draw-cost { color: var(--good); font-size: var(--t-sm); white-space: nowrap; }
.draw-when { margin-top: var(--s1); }
.draw-status { color: var(--muted); font-size: var(--t-sm); margin-top: 2px; }
.draw-covers { list-style: none; margin-top: var(--s2); columns: 2; column-gap: var(--s6); }
.draw-covers li { color: var(--muted); font-size: var(--t-sm); padding-left: 10px; border-left: 2px solid var(--line); margin-bottom: 2px; break-inside: avoid; }
.draw-cta { display: inline-block; margin-top: var(--s2); color: var(--accent); text-decoration: none; border: 1px solid var(--accent); padding: 3px 10px; font-size: var(--t-sm); }
.draw-cta:hover { background: rgba(90, 169, 230, .08); }
.draw-total { margin-top: var(--s2); padding: var(--s2) var(--s3); border: 1px solid var(--line); color: var(--text); font-weight: 600; }
.gen-rec { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px solid var(--line); }
#gen-tests, #mri-findings, #vax-recs, #vax-history { margin-top: var(--s4); }
.rt-do .rt-v { color: var(--warn); }

/* inbox */
#dropzone { margin-top: var(--s4); border: 1px dashed var(--faint); padding: var(--s7) var(--s4); text-align: center; cursor: pointer; }
#dropzone.over { border-color: var(--accent); background: var(--panel); }
.drop-title { font-size: var(--t-lg); font-weight: 600; }
.drop-sub { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); }
.drop-sub.faint { color: var(--muted); }
.drop-sub code { color: var(--muted); }
#inbox-files { margin-top: var(--s4); }

/* ---- supplements: daytime / nighttime regimen ---- */
.supp-block { margin-top: var(--s6); }
.supp-when { display: flex; align-items: center; gap: 6px; margin-bottom: var(--s2); }
.supp-when .ico { color: var(--muted); }
.supp-pills { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 4px; }
.supp-row { display: grid; grid-template-columns: 96px 1fr auto; gap: var(--s3); padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.supp-pill { display: flex; align-items: center; gap: var(--s2); }
.pill { width: 32px; height: 32px; flex-shrink: 0; }
.supp-amt { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; font-size: var(--t-sm); }
.supp-main { min-width: 0; }
.supp-name { font-weight: 600; color: var(--text); }
.supp-dose { font-weight: 400; color: var(--muted); font-size: var(--t-sm); margin-left: 8px; }
.supp-meta { font-size: var(--t-md); color: var(--muted); margin-top: 3px; line-height: 1.5; }
.supp-change { color: var(--amber); font-size: var(--t-sm); margin-top: var(--s1); }
.supp-markers { margin-top: var(--s2); display: flex; flex-wrap: wrap; gap: 4px var(--s4); }
.supp-marker { font-size: var(--t-sm); color: var(--muted); }
.supp-side { flex-shrink: 0; }
.supp-buy { color: var(--accent); font-size: var(--t-sm); text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 2px; }
.supp-buy:hover { text-decoration: underline; }
.supp-buy .ico { width: 13px; height: 13px; }

footer {
  max-width: 1180px; margin: 0 auto; padding: var(--s3) 20px var(--s7);
  color: var(--muted); font-size: var(--t-sm); border-top: 1px solid var(--line-strong);
}
footer .warnico { color: var(--amber); }

@media (max-width: 900px) { .metrics.c8, .metrics.c7 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 760px) { .supp-grid { grid-template-columns: 1fr; } }

/* profile strip */
#profile:empty { display: none; }
/* profile: a quiet passport stamp, not content */
.profile { margin-top: var(--s3); color: var(--muted); font-size: var(--t-sm); }
.pbit { color: var(--muted); }
.pbit.faint { color: var(--muted); }
.psep { color: var(--faint); margin: 0 6px; }
.pf-more { display: inline-block; margin-left: 10px; }
.pf-detail { color: var(--muted); margin-top: var(--s1); max-width: 900px; }

/* -------------------------------------------- ask (floating chat drawer) */
/* The FAB is the one place the accent becomes a solid surface — the single
   bold gesture. Everything inside the drawer stays as quiet as the rest of
   the app. */
#chat-fab { position: fixed; right: 22px; bottom: 22px; z-index: 60;
  width: 48px; height: 48px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease, opacity .15s ease; }
#chat-fab .ico { width: 22px; height: 22px; }
#chat-fab:hover { transform: translateY(-2px); }
#chat-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#chat-fab.hidden { opacity: 0; transform: scale(.6); pointer-events: none; }

#chat-drawer { position: fixed; top: 0; right: 0; z-index: 61; height: 100vh;
  width: var(--chat-w); display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .2s ease; }
#chat-drawer.on { transform: translateX(0); }
/* dock, don't cover: when open, shrink the app into the space beside the drawer */
body { transition: padding-right .2s ease; }
body.chat-on { padding-right: var(--chat-w); }
@media (max-width: 760px) {
  #chat-drawer { width: 100vw; }
  body.chat-on { padding-right: 0; }  /* too narrow to dock — overlay on mobile */
}

.chat-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) 16px; border-bottom: 1px solid var(--line); }
.chat-title { font-size: var(--t-xl); font-weight: 650; color: var(--text); }
.chat-ctx { color: var(--muted); font-weight: 400; font-size: var(--t-sm); }
.chat-ctx:not(:empty)::before { content: "· "; color: var(--faint); }
.chat-actions { display: flex; align-items: center; gap: 2px; }
.chat-x { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; display: flex; }
.chat-x .ico { width: 18px; height: 18px; }
.chat-x:hover { color: var(--text); background: var(--surface); }

/* history mode: hide the live chat chrome, show the saved-session list */
#chat-drawer.show-history .chat-controls,
#chat-drawer.show-history .chat-compose,
#chat-drawer.show-history .chat-foot { display: none; }
#chat-drawer.show-history #chat-history { color: var(--accent); }
#chat-drawer.show-history .chat-log { gap: var(--s2); }
.chat-empty { color: var(--muted); font-size: var(--t-sm); }
.chat-hrow { display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; }
.chat-hrow:hover { border-color: var(--raised); background: var(--surface); }
.chat-hrow.on { border-color: var(--accent); }
.chat-hmeta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-htitle { color: var(--text); font-size: var(--t-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-hago { color: var(--muted); font-size: var(--t-sm); }
.chat-hdel { flex: 0 0 auto; background: none; border: none; color: var(--faint); cursor: pointer; padding: 4px; display: flex; }
.chat-hdel .ico { width: 15px; height: 15px; }
.chat-hdel:hover { color: var(--warn); }

.chat-controls { flex: 0 0 auto; padding: var(--s3) 16px; border-bottom: 1px solid var(--line); }
.chat-pickers { display: flex; gap: var(--s2); align-items: center; }
#chat-provider, #chat-model { font: inherit; font-size: var(--t-sm); color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; }
#chat-provider { flex: 1; min-width: 0; }
#chat-model { flex: 1; min-width: 0; }
#chat-model:disabled { opacity: .45; }
#chat-provider:focus, #chat-model:focus, #chat-text:focus { outline: none; border-color: var(--accent); }
.chat-ghost { font: inherit; font-size: var(--t-sm); color: var(--muted); background: none;
  border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; cursor: pointer; }
.chat-ghost:hover { color: var(--text); border-color: var(--raised); }
.chat-alert { display: flex; margin-top: var(--s2); padding: 8px 10px;
  border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 0 6px 6px 0;
  background: var(--surface); color: var(--muted); font-size: var(--t-sm); line-height: 1.45; }
.chat-alert code { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; font-size: 11.5px; }
.chat-alert a { color: var(--accent); text-decoration: none; }
.chat-alert a:hover { text-decoration: underline; }

.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: var(--s4); }
.chat-hello { color: var(--muted); font-size: var(--t-md); line-height: 1.55; display: flex; flex-direction: column; gap: var(--s2); }
.chat-hello p { margin-bottom: var(--s1); }
.chat-eg { text-align: left; font: inherit; font-size: var(--t-sm); color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 8px 11px; cursor: pointer; }
.chat-eg:hover { color: var(--text); border-color: var(--raised); }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.asst { flex-direction: column; align-items: flex-start; }
.chat-bubble { font-size: var(--t-md); line-height: 1.6; }
.chat-msg.user .chat-bubble { background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px 12px 3px 12px; padding: 8px 12px; color: var(--text); max-width: 88%; }
.chat-msg.asst .chat-bubble { color: var(--text); max-width: 100%; }
.chat-bubble code { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.chat-thinking { color: var(--faint); font-size: var(--t-sm); margin-bottom: 5px; }
.chat-thinking summary { cursor: pointer; text-transform: uppercase; letter-spacing: var(--ls); font-weight: 600; }
.chat-thinking[open] { color: var(--muted); line-height: 1.5; }
.chat-dots { color: var(--muted); font-style: italic; }

/* rendered markdown (assistant replies) — kept within the design system */
.chat-md > :first-child { margin-top: 0; }
.chat-md > :last-child { margin-bottom: 0; }
.chat-md p { margin: 0 0 var(--s2); line-height: 1.6; }
.chat-md ul, .chat-md ol { margin: 0 0 var(--s2); padding-left: 20px; }
.chat-md li { margin: 2px 0; }
.chat-md li::marker { color: var(--faint); }
.chat-md h1, .chat-md h2, .chat-md h3, .chat-md h4 { color: var(--text); font-weight: 650; line-height: 1.3; margin: var(--s3) 0 var(--s1); }
.chat-md h1, .chat-md h2 { font-size: var(--t-lg); }
.chat-md h3, .chat-md h4 { font-size: var(--t-md); }
.chat-md strong { color: var(--text); font-weight: 650; }
.chat-md a { color: var(--accent); text-decoration: none; }
.chat-md a:hover { text-decoration: underline; }
.chat-md code { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.chat-md pre { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; overflow-x: auto; margin: 0 0 var(--s2); }
.chat-md pre code { background: none; border: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
.chat-md blockquote { border-left: 3px solid var(--line); margin: 0 0 var(--s2); padding: 2px 0 2px 12px; color: var(--muted); }
.chat-md img { max-width: 100%; height: auto; border-radius: 7px; margin: var(--s1) 0; }
.chat-md hr { border: none; border-top: 1px solid var(--line); margin: var(--s3) 0; }
.chat-md table { border-collapse: collapse; width: 100%; margin: 0 0 var(--s2); font-size: var(--t-sm); }
.chat-md th, .chat-md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.chat-md th { color: var(--label); font-weight: 600; background: var(--surface); }

.chat-compose { flex: 0 0 auto; padding: 12px 16px; border-top: 1px solid var(--line); }
.chat-input { display: flex; gap: var(--s2); align-items: flex-end; }
#chat-text { flex: 1; font: inherit; font-size: var(--t-md); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; resize: none; max-height: 140px; line-height: 1.45; }
#chat-text:disabled { opacity: .5; }
.chat-send { flex: 0 0 auto; width: 38px; height: 38px; border: none; border-radius: 7px; cursor: pointer;
  background: var(--accent); color: var(--bg); display: flex; align-items: center; justify-content: center; }
.chat-send .ico { width: 18px; height: 18px; }
.chat-send:disabled { background: var(--line); color: var(--faint); cursor: default; }
.chat-hint { color: var(--muted); font-size: var(--t-sm); margin-top: 6px; }

.chat-foot { flex: 0 0 auto; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.chat-mcp > summary { cursor: pointer; list-style: none; color: var(--faint); font-size: var(--t-sm);
  text-transform: uppercase; letter-spacing: var(--ls); font-weight: 600; }
.chat-mcp > summary::-webkit-details-marker { display: none; }
.chat-mcp > summary::before { content: "›"; display: inline-block; margin-right: 6px; color: var(--muted); font-size: 14px; line-height: 1; font-weight: 600; transition: transform .2s ease; }
.chat-mcp[open] > summary::before { transform: rotate(90deg); }
.chat-mcp p { color: var(--muted); font-size: var(--t-sm); line-height: 1.5; margin: var(--s2) 0; }
.chat-mcp code { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11.5px; }
.chat-code { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  overflow-x: auto; font-size: 11.5px; line-height: 1.5; color: var(--muted); margin-bottom: var(--s2); }

@media (prefers-reduced-motion: reduce) { #chat-drawer, #chat-fab { transition: none; } }

/* ------------------------------------------------------------ settings */
#settings-integrations { margin-top: 40px; }
.set-note { color: var(--muted); font-size: var(--t-md); max-width: 680px; margin-top: calc(-1 * var(--s2)); margin-bottom: var(--s4); line-height: 1.55; }

/* privacy panel — the local-only / device-encryption assurance */
/* flat 2-col fact list, not a 4-tile card grid — these are read-once assurances,
   not dashboard widgets. Icons are inert chrome (faint), never accent. */
.privacy-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s4) var(--s6); margin-top: var(--s4); }
.privacy-item { background: none; border: 0; border-radius: 0; padding: 0; }
.privacy-h { display: flex; align-items: center; gap: var(--s2); color: var(--text); font-weight: 600; font-size: var(--t-md); margin-bottom: 6px; }
.privacy-h .ico { width: 15px; height: 15px; color: var(--faint); }
.privacy-item p { color: var(--muted); font-size: var(--t-sm); line-height: 1.55; }
.privacy-item code { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11.5px; }
@media (max-width: 760px) { .privacy-grid { grid-template-columns: 1fr; } }

/* every source is ONE flat row — icon · name · brings · status+action (no cards).
   Connected sources and catalogue entries share this component. */
.intg-live { margin-top: var(--s2); }
.intg-list { margin-top: var(--s1); }
.intg-row { display: grid; grid-template-columns: minmax(190px, 1.1fr) 2fr auto; gap: var(--s4);
  align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.intg-row-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.intg-row-head .ico { width: 15px; height: 15px; flex-shrink: 0; }
.intg-row-head .ico:not(.ico-brand) { color: var(--faint); }  /* line glyphs stay grey; brand marks keep their color */
.intg-row-name { color: var(--text); font-weight: 600; }
.intg-row-brings { color: var(--muted); font-size: var(--t-sm); min-width: 0; }
.intg-row-status { justify-self: end; display: flex; align-items: center; gap: var(--s3); white-space: nowrap; }
/* the catalogue disclosure: everything not yet wired up, tucked away by default */
/* a plain disclosure, NOT a bordered panel — its flat rows must align
   edge-to-edge with the connected strip above (no inset, no box, no fill) */
.intg-catalogue { margin-top: var(--s4); border: 0; background: none; padding: 0; }
.intg-catalogue > summary { margin-bottom: var(--s2); }
.intg-catalogue .set-note { margin-top: var(--s1); }
.intg-catalogue .intg-cat:first-of-type { margin-top: var(--s3); }
@media (max-width: 760px) {
  .intg-row { grid-template-columns: 1fr auto; }
  .intg-row-brings { display: none; }
}

/* integration cards */
.intg-cat { margin-top: var(--s6); }
.intg-cat .eyebrow { display: block; margin-bottom: var(--s3); }
.intg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s3); }
.intg-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: var(--s4); display: flex; flex-direction: column; }
.intg-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.intg-name { color: var(--text); font-weight: 600; font-size: var(--t-lg); }
.intg-badge { font-size: var(--t-sm); font-weight: 600; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.intg-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.intg-badge.ok { color: var(--good); }
.intg-badge.ok::before { background: var(--good); }
/* works/connectable now — brighter than a "Planned" (base muted) badge */
.intg-badge.live { color: var(--label); }
.intg-badge.live::before { background: var(--muted); }
.intg-brings { color: var(--muted); font-size: var(--t-sm); line-height: 1.5; margin-top: var(--s1); }
.intg-form { margin-top: var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.intg-field { display: flex; flex-direction: column; gap: 4px; font-size: var(--t-sm); color: var(--label); }
.intg-field input { font: inherit; font-size: var(--t-md); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
.intg-field input:focus { outline: none; border-color: var(--accent); }
.intg-hint { color: var(--muted); font-size: var(--t-sm); line-height: 1.5; }
.intg-actions { display: flex; gap: var(--s2); align-items: center; margin-top: 2px; }
.intg-btn { font: inherit; font-size: var(--t-sm); font-weight: 600; color: var(--bg); background: var(--accent);
  border: none; border-radius: 7px; padding: 6px 14px; cursor: pointer; }
.intg-btn:disabled { background: var(--line); color: var(--faint); cursor: default; }
/* planned sources: a receding ghost, so full-saturation accent is reserved for
   buttons that actually connect something (Blue-Means-Clickable) */
.intg-btn-ghost { background: none; color: var(--muted); border: 1px solid var(--line); }
.intg-btn-ghost:hover { color: var(--text); border-color: var(--raised); }
.intg-ghost { font: inherit; font-size: var(--t-sm); color: var(--muted); background: none; border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.intg-ghost:hover { color: var(--warn); border-color: var(--raised); }
.intg-link { color: var(--accent); text-decoration: none; font-size: var(--t-sm); font-weight: 600; margin-top: var(--s3); }
.intg-link:hover { text-decoration: underline; }
.intg-docs { color: var(--faint); text-decoration: none; font-size: var(--t-sm); }
.intg-docs:hover { color: var(--muted); }
.intg-foot { margin-top: var(--s3); display: flex; }
.intg-help { color: var(--muted); font-size: var(--t-sm); line-height: 1.45; }

/* connection dialog (modal) */
.modal { position: fixed; inset: 0; z-index: 80; display: none; }
.modal.on { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.modal-card { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(460px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s4) var(--s3); border-bottom: 1px solid var(--line); }
.modal-title { color: var(--text); font-size: var(--t-lg); font-weight: 650; }
.modal-sub { color: var(--muted); font-size: var(--t-sm); margin-top: 3px; line-height: 1.5; }
.modal-body { padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }

/* ------------------------------------------------------------ calendar (habits) */
#page-calendar { margin-top: var(--s6); }
/* summary: one flat card per habit — streak + 30-day count */
.cal-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line);
  border: 1px solid var(--line); margin-top: var(--s2); }
.cal-card { background: var(--panel); padding: var(--s3) var(--s4); }
.cal-card-h { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--t-sm);
  font-weight: 600; }
.cal-card-h .ico { width: 14px; height: 14px; color: var(--faint); }
.cal-card.active .cal-card-h .ico { color: var(--good); }
.cal-card-streak { color: var(--text); font-size: var(--t-3xl); font-weight: 650; margin-top: 4px;
  display: flex; align-items: baseline; gap: 6px; }
.cal-card-unit { color: var(--muted); font-size: var(--t-sm); font-weight: 400; }
.cal-card-sub { color: var(--muted); font-size: var(--t-sm); margin-top: 2px; }

/* month navigator */
.cal-nav { display: flex; align-items: center; justify-content: center; gap: var(--s4); margin: var(--s6) 0 var(--s3); }
.cal-month { color: var(--text); font-weight: 600; font-size: var(--t-lg); min-width: 160px; text-align: center; }
.cal-page { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  background: none; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); cursor: pointer; }
.cal-page:hover:not(:disabled) { color: var(--text); border-color: var(--raised); }
.cal-page:disabled { opacity: .35; cursor: default; }
.cal-page .ico { width: 16px; height: 16px; }
.cal-page.prev .ico { transform: rotate(180deg); }

/* grid */
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--s2); margin-bottom: 6px; }
.cal-weekdays span { text-align: center; color: var(--faint); font-size: var(--t-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: var(--ls); }
.cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--s2); }
.cal-cell { position: relative; min-height: 74px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2);
  transition: background-color .12s ease, border-color .12s ease; }
.cal-cell:hover:not(:disabled):not(.blank) { background: var(--surface); border-color: var(--raised); }
.cal-cell.blank { background: none; border: 0; cursor: default; }
.cal-cell.future { opacity: .4; cursor: default; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.perfect { background: rgba(78, 194, 145, .1); }
.cal-num { color: var(--muted); font-size: var(--t-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell.today .cal-num { color: var(--accent); }
.cal-marks { display: flex; flex-wrap: wrap; gap: 3px; align-self: flex-start; }
.cal-mark { display: inline-flex; }
.cal-mark .ico { width: 13px; height: 13px; color: var(--text); }
.cal-cell.perfect .cal-mark .ico { color: var(--good); }

/* legend */
.cal-legends { display: flex; flex-wrap: wrap; gap: var(--s4); margin-top: var(--s4); }
.cal-leg { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--t-sm); }
.cal-leg .cal-mark .ico { width: 14px; height: 14px; color: var(--faint); }
.cal-leg-src { color: var(--faint); font-size: var(--t-sm); }
.cal-note { margin-top: var(--s2); margin-bottom: 0; }

/* day editor rows (in the modal) — big tap targets */
.day-rows { padding: var(--s3) var(--s4) var(--s4); gap: var(--s2); }
.day-row { display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; cursor: pointer;
  color: var(--text); font: inherit; transition: background-color .12s ease, border-color .12s ease; }
.day-row:hover:not(:disabled) { background: var(--surface); border-color: var(--raised); }
.day-row:disabled { cursor: default; }
.day-row-ico { display: inline-flex; }
.day-row-ico .ico { width: 18px; height: 18px; color: var(--faint); }
.day-row.done .day-row-ico .ico { color: var(--good); }
.day-row-main { flex: 1; display: flex; flex-direction: column; font-weight: 600; }
.day-row-sub { color: var(--muted); font-size: var(--t-sm); font-weight: 400; margin-top: 1px; }
.day-row-check { display: inline-flex; color: var(--good); }
.day-row-check .ico { width: 18px; height: 18px; }

@media (max-width: 760px) {
  .cal-cards { grid-template-columns: 1fr; }
  .cal-cell { min-height: 42px; padding: 4px; }
  .cal-mark .ico { width: 11px; height: 11px; }
}
