/* ════════════════════════════════════════════════════════════════════════════
   ILAI DESIGN SYSTEM · v2.0 "PULSE" — the living interface
   Two temperatures, one organism. Daylight: warm bright canvas, deepened
   aurora. Night: the void, electric accents. The aurora (gold→lime→teal)
   is identity; signal color is reserved for clinical meaning; the surface
   itself knows how you're doing (state-aware ambience).
   ════════════════════════════════════════════════════════════════════════════ */

:root,[data-theme="light"]{
  /* ── Brand / identity ── */
  --brand:               #C8941E;       /* flame gold · daylight-deepened */
  --brand-hi:            #D9A82A;
  --brand-lo:            #9C7314;
  --gold:                #C8941E;
  --lime:                #76B41C;
  --teal:                #0FA793;
  --tr-ic-photo:         #7C5CC4;       /* icon identity colours (topics, never state) */
  --tr-ic-hiit:          #C2456E;
  /* Design pass 2026-10-06 (approved): the aurora gradient is retired. The names stay so old rules resolve to flat gold. */
  --aurora:              #C8941E;
  --aur-glow:            transparent;
  --on-aurora:           #1C1B16;

  /* ── Surfaces ── */
  --bg-canvas:           #F4F3ED;       /* the page */
  --bg-surface:          #FFFFFF;       /* default card */
  --bg-raised:           #FAF9F4;       /* nested card / hover */
  --bg-sunken:           #F3F1EA;       /* input / well */
  --bg-wash:             #F4F3ED;

  /* ── Borders ── */
  --stroke-subtle:       #ECE9DF;
  --stroke-default:      #DAD6C9;
  --stroke-strong:       #C7C2B2;
  --ring-track:          #ECE9DF;

  /* ── Text ── */
  --ink-primary:         #1C1B16;
  --ink-secondary:       #605E54;
  --ink-muted:           #7C786B;       /* was #A39F92 (2.6:1) — fails AA on every footnote; 4.6:1 now (review 2026-09-19) */
  --ink-inverse:         #FBFAF6;

  /* ── Clinical signal palette — RESERVED for health meaning ── */
  --sig-good:            #0C9D61;
  --sig-good-wash:       rgba(12,157,97,0.09);
  --sig-good-edge:       rgba(12,157,97,0.20);
  --sig-warn:            #DD8500;
  --sig-warn-wash:       rgba(221,133,0,0.10);
  --sig-warn-edge:       rgba(221,133,0,0.22);
  --sig-risk:            #DE3A2F;
  --sig-risk-wash:       rgba(222,58,47,0.08);
  --sig-risk-edge:       rgba(222,58,47,0.20);
  --sig-info:            #1F6FEB;
  --sig-info-wash:       rgba(31,111,235,0.08);
  --sig-info-edge:       rgba(31,111,235,0.18);
  --sig-cross:           #C8941E;
  --sig-cross-wash:      rgba(200,148,30,0.10);
  --sig-cross-edge:      rgba(200,148,30,0.24);
  /* Violet is retired: ILAI's own voice signs in deep gold (--brand-lo). */
  --sig-ai:              #8A6510;
  --sig-ai-wash:         transparent;
  --sig-ai-edge:         #ECE9DF;
  --on-ai:               #FFFFFF;       /* text on a --sig-ai fill */
  --accent:              #8A6510;
  --accent-bg:           transparent;
  --purple:              #8A6510;
  --purple-bg:           transparent;
  --purple-border:       #ECE9DF;
  --badge-purple-bg:     transparent;
  --hp-aur:              none;
  --hp-glass:            #FFFFFF;
  --hp-glass-b:          #FFFFFF;
  --bg-grad:             #F4F3ED;
  --text-muted:          #7C786B;

  /* ── State ambience (aurora room-tint) ── */
  --amb-good:none; --amb-warn:none; --amb-risk:none;

  /* ── Body map plate (anatomical figure) ──
     Deliberately non-semantic greys: the plate's NORMAL state must read as unremarkable, so
     these never borrow from the --sig-* scale. Only the one flagged system takes --sig-risk. */
  --bm-fill:             rgba(0,0,0,0.028);
  --bm-line:             rgba(0,0,0,0.46);
  --bm-muscle:           rgba(0,0,0,0.21);
  --bm-organ:            #4C4D55;
  --bm-watch:            rgba(0,0,0,0.065);
  --bm-thin:             #C3C6CC;

  /* ── Decile ramp ── */
  --dec-1:  #DE3A2F;  --dec-2:  #E25A2B;  --dec-3:  #DD8500;
  --dec-4:  #C2A013;  --dec-5:  #9CB016;  --dec-6:  #76B41C;
  --dec-7:  #3FAE3F;  --dec-8:  #0C9D61;  --dec-9:  #10A87B;  --dec-10: #0FA793;

  /* ── Elevation — warm, soft ── */
  /* Hairline elevation; only drawers and menus carry one soft shadow (--shadow-3). */
  --shadow-1:            none;
  --shadow-2:            none;
  --shadow-3:            0 8px 24px rgba(0,0,0,0.08);
  --shadow:              none;

  /* ── Radius ── */
  /* Three radii: 6 controls · 10 cards and panels · pill. The other names alias them. */
  --r-xs:   6px;  --r-sm:   6px;  --r-md:   10px;
  --r-lg:   10px; --r-xl:   10px; --r-pill: 999px;

  /* ── Spacing (8px rhythm with half-steps below 16) ── */
  --sp-1:   2px;  --sp-2:   4px;  --sp-3:   6px;  --sp-4:   8px;
  --sp-5:   10px; --sp-6:   12px; --sp-7:   14px; --sp-8:   16px;
  --sp-10:  20px; --sp-12:  24px; --sp-16:  32px; --sp-20:  40px;
  --sp-24:  48px; --sp-32:  64px;

  /* ── Typography ── */
  --font-sans:  'Geist',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --font-disp:  'Geist',-apple-system,sans-serif;
  /* figures use the sans with tabular digits (2026-10-12, Barry: "everything should be consistent"): the mono face gave a comma a
     full cell ("2 , 002", "7 h 28 min"). The token name stays so every rule that reads it follows. */
  --font-mono:  'Geist',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;

  /* Type scale */
  /* 13px floor: the small steps alias 13 (design pass 2026-10-06). */
  --t-9:    13px; --t-10:   13px; --t-11:   13px; --t-12:   13px;
  --t-13:   13px; --t-14:   14px; --t-16:   16px; --t-18:   18px;
  --t-20:   20px; --t-24:   24px; --t-30:   30px; --t-40:   40px;
  --t-56:   56px; --t-72:   72px;

  /* ── Motion ── */
  --ease:    cubic-bezier(0.22,1,0.36,1);
  --ease-io: cubic-bezier(0.4,0,0.2,1);
  --dur-fast:    120ms;
  --dur-base:    180ms;
  --dur-slow:    300ms;
  --dur-slowest: 500ms;
}

