/* NurseJoy Tier 0 — calm, warm, accessible UI for an older adult.
   Priorities: very large text, high contrast, big touch targets, minimal chrome.
   No framework, no build step. */

:root {
  /* ============================================================================
     NURSE JOY — "SOFT SLATE" DESIGN SYSTEM (whole Tier 0 web app).
     A quiet, dignified MONOCHROME brand: warm-tinted greys from near-white to
     near-black, with ONE small red accent borrowed from the logo's cross (the live
     "listening" dot). Eldercare, not enterprise: calm, clinical, very high contrast,
     large touch targets, gentle motion. ONE brand across BOTH surfaces — the
     caregiver/admin screens (sign-in gate + settings) AND the patient conversation
     view (tuned bigger/calmer further down). All pairings verified WCAG 2.1 AA
     (ratios noted per token; see DESIGN-SYSTEM.md and check-contrast.mjs).
     ============================================================================ */

  /* --- Base text size — the whole UI scales from here via rem. ----------------
     A sane, readable default (no longer an oversized fixed 22px). Caregivers scale
     it up (low vision) or down with the "Text size" slider in admin Settings, which
     sets --fz-scale (persisted per device). --fz-base stays responsive (shrinks on
     small screens); --fz-scale is the saved preference, so the two COMPOSE — the
     slider never clobbers the responsive base. */
  --fz-base: 18px;
  --fz-scale: 1;
  font-size: calc(var(--fz-base) * var(--fz-scale));

  /* --- Brand: warm-grey tonal scale (PRIMARY is a deep charcoal) --- */
  --gray-50:  #f6f5f3;   /* page field, tints, hovered rows              */
  --gray-100: #eceae6;   /* soft fills, NurseJoy's bubble                */
  --gray-200: #dcd9d3;   /* dividers, patient's bubble                   */
  --gray-300: #bdb8b0;   /* decorative only (1.7:1 — not for text)       */
  --gray-400: #928d85;   /* input borders / large non-text (3.3:1)      */
  --gray-500: #6e6960;   /* muted hints on white        (5.5:1)          */
  --gray-600: #565149;   /* secondary text on white     (7.9:1)          */
  --gray-700: #403c36;   /* PRIMARY — buttons           (11.0:1)         */
  --gray-800: #2c2925;   /* primary hover, links, focus (14.5:1)         */
  --gray-900: #1b1916;   /* ink / headings / deepest    (17.5:1)         */

  /* --- Accent: the logo's red cross. Used VERY small (the live listening dot only),
         never as the sole carrier of meaning, never a UI status color. --- */
  --red-500: #cf2e2e;   /* cross + listening dot — 5.1:1 graphic on white */
  --red-600: #b3261e;   /* AA red text on white          (6.5:1)         */

  /* --- Semantic roles (admin + shared) --- */
  --primary:        var(--gray-700);
  --primary-strong: var(--gray-800);
  --primary-soft:   var(--gray-100);
  --primary-tint:   var(--gray-50);
  --on-primary:     #ffffff;            /* 11.0:1 on --primary             */
  --accent-red:     var(--red-500);     /* the one spark of colour          */
  --brand-heading:  var(--gray-900);
  --brand-link:     var(--gray-800);

  /* --- Warm-grey neutrals (surfaces) --- */
  --admin-bg:       #f6f5f3;            /* soft warm-grey field            */
  --admin-surface:  #ffffff;
  --admin-surface-2:#f1efea;            /* faint warm grey                 */
  --admin-ink:      #1b1916;            /* near-black (17.5:1 on white)    */
  --admin-ink-soft: #565149;            /* secondary text  (7.9:1)         */
  --admin-ink-muted:#6e6960;            /* hints on white  (5.5:1)         */
  --admin-line:     #dcd9d3;            /* grey hairline (decorative)      */
  --admin-line-2:   #928d85;            /* input borders   (3.3:1 — 1.4.11)*/

  /* --- Semantic status (all AA on white; kept distinct from the grey brand) --- */
  --ok:     #1f7a52;   /* 5.3:1  */
  --notice: #8a4b12;   /* 6.8:1  */
  --danger: #b3261e;   /* 6.5:1  */

  /* --- Typography scale (rem) --- */
  --fs-xs: 0.8rem;   --fs-sm: 0.95rem; --fs-md: 1.05rem;
  --fs-lg: 1.3rem;   --fs-xl: 1.6rem;  --fs-2xl: 2rem;
  --lh-tight: 1.25;  --lh-body: 1.5;
  --fw-regular: 400; --fw-medium: 600; --fw-bold: 700;

  /* --- Spacing scale (4px rhythm) --- */
  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.5rem; --space-6: 2rem;

  /* --- Radius (a touch softer than before — gentle, dignified) --- */
  --radius-sm: 8px;  --radius-md: 12px; --radius-lg: 18px;
  --radius-xl: 24px; --radius-pill: 999px;

  /* --- Elevation (soft, neutral — rgba of --gray-900) --- */
  --elev-1: 0 1px 2px rgba(27,25,22,0.06), 0 2px 8px rgba(27,25,22,0.07);
  --elev-2: 0 6px 18px rgba(27,25,22,0.10);
  --elev-3: 0 18px 48px rgba(27,25,22,0.18);

  /* --- Focus + motion --- */
  --focus-ring: var(--gray-800);       /* 14.5:1 — well above 3:1         */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-settle: cubic-bezier(0.34, 1.4, 0.64, 1);  /* gentle follow-through */
  --dur: 180ms;

  /* ============================================================================
     COMPANION / PATIENT CONVERSATION LAYER.
     The SAME Soft Slate brand, tuned for the patient: bigger type, generous spacing,
     gentle motion, very high contrast, low clutter. The two speakers are told apart
     by FILL (two distinct greys) + ALIGNMENT + LABEL — NurseJoy in a lighter grey,
     the patient in a slightly deeper grey — so value is reinforcement, never the only
     cue. The only colour anywhere is the red listening dot.
     ============================================================================ */
  --companion-bg:        var(--admin-bg);      /* warm-grey field                 */
  --companion-ink:       var(--admin-ink);     /* 16.1:1 on field                 */
  --companion-ink-soft:  var(--admin-ink-soft);/* 7.2:1 on field (hints, status)  */
  --nursejoy-bubble:        var(--gray-100);   /* NurseJoy's voice — light grey   */
  --nursejoy-bubble-ink:    var(--admin-ink);  /* 14.6:1 on gray-100             */
  --me-bubble:           var(--gray-200);      /* patient's words — deeper grey   */
  --me-bubble-ink:       var(--admin-ink);     /* 12.5:1 on gray-200             */
  --companion-accent:        var(--gray-700);  /* primary actions (Start, Send)   */
  --companion-accent-strong: var(--gray-800);  /* hover / active                  */
  /* Red glow used by the ambient listening pulse (rgb of --red-500). */
  --companion-pulse: 207, 46, 46;

  /* --- Legacy aliases — app.js + the conversation CSS reference these names; they
         now re-point at the Soft Slate tokens above so there is ONE brand. --- */
  --bg: var(--companion-bg);          /* warm-grey field                        */
  --surface: var(--admin-surface);    /* white                                  */
  --ink: var(--companion-ink);        /* near-black                             */
  --ink-soft: var(--companion-ink-soft);/* secondary text                       */
  --me-bg: var(--me-bubble);          /* patient's words: deeper grey           */
  --me-ink: var(--me-bubble-ink);
  --them-bg: var(--nursejoy-bubble);     /* NurseJoy's voice: light grey           */
  --them-ink: var(--nursejoy-bubble-ink);
  --accent: var(--companion-accent);  /* charcoal primary — actions             */
  --accent-ink: var(--on-primary);    /* white (11.0:1 on accent)               */
  --accent-strong: var(--companion-accent-strong);
  --warn: var(--notice);              /* safety/help notice (6.8:1 on white)    */
  --warn-bg: #f3ece0;                 /* soft warm notice fill                  */
  --line: var(--admin-line);          /* decorative hairline (dividers)         */
  --line-strong: var(--admin-line-2); /* visible control borders (3.3:1)        */
  --focus: var(--focus-ring);         /* charcoal focus (14.5:1)                */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.6rem 1rem; z-index: 10; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.9rem 1.2rem;
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: var(--elev-1);
}
/* Brand: a small nurse-cap + red-cross mark beside the companion name. Decorative
   (aria-hidden) — it carries warmth, not information. Kept modest to stay calm. */
