/* ══════════════════════════════════════════════════════════════════════
   HeartDaily · COMPONENT LAYER — SINGLE SOURCE OF TRUTH
   heartdailyapp.org · v2 (28/09/2026 — shared by app + dashboard + admin)

   The canonical, token-driven definitions of the product's reusable
   components. Built ONLY from var(--token) in /assets/tokens.css, so a token
   change cascades here, and a component change here cascades everywhere that
   consumes this file:

     • /app/        React PWA — heartdaily/src/index.css does @import '../../assets/components.css'
                    → Vite INLINES it into the bundle at build (offline-safe).
     • /dashboard/  /admin/ — <link>ed with <html class="dense"> (compact metrics, same components).
     • /styleguide/ Living design system — links this file so it renders the REAL classes.

   ONE component, TWO densities (decisions.md [28/09]): sizes come from the density tokens
   (--btn-*, --input-*, --badge-*, --modal-w …) in tokens.css; the clinician surfaces switch
   them with `dense`. Colour, radius, weight and states never differ by surface. Where the
   app and the old dashboard/admin disagreed, the APP's value is the standard.

   Legacy aliases (.b-red, .btn-teal, .inp, .reg-input, .form-input …) keep the dashboard/admin
   markup working while it migrates — new markup uses the canonical names.

   ⚠️ These are the ACTUAL classes every surface renders. Do NOT re-declare them in a
   surface stylesheet (tools/check-ds-parity.sh enforces it) — edit them HERE. Only class
   selectors live here: no bare element rules (this file is inlined into the app bundle).
   Exception: the two global accessibility resets below (:focus-visible, prefers-reduced-motion)
   are pseudo-class/media rules, not element rules — they carry no specificity risk for a real
   element and are meant to apply everywhere, which is the whole point of moving them here (29/09:
   deduped out of heartdaily/src/index.css, which had them but dashboard/admin never did).

   Requires /assets/tokens.css to be loaded first (for the var(--token)s).
   ══════════════════════════════════════════════════════════════════════ */

/* ── Icon (29/09) ───────────────────────────────────────────────── */
/* One visual weight for every icon, both surfaces: assets/icons.svg is the single source
   (app: generated into icons.jsx by tools/gen-icons.js; dashboard: <use href="…icons.svg#i-x">).
   Colour is never baked into the symbol — it's the element's `color`, so an icon inherits its
   context (teal only when interactive/active, neutral otherwise — 60-30-10, @design.md). */