[data-theme="dark"]{
  --brand:               #F2C14E;       /* flame gold · electric at night */
  --brand-hi:            #F6D06E;
  --brand-lo:            #C39A33;
  --gold:                #F2C14E;
  --lime:                #B8F135;
  --teal:                #3EE6C4;
  --tr-ic-photo:         #A68BF0;
  --tr-ic-hiit:          #F07AA0;
  --aurora:              #F2C14E;
  --aur-glow:            transparent;
  --on-aurora:           #0A0A10;

  --bg-canvas:           #07070B;
  --bg-surface:          #12121A;
  --bg-raised:           #1A1A23;
  --bg-sunken:           #04040A;
  --bg-wash:             #07070B;

  --stroke-subtle:       rgba(255,255,255,0.08);
  --stroke-default:      rgba(255,255,255,0.14);
  --stroke-strong:       rgba(255,255,255,0.20);
  --ring-track:          rgba(255,255,255,0.07);

  --ink-primary:         #F2F2F7;
  --ink-secondary:       #A9A9BC;
  --ink-muted:           #8A8A99;       /* #62626F was 3:1 on the surface; AA now */
  --ink-inverse:         #0A0A10;

  --sig-good:            #3FE08C;
  --sig-good-wash:       rgba(63,224,140,0.10);
  --sig-good-edge:       rgba(63,224,140,0.20);
  --sig-warn:            #FFB224;
  --sig-warn-wash:       rgba(255,178,36,0.10);
  --sig-warn-edge:       rgba(255,178,36,0.20);
  --sig-risk:            #FF5C5C;
  --sig-risk-wash:       rgba(255,92,92,0.10);
  --sig-risk-edge:       rgba(255,92,92,0.20);
  --sig-info:            #4DA6FF;
  --sig-info-wash:       rgba(77,166,255,0.10);
  --sig-info-edge:       rgba(77,166,255,0.20);
  --sig-cross:           #F2C14E;
  --sig-cross-wash:      rgba(242,193,78,0.10);
  --sig-cross-edge:      rgba(242,193,78,0.24);
  --sig-ai:              #E0B450;
  --sig-ai-wash:         transparent;
  --sig-ai-edge:         rgba(255,255,255,0.08);
  --on-ai:               #0A0A10;
  --accent:              #E0B450;
  --accent-bg:           transparent;
  --purple:              #E0B450;
  --purple-bg:           transparent;
  --purple-border:       rgba(255,255,255,0.08);
  --badge-purple-bg:     transparent;
  --hp-aur:              none;
  --hp-glass:            #12121A;
  --hp-glass-b:          #12121A;
  --bg-grad:             #07070B;
  --text-muted:          #8A8A99;

  --amb-good:none; --amb-warn:none; --amb-risk:none;

  /* ── Body map plate ── */
  --bm-fill:             rgba(255,255,255,0.035);
  --bm-line:             rgba(255,255,255,0.30);
  --bm-muscle:           rgba(255,255,255,0.14);
  --bm-organ:            #9A9CA5;
  --bm-watch:            rgba(255,255,255,0.075);
  --bm-thin:             #3D4450;

  --dec-1:  #FF5C5C;  --dec-2:  #FF7A4D;  --dec-3:  #FFB224;
  --dec-4:  #E0C92E;  --dec-5:  #C9E03A;  --dec-6:  #B8F135;
  --dec-7:  #7FE36A;  --dec-8:  #3FE08C;  --dec-9:  #2EDFAD;  --dec-10: #3EE6C4;

  --shadow-1:            none;
  --shadow-2:            none;
  --shadow-3:            0 8px 24px rgba(0,0,0,0.40);
  --shadow:              none;
}