.topbar-brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: 0 0 auto; display: block; }
.title { margin: 0; font-size: 1.7rem; font-weight: 700; letter-spacing: 0.2px;
  color: var(--brand-heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  font-size: 1.05rem; padding: 0.7rem 1.1rem;
  min-height: 56px; border: 2px solid var(--line-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
/* Anchor styled as an icon-btn (e.g. the Guides link to the static condition guides). As a flex child it
   already picks up the box, but keep the label centred and drop the default link underline/colour. */
a.icon-btn { display: inline-flex; align-items: center; text-decoration: none; }
.icon-btn:hover { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-strong); }
.icon-btn:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* ---- Conversation stage ---- */
.stage {
  flex: 1; width: 100%; max-width: 820px; margin: 0 auto;
  padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem;
}

.transcript {
  flex: 1; min-height: 40vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1rem;
  padding: 0.4rem;
}

.hint { color: var(--ink-soft); font-size: 1.2rem; text-align: center; margin: auto; }

.bubble {
  max-width: 90%; padding: 1rem 1.2rem; border-radius: var(--radius-lg);
  font-size: 1.35rem; line-height: var(--lh-body);
  white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--elev-1);
  /* Gentle entrance — a new message settles in softly (invest motion in arrivals). */
  animation: bubble-in 280ms var(--ease-settle) both;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}
/* Speaker label: explicit soft-ink color (not opacity) so it stays AA on both
   the two grey bubble fills. */
.bubble .who { display: block; font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--companion-ink-soft); margin-bottom: 0.25rem; }