.ico { display: inline-block; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: var(--ico-sw); stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ico-mirror { transform: scaleX(-1); }

/* ── Focus & motion (29/09) ─────────────────────────────────────── */
/* Was only in heartdaily/src/index.css (app-only) — dashboard/admin/styleguide had neither a
   focus ring nor a motion-reduction rule until this moved here. --td (not --t) so the ring itself
   clears 3:1 non-text contrast (WCAG 1.4.11); --t on white is only 2.45:1. */
:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ── Badge ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: var(--badge-gap);
  padding: var(--badge-py) var(--badge-px); border-radius: var(--rpill);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: var(--badge-ls); line-height: var(--badge-lh);
}
.dense .badge { white-space: nowrap; }
.badge-green, .b-grn  { background: var(--green-bg); color: var(--green-tx); }
.badge-amber, .b-amb, .b-org { background: var(--amber-bg); color: var(--amber-tx); }
.badge-red,   .b-red  { background: var(--red-bg);  color: var(--color-text-danger); }
.badge-blue,  .b-blu, .b-rose { background: var(--blue-bg);  color: var(--blue-tx); }
.badge-gray,  .b-gray { background: var(--color-surface-subtle);           color: var(--color-text-secondary); }
.badge-teal, .b-pur    { background: var(--teal-bg); color: var(--color-text-action); }
.b-teal               { background: var(--color-surface-subtle);           color: var(--color-text-secondary); }   /* clinician: teal is reserved for action, so the old "teal" pill is neutral */
/* Opt-in status dot (not default — the app's badges carry no dot). */
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* ── Card ───────────────────────────────────────────────────────── */
.card { background: var(--color-surface-card); border-radius: var(--r); box-shadow: var(--sh-1); overflow: hidden; }
.cmp-card {
  /* Neutralised (60-30-10): was a brand soft-gradient + teal border. A generic
     container should not carry brand colour — reserve gradient for genuine hero/
     primary surfaces (btn-primary, HD-ID card). */
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--r);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}
.hlcard { background: var(--grad); border-radius: var(--r); padding: var(--sp-5); color: #fff; }

/* ── BP 3-field input ───────────────────────────────────────────── */
.bp3r { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.bp3l { font-size: var(--text-sm); font-weight: 600; color: var(--color-text-secondary); width: 88px; flex-shrink: 0; line-height: 1.4; }
.bp3i {
  flex: 1; background: var(--color-surface-subtle); border-radius: var(--rs);
  border: 1.5px solid transparent; transition: border-color var(--motion-fast);
}
.bp3i:focus-within { border-color: var(--t); background: white; }
.bp3i input {
  width: 100%; border: none; background: none;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl); font-weight: 500; color: var(--color-text);
  outline: none; text-align: center; padding: 14px 10px;
}
.bp3u { font-size: var(--text-sm); color: var(--color-text-muted); width: 36px; flex-shrink: 0; text-align: right; }

/* ── Countdown badge ────────────────────────────────────────────── */
.countdown-badge {
  background: var(--teal-bg); border: 1px solid var(--teal-bd);
  border-radius: var(--rs); padding: 12px var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--text-sm); color: var(--color-text-action); margin-bottom: var(--sp-3);
}

/* ── Toggle ─────────────────────────────────────────────────────── */
.tog {
  position: relative; width: 44px; height: 26px; border-radius: var(--rpill);
  border: none; cursor: pointer; background: var(--bord); transition: background var(--motion-base); flex-shrink: 0;
}
.tog::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: transform var(--motion-base);
}
.tog.on { background: var(--t); }
@media (hover: hover) { .tog:hover { filter: brightness(.95); } }
.tog:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.tog.on::after { transform: translateX(18px); }

/* ── Text input / select / textarea ─────────────────────────────── */
.hd-input, .inp, .reg-input, .form-input, .form-select, .search-input {
  width: 100%; padding: var(--input-py) var(--input-px); height: var(--input-h);   /* a u-h-* utility can still override the height */
  border: 1.5px solid var(--color-border); border-radius: var(--rs);
  font-size: var(--input-fs); font-family: 'Inter', sans-serif;
  color: var(--color-text); background: white; outline: none;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast); -webkit-appearance: none; appearance: none;
}
.hd-input:focus, .inp:focus, .reg-input:focus, .form-input:focus, .form-select:focus, .search-input:focus { border-color: var(--t); box-shadow: var(--focus-ring); }
.hd-input.error, .inp.error, .reg-input.error, .form-input.error, .form-select.error, .search-input.error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.10); }
.hd-input::placeholder, .inp::placeholder, .reg-input::placeholder, .form-input::placeholder, .search-input::placeholder { color: var(--color-text-muted); }
@media (hover: hover) { .hd-input:hover { border-color: var(--mute); } }
.hd-input:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); cursor: not-allowed; }
/* <select>: appearance is stripped above, so draw the chevron here. */
select.hd-input, select.inp, select.reg-input, select.form-select {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
textarea.hd-input, textarea.inp { height: auto; min-height: var(--textarea-minh); resize: vertical; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn-primary, .btn-accent {
  width: var(--btn-w); padding: var(--btn-py) var(--btn-px); background: var(--grad-btn);
  border: none; border-radius: var(--rs); color: white;
  font-size: var(--btn-fs); font-weight: 700; font-family: 'Inter', sans-serif;
  cursor: pointer; display: var(--btn-display); align-items: center; justify-content: center;
  gap: var(--sp-2); min-height: var(--btn-minh); box-shadow: var(--sh-btn);
  transition: opacity var(--motion-fast), transform .1s;
}
.btn-primary, .btn-accent, .btn-secondary { text-decoration: none; }   /* also used on <a> (tel: links) */
.btn-primary:active, .btn-accent:active { transform: scale(.99); opacity: .92; }
@media (hover: hover) { .btn-primary:hover, .btn-accent:hover { filter: brightness(.94); } }   /* darker only: --grad-btn already clears AA, a lighter hover would not */
.btn-primary:disabled, .btn-accent:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); box-shadow: none; cursor: not-allowed; }