/* ── Base resets ── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{background:var(--bg-wash);color:var(--ink-primary);
  font-family:var(--font-sans);font-size:var(--t-14);line-height:1.5;
  -webkit-font-smoothing:antialiased;min-height:100%}
body{min-height:100vh;padding:var(--sp-8) var(--sp-16) var(--sp-20)}
/* Every page is fixed sideways like an app, on every device (2026-11-16, Barry: "the pages must appear fixed like it's an app
   not a webpage"; iPad Split View let the whole page pan left and right). ONE rule for index, clinic, admin and login (they all
   load this sheet): the page never pans sideways and never rubber-bands as a whole. clip, never hidden, on body: hidden made body
   a scroll container and the sticky top bar stopped sticking (index.html note). hidden first is the fallback for engines without
   clip. Vertical scrolling of the page and of every sheet is unchanged (overscroll-behavior stops the bounce, not the scroll).
   Rows meant to slide sideways contain their own overscroll so a swipe on them never drags the page. The app-only pinch rule
   (maximum-scale=1, touch-action) lives in index.html / login.html: browsers keep zoom. */
html{overflow-x:hidden;overflow-x:clip;overscroll-behavior:none}
body{overflow-x:clip;overscroll-behavior:none}
:where(.aif-tw,.as-nav,.bio-ask-chips,.bio-chart-scroll,.bio-tbl-wrap,.cs-panel-strip,.cb-start,.tr-hist,.cs-metrics,.cs-sym-cats,.cd-foot,
  .g1-tw,.il-bk-days,.iq-action-board,.md2-gw,.me-tabs,.mp-adv-chips,.pq-tabs,.rx-nav,.rx-nav-v2,.rx-nav-v3,.rx-sched-strip,.tcp-row,
  .td-usu-row,#timelineContainer,.tr-nav,.tvb-scroll,.ua-scroll,.pf-scroll,.pa-tw,.pa-nav,.tw,.seg,.hqnav,.mk-tbl,
  [style*="overflow-x:auto"],[style*="overflow-x: auto"],[style*="overflow-x:scroll"],[style*="overflow:auto"]){overscroll-behavior-x:contain}
/* Every VERTICAL scroller is fixed sideways too (2026-11-17, Barry on his iPad: "today panel on ipad is still moveable side to
   side"). A box with overflow-y:auto computes overflow-x to auto as well, so a child even 1 px too wide (the Today band stood 2 px
   past #dayRailBody) let a finger pan the panel itself. ONE list for the panels, sheets, drawers and dialogs that scroll up and down:
   overflow-x clip (computes to hidden on a scroller: never user-scrollable sideways), overscroll kept inside, touch-action pan-y
   (pinch-zoom kept where the browser allows it; the app turns zoom off anyway). A sideways row inside keeps scrolling: touch-action
   resets at every scroll container, and the rows above contain their own overscroll. Boxes meant to pan both ways (data tables,
   <pre>, the document viewer, the timeline) are deliberately NOT here. A new vertical sheet joins this list. !important because
   each sheet's own overflow shorthand loads after this file. scripts/smoke_tabs.py fails when one of them is wider than itself. */