.from-them { align-self: flex-start; background: var(--them-bg); color: var(--them-ink);
  border-bottom-left-radius: var(--radius-sm); }
.from-me { align-self: flex-end; background: var(--me-bg); color: var(--me-ink);
  border-bottom-right-radius: var(--radius-sm); }

/* Safety/help notice — a calm, distinct warm card (semantic --notice amber, not the grey brand). */
.bubble.safety {
  align-self: stretch; max-width: 100%;
  background: var(--warn-bg); color: var(--warn);
  border: 2px solid var(--warn); border-radius: var(--radius-md);
  box-shadow: none;
}
.bubble.safety .who { color: var(--warn); }

.status { min-height: 1.6rem; color: var(--ink-soft); font-size: 1.05rem; text-align: center; }
.status.error { color: var(--warn); font-weight: 700; }

/* ---- Composer (the always-available text box) ---- */
.composer { display: flex; gap: 0.7rem; align-items: stretch; flex-wrap: wrap; }

.text-input {
  flex: 1 1 60%; min-width: 12ch;
  font-size: 1.4rem; padding: 1rem 1.1rem;
  border: 3px solid var(--line-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.text-input::placeholder { color: var(--admin-ink-muted); }
.text-input:focus { outline: 4px solid var(--focus); outline-offset: 2px;
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.btn {
  font-size: 1.3rem; font-weight: 700; cursor: pointer;
  min-height: 64px; padding: 0.8rem 1.4rem;
  border-radius: var(--radius-md); border: 3px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
/* Subtle press — a small, calm acknowledgement of touch (Fitts/Doherty feedback). */
.btn:not([disabled]):active, .icon-btn:active { transform: translateY(1px) scale(0.99); }
@media (prefers-reduced-motion: reduce) {
  .btn, .btn:active, .icon-btn:active { transition: none; transform: none; }
}

.btn-send { background: var(--accent); color: var(--accent-ink); }
.btn-send:not([disabled]):hover { background: var(--accent-strong); }
.btn-mic { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-mic[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.btn-start { background: var(--accent); color: var(--accent-ink); flex: 1; min-height: 72px; font-size: 1.5rem; }
.btn-start:hover { background: var(--accent-strong); }
/* Stop listening: an explicit mic-OFF control. Same footprint as Start (they swap), but reads as a
   calmer secondary/off action — surface fill, strong grey outline — so "on" vs "off" is obvious. */
.btn-stop { background: var(--surface); color: var(--ink); border-color: var(--line-strong); flex: 1; min-height: 72px; font-size: 1.5rem; }
.btn-stop:hover { background: var(--primary-tint); border-color: var(--primary); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--primary-tint); border-color: var(--primary); }

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; gap: 0.7rem; }

.mic-note {
  margin: 0; padding: 0.8rem 1rem; font-size: 1.05rem;
  color: var(--ink-soft); background: var(--surface);
  border: 2px dashed var(--line); border-radius: 12px;
}

/* ---- Settings dialog (admin/caregiver management surface) ---- */
.settings {
  border: none; border-radius: var(--radius-xl); padding: 0; max-width: 560px; width: 92%;
  background: var(--admin-surface); color: var(--admin-ink); box-shadow: var(--elev-3);
}
.settings::backdrop { background: rgba(27, 25, 22, 0.42); }  /* neutral charcoal scrim (rgba of --gray-900) */
.settings-form { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-2); }

/* Header: the nurse-cap + red-cross mark beside the title to carry the brand into the panel. */
.settings-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.settings-head .logo-mark { width: 40px; height: 40px; }
.settings-form h2 {
  margin: 0; font-size: var(--fs-xl); line-height: var(--lh-tight);
  font-weight: var(--fw-bold); color: var(--brand-heading);
}
.settings-form label {
  font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--admin-ink);
  margin-top: var(--space-4);
}
.field-hint {
  margin: var(--space-1) 0 0; font-size: var(--fs-sm); font-weight: var(--fw-regular);
  color: var(--admin-ink-muted); line-height: var(--lh-body);
}
.settings-form input, .settings-form select {
  font-size: var(--fs-lg); padding: 0.75rem 0.85rem; margin-top: var(--space-2);
  border: 2px solid var(--admin-line-2); border-radius: var(--radius-md);
  background: var(--admin-surface); color: var(--admin-ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.settings-form input:focus, .settings-form select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
/* Advanced toggle row (e.g. audio duplex). A horizontal label+checkbox; overrides the generic
   full-width .settings-form input sizing so the box renders inline and compact. */
.settings-toggle {
  display: flex; align-items: flex-start; gap: var(--space-3);
  flex-direction: row; cursor: pointer;
}
.settings-toggle input[type="checkbox"] {
  flex: 0 0 auto; width: 1.25rem; height: 1.25rem; margin-top: 0.15rem; padding: 0;
  accent-color: var(--primary);
}
.advanced-tag {
  display: inline-block; margin-left: var(--space-2); padding: 0.1rem 0.5rem;
  font-size: var(--fs-sm); font-weight: var(--fw-bold); border-radius: var(--radius-md);
  background: var(--primary-soft); color: var(--primary); vertical-align: middle;
}
.settings-actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); }
.settings-actions .btn { flex: 1; }

/* Conversation-mode switch (turn-based ⟷ duplex): a TRUE on/off toggle, not a checkbox. */
.cfg-sublabel { display: block; font-weight: var(--fw-medium); color: var(--admin-ink); margin-top: var(--space-4); }
.mode-switch { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-2) 0 var(--space-1); }
.mode-switch-opt { font-size: var(--fs-sm); color: var(--admin-ink-muted); transition: color var(--dur) var(--ease); }
.mode-switch-opt.is-on { color: var(--admin-ink); font-weight: var(--fw-bold); }
.switch {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 var(--space-2); border: 0; background: none; cursor: pointer;
}
.switch-track {
  position: relative; display: block; width: 56px; height: 30px; border-radius: var(--radius-pill);
  background: var(--admin-line-2); transition: background var(--dur) var(--ease);
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: var(--elev-1); transition: transform var(--dur) var(--ease);
}
.switch[aria-checked="true"] .switch-track { background: var(--primary); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(26px); }
.switch:focus-visible { outline: none; }
.switch:focus-visible .switch-track { box-shadow: 0 0 0 3px var(--primary-soft); }
@media (prefers-reduced-motion: reduce) { .switch-track, .switch-thumb, .mode-switch-opt { transition: none; } }

/* Chat-side reflection of the active conversation mode (gates the chat interface visibly). */
.audio-mode-chip {
  align-self: center; display: inline-flex; align-items: center; gap: var(--space-2);
  margin: var(--space-2) auto 0; padding: 0.15rem 0.7rem; border-radius: var(--radius-pill);
  background: var(--primary-tint); border: 1px solid var(--admin-line);
  font-size: var(--fs-xs); color: var(--admin-ink-soft);
}
.audio-mode-chip .mode-glyph { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--admin-line-2); }
html[data-audio-mode="duplex"] .audio-mode-chip { background: var(--primary-soft); color: var(--admin-ink); }
html[data-audio-mode="duplex"] .audio-mode-chip .mode-glyph { background: var(--primary); }