.btn-secondary {
  width: var(--btn-w); padding: var(--btn2-py) var(--sp-5); background: var(--color-surface-subtle);
  border: none; border-radius: var(--rs); color: var(--color-text-secondary);
  font-size: var(--btn2-fs); font-weight: 600; font-family: 'Inter', sans-serif;
  cursor: pointer; display: var(--btn-display); align-items: center; justify-content: center;
  gap: var(--sp-2); min-height: var(--btn2-minh); transition: background var(--motion-fast);
}
@media (hover: hover) { .btn-secondary:hover { background: var(--bord); } }
.btn-secondary:active { background: var(--bord); }
.btn-secondary:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); cursor: not-allowed; }

/* Compact action button (table rows, cards, toolbars). Neutral by default — colour is signal, so only
   .btn-danger (crisis / destructive) and .btn-soft-danger carry a hue. */
.btn-sm {
  height: var(--btn-sm-h); padding: 0 var(--btn-sm-px); border-radius: var(--rxs);
  font-size: var(--btn-sm-fs); font-weight: 600; border: none; transition: all var(--motion-fast);
  cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 5px;
}
.btn-sm:active { filter: brightness(.92); }
.btn-sm:disabled, .btn-sm:disabled:hover { background: var(--color-surface-subtle); color: var(--color-text-muted); box-shadow: none; filter: none; cursor: not-allowed; }
.btn-teal, .btn-grn, .btn-t, .btn-pur { background: var(--color-surface-subtle); color: var(--color-text-body); }
.btn-teal:hover, .btn-grn:hover, .btn-t:hover, .btn-pur:hover { background: var(--bord); }
.btn-gray { background: var(--color-surface-subtle); color: var(--color-text-secondary); }
.btn-gray:hover { background: var(--bord); }
.btn-danger, .btn-red { background: var(--danger); color: #fff; }   /* 30/09: separate token from --red-tx (badges/notices stay on the original red) — see tokens.css comment. 29/09: was var(--red) = 3.76:1, failed AA */
.btn-danger:hover, .btn-red:hover { background: var(--danger-dk); }
.btn-soft-danger { background: var(--red-soft); color: var(--color-text-danger); }
.btn-soft-danger:hover { background: var(--red-bd); }
.btn-soft-teal { background: var(--teal-bg); color: var(--color-text-action); }
.btn-soft-ok { background: var(--green-bg); color: var(--green-tx); }
.btn-xs { height: 28px; padding: 0 12px; font-size: var(--text-xs); }               /* compact pill inside banners/strips */
.btn-solid { background: var(--td); color: #fff; }        /* solid-colour compact action (pill with .btn-pill) */
.btn-solid-blue { background: var(--b); color: #fff; }
/* Colour/shape modifiers — combine with .btn-primary / .btn-secondary / .btn-sm */
.btn-primary.btn-danger { box-shadow: var(--sh-btn-red); }
/* No .btn-primary.btn-danger:hover override (29/09: removed a real bug — its 3-class
   specificity beat .btn-danger:hover above and silently reset the fill back to the
   lighter default on hover, so the darken-on-hover never actually rendered). */
.btn-primary.btn-danger:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); box-shadow: none; }
.btn-outline { background: var(--color-surface-card); color: var(--color-text-action); box-shadow: inset 0 0 0 1.5px var(--t); }
.btn-outline:active { background: var(--teal-bg); }
@media (hover: hover) { .btn-outline:hover { background: var(--teal-bg); } }
.btn-secondary.btn-outline:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); box-shadow: none; cursor: not-allowed; }
.btn-grad { background: var(--grad-btn); color: #fff; }
.btn-pill { border-radius: var(--rpill); }
.btn-row { display: flex; gap: var(--btn-row-gap, 6px); flex-wrap: var(--btn-row-wrap, nowrap); }   /* a surface sets --btn-row-wrap:wrap where cells are narrow (admin) */

/* Loading — set aria-busy="true" on the button: spinner before the label, not clickable, colours unchanged. */
.btn-primary[aria-busy="true"]::before, .btn-secondary[aria-busy="true"]::before, .btn-sm[aria-busy="true"]::before {
  content: ''; flex-shrink: 0; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
.btn-primary[aria-busy="true"], .btn-secondary[aria-busy="true"], .btn-sm[aria-busy="true"] { pointer-events: none; cursor: progress; }

/* Tap targets — the visible size stays; the clickable area grows to 44px (--hit-on is 1 on touch, 0 in dense). */
.tog, .modal-x, .btn-sm { position: relative; }
.tog::before   { content: ''; position: absolute; inset: calc(-9px * var(--hit-on)) 0; }
.modal-x::before { content: ''; position: absolute; inset: calc(-7px * var(--hit-on)); }
.btn-sm::after { content: ''; position: absolute; left: 0; right: 0; top: calc(-4px * var(--hit-on)); bottom: calc(-4px * var(--hit-on)); }
.btn-xs::after { top: calc(-8px * var(--hit-on)); bottom: calc(-8px * var(--hit-on)); }

/* ── Modal (dialog on desktop; the dashboard turns it into a bottom sheet on phones) ── */
.modal-wrap { position: fixed; inset: 0; background: var(--scrim); display: none; align-items: center; justify-content: center; z-index: var(--z-modal); padding: 20px; }
.modal-wrap.open { display: flex; }
.modal { background: var(--color-surface-card); border-radius: var(--r); max-width: var(--modal-w); width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 14px; border-bottom: 1px solid var(--color-border); }
.modal-title { font-size: var(--text-md); font-weight: 700; }
.modal-x { width: 30px; height: 30px; border-radius: var(--rpill); background: var(--color-surface-subtle); border: none; font-size: var(--text-md); color: var(--color-text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-body { padding: 20px 24px 24px; }
.modal-acts { display: flex; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--color-border); }
/* App variants: centred dialog (crisis, QR), bottom sheet (forms) — same .modal-wrap/.modal, different shape */
.modal-wrap.strong { background: var(--scrim-strong); }
.modal-wrap.bottom { align-items: flex-end; padding: 0; }
.modal.dialog { max-width: 340px; border-radius: var(--r-lg); overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.sheet { max-width: 430px; border-radius: var(--r-lg) var(--r-lg) 0 0; }
.modal-band { padding: 24px 24px 20px; text-align: center; }
.modal-band.red { background: var(--red-soft); }
.modal-band.blue { background: var(--blue-soft); }
@media (max-width: 768px) {
  .dense .modal { border-radius: var(--r) var(--r) 0 0; position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; max-height: 88vh; margin: 0; }
  .dense .modal-wrap { align-items: flex-end; }
}

/* ── Toast (JS adds .show; default is the neutral ink pill) ─────── */
.toast { position: fixed; bottom: 24px; right: 24px; z-index: var(--z-toast); background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--rs); font-size: var(--text-sm); font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,.2); display: none; animation: slideUp .3s ease; }
.toast.show { display: block; }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Loading / empty ────────────────────────────────────────────── */
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--color-border); border-top-color: var(--accent); animation: spin .7s linear infinite; margin: 36px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { text-align: center; color: var(--color-text-muted); font-size: var(--text-sm); padding: 28px; }
.empty { text-align: center; padding: 44px 20px; color: var(--color-text-muted); }

/* ── Form field bits ────────────────────────────────────────────── */
.f-label { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--color-text-secondary); margin-bottom: 6px; }
.f-help  { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 5px; }
.f-err   { display: flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--color-text-danger); font-weight: 600; margin-top: 5px; }