#dayRailBody,body.rail-on #dayRail,.d2-drawer-body,.iq-sheet,.md2-sheet,.ask-body,.akt-list,.cd-body,.cmp-modal>.cmp-form,.c-modal-body,
.ckc-body,.checkin-body,.cn-body,.as-body,.rx-body,.pq-body,.wn-body,.gs-sheet,.me-dlg,.ss3-sh,.h3-wys,.td-pop-c,
.bio-detail-panel,.le-detail-inner,.dd-inner,.tr-arc-body,.ilx-sh-b,.il-bk-b,.nut-body,.mp-adv-panel,.cs-chat-msgs,.chat-msgs,
.bio-ask-thread,#csSymModal .sym-list,.tr-sess-list,.ha-ov,.cns-ov,#cgiSheet .cg-bd,#medsSheet .ms-bd,.scr-sheet>div,.ehr-p,
.ims-hist,.ca-body{overflow-x:clip!important;overscroll-behavior:contain;touch-action:pan-y pinch-zoom}
a{color:inherit;text-decoration:none}
button{font-family:inherit;cursor:pointer}

/* ── Aurora ambience — the surface knows how you're doing ──
   Fixed back-layer; body[data-chai-state] crossfades the room tint.
   z-index:-1 keeps it behind all content; html bg-wash sits behind it. */
.chai-aurora{display:none!important}
.chai-aurora div{position:absolute;inset:0;opacity:0;transition:opacity 900ms ease}
.chai-aurora .ca-good{background:var(--amb-good)}
.chai-aurora .ca-warn{background:var(--amb-warn)}
.chai-aurora .ca-risk{background:var(--amb-risk)}
body[data-chai-state="good"] .chai-aurora .ca-good{opacity:1}
body[data-chai-state="warn"] .chai-aurora .ca-warn{opacity:1}
body[data-chai-state="risk"] .chai-aurora .ca-risk{opacity:1}

/* ── Motion — three rules: breathe, draw, drift ── */
@keyframes chaiBreathe{0%,100%{transform:scale(1)}50%{transform:scale(1.022)}}
@keyframes chaiDraw{to{stroke-dashoffset:0}}
@keyframes chaiDrift{from{background-position:0% 0}to{background-position:100% 0}}
.breathe{animation:none}
.aurora-text{background:none;color:var(--brand-lo);-webkit-text-fill-color:currentColor}
.aurora-fill{background:var(--aurora);color:var(--on-aurora)}
.chart-draw polyline,.chart-draw path.ln{stroke-dasharray:600;stroke-dashoffset:600;animation:chaiDraw 1.8s var(--ease-io) forwards}
@media (prefers-reduced-motion: reduce){
  .breathe,.aurora-text,.chart-draw polyline,.chart-draw path.ln{animation:none!important}
  .chart-draw polyline,.chart-draw path.ln{stroke-dashoffset:0}
}

/* ── Utility classes ── */
.mono{font-family:var(--font-mono)}
.disp{font-family:var(--font-disp)}
.ink-1{color:var(--ink-primary)}
.ink-2{color:var(--ink-secondary)}
.ink-3{color:var(--ink-muted)}
/* Labels: sentence case, Geist 13px semibold (design pass 2026-10-06). */
.ttl,.kicker{font-family:var(--font-sans);font-size:13px;font-weight:600;letter-spacing:0;
  text-transform:none;color:var(--ink-secondary)}
.headline{font-family:var(--font-disp);font-size:var(--t-24);font-weight:600;letter-spacing:-0.02em;line-height:1.25}
.headline-lg{font-family:var(--font-disp);font-size:var(--t-30);font-weight:600;letter-spacing:-0.025em;line-height:1.2}
.num-lg{font-family:var(--font-disp);font-size:var(--t-40);font-weight:600;
  letter-spacing:-0.035em;line-height:1;color:var(--ink-primary);font-variant-numeric:tabular-nums}
.num-xl{font-family:var(--font-disp);font-size:var(--t-56);font-weight:600;
  letter-spacing:-0.04em;line-height:1;color:var(--ink-primary);font-variant-numeric:tabular-nums}
.num-2xl{font-family:var(--font-disp);font-size:var(--t-72);font-weight:600;
  letter-spacing:-0.045em;line-height:1;color:var(--ink-primary);font-variant-numeric:tabular-nums}

/* Delta inline token */
.delta{font-family:var(--font-sans);font-variant-numeric:tabular-nums;font-size:13px;font-weight:600}
.delta-up{color:var(--sig-good)}
.delta-dn{color:var(--sig-risk)}
.delta-flat{color:var(--ink-muted)}
.delta-warn{color:var(--sig-warn)}

/* digits line up everywhere (the job the mono face did) */
html{font-variant-numeric:tabular-nums}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}   /* iPad Safari enlarged long wrapped lines on its own (text autosizing): every size is the one set (Barry 11-23) */