/* ---- Settings hub: ONE dialog with internal tabs (Care · Circle · Nurse settings · Admin) ----
   Consolidates the former separate top-bar surfaces. The head + tab strip are direct children of the
   dialog (which has padding:0), so they carry their own horizontal padding; each tab's content sits in
   a .settings-form, which supplies the inner padding as before. */
.settings-hub { max-width: 600px; }
.settings-hub .settings-head {
  padding: var(--space-6) var(--space-6) 0; margin-bottom: var(--space-3);
}
.settings-x { margin-left: auto; min-height: 44px; padding: 0.4rem 0.7rem; line-height: 1; }
.settings-tabs {
  display: flex; flex-wrap: wrap; gap: var(--space-1);
  padding: 0 var(--space-6); margin: 0;
  border-bottom: 1px solid var(--admin-line-2);
}
.tab-btn {
  appearance: none; border: none; background: transparent; cursor: pointer;
  font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--admin-ink-muted);
  padding: 0.7rem 0.9rem; border-bottom: 3px solid transparent; margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab-btn:hover { color: var(--admin-ink); }
.tab-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.tab-btn[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.settings-panel { display: none; }
.settings-panel.is-active { display: block; }
/* Care-circle controls (rendered into #circle-host by tenant.js). */
.cc-fieldset {
  border: 1px solid var(--admin-line-2); border-radius: var(--radius-md);
  padding: var(--space-4); margin-top: var(--space-4);
}
.cc-fieldset legend { padding: 0 var(--space-2); font-weight: var(--fw-bold); }
.cc-code-out { width: 100%; font-family: monospace; }

/* ---- Text-size slider (admin Settings → "Text size") ----
   Drives --fz-scale live as the caregiver drags; the whole UI rescales. The two
   "A" glyphs (small → large) signal direction without relying on color. */
.fontsize-row {
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-2);
}
.fontsize-row .fontsize-min,
.fontsize-row .fontsize-max {
  flex: 0 0 auto; color: var(--admin-ink-soft); font-weight: var(--fw-bold);
  line-height: 1; user-select: none;
}
.fontsize-row .fontsize-min { font-size: 1rem; }
.fontsize-row .fontsize-max { font-size: 1.7rem; }
.fontsize-row input[type="range"] {
  flex: 1 1 auto; min-width: 8rem; height: 2.25rem; margin: 0; padding: 0;
  accent-color: var(--primary); cursor: pointer; background: transparent;
}
.fontsize-row input[type="range"]:focus-visible {
  outline: 4px solid var(--focus); outline-offset: 3px; border-radius: var(--radius-pill);
}
.fontsize-val {
  flex: 0 0 auto; min-width: 3.5ch; text-align: right;
  font-size: var(--fs-md); font-weight: var(--fw-bold);
  color: var(--admin-ink); font-variant-numeric: tabular-nums;
}