/* ── Notice — tinted message with an icon (icon = the meaning, colour only reinforces it) ── */
.notice { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; border-radius: var(--rs); font-size: var(--text-sm); line-height: 1.45; }
.notice > svg, .notice > .ni { flex-shrink: 0; margin-top: 1px; }
.notice-teal { background: var(--teal-bg);  color: var(--color-text-action); }
.notice-info { background: var(--blue-bg);  color: var(--blue-dk); }
.notice-ok   { background: var(--green-bg); color: var(--green-dk); }
.notice-warn { background: var(--amber-bg); color: var(--amber-dk); }
.notice-err  { background: var(--red-bg);   color: var(--red-dk); }
.notice-sm   { font-size: var(--text-xs); padding: 10px 12px; }
.notice-strip { border-radius: 0; padding: 10px 16px; align-items: center; }   /* full-bleed banner under the status bar */

/* ── BP risk scale ──────────────────────────────────────────────── */
/* Small caption above the scale: which number (upper/lower) the ticks track. */
.hd-scale-cap { font-size: var(--text-xs); color: var(--color-text-muted); text-align: right;
  margin-top: 12px; margin-bottom: 2px; }
/* Zone stops centre on 33% (normal→elevated) · 58% (elevated→high) · 83%
   (high→crisis) to match bpMarkerPct + classifyBP boundaries. */
