  /* === DESIGN TOKENS — default theme (dark). See docs/frontend-spec.md.
     Three segregated families: chrome (neutral) · status (reserved clinical) · accent (interactive).
     Reference every colour via a role token (var(--…)); never hardcode a hex in markup. */
  :root {
    /* chrome — neutral surfaces, text, lines */
    --chrome-bg:#0f1720; --chrome-bg-2:#0b121a; --chrome-panel:#17212b;
    --chrome-line:#243442; --chrome-hover:#1e2a36;
    --text:#e6edf3; --text-muted:#8aa0b2; --text-inverse:#fff;
    --overlay-scrim:#000a;
    /* status — reserved for clinical/semantic state, never a generic control */
    --status-ok:#2ea043;   --status-ok-bg:#0f2e18;
    --status-warn:#d8a000; --status-warn-bg:#3a2d00;
    --status-bad:#e5534b;  --status-bad-bg:#2e1210;
    /* accent — the single interactive / brand signal */
    --accent:#4aa3ff; --accent-bg:#0d2740; --accent-contrast:#07121d; --accent-wash:rgba(74,163,255,.12);
    /* derived seeds */
    --radius:12px;
    /* legacy aliases — migrated incrementally (frontend-spec Phase 1) */
    --bg:var(--chrome-bg); --bg2:var(--chrome-bg-2); --panel:var(--chrome-panel);
    --line:var(--chrome-line); --fg:var(--text); --muted:var(--text-muted);
    --ok:var(--status-ok); --bad:var(--status-bad); --warn:var(--status-warn);
  }
  /* Self-hosted theme fonts (OFL), served from /ui/fonts — no external fetch, offline-safe.
     Themes opt in via their font-family token; the default Care0 look stays on system-ui. */
  @font-face { font-family:'Hanken Grotesk'; src:url('/ui/fonts/HankenGrotesk.woff2') format('woff2'); font-weight:100 900; font-style:normal; font-display:swap; }
  @font-face { font-family:'Bubblegum Sans'; src:url('/ui/fonts/BubblegumSans.woff2') format('woff2'); font-weight:400; font-style:normal; font-display:swap; }
  @font-face { font-family:'VT323'; src:url('/ui/fonts/VT323.woff2') format('woff2'); font-weight:400; font-style:normal; font-display:swap; }
  * { box-sizing:border-box; }
  html,body { height:100%; }
  body { margin:0; font:15px/1.55 system-ui,-apple-system,sans-serif; background:var(--bg); color:var(--fg); }
  a,.link { color:var(--accent); cursor:pointer; text-decoration:none; }
  button { font:inherit; color:var(--accent-contrast); background:var(--accent); border:none; border-radius:8px; padding:8px 14px; font-weight:600; cursor:pointer; }
  button.ghost { background:transparent; color:var(--fg); border:1px solid var(--line); font-weight:500; }
  button.sm { padding:4px 10px; font-size:13px; }
  button:disabled { opacity:.4; cursor:not-allowed; }
  input,textarea,select { font:inherit; color:var(--fg); background:var(--bg2); border:1px solid var(--line); border-radius:8px; padding:9px 12px; }
  textarea { width:100%; resize:vertical; min-height:70px; }

  /* home */
  #home { min-height:calc(100vh / var(--app-zoom,1)); display:flex; flex-direction:column; align-items:center; justify-content:center; padding:24px; gap:18px; }
  #home.hidden { display:none; }
  .brand { font-size:40px; font-weight:700; letter-spacing:-.02em; }
  .brand .dot { color:var(--accent); }
  /* white-label logo: scales with the brand font-size, so it fits both the home brand and the topbar */
  .brand-logo { height:1em; width:auto; vertical-align:-0.15em; margin-right:.3em; }
  .tagline { color:var(--muted); margin-top:-8px; }
  .tagline:empty { display:none; }
  .ask { width:min(640px,100%); position:relative; }
  .ask input { width:100%; font-size:18px; padding:16px 18px; border-radius:28px; border:1px solid var(--line); background:var(--panel); box-shadow:0 8px 30px rgba(0,0,0,.35); }
  .ask input:focus { outline:none; border-color:var(--accent); }
  .examples { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; width:min(640px,100%); }
  /* Home quick-action chips: a centered wrap group, so they stay centred when the UI is scaled up. */
  .homeacts { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; max-width:760px; }
  .chip { border:1px solid var(--line); border-radius:20px; padding:5px 12px; font-size:13px; color:var(--muted); cursor:pointer; background:var(--panel); }
  .chip:hover { border-color:var(--accent); color:var(--fg); }

  /* Landing "Examples & setup" disclosure: one quiet trigger that reveals the
     secondary stuff (examples, demo/setup chips, scope note) on demand, so the
     home screen itself stays logo + search. */
  .home-more-btn { margin-top:2px; background:transparent; border:none; color:var(--muted); font-size:13px; cursor:pointer;
    display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:16px; }
  .home-more-btn:hover { color:var(--fg); }
  .home-more-btn .chev { font-size:11px; transition:transform .18s ease; }
  .home-more-btn.open .chev { transform:rotate(180deg); }
  .home-more { width:min(640px,100%); display:flex; flex-direction:column; gap:16px; background:var(--panel);
    border:1px solid var(--line); border-radius:16px; padding:18px; box-shadow:0 12px 40px rgba(0,0,0,.35); }
  /* an author display: wins over the UA [hidden] rule, so hide it explicitly */
  .home-more[hidden] { display:none; }
  .home-more-sec { display:flex; flex-direction:column; gap:10px; }
  .home-more-h { font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); }
  .home-more .examples, .home-more .homeacts { justify-content:flex-start; width:auto; max-width:none; }
  .home-scope { font-size:13px; display:flex; flex-wrap:wrap; align-items:center; gap:10px; }

  /* suggestions dropdown */
  .sugg { position:absolute; top:calc(100% + 8px); left:0; right:0; background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; box-shadow:0 12px 40px rgba(0,0,0,.45); z-index:10; }
  .sugg .grp { padding:6px 14px; font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); background:var(--bg2); }
  .sugg .item { padding:10px 14px; display:flex; gap:10px; align-items:center; cursor:pointer; }
  .sugg .item:hover, .sugg .item.active { background:var(--chrome-hover); }
  .sugg .item .ico { width:22px; text-align:center; opacity:.8; }
  .sugg .item .hint { color:var(--muted); font-size:13px; margin-left:auto; }
  /* Voice input: a mic inside the omnibox. Hidden until /speech/config reports a live backend. */
  .mic { position:absolute; right:8px; top:50%; transform:translateY(-50%); width:40px; height:40px; padding:0;
    border-radius:50%; background:var(--panel); color:var(--fg); border:1px solid var(--line); box-shadow:none;
    display:flex; align-items:center; justify-content:center; font-size:18px;
    touch-action:none; user-select:none; -webkit-user-select:none; }
  .mic:hover { border-color:var(--accent); }
  .mic svg { width:20px; height:20px; display:block; }
  .topbar .mini .mic svg { width:16px; height:16px; }
  .mic.fieldmic svg { width:16px; height:16px; }
  .mic.recording { background:var(--bad); color:var(--text-inverse); border-color:var(--bad); animation:micpulse 1.2s ease-in-out infinite; }
  @keyframes micpulse { 0%,100%{ box-shadow:0 0 0 0 rgba(229,83,75,.5); } 50%{ box-shadow:0 0 0 9px rgba(229,83,75,0); } }
  .ask.has-mic input { padding-right:58px; }
  .topbar .mini .mic { width:30px; height:30px; right:5px; font-size:15px; }
  .topbar .mini.has-mic input { padding-right:42px; }
  .micnote { padding:11px 14px; color:var(--muted); font-size:13px; display:flex; gap:9px; align-items:center; }
  .micnote .rec { width:9px; height:9px; border-radius:50%; background:var(--bad); animation:micpulse 1.2s ease-in-out infinite; }
  /* Dictation on a narrative <textarea>: a hold-to-talk mic in its bottom-right corner. */
  .fieldmic-wrap { position:relative; }
  .fieldmic-wrap textarea { padding-right:44px; }
  .mic.fieldmic { width:32px; height:32px; right:8px; bottom:10px; top:auto; transform:none; font-size:15px; }
  .micstatus { font-size:12px; color:var(--muted); min-height:16px; margin-top:2px; }
  .micstatus .micnote { padding:2px 0; }

  /* surface */
  #app { min-height:calc(100vh / var(--app-zoom,1)); display:none; flex-direction:column; }
  #app.show { display:flex; }
  .topbar { position:sticky; top:0; z-index:5; display:flex; gap:12px; align-items:center; padding:10px 16px; background:color-mix(in srgb, var(--chrome-bg) 92%, transparent); backdrop-filter:blur(6px); border-bottom:1px solid var(--line); }
  .topbar .brand2 { font-weight:700; cursor:pointer; white-space:nowrap; }
  .topbar .brand2 .dot { color:var(--accent); }
  .topbar .mini { flex:1; position:relative; max-width:560px; }
  .topbar .mini input { width:100%; border-radius:20px; padding:8px 14px; }
  .surface { padding:22px 16px 60px; max-width:900px; width:100%; margin:0 auto; }

  .card { background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:18px; margin-bottom:16px; }
  h1.name { margin:0; font-size:26px; letter-spacing:-.01em; }
  .patient-header-main { display:flex; align-items:flex-start; justify-content:space-between; flex-wrap:wrap; gap:12px 28px; }
  .patient-header-identity { flex:1 1 280px; min-width:0; }
  .patient-header-identity .sub { margin:5px 0 0; overflow-wrap:anywhere; }
  .patient-header #ethnicity-profile { flex:1 1 280px; max-width:500px; min-width:0; padding-top:5px; }
  .ethnicity-summary { display:flex; justify-content:space-between; align-items:baseline; gap:12px; list-style:none; }
  .ethnicity-summary::-webkit-details-marker { display:none; }
  .ethnicity-summary > span:first-child { min-width:0; overflow-wrap:anywhere; }
  .ethnicity-edit-label { flex-shrink:0; color:var(--accent); font-size:13px; }
  .ethnicity-edit-label::before { content:"▸ "; }
  .ethnicity-editor[open] .ethnicity-edit-label::before { content:"▾ "; }
  .ethnicity-editor form { padding-top:12px; }
  .ethnicity-save-notice { display:block; margin-top:4px; color:var(--ok); font-size:12px; }
  .sub { color:var(--muted); margin-top:2px; }
  .chips { display:flex; gap:8px; flex-wrap:wrap; margin-top:12px; }
  .pill { display:inline-flex; align-items:center; gap:6px; padding:3px 10px; border-radius:16px; font-size:13px; background:var(--accent-bg); color:var(--accent); }
  .pill.ok { background:var(--status-ok-bg); color:var(--ok); } .pill.bad { background:var(--status-bad-bg); color:var(--bad); }
  .pill.warn { background:var(--status-warn-bg); color:var(--warn); } .pill.mut { background:var(--bg2); color:var(--muted); }
  .pill.ai { background:var(--status-warn-bg); color:var(--warn); }
  .actionbar { display:flex; gap:8px; flex-wrap:wrap; margin:4px 0 18px; }
  .tawrap { position:relative; }
  .tadrop { position:absolute; top:calc(100% + 4px); left:0; min-width:320px; max-width:520px; max-height:280px; overflow:auto; z-index:40; background:var(--panel); border:1px solid var(--line); border-radius:10px; box-shadow:0 12px 40px rgba(0,0,0,.45); }
  .taitem { padding:9px 12px; cursor:pointer; font-size:14px; border-bottom:1px solid var(--bg2); }
  .taitem:last-child { border-bottom:none; }
  .taitem:hover { background:var(--chrome-hover); }
  .sectionhdr { font-size:12px; text-transform:uppercase; letter-spacing:.07em; color:var(--muted); margin:22px 0 8px; }

  .tl { list-style:none; margin:0; padding:0; position:relative; }
  .tl:before { content:""; position:absolute; left:14px; top:4px; bottom:4px; width:2px; background:var(--line); }
  .tl li { position:relative; padding:8px 0 8px 40px; }
  .tl li .dot { position:absolute; left:8px; top:12px; width:14px; height:14px; border-radius:50%; background:var(--panel); border:2px solid var(--accent); }
  .tl li .dot.res { border-color:var(--warn); } .tl li .dot.dx { border-color:var(--bad); } .tl li .dot.rx { border-color:var(--ok); }
  .tl li .dot.doc { border-color:var(--muted); background:var(--muted); }
  .tl li .when { color:var(--muted); font-size:12px; }

  table { width:100%; border-collapse:collapse; }
  th,td { text-align:left; padding:10px 12px; border-bottom:1px solid var(--line); }
  th { font-size:12px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); font-weight:600; }
  tr.click { cursor:pointer; } tr.click:hover td { background:var(--chrome-hover); }
  .empty { color:var(--muted); font-style:italic; }
  .result { margin-top:10px; padding:9px 12px; border-radius:8px; white-space:pre-wrap; font-size:13px; }
  .result.ok { background:var(--status-ok-bg); border:1px solid var(--ok); } .result.bad { background:var(--status-bad-bg); border:1px solid var(--bad); }
  .foot { text-align:center; color:var(--muted); font-size:12px; padding:20px; }
  .inlineform { display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
  .inlineform input { flex:1; min-width:120px; }

  /* collapsible governance (data custody + connected apps) — folded away from the clinical view */
  details.gov { margin:22px 0 4px; }
  details.gov > summary { cursor:pointer; list-style:none; padding:9px 0; color:var(--muted);
    font-size:12px; text-transform:uppercase; letter-spacing:.07em; display:flex; align-items:center; gap:10px; border-top:1px solid var(--line); }
  details.gov > summary::-webkit-details-marker { display:none; }
  details.gov > summary:before { content:"▸"; color:var(--muted); font-size:11px; }
  details.gov[open] > summary:before { content:"▾"; }
  details.gov > summary .pill { text-transform:none; letter-spacing:0; }
  details.gov .sectionhdr:first-child { margin-top:10px; }
  details.tl-more > summary { cursor:pointer; color:var(--accent); font-size:13px; padding:6px 0; list-style:none; user-select:none; }
  details.tl-more > summary::-webkit-details-marker { display:none; }
  details.tl-more > summary:hover { text-decoration:underline; }
  details.tl-more > summary:before { content:"⌄ "; }
  details.tl-more[open] > summary { color:var(--muted); }
  details.tl-more[open] > summary:before { content:"⌃ "; }
  /* Flyover tour — a prominent, hard-to-miss pitch card */
  #tourback { position:fixed; inset:0; z-index:9998; background:radial-gradient(ellipse at 50% 70%, transparent 30%, rgba(3,8,14,.55) 100%); pointer-events:none; }
  #tourcard { position:fixed; left:50%; bottom:26px; transform:translateX(-50%); z-index:9999; width:min(620px, calc(100% - 28px));
    background:linear-gradient(180deg, #16293d 0%, var(--panel) 60%); border:1px solid var(--accent);
    border-radius:16px; padding:18px 20px 16px; box-shadow:0 18px 60px rgba(0,0,0,.6), 0 0 0 4px var(--accent-wash);
    animation:tourpop .32s cubic-bezier(.2,.8,.3,1.2); }
  @keyframes tourpop { from { opacity:0; transform:translateX(-50%) translateY(14px) scale(.97); } to { opacity:1; transform:translateX(-50%) translateY(0) scale(1); } }
  #tourcard .kicker { font-size:11px; letter-spacing:.14em; text-transform:uppercase; color:var(--accent); font-weight:700; }
  #tourcard h3 { margin:3px 0 6px; font-size:20px; line-height:1.2; }
  #tourcard .body { color:var(--fg); opacity:.9; line-height:1.5; margin:0 0 10px; }
  #tourcard .why { background:var(--accent-wash); border-left:3px solid var(--accent); border-radius:0 8px 8px 0;
    padding:8px 12px; margin:0 0 14px; font-size:14px; line-height:1.45; }
  #tourcard .why b { color:var(--accent); }
  #tourcard .pbar { height:4px; background:var(--bg2); border-radius:3px; overflow:hidden; flex:1; }
  #tourcard .pbar > div { height:100%; background:var(--accent); transition:width .3s ease; }
  #tourcard button { font-size:14px; }
  #tourcard .tbtn-ghost { background:transparent; border:1px solid var(--line); color:var(--muted); }

  /* ===================== RESPONSIVE — phone-first additions (frontend-spec Phase 2) ===================== */
  @media (max-width:640px) {
    .surface { padding:16px 12px 56px; }
    .card { padding:14px; }
    h1.name { font-size:22px; }

    /* topbar: brand + jurisdiction on row 1, full-width omnibox on row 2 */
    .topbar { flex-wrap:wrap; gap:8px; padding:8px 12px; }
    .topbar .brand2 { order:1; font-size:15px; }
    .topbar > button { order:2; margin-left:auto; }
    .topbar .mini { order:3; flex:1 1 100%; max-width:none; }

    /* comfortable tap targets */
    button { min-height:44px; }
    button.sm { min-height:38px; padding:7px 12px; }
    .chip { padding:8px 13px; }
    .actionbar { gap:10px; }

    /* 16px fields so iOS doesn't zoom the page on focus */
    input,textarea,select { font-size:16px; }

    /* typeahead dropdown kept within the viewport */
    .tadrop { min-width:0; width:calc(100vw - 32px); max-width:none; }

    /* board lane rows wrap instead of overflowing */
    .boardrow { flex-wrap:wrap; }

    /* tables collapse to stacked label/value rows; responsiveTables() stamps data-label */
    .surface table, .surface tbody, .surface tr, .surface td { display:block; width:auto; }
    .surface thead { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
    .surface tr { border-bottom:1px solid var(--chrome-line); padding:10px 0; }
    .surface tr:last-child { border-bottom:none; }
    .surface td { border:none; display:block; padding:4px 0; text-align:left; }
    .surface td[data-label]::before { content:attr(data-label); display:inline-block; width:40%; min-width:96px;
      padding-right:10px; color:var(--text-muted); font-size:11px; text-transform:uppercase; letter-spacing:.04em;
      vertical-align:baseline; }
  }
  @media (max-width:400px) {
    .surface { padding:14px 10px 52px; }
    .topbar .brand2 { font-size:14px; }
  }

  /* ===================== PATIENT COCKPIT (feat/ui-cockpit) =====================
     Identity strip + one Actions home + state-driven centre + standing-facts rail. */
  .pc-ident { display:flex; align-items:flex-start; gap:12px 24px; flex-wrap:wrap; }
  .pc-who { flex:1 1 280px; min-width:0; }
  .pc-meta { display:flex; align-items:baseline; flex-wrap:wrap; gap:5px; }
  .pc-side { margin-left:auto; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
  .data-edit { font:inherit; color:var(--accent); background:none; border:none; padding:0; cursor:pointer; border-bottom:1px dashed transparent; }
  .data-edit:hover { border-bottom-color:var(--line); }
  .pc-menuwrap { position:relative; }
  .pc-actions-btn { font:inherit; font-weight:600; font-size:13px; cursor:pointer; border:1px solid var(--line); background:var(--panel); color:var(--fg); border-radius:9px; padding:7px 13px; }
  .pc-actions-btn:hover { border-color:var(--accent); }
  .pc-menu { position:absolute; right:0; top:calc(100% + 7px); z-index:50; width:280px; max-width:82vw; background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); box-shadow:0 16px 48px rgba(0,0,0,.45); padding:6px; }
  .pc-mgrp { padding:9px 10px 4px; font-size:10.5px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); }
  .pc-mitem { display:block; width:100%; text-align:left; font:inherit; font-size:13.5px; color:var(--fg); background:none; border:none; border-radius:8px; padding:8px 10px; cursor:pointer; }
  .pc-mitem:hover { background:var(--chrome-hover); }
  .pc-grid { display:grid; grid-template-columns:minmax(0,1fr) 290px; gap:16px; align-items:start; margin-bottom:16px; }
  .pc-main { min-width:0; }
  .pc-rail { display:flex; flex-direction:column; gap:12px; }
  .pc-railcard { padding:13px 14px; margin:0; }
  .pc-railh { font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); display:flex; justify-content:space-between; }
  .pc-flist { list-style:none; margin:9px 0 0; padding:0; display:flex; flex-direction:column; gap:7px; font-size:13.5px; }
  .pc-flist li { display:flex; align-items:center; gap:8px; }
  .pc-flist li .when { margin-left:auto; white-space:nowrap; }
  .pc-dot { width:7px; height:7px; border-radius:50%; flex:none; }
  @media (max-width:860px) { .pc-grid { grid-template-columns:1fr; } }

  /* ===================== APPOINTMENT BOARD (scheduling v2) — responsive =====================
     The resource-columned day grid squeezes badly on a phone; let it scroll sideways instead of
     crushing columns, and keep the booking/action sheets within the viewport. */
  .sched-ec-wrap { overflow:hidden; }
  @media (max-width:640px) {
    .sched-ec-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
    .sched-ec-wrap > #sched-ec { min-width:560px; }   /* legible columns; scroll rather than shrink */
    #book-overlay, #resv-overlay, #find-appt-overlay { padding:12px !important; place-items:start center !important; }
    #book-overlay > .card, #resv-overlay > .card, #find-appt-overlay > .card { margin-top:2vh; }
  }

  /* ===================== STAFF SIGN-IN GATE =====================
     A full-screen, branded sign-in shown IN PLACE OF the console chrome (never over it). Until a live
     staff session exists the topbar, omnibox and chat dock stay hidden, so an expired or anonymous
     visitor sees a clean login — not a chromed console where every call 401s. Reuses the tenant brand
     (cloned from #home .brand) and the theme tokens, matching deploy/login.html's look. */
  #stafflogin { position:fixed; inset:0; z-index:10000; display:flex; align-items:center; justify-content:center;
    padding:24px; background:radial-gradient(1100px 560px at 50% -10%, color-mix(in srgb, var(--accent) 15%, var(--bg)) 0%, var(--bg) 62%); }
  #stafflogin[hidden] { display:none; }
  #stafflogin .login-card { width:100%; max-width:400px; background:var(--panel); border:1px solid var(--line);
    border-radius:16px; padding:34px 30px; box-shadow:0 18px 60px rgba(0,0,0,.5); text-align:center; }
  #stafflogin .login-brand { font-size:38px; font-weight:800; letter-spacing:-.02em; margin-bottom:6px; }
  #stafflogin .login-brand .dot { color:var(--accent); }
  #stafflogin .login-brand .brand-logo { height:1em; width:auto; vertical-align:-0.15em; margin-right:.3em; }
  #stafflogin .login-sub { color:var(--muted); font-size:14px; margin:0 0 22px; }
  #stafflogin .login-note { color:var(--accent); font-size:13px; margin:0 0 16px; }
  #stafflogin .login-btn { width:100%; padding:12px 14px; font-size:15px; font-weight:700; }
  #stafflogin .login-hint { color:var(--muted); font-size:12.5px; margin:14px 0 0; line-height:1.45; }
  #stafflogin .login-foot { color:var(--muted); font-size:12px; margin:18px 0 0; }
  /* While gated, the messenger dock must not show — the two auth states stay in sync. */
  body.gated #care0chat-launch, body.gated #care0chat-panel { display:none !important; }