/* ---- App shell + caregiver/admin auth gate (Clerk, §1.10) ---- */
/* #app-root holds the whole companion UI; it stays a flex column so the stage layout is unchanged. */
#app-root { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.topbar-actions { display: flex; align-items: center; gap: 0.8rem; }
.user-button { display: inline-flex; align-items: center; min-height: 40px; }
.user-button:empty { display: none; }

/* While Clerk is configured AND no one is signed in, show only the gate. Set on <html> early to
   avoid a flash of the app; cleared by auth.js once a caregiver/admin signs in. */
#auth-gate { display: none; }
html.auth-gating #app-root { display: none; }
/* The gate sits on the warm-grey field; a soft grey wash adds calm depth. */
html.auth-gating #auth-gate {
  display: flex; align-items: center; justify-content: center;
  flex: 1; min-height: 100vh; padding: 1.5rem;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--gray-100) 0%, rgba(236,234,230,0) 60%),
    var(--admin-bg);
}
.auth-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-line);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-5) var(--space-5);
  max-width: 27rem; width: 100%; text-align: center;
  box-shadow: var(--elev-2);
}

/* Logo + halo. The logo's white-fading bottom would vanish on a plain surface, so it
   rests on a faint grey disc (the "background treatment") that keeps the base soft
   but visible. On the warm-grey app field elsewhere the bottom is meant to dissolve. */
.logo-halo {
  width: 116px; height: 116px; margin: 0 auto var(--space-4);
  display: grid; place-items: center; border-radius: var(--radius-pill);
  /* Soft grey disc — gives the logo's white-fading base something gentle to sit on. */
  background: radial-gradient(closest-side, var(--gray-100) 0%, rgba(236,234,230,0.55) 62%, rgba(236,234,230,0) 100%);
}
.logo-mark { width: 76px; height: 76px; display: block; }

.auth-title {
  margin: 0 0 var(--space-2); font-size: var(--fs-xl); line-height: var(--lh-tight);
  font-weight: var(--fw-bold); color: var(--brand-heading); letter-spacing: 0.1px;
}
.auth-sub { margin: 0 0 var(--space-5); color: var(--admin-ink-soft); font-size: var(--fs-md); }
#sign-in { display: flex; justify-content: center; }

/* Quiet reassurance line — clarifies caregiver-only access (PROJECT-PLAN §1.10). */
.auth-foot {
  margin: var(--space-5) 0 0; padding-top: var(--space-4);
  border-top: 1px solid var(--admin-line);
  color: var(--admin-ink-muted); font-size: var(--fs-sm); line-height: var(--lh-body);
}
.auth-error { color: var(--danger); font-weight: var(--fw-bold); }

/* Best-effort cosmetic theming for the Clerk-mounted widget (purely visual; the gate
   works regardless of whether these .cl-* hooks match the loaded Clerk version). */
#sign-in .cl-formButtonPrimary { background: var(--primary); }
#sign-in .cl-formButtonPrimary:hover { background: var(--primary-strong); }
#sign-in a, #sign-in .cl-footerActionLink { color: var(--brand-link); }

/* ---- Primary action button (admin surfaces) ---- */
.btn-primary {
  background: var(--primary); color: var(--on-primary); border-color: transparent;
  transition: background var(--dur) var(--ease);
}
.btn-primary:hover { background: var(--primary-strong); }
/* White gap + charcoal ring stays visible on both the button and the page. */
.btn-primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--admin-surface), 0 0 0 6px var(--focus-ring);
}

/* Respect users who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .btn-primary, .settings-form input, .settings-form select,
  .icon-btn, .text-input { transition: none; }
  .bubble { animation: none; }
}

/* ---- Ambient listening indicator (replaces push-to-talk; §1.11/§1.12) ----
   Once the mic is allowed, NurseJoy listens continuously. This calm strip just shows the live state:
   a soft pulsing dot + a plain-language label. No button, nothing to press. */
.voice-indicator {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 1.1rem; border-radius: var(--radius-pill);
  background: var(--primary-tint); border: 2px solid var(--gray-200);
  color: var(--companion-ink-soft); font-size: 1.15rem; font-weight: var(--fw-medium);
  align-self: center;
}
.voice-indicator .vi-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent-red); flex: 0 0 auto;   /* the one spark of colour — a live "recording" dot */
}
/* Listening (resting): the red dot breathes gently (the single accent in the UI). */
.voice-indicator[data-state="listening"] {
  border-color: var(--accent); color: var(--accent-strong);
}
.voice-indicator[data-state="listening"] .vi-dot {
  animation: vi-pulse 1.8s var(--ease) infinite;
}
/* Speaking: invite interruption (this is the stop-and-listen state). */
.voice-indicator[data-state="speaking"] { border-color: var(--accent); color: var(--accent-strong); }
.voice-indicator[data-state="speaking"] .vi-dot { animation: vi-pulse 1.1s var(--ease) infinite; }
/* Thinking: steady, no pulse — a calm, muted dot. */
.voice-indicator[data-state="thinking"] .vi-dot { background: var(--companion-ink-soft); animation: none; }
/* Muted / inactive: the mic is NOT yet live for the session — before the one-time Start gesture, or
   any time capture isn't actually running. Grayed dot, muted text, neutral border, no pulse: it must
   clearly read as NOT listening (this is the resting/off state, not the active red dot).
   AA: text ≥ 7:1 on the near-white fill; border passes 1.4.11 (non-text). */