.hd-scale { height: 4px; border-radius: var(--rpill); margin-top: 14px; position: relative;
  background: linear-gradient(90deg,var(--green-lt) 0%,var(--green-lt) 28%,var(--amber-lt) 38%,var(--amber-lt) 53%,var(--red-lt) 63%,var(--red-lt) 78%,var(--red-tx) 88%,var(--red-tx) 100%); }
.hd-scale-mk { position: absolute; top: -6px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transform: translateX(-50%); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
/* Ticks positioned absolutely at the colour boundaries (120 / 135|140 / 180 at
   33/58/83%) so each number sits under where its colour starts. */
.hd-scale-lbl { position: relative; height: 14px; font-size: var(--text-xs);
  color: var(--color-text-muted); margin-top: 6px; }
.hd-scale-lbl span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

/* ── Home hero (latest reading) ─────────────────────────────────── */
/* White card, ink BP number, ♥ pulse; use as `.card .hero-card`. */
.hero-card { box-shadow: var(--sh-2); }
.hero-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; font-size: var(--text-hero);
  line-height: 1; color: var(--color-text); }
.hero-num .sl { color: var(--color-text-muted); font-weight: 400; }
.hero-pulse { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.hero-pulse .pv { display: flex; align-items: center; gap: 5px; }
.hero-pulse .hrt { color: var(--t); display: inline-flex; align-items: center; line-height: 1; }
.hero-pulse .v { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--text-xl); font-weight: 600; color: var(--color-text); }
.hero-pulse .u { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── Comparison banner (vs previous reading — arrow + words, no delta) ── */
.cmp-banner { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px;
  background: var(--green-bg); border-radius: var(--rs); padding: 9px 12px; color: var(--green-dk); }
.cmp-banner.higher { background: var(--red-bg); color: var(--red-dk); }
.cmp-banner.same   { background: var(--color-surface-subtle); color: var(--color-text-secondary); }
.cmp-banner .ar { font-size: var(--text-base); font-weight: 800; line-height: 1.35; flex-shrink: 0; }
.cmp-banner .cmp-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cmp-banner .cmp-txt b { font-size: var(--text-sm); font-weight: 700; line-height: 1.3; }
.cmp-banner .cmp-txt .sub { font-size: var(--text-xs); line-height: 1.4; opacity: .82; }