.voice-indicator[data-state="muted"] {
  background: var(--admin-surface-2);
  border-color: var(--admin-line-2);
  color: var(--companion-ink-soft);
}
.voice-indicator[data-state="muted"] .vi-dot {
  background: var(--admin-ink-muted); animation: none; opacity: 0.85;
}

@keyframes vi-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(var(--companion-pulse), 0.45); }
  70%  { box-shadow: 0 0 0 12px rgba(var(--companion-pulse), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--companion-pulse), 0); }
}
@media (prefers-reduced-motion: reduce) {
  .voice-indicator .vi-dot { animation: none !important; }
}

/* ============================================================================
   CONVERSATION MODES — turn-based (conventional chatbot) vs duplex (voice-first).
   The whole screen reflows off html[data-audio-mode] (set live by the settings
   toggle, applyAudioMode). Same bubbles + brand; only the INPUT model changes.
   ============================================================================ */

/* --- Chatbot composer: a rounded bar with round mic + send icon buttons. --- */
.composer { flex-wrap: nowrap; align-items: center; gap: 0.5rem; }
.composer .text-input { flex: 1 1 auto; min-width: 0; }
.icon-round {
  flex: 0 0 auto; width: 56px; height: 56px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 3px solid transparent; cursor: pointer; background: var(--surface); color: var(--ink);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-round:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
.icon-round:not([disabled]):active { transform: scale(0.94); }
.icon-round[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-send.icon-round { background: var(--accent); color: var(--accent-ink); }
.btn-send.icon-round:not([disabled]):hover { background: var(--accent-strong); }
.btn-mic.icon-round { background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
.btn-mic.icon-round:hover { border-color: var(--accent); }
.btn-mic.icon-round[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Voice focal zone: the listening cluster (indicator + the one-time grant/stop). --- */
.voice-stage { display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.btn-start, .btn-stop { flex: 0 0 auto; width: min(420px, 100%); }
.actions { justify-content: space-between; align-items: center; }

/* --- Typing indicator (chatbot "…"). --- */
.typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: 0.9rem 1.1rem; margin: 0 0 0 0.4rem;
  background: var(--them-bg); border-radius: var(--radius-lg); border-bottom-left-radius: var(--radius-sm); }
.typing[hidden] { display: none; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--companion-ink-soft); opacity: 0.6;
  animation: typing-bounce 1.2s var(--ease) infinite; }
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; } }

/* --- TURN-BASED: a conventional chatbot. The composer is the whole input (text + mic + send),
       pinned at the bottom; the orb / big Start are hidden (the mic button grants the mic). --- */
html[data-audio-mode="turn"] .voice-stage { display: none; }
html[data-audio-mode="turn"] .composer { position: sticky; bottom: 0; z-index: 1; background: var(--companion-bg); padding: 0.5rem 0; }

/* --- DUPLEX: voice-first. The listening cluster is the focal point; typing is demoted to a slim
       secondary "or type" bar (its mic button hidden — the orb is the mic). --- */
html[data-audio-mode="duplex"] .voice-stage { display: flex; margin: 0.4rem 0 0.2rem; }
html[data-audio-mode="duplex"] .voice-indicator { flex-direction: column; padding: 1.4rem 1.8rem; gap: 0.7rem; border-radius: var(--radius-xl); font-size: 1.25rem; text-align: center; }
html[data-audio-mode="duplex"] .voice-indicator .vi-dot { width: 26px; height: 26px; }
html[data-audio-mode="duplex"] .btn-mic { display: none; }
html[data-audio-mode="duplex"] .text-input { font-size: 1.15rem; padding: 0.75rem 1rem; }
html[data-audio-mode="duplex"] .composer { opacity: 0.95; }

/* ---- Degraded voice (mobile / no live STT): make the TEXT BOX the obvious primary input ---- */
/* When live speech-to-text isn't available, testers on phones must still see typing front-and-centre.
   Emphasize the input, give Send full weight, and let the mic note read as a clear instruction. */
.voice-degraded .text-input {
  flex-basis: 100%;
  font-size: 1.5rem;
  border-width: 3px; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--companion-pulse), 0.14);
}
.voice-degraded .composer { gap: 0.6rem; }
.voice-degraded .btn-send { flex: 1 1 100%; min-height: 68px; font-size: 1.4rem; }
.voice-degraded .mic-note {
  border-style: solid; border-color: var(--accent);
  color: var(--ink); background: var(--surface); font-weight: 600;
}

/* Larger phones / small screens: stack the composer. */
@media (max-width: 520px) {
  :root { --fz-base: 17px; }   /* responsive base only; --fz-scale (user pref) still applies */
  .text-input { flex-basis: 100%; }
  .btn-send { flex: 1; }
}

/* ---- Admin ⇄ Patient mode gate (§1.10) ----
   PATIENT mode is the default and unlocked; admin controls are hidden until a correct PIN unlocks admin
   for this session only. The gate now lives inside the Settings hub's Admin tab (rather than a top-bar
   button); everything marked .admin-only (e.g. the Nurse-settings tab) is revealed only in admin mode. */
.admin-only { display: none; }
body.admin-mode .admin-only { display: inline-flex; }

/* ---- Setup wizard + PIN modal ---- (reuse the .settings dialog shell + brand tokens) */
.settings textarea {
  font-size: var(--fs-lg); padding: 0.75rem 0.85rem; margin-top: var(--space-2);
  border: 2px solid var(--admin-line-2); border-radius: var(--radius-md);
  background: var(--admin-surface); color: var(--admin-ink);
  font-family: inherit; line-height: var(--lh-body); resize: vertical; width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.settings textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.setup-progress { margin-top: 0; font-weight: var(--fw-medium); color: var(--admin-ink-soft); }
.setup-step { display: flex; flex-direction: column; }
/* The wizard shows one step at a time via the [hidden] attribute; the display:flex above would
   otherwise override the UA [hidden] rule, so re-assert it. */
.setup-step[hidden] { display: none; }
.setup-intake-lead { margin-top: 0; }

/* Guided patient-intake conversation (setup step 3): a compact chat inside the wizard. Reuses the
   conversation bubble styles but sized for the dialog. */
.intake-log {
  margin-top: var(--space-3);
  max-height: 38vh; min-height: 8rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-3);
  background: var(--admin-surface-2); border: 1px solid var(--admin-line); border-radius: var(--radius-md);
}
.intake-log .bubble { max-width: 100%; font-size: var(--fs-md); padding: 0.7rem 0.9rem; box-shadow: none; }
.intake-log:empty { display: none; }
.intake-input-row { display: flex; gap: var(--space-2); align-items: stretch; margin-top: var(--space-3); }
.intake-input-row .text-input { flex: 1 1 auto; font-size: var(--fs-md); margin-top: 0; }
.intake-send { flex: 0 0 auto; min-height: 0; }
/* Errors/alerts in setup + PIN: semantic danger (6.5:1 on white), distinct from the brand. */
.setup-err { color: var(--danger); font-weight: var(--fw-bold); }
.pin-modal { max-width: 420px; }

/* Admin voice enrollment (caregiver voiceprint), inside Settings (admin-only, behind the PIN). */
.enroll-box {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-3) var(--space-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md, 12px);
  background: var(--admin-surface-2);
}
.enroll-box legend { padding: 0 var(--space-2); font-weight: var(--fw-bold); color: var(--brand-heading); }
.enroll-status { margin-top: 0; }
.enroll-script em { color: var(--ink); }
.enroll-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.enroll-feedback { margin-top: var(--space-2); }
.enroll-feedback.error { color: var(--danger); font-weight: var(--fw-bold); }
.enroll-feedback.ok { color: var(--ok); font-weight: var(--fw-bold); }
#enroll-record.recording { background: var(--danger); border-color: var(--danger); }

/* Voiceprints management panel (list + alias/rename + remove + add-another), admin-only, behind PIN. */
.vp-box { margin-top: var(--space-3); }
.vp-list { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.vp-item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-md, 12px); background: var(--surface);
}
.vp-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); min-width: 0; }
.vp-name { font-weight: var(--fw-bold); color: var(--ink); word-break: break-word; }
.vp-rel { color: var(--muted, #5a5a5a); font-size: 0.9em; }
.vp-badge {
  font-size: 0.72rem; font-weight: var(--fw-bold); padding: 2px 9px; border-radius: 999px;
  background: var(--primary-tint); color: var(--brand-heading); white-space: nowrap;
}
.vp-role-admin { background: #ffe9c7; color: #8a5a00; }
.vp-role-known { background: #e3f0e3; color: #2e6b2e; }
.vp-role-unknown { background: var(--surface); color: var(--muted, #5a5a5a); }
.vp-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
.vp-actions .btn { padding: 6px 12px; font-size: 0.9rem; }
.vp-edit { display: flex; flex-wrap: wrap; gap: var(--space-2); width: 100%; align-items: center; }
.vp-edit input { flex: 1 1 14ch; min-width: 10ch; margin: 0; }
.vp-edit-err { color: var(--danger); font-weight: var(--fw-bold); width: 100%; }
.vp-add { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line-strong); }
.vp-add-title { margin: 0 0 var(--space-2); font-size: 1rem; color: var(--brand-heading); }
.vp-add.disabled input, .vp-add.disabled select, .vp-add.disabled button { opacity: 0.55; pointer-events: none; }
#vp-add-record.recording { background: var(--danger); border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .settings textarea { transition: none; }
}

/* Always-visible educational disclaimer (patient-facing health product). Calm and unobtrusive but
   never hidden — Nurse Joy is supportive education, not a substitute for the care team. */
.care-disclaimer {
  margin: 1.1rem auto 0;
  max-width: 46ch;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.45;
  opacity: 0.85;
}
.care-disclaimer strong { font-weight: 700; }

/* Care & health panel */
.care-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.4rem 0; }
.care-row input { flex: 1 1 12rem; }
.care-meds, .care-checkin { border: 1px solid var(--line, rgba(0,0,0,0.15)); border-radius: 12px; padding: 0.8rem 1rem; margin: 0.8rem 0; }
.care-meds legend, .care-checkin legend { font-weight: 700; padding: 0 0.4rem; }
.care-med-list { list-style: none; padding: 0; margin: 0.4rem 0; }
.care-med-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.3rem 0; }
.care-med-add { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.care-med-add input { flex: 1 1 8rem; }
.care-checkin-log { max-height: 12rem; overflow-y: auto; margin: 0.4rem 0; }
.care-checkin-log p { margin: 0.35rem 0; padding: 0.5rem 0.7rem; border-radius: 10px; }
.care-checkin-log .ci-nurse { background: var(--bubble-bot, rgba(27,25,22,0.07)); }
.care-checkin-log .ci-me { background: var(--bubble-me, rgba(0,0,0,0.05)); text-align: right; }
.care-output { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.95rem; white-space: pre; }

/* ---- Research tab (patient/family disease-research browser, inside the Settings dialog) ----
   Lives in #panel-research as a 5th Settings tab. Everything is sized in rem so it scales with the
   Text-size slider. Calm, high-contrast, generous spacing for the caregiver/older-adult audience. */

/* 988 crisis banner — only shown for the mental-health conditions. Uses the warm notice tokens, with the
   one allowed accent (red) on the left edge so it reads as "important" without alarm. */
.research-crisis {
  margin: var(--space-3) 0; padding: var(--space-3) var(--space-4);
  background: var(--warn-bg); color: var(--admin-ink);
  border: 1px solid var(--admin-line); border-left: 4px solid var(--accent-red);
  border-radius: var(--radius-md); font-size: var(--fs-sm); line-height: var(--lh-body);
}
.research-crisis strong { font-weight: var(--fw-bold); }

.research-search-row { display: flex; }
.research-search-row input { flex: 1; }

/* Latest research & trials feed. */
.research-latest { margin-top: var(--space-5); }
.research-h3 {
  font-size: var(--fs-lg); font-weight: var(--fw-bold); color: var(--brand-heading);
  margin: var(--space-5) 0 var(--space-2); line-height: var(--lh-tight);
}
.research-latest-body { display: flex; flex-direction: column; gap: var(--space-3); }
.research-empty {
  background: var(--admin-surface-2); border: 1px dashed var(--admin-line-2);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin: 0;
}
.research-update {
  background: var(--admin-surface-2); border: 1px solid var(--admin-line);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
}
.research-update-title { margin: var(--space-2) 0 0; font-weight: var(--fw-bold); color: var(--admin-ink); }
.research-update-sum { margin: var(--space-1) 0 0; color: var(--admin-ink-soft); line-height: var(--lh-body); }

/* Kind + date chips on a feed item. */
.research-kind {
  display: inline-block; font-size: var(--fs-xs); font-weight: var(--fw-bold);
  padding: 2px 8px; border-radius: var(--radius-pill); border: 1px solid var(--admin-line-2);
  color: var(--admin-ink); background: var(--admin-surface);
}
.research-kind-trial { border-color: var(--primary); background: var(--primary-soft); }
.research-date { display: inline-block; margin-left: var(--space-2); font-size: var(--fs-xs); color: var(--admin-ink-muted); }

/* The sectioned knowledge base. */
.research-sections { margin-top: var(--space-2); }
.research-group { margin-top: var(--space-4); }
.research-entry {
  background: var(--admin-surface); border: 1px solid var(--admin-line);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin: var(--space-3) 0;
}
.research-entry-title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--admin-ink); line-height: var(--lh-tight); }
.research-entry-sum { margin: var(--space-2) 0 0; color: var(--admin-ink); line-height: var(--lh-body); }
.research-entry-detail { margin: var(--space-2) 0 0; color: var(--admin-ink-soft); line-height: var(--lh-body); }
.research-more { margin-top: var(--space-2); padding: 6px 14px; font-size: var(--fs-sm); }

/* Evidence pill (honest framing of how strong the evidence is). */
.research-evidence {
  display: inline-block; margin-top: var(--space-2); margin-right: var(--space-2);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--admin-ink-soft);
  background: var(--admin-surface-2); border: 1px solid var(--admin-line);
  border-radius: var(--radius-pill); padding: 2px 10px;
}
.research-caution { margin: var(--space-2) 0 0; font-size: var(--fs-sm); color: var(--notice); line-height: var(--lh-body); }

.research-sources { margin: var(--space-2) 0 0; font-size: var(--fs-sm); color: var(--admin-ink-muted); line-height: var(--lh-body); }
.research-sources-label { font-weight: var(--fw-medium); }
.research-source-link { color: var(--brand-link); text-decoration: underline; }
.research-source-link:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
.research-update .research-source-link { display: inline-block; margin-top: var(--space-2); font-size: var(--fs-sm); }
