/* ==========================================================================
   Alternative Health Grand Forks — practice workspace design system
   --------------------------------------------------------------------------
   The same house as the clinic website: ivory paper, a deep navy spine and
   champagne gold for the moments that matter. Playfair Display carries
   headings, the wordmark and big numbers; Inter does the work everywhere
   else. Hairline borders, quiet shadows, modest radii. Gold is decoration
   and the primary call to action only — it never carries small text.
     navy #1B2A41 · deep navy #152233 · ivory #F7F4EF · gold #C9A86C
     gold hover #E0C58F · gold ink #7A5F30 · hairline #E6E0D6
   Every colour is a token. Components never hardcode a hex.
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;

  /* the house palette — fixed in every theme */
  --navy:        #1B2A41;
  --navy-deep:   #152233;
  --navy-2:      #2C4160;
  --ivory:       #F7F4EF;
  --gold:        #C9A86C;
  --gold-hover:  #E0C58F;
  --gold-ink:    #7A5F30;   /* gold as text: 5.5:1 on ivory. Raw gold is 2:1 — decoration only */
  --gold-soft:   #F3ECDD;
  --on-gold:     #1B2A41;

  /* surfaces — warm paper, never flat grey */
  --canvas:        #F7F4EF;
  --canvas-2:      #EFEAE2;
  --surface:       #FFFFFF;
  --surface-2:     #FBF9F5;
  --surface-3:     #F3EEE6;
  --surface-inset: #F9F6F1;

  /* the rail — navy, like the website header */
  --rail:          #1B2A41;
  --rail-2:        #152233;
  --rail-ink:      #D5DBE4;
  --rail-muted:    #8F9BAD;
  --rail-hover:    rgba(247,244,239,.06);
  --rail-line:     rgba(247,244,239,.09);

  /* ink */
  --ink:        #1B2A41;
  --ink-2:      #33415A;
  --ink-3:      #4D596A;
  --ink-4:      #5F6B78;
  --ink-invert: #FFFFFF;

  /* lines — hairlines */
  --line:        #E6E0D6;
  --line-strong: #D5CDBF;
  --line-soft:   #EFEAE2;

  /* accent — navy for anything interactive, gold for ornament */
  --accent:        #1B2A41;
  --accent-hover:  #2C4160;
  --accent-2:      #C9A86C;
  --accent-soft:   #F3ECDD;
  --accent-softer: #FAF6EE;
  --accent-ink:    #7A5F30;
  --on-accent:     #F7F4EF;
  /* The names are historical. --grad is gold ornament (bars, rails, meters);
     --grad-cta is solid navy that always carries ivory text; --grad-value
     tints large numerals; --grad-soft is a faint warm wash. */
  --grad:          linear-gradient(135deg, #B8955A 0%, #C9A86C 50%, #E0C58F 100%);
  --grad-cta:      linear-gradient(180deg, #22344F 0%, #1B2A41 100%);
  --grad-value:    linear-gradient(180deg, #1B2A41 0%, #2C4160 100%);
  --grad-soft:     linear-gradient(135deg, rgba(201,168,108,.10), rgba(27,42,65,.03));
  --glow:          0 1px 2px rgba(27,42,65,.10), 0 6px 16px -10px rgba(27,42,65,.40);

  --rail-ink-strong:    #F7F4EF;
  --rail-mark-glow:     none;
  --rail-active-bg:     rgba(201,168,108,.13);
  --rail-active-shadow: none;
  --rail-active-icon:   #C9A86C;
  --rail-count-ink:     #F7F4EF;
  --rail-accent:        #C9A86C;   /* wordmark tagline, group labels */

  --hero-grad:   linear-gradient(115deg, #152233 0%, #1B2A41 58%, #22344F 100%);
  --hero-glow-1: rgba(201,168,108,.20);
  --hero-glow-2: rgba(247,244,239,.05);
  --hero-ink:    #F7F4EF;
  --hero-ink-2:  rgba(247,244,239,.80);
  --hero-ink-3:  rgba(247,244,239,.68);

  /* semantic — earthy, so status never shouts over the brand */
  --urgent:       #B3261E;  --urgent-soft:  #FBEAE7;
  --caution:      #8A5A12;  --caution-soft: #F8EEDB;
  --stable:       #2E6B4F;  --stable-soft:  #E3EFE8;
  --info:         #2B4E7A;  --info-soft:    #E6ECF4;
  --muted-tone:   #5F6B78;  --muted-soft:   #EFEBE4;
  --purple:       #6B4A7E;  --purple-soft:  #F0E9F2;

  /* elevation — navy-tinted and quiet */
  --shadow-1: 0 1px 2px rgba(27,42,65,.06);
  --shadow-2: 0 1px 2px rgba(27,42,65,.05), 0 8px 22px -14px rgba(27,42,65,.24);
  --shadow-3: 0 24px 50px -22px rgba(27,42,65,.38), 0 4px 12px rgba(27,42,65,.08);
  --ring: 0 0 0 2px var(--surface), 0 0 0 4px rgba(201,168,108,.9);

  /* geometry — modest, like the website */
  --r-xs: 6px; --r-sm: 8px; --r-md: 10px; --r-lg: 12px; --r-xl: 16px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 56px;

  --sidebar-w: 288px;
  --topbar-h: 64px;
  --row-h: 56px;

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --display: "Playfair Display", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --dur: 180ms;
  --ease: cubic-bezier(.2,.8,.2,1);
}

/* ------------------------------------------------------------------- dark
   Evening at the clinic: deep navy surfaces, ivory ink, gold accents. Gold
   is light enough here to carry text, so the accent moves from navy to gold. */
html[data-theme="dark"] {
  color-scheme: dark;

  --gold-ink:  #D9BE8A;
  --gold-soft: rgba(201,168,108,.16);

  --canvas:        #0E1622;
  --canvas-2:      #111B29;
  --surface:       #152233;
  --surface-2:     #192840;
  --surface-3:     #203049;
  --surface-inset: #101A28;

  --rail:          #0B121C;
  --rail-2:        #070C14;
  --rail-ink:      #C9D1DC;
  --rail-muted:    #7F8C9E;
  --rail-hover:    rgba(247,244,239,.05);
  --rail-line:     rgba(247,244,239,.07);

  --ink:        #F3EFE7;
  --ink-2:      #CDD4DE;
  --ink-3:      #A6B0BE;
  --ink-4:      #8B97A7;
  --ink-invert: #0E1622;

  --line:        #253550;
  --line-strong: #33476A;
  --line-soft:   #1D2C43;

  --accent:        #D4B57C;
  --accent-hover:  #E6CD9C;
  --accent-2:      #C9A86C;
  --accent-soft:   rgba(201,168,108,.15);
  --accent-softer: rgba(201,168,108,.07);
  --accent-ink:    #E3CA98;
  --on-accent:     #152233;
  --grad:          linear-gradient(135deg, #B8955A 0%, #C9A86C 50%, #E0C58F 100%);
  --grad-cta:      linear-gradient(180deg, #34507A 0%, #2C4160 100%);
  --grad-value:    linear-gradient(180deg, #F3EFE7 0%, #E0C58F 100%);
  --grad-soft:     linear-gradient(135deg, rgba(201,168,108,.08), rgba(247,244,239,.02));
  --glow:          0 6px 18px -10px rgba(0,0,0,.7);

  --hero-grad:   linear-gradient(115deg, #0B121C 0%, #152233 60%, #1D2D45 100%);

  --urgent:     #F09A90;  --urgent-soft:  rgba(240,154,144,.14);
  --caution:    #E6C07A;  --caution-soft: rgba(230,192,122,.14);
  --stable:     #8CC7A6;  --stable-soft:  rgba(140,199,166,.14);
  --info:       #9DB8DC;  --info-soft:    rgba(157,184,220,.14);
  --muted-tone: #A6B0BE;  --muted-soft:   rgba(166,176,190,.12);
  --purple:     #C7A8D6;  --purple-soft:  rgba(199,168,214,.14);

  --shadow-1: 0 1px 2px rgba(0,0,0,.45);
  --shadow-2: 0 1px 2px rgba(0,0,0,.4), 0 10px 26px -14px rgba(0,0,0,.7);
  --shadow-3: 0 24px 56px -20px rgba(0,0,0,.85), 0 4px 14px rgba(0,0,0,.45);
  --ring: 0 0 0 2px var(--surface), 0 0 0 4px rgba(224,197,143,.9);
}

/* ------------------------------------------------------------------ paper
   (stored as "green" for older preferences.) Crisp white paper with the
   practice's own accent colour. --brand is set inline by base.html, per
   practice and per user when someone overrides it on their profile.

   --brand-deep is that same colour darkened server-side until white on it
   clears 4.5:1. Anything carrying text uses --brand-deep, so no accent anyone
   picks — however pale — can break contrast. --brand is only for decoration:
   bars, meter fills and tints, never under text. Gold stays the ornament. */
html[data-theme="green"] {
  color-scheme: light;

  /* fallbacks only — base.html sets both inline on <html> */
  --brand:      #1B2A41;
  --brand-deep: #1B2A41;

  --canvas:        #F4F3F0;
  --canvas-2:      #EAE8E3;
  --surface:       #FFFFFF;
  --surface-2:     #FAFAF8;
  --surface-3:     #F1F0EC;
  --surface-inset: #F7F6F3;

  --rail:          #FFFFFF;
  --rail-2:        #F4F3F0;
  --rail-ink:      #33415A;
  --rail-muted:    #5F6B78;
  --rail-hover:    rgba(27,42,65,.05);
  --rail-line:     #E6E3DD;

  --ink:        #1B2A41;
  --ink-2:      #33415A;
  --ink-3:      #4D596A;
  --ink-4:      #5F6B78;
  --ink-invert: #FFFFFF;

  --line:        #E6E3DD;
  --line-strong: #D1CDC5;
  --line-soft:   #EFEDE9;

  --accent:        var(--brand-deep);
  --accent-hover:  color-mix(in srgb, var(--brand-deep) 84%, #000);
  --accent-2:      #C9A86C;
  --accent-soft:   color-mix(in srgb, var(--brand) 9%, #FFF);
  --accent-softer: color-mix(in srgb, var(--brand) 4%, #FFF);
  --accent-ink:    color-mix(in srgb, var(--brand-deep) 88%, #000);
  --on-accent:     #FFFFFF;
  --grad-cta:      linear-gradient(180deg, color-mix(in srgb, var(--brand-deep) 88%, #FFF), var(--brand-deep));
  --grad-value:    linear-gradient(180deg, var(--brand-deep), color-mix(in srgb, var(--brand-deep) 80%, #000));
  --grad-soft:     linear-gradient(135deg, color-mix(in srgb, var(--brand) 5%, transparent), transparent);

  --ring: 0 0 0 2px var(--surface), 0 0 0 4px color-mix(in srgb, var(--brand) 55%, transparent);

  /* a light rail: the brand mark and the active item carry the colour */
  --rail-ink-strong:    #1B2A41;
  --rail-active-bg:     color-mix(in srgb, var(--brand) 8%, #FFF);
  --rail-active-shadow: none;
  --rail-accent:        #7A5F30;
  --rail-active-icon:   var(--brand-deep);
  --rail-count-ink:     #1B2A41;

  /* the hero stays deep whatever colour someone picks, so its labels clear 4.5:1 */
  --hero-grad:   linear-gradient(115deg, color-mix(in srgb, var(--brand-deep) 70%, #000) 0%, var(--brand-deep) 100%);
}

html[data-density="compact"] { --row-h: 44px; --sp-4: 12px; --sp-5: 16px; --sp-6: 18px; --topbar-h: 56px; }

/* ------------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
/* The signed-in workspace scrolls inside its panes, never outside the viewport. */
html.app-shell, .app-shell body { width: 100%; max-width: 100%; overflow: hidden; }
.app-shell .app { width: 100%; max-width: 100%; min-width: 0; }
.app-shell .page { min-width: 0; }
.app-shell .table-wrap { min-width: 0; max-width: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4,h5 {
  margin: 0; font-family: var(--font); font-weight: 650;
  letter-spacing: -.01em; line-height: 1.25; color: var(--ink);
}
/* Playfair for the big moments (page titles, section heads); Inter below 16px, where a serif gets fussy. */
h1, h2 { font-family: var(--display); font-weight: 500; letter-spacing: -.005em; font-variant-numeric: lining-nums; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 19px; } h3 { font-size: 14.5px; } h4 { font-size: 13px; }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent-hover); }
img, svg { vertical-align: middle; max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-5) 0; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); color: var(--accent-ink); }
.num, td.num, .tabular {
  font-family: var(--mono); font-variant-numeric: tabular-nums lining-nums;
  font-size: .94em; letter-spacing: -.02em;
}
code, kbd { font-family: var(--mono); font-size: .9em; }
kbd {
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--r-xs); padding: 2px 6px; color: var(--ink-3); font-size: 10.5px;
}

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 9px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }

/* ------------------------------------------------------------------ layout */
/* The shell itself never scrolls — .page is the content scroll container, so the
   rail stays pinned no matter how long a list gets. Every flex/grid child in
   the chain needs min-height:0, otherwise the default `min-height:auto`
   refuses to shrink, the pane overflows its parent, and the whole page
   scrolls instead (which is what dragged the sidebar out of view). */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- the rail ----
   The clinic's navy spine: the heart-and-pulse lockup, gold section labels
   with a hairline running out from them, and a thin gold bar on the page
   you're on. Collapses to an icon rail (the toggle beside the brand, or
   Ctrl/⌘ + \); the choice is remembered per browser and painted before first
   render by base.html. On a phone it is the slide-out menu instead. */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--rail);
  color: var(--rail-ink);
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
  z-index: 40; overflow: hidden; position: relative;
  border-right: 1px solid var(--rail-line);
  --bm-cut: var(--rail);
}
.sidebar__brand {
  display: flex; align-items: center; gap: 4px;
  height: var(--topbar-h); padding: 0 10px 0 18px;
  flex: 0 0 auto; position: relative; z-index: 1;
}
.sidebar__brand::after {
  content: ""; position: absolute; left: 18px; right: 18px; bottom: 0; height: 1px;
  background: linear-gradient(90deg, var(--rail-accent), transparent);
  opacity: .55;
}
.sidebar__home {
  display: flex; align-items: center; gap: 11px; flex: 1 1 auto; min-width: 0;
  color: inherit; text-decoration: none; border-radius: var(--r-sm);
}
.sidebar__home:hover { color: inherit; }
.sidebar__home:focus-visible { box-shadow: 0 0 0 2px var(--rail-accent); }
.sidebar__mark { width: 38px; height: 34px; flex: 0 0 38px; display: grid; place-items: center; }
.sidebar__mark .brand-mark { width: 38px; height: 34px; }
.sidebar__brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1; }
.sidebar__name {
  font-family: var(--display); font-weight: 500; color: var(--rail-ink-strong);
  font-size: 16.5px; letter-spacing: .005em; white-space: nowrap; line-height: 1.05;
}
.sidebar__sub {
  margin-top: 6px; font-size: 9px; font-weight: 650; letter-spacing: .24em; text-transform: uppercase;
  color: var(--rail-accent); white-space: nowrap; line-height: 1;
}

/* ---- the brand mark: a gold heart crossed by a pulse line ---- */
.brand-mark { display: block; overflow: visible; }
.brand-mark .bm-heart { fill: var(--gold); transform-origin: 24px 22px; transition: transform .5s var(--ease); }
.brand-mark .bm-pulse, .brand-mark .bm-pulse-out {
  fill: none; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 90; stroke-dashoffset: 0;
}
.brand-mark .bm-pulse { stroke: var(--bm-cut, var(--navy)); }
.brand-mark .bm-pulse-out { stroke: var(--gold); }
a:hover .brand-mark .bm-heart { transform: scale(1.06); }
a:hover .brand-mark .bm-pulse, a:hover .brand-mark .bm-pulse-out { animation: bm-beat 1.1s var(--ease); }
@keyframes bm-beat { 0% { stroke-dashoffset: 90; } 100% { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .brand-mark .bm-heart { transition: none; }
  a:hover .brand-mark .bm-pulse, a:hover .brand-mark .bm-pulse-out { animation: none; }
}

/* ---- the list ---- */
.sidebar__scroll { flex: 1 1 auto; overflow-y: auto; padding: 18px 12px 16px; position: relative; z-index: 1; scrollbar-width: thin; }
.sidebar__scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--rail-ink) 18%, transparent); background-clip: content-box; }
.nav-group { margin-bottom: 22px; }
.nav-group__label {
  display: flex; align-items: center; gap: 10px;
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .22em;
  color: var(--rail-accent); padding: 0 12px 9px; font-weight: 650; white-space: nowrap;
}
.nav-group__label::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--rail-line); }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--r-xs);
  color: var(--rail-ink); font-size: 13.5px; font-weight: 500;
  margin-bottom: 1px; position: relative; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; color: var(--rail-muted); transition: color var(--dur) var(--ease); }
.nav-item:hover { background: var(--rail-hover); color: var(--rail-ink-strong); }
.nav-item:hover svg { color: var(--rail-accent); }
.nav-item:focus-visible { box-shadow: inset 0 0 0 2px var(--rail-accent); }
.nav-item.is-active {
  background: var(--rail-active-bg);
  color: var(--rail-ink-strong); font-weight: 600;
  box-shadow: var(--rail-active-shadow);
}
.nav-item.is-active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 70%; border-radius: 0 2px 2px 0; background: var(--rail-active-icon);
}
.nav-item.is-active svg { color: var(--rail-active-icon); }
.nav-item__count {
  margin-left: auto; font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  background: color-mix(in srgb, var(--rail-ink) 14%, transparent); color: var(--rail-count-ink);
  border-radius: var(--r-pill); padding: 2px 8px; min-width: 22px; text-align: center;
}
.nav-item__count.is-alert { background: var(--gold); color: var(--navy); font-weight: 700; }
/* "Soon": a feature that ships later (the Phone line). Quiet, not an alert. */
.nav-item__count--soon { background: transparent; border: 1px solid currentColor; opacity: .7; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }

/* ---- the account ---- */
.sidebar__footer { flex: 0 0 auto; border-top: 1px solid var(--rail-line); padding: 12px; position: relative; z-index: 1; }
.sidebar__user { width: 100%; margin: 0; background: transparent; border: 0; cursor: pointer; text-align: left; font: inherit; padding: 8px 10px; }
.sidebar__user .avatar { box-shadow: 0 0 0 2px var(--rail), 0 0 0 3px var(--gold); }
.sidebar__user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar__user-name { color: var(--rail-ink-strong); font-size: 13px; font-weight: 600; }
.sidebar__user-role { font-size: 11px; color: var(--rail-muted); }
.sidebar__user-chevron { margin-left: auto; display: flex; }
.sidebar__user-chevron svg { width: 15px; height: 15px; }
.sidebar__menu { bottom: calc(100% + 6px); top: auto; left: 0; right: 0; }
.sidebar__menu-who { display: flex; align-items: center; gap: 12px; padding: 10px 11px 8px; }
.sidebar__menu-who b { display: block; font: 500 17px/1.2 var(--display); color: var(--ink); }
.sidebar__menu-who small { font-size: 12px; color: var(--ink-4); }

/* ---- collapse toggle ---- */
.sidebar__toggle {
  flex: 0 0 auto; width: 32px; height: 32px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--rail-muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.sidebar__toggle:hover { background: var(--rail-hover); color: var(--rail-ink-strong); }
.sidebar__toggle:focus-visible { box-shadow: 0 0 0 2px var(--rail-accent); border-radius: var(--r-sm); }
.sidebar__toggle svg { width: 18px; height: 18px; }
.sidebar__toggle > span { display: grid; place-items: center; }
.sidebar__toggle-open { display: none !important; }

/* A tooltip for the icon-only rail. It lives on <body> (the rail clips its
   overflow), placed by app.js beside whichever item is hovered or focused. */
.rail-tip {
  position: fixed; z-index: 80; pointer-events: none;
  padding: 7px 11px; border-radius: var(--r-xs); transform: translate(-4px, -50%);
  background: var(--navy-deep); color: var(--ivory); border: 1px solid rgba(201,168,108,.4);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; letter-spacing: -.005em;
  box-shadow: 0 10px 24px -10px rgba(21,34,51,.6);
  opacity: 0; transition: opacity 120ms var(--ease), transform 120ms var(--ease);
}
.rail-tip.is-on { opacity: 1; transform: translate(0, -50%); }
.rail-tip::before {
  content: ""; position: absolute; left: -5px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
  background: inherit; border-left: inherit; border-bottom: inherit; transform: rotate(45deg);
}

@media (min-width: 761px) {
  .sidebar { transition: width 220ms var(--ease), flex-basis 220ms var(--ease); }
  html[data-sidebar="collapsed"] { --sidebar-w: 78px; }
  html[data-sidebar="collapsed"] .sidebar__brand { padding: 0; justify-content: center; }
  html[data-sidebar="collapsed"] .sidebar__brand::after { left: 16px; right: 16px; }
  html[data-sidebar="collapsed"] .sidebar__home { flex: 0 0 auto; }
  html[data-sidebar="collapsed"] .sidebar__brand-text { display: none; }
  /* Collapsed, the toggle sits on the brand mark and shows on hover or focus. */
  html[data-sidebar="collapsed"] .sidebar__toggle {
    position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; border-radius: 50%;
    background: var(--rail-2); color: var(--rail-ink-strong); box-shadow: inset 0 0 0 1px var(--rail-accent); opacity: 0;
  }
  html[data-sidebar="collapsed"] .sidebar__brand:hover .sidebar__toggle,
  html[data-sidebar="collapsed"] .sidebar__toggle:focus-visible { opacity: 1; }
  html[data-sidebar="collapsed"] .sidebar__toggle-open { display: grid !important; }
  html[data-sidebar="collapsed"] .sidebar__toggle-close { display: none !important; }
  html[data-sidebar="collapsed"] .sidebar__scroll { padding: 14px 12px; scrollbar-width: none; }
  html[data-sidebar="collapsed"] .sidebar__scroll::-webkit-scrollbar { display: none; }
  html[data-sidebar="collapsed"] .nav-group { margin-bottom: 8px; }
  html[data-sidebar="collapsed"] .nav-group__label {
    height: 1px; padding: 0; margin: 8px 12px 12px; overflow: hidden;
    font-size: 0; background: var(--rail-line);
  }
  html[data-sidebar="collapsed"] .nav-group__label::after { display: none; }
  html[data-sidebar="collapsed"] .nav-item { justify-content: center; gap: 0; padding: 11px 0; border-radius: 50%; width: 44px; height: 44px; margin: 0 auto 4px; }
  html[data-sidebar="collapsed"] .nav-item.is-active::before { left: -11px; height: 50%; }
  html[data-sidebar="collapsed"] .nav-item svg { width: 19px; height: 19px; flex-basis: 19px; }
  html[data-sidebar="collapsed"] .nav-item__label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  html[data-sidebar="collapsed"] .nav-item__count {
    position: absolute; top: 1px; right: -2px; margin: 0; min-width: 17px; height: 17px;
    padding: 0 4px; font-size: 9.5px; line-height: 17px; border-radius: 999px;
    box-shadow: 0 0 0 2px var(--rail);
  }
  html[data-sidebar="collapsed"] .sidebar__footer { padding: 12px 10px; }
  html[data-sidebar="collapsed"] .sidebar__user { justify-content: center; padding: 8px 0; width: 100%; height: auto; border-radius: var(--r-sm); }
  html[data-sidebar="collapsed"] .sidebar__user-text,
  html[data-sidebar="collapsed"] .sidebar__user-chevron { display: none; }
  html[data-sidebar="collapsed"] .sidebar__menu,
  html[data-sidebar="collapsed"] .sidebar__menu.menu--up {
    position: fixed; left: calc(var(--sidebar-w) + 8px); right: auto; bottom: 12px; top: auto; width: 268px;
  }
}
@media (min-width: 761px) and (hover: none) {
  /* Touch screens can't hover to find the toggle: show it instead of the mark. */
  html[data-sidebar="collapsed"] .sidebar__toggle { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .rail-tip { transition: none; }
}

.main {
  flex: 1 1 auto; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ---- topbar ---- */
.topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
.topbar__search { flex: 1 1 auto; min-width: 0; max-width: 520px; position: relative; }
.topbar .topbar__search input {
  width: 100%; height: 38px; min-height: 38px; padding: 0 52px 0 38px;
  background: var(--canvas); border: 1px solid transparent;
  border-radius: var(--r-sm); color: var(--ink); font-size: 13.5px; font-family: inherit;
  box-shadow: none;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.topbar .topbar__search input:hover { border-color: var(--line-strong); }
.topbar .topbar__search input:focus { background: var(--surface); border-color: var(--ink-4); box-shadow: var(--ring); }
.topbar__search input::placeholder { color: var(--ink-4); }
.topbar__search svg { position: absolute; left: 13px; top: 10.5px; width: 17px; height: 17px; color: var(--ink-4); }
.topbar__search kbd { position: absolute; right: 10px; top: 9px; background: var(--surface); }
.topbar__spacer { flex: 1 1 auto; }

/* ---- the dialer button (opens the floating dial pad; phones use the Phone tab) ---- */
.topbar__dialer {
  position: relative; flex: 0 0 auto; height: 38px; min-width: 38px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink-2);
  box-shadow: none; cursor: pointer; font: inherit;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.topbar__dialer:hover { border-color: var(--line-strong); color: var(--ink); }
.topbar__dialer:focus-visible { outline: none; box-shadow: var(--ring); }
.topbar__dialer[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.topbar__dialer-icon { display: grid; place-items: center; }
.topbar__dialer-icon svg { width: 17px; height: 17px; }
.topbar__dialer-dot {
  position: absolute; left: 25px; top: 7px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-4); box-shadow: 0 0 0 2px var(--surface);
}
.topbar__dialer[data-state="ready"] .topbar__dialer-dot { background: var(--stable); }
.topbar__dialer[data-state="connecting"] .topbar__dialer-dot,
.topbar__dialer[data-state="offline"] .topbar__dialer-dot { background: var(--caution); }
.topbar__dialer[data-state="unavailable"] .topbar__dialer-dot { background: var(--urgent); }
.topbar__dialer[data-state="simulated"] .topbar__dialer-dot { background: var(--info); }
.topbar__dialer-timer { display: none; font-family: var(--mono); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.topbar__dialer[data-state="busy"] {
  background: #2E6B4F; color: #fff; border-color: transparent;
  box-shadow: none;
}
.topbar__dialer[data-state="busy"] .topbar__dialer-timer:not(:empty) { display: inline; }
.topbar__dialer[data-state="busy"] .topbar__dialer-dot { background: rgba(255,255,255,.8); box-shadow: none; }
.topbar__dialer[data-state="ringing"] { color: var(--stable); border-color: color-mix(in srgb, var(--stable) 50%, transparent); animation: dialer-ring-pulse 1.3s ease-out infinite; }
@keyframes dialer-ring-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--stable) 45%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
.topbar__count {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center; border-radius: 999px;
  font-family: var(--mono); font-size: 10px; font-weight: 700; line-height: 1; color: var(--navy);
  background: var(--gold); box-shadow: 0 0 0 2px var(--canvas);
}
.topbar__bell { position: relative; }
.topbar__bell-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--urgent); box-shadow: 0 0 0 2px var(--canvas); }
@media (max-width: 760px) { .topbar__dialer { display: none; } }

/* ---- connection lights: Twilio, Stripe and AI on or off (core/service_status.py) ----
   Wide screens say it in words ("Twilio On"); narrower ones show each service's
   icon with a coloured dot; phones fold the three into a stack of lights. The
   button opens a menu that explains each one. */
.topbar__services { flex-shrink: 0; }
.svc {
  height: 38px; display: inline-flex; align-items: center; padding: 0 3px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
  box-shadow: none; color: var(--ink-3); cursor: pointer; font: inherit;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.svc:hover { border-color: var(--line-strong); }
.svc:focus-visible { outline: none; box-shadow: var(--ring); }
.svc[aria-expanded="true"] { border-color: var(--accent); }
.svc--attention { border-color: color-mix(in srgb, var(--urgent) 45%, var(--line)); }
/* data-svc="on|off|test|problem" colours anything that shows a connection's state */
[data-svc] { --svc-dot: var(--ink-4); --svc-ink: var(--ink-3); --svc-soft: var(--muted-soft); }
[data-svc="on"] { --svc-dot: var(--stable); --svc-ink: var(--stable); --svc-soft: var(--stable-soft); }
[data-svc="test"] { --svc-dot: var(--caution); --svc-ink: var(--caution); --svc-soft: var(--caution-soft); }
[data-svc="problem"] { --svc-dot: var(--urgent); --svc-ink: var(--urgent); --svc-soft: var(--urgent-soft); }
.svc__item {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 7px 0 9px;
  font-size: 12.5px; white-space: nowrap;
}
.svc__item + .svc__item { border-left: 1px solid var(--line-soft); }
.svc__icon { position: relative; display: none; place-items: center; color: var(--ink-3); }
.svc__icon svg { width: 16px; height: 16px; }
.svc__dot {
  position: absolute; right: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--svc-dot); box-shadow: 0 0 0 2px var(--surface);
}
.svc__name { font-weight: 600; color: var(--ink-2); }
.svc__state {
  display: inline-flex; align-items: center; height: 19px; padding: 0 7px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: var(--svc-ink); background: var(--svc-soft);
}
.svc__lights { display: none; flex-direction: column; gap: 3px; padding: 0 9px; }
.svc__light { width: 7px; height: 7px; border-radius: 50%; background: var(--svc-dot); }
.svc__item[data-svc="problem"] .svc__dot, .svc__light[data-svc="problem"] { animation: svc-pulse 1.8s ease-out infinite; }
@keyframes svc-pulse {
  0% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 2px color-mix(in srgb, var(--urgent) 55%, transparent); }
  100% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 8px transparent; }
}
@media (prefers-reduced-motion: reduce) { .svc__item[data-svc="problem"] .svc__dot, .svc__light[data-svc="problem"] { animation: none; } }

.svc-menu { width: 348px; max-width: calc(100vw - 24px); padding: 6px 6px 8px; }
.svc-menu__row { display: flex; gap: 11px; padding: 10px 11px; border-radius: var(--r-sm); }
.svc-menu__row + .svc-menu__row { border-top: 1px solid var(--line-soft); border-top-left-radius: 0; border-top-right-radius: 0; }
.svc-menu__icon {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: var(--r-sm); display: grid; place-items: center;
  color: var(--svc-ink); background: var(--svc-soft);
}
.svc-menu__body { min-width: 0; flex: 1 1 auto; }
.svc-menu__head { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.svc-menu__head strong { font-size: 13.5px; font-weight: 650; color: var(--ink); }
.svc-menu__service { font-size: 12px; color: var(--ink-4); }
.svc-pill {
  margin-left: auto; align-self: center; display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap;
  color: var(--svc-ink); background: var(--svc-soft);
}
.svc-pill__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--svc-dot); }
.svc-menu__detail { margin: 3px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-3); }
.svc-menu__fix {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 5px;
  font-size: 12.5px; font-weight: 600; color: var(--accent);
}
.svc-menu__fix:hover { text-decoration: underline; text-underline-offset: 2px; }
.svc-menu__note { margin: 0; padding: 6px 11px 2px; font-size: 12px; line-height: 1.45; color: var(--ink-4); }

/* Room is short: first the words go (icons with dots), then on phones the lights stack. */
@media (max-width: 1280px) {
  .topbar__action-label { display: none; }
  .topbar .topbar__action { width: 36px; height: 36px; padding: 0; }
}
@media (max-width: 960px) {
  .svc__item { padding: 0 9px; }
  .svc__icon { display: grid; }
  .svc__name, .svc__state { display: none; }
}
@media (max-width: 760px) {
  .svc { width: 34px; height: 34px; padding: 0; justify-content: center; }
  .svc__item { display: none; }
  .svc__lights { display: flex; padding: 0; }
  /* the button sits near the left on a phone: open the menu across the screen */
  .menu.svc-menu { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 4px); width: auto; max-width: none; }
}
@media (max-width: 430px) {
  /* room for the search box: New text is on the Inbox tab */
  .topbar .topbar__action--text { display: none; }
}
@media (prefers-reduced-motion: reduce) { .topbar__dialer[data-state="ringing"] { animation: none; } }
.topbar > .btn, .topbar > .has-menu { flex-shrink: 0; }
.topbar .topbar__nav-toggle { display: none; }

.topbar__theme-light { display: flex; }
.topbar__theme-dark, .topbar__theme-green { display: none; }
html[data-theme="dark"] .topbar__theme-light { display: none; }
html[data-theme="dark"] .topbar__theme-dark { display: flex; }
html[data-theme="green"] .topbar__theme-light { display: none; }
html[data-theme="green"] .topbar__theme-green { display: flex; }

/* The page scrolls; its content keeps a readable measure, centred like the website's .wrap. */
.page {
  padding: 32px max(28px, calc((100% - 1440px) / 2)) 40px;
  width: 100%; flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
}
.page--flush { padding: 0; max-width: none; display: flex; flex-direction: column; min-height: 0; }

.page-head {
  display: flex; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap;
  padding-bottom: var(--sp-5); border-bottom: 1px solid var(--line);
}
.page-head__text { min-width: 0; flex: 1 1 260px; }
.page-head__text::before {
  content: ""; display: block; width: 32px; height: 2px; margin-bottom: 14px; background: var(--gold);
}
.page-head h1 { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; font-size: 34px; }
.page-head__sub { color: var(--ink-3); font-size: 13.5px; margin-top: 6px; }
.page-eyebrow { margin: 0 0 8px; font-size: 10.5px; font-weight: 650; letter-spacing: .22em; text-transform: uppercase; color: var(--accent-ink); }
.page-head__text:has(> .page-eyebrow)::before { margin-bottom: 12px; }
.page-head__actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.pipeline-page-head { margin-bottom: var(--sp-4); }
.pipeline-page-head h1::before { content: none; }

.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-4); margin-bottom: 8px; }
.breadcrumbs a { color: var(--ink-3); font-weight: 500; }
.breadcrumbs a:hover { color: var(--accent); }

/* ---- hero band (dashboard) ---- */
.hero {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg); padding: var(--sp-8) var(--sp-8) var(--sp-6);
  background: var(--hero-grad);
  color: var(--hero-ink); margin-bottom: var(--sp-5);
  box-shadow: var(--shadow-2);
  border-bottom: 3px solid var(--gold);
}
.hero::before {
  content: ""; position: absolute; inset: -60% -20% auto 55%; height: 240%;
  background: radial-gradient(closest-side, var(--hero-glow-1), transparent 70%);
}
.hero::after {
  content: ""; position: absolute; inset: auto auto -70% -10%; width: 420px; height: 420px;
  background: radial-gradient(closest-side, var(--hero-glow-2), transparent 70%);
}
.hero > * { position: relative; z-index: 1; }
.hero h1, .hero .hero__title { color: var(--hero-ink); font-family: var(--display); font-weight: 500; font-size: 32px; letter-spacing: 0; }
.hero__sub { color: var(--hero-ink-2); font-size: 13.5px; margin-top: 6px; }
.hero__stats { display: flex; gap: var(--sp-6); flex-wrap: wrap; margin-top: var(--sp-5); }
.hero__stat { min-width: 92px; }
.hero__stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .2em; color: var(--gold); font-weight: 650; }
.hero__stat-value {
  font-family: var(--display); font-size: 32px; font-weight: 500; letter-spacing: 0;
  color: var(--hero-ink); margin-top: 4px; font-variant-numeric: lining-nums tabular-nums;
}

/* ------------------------------------------------------------------- grids */
.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
.grid--sidebar { grid-template-columns: minmax(0,1fr) 352px; align-items: start; }
.grid--aside { grid-template-columns: 312px minmax(0,1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack--sm { gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  overflow: hidden; position: relative;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover { box-shadow: var(--shadow-1); }
.patient-header-card { overflow: visible; z-index: 2; }
.card--flat { box-shadow: none; }
.card--flat:hover { box-shadow: none; }
.card--inset { background: var(--surface-2); }
.card__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line-soft);
}
.card__head h2, .card__head h3 { font-family: var(--display); font-size: 18px; font-weight: 500; letter-spacing: 0; }
.card__head .btn { margin-left: auto; }
.card__body { padding: var(--sp-5); }
.card__body--tight { padding: var(--sp-3) var(--sp-4); }
.card__foot {
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line-soft);
  background: var(--surface-2); font-size: 12.5px; color: var(--ink-3);
}
.card__title-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--gold-soft); color: var(--gold-ink); flex: 0 0 32px; border-radius: 50%;
}
.card__title-icon svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------- stat tile */
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-5);
  box-shadow: var(--shadow-1); position: relative; overflow: hidden;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat::before { content: none; }
.stat::after { content: none; }
.stat > * { position: relative; z-index: 1; }
.stat__label { font-size: 10px; text-transform: uppercase; letter-spacing: .2em; color: var(--accent-ink); font-weight: 650; }
.stat__value {
  font-family: var(--display); font-size: 40px; font-weight: 500; letter-spacing: 0;
  margin-top: 10px; font-variant-numeric: tabular-nums lining-nums; line-height: 1;
  color: var(--ink);
}
.stat__meta {
  display: flex; align-items: center; gap: 6px; margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--ink-3);
}
.encounter-overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.stat--compact { padding: var(--sp-4); }
.stat--compact .stat__value { font-size: 28px; }
.stat--compact .stat__meta svg { width: 14px; height: 14px; }
.stat--attention::before { background: var(--caution); }
.stat__delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 650; }
.stat__delta svg { width: 13px; height: 13px; }
.stat__delta.up { color: var(--stable); }
.stat__delta.down { color: var(--urgent); }
.stat__icon {
  position: absolute; right: var(--sp-5); top: var(--sp-5);
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); color: var(--gold-ink); z-index: 2;
}
.stat__icon svg { width: 17px; height: 17px; }
.stat__spark { margin-top: var(--sp-3); height: 34px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px; border-radius: var(--r-sm);
  border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  box-shadow: inset 0 0 0 1.5px var(--line-strong);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.btn:hover { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn:active { transform: scale(.98); }
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--gold); color: var(--navy); box-shadow: none; }
.btn--primary:hover { background: var(--gold-hover); color: var(--navy); box-shadow: none; }
/* Paper takes the practice's own colour for its main buttons */
html[data-theme="green"] .btn--primary { background: var(--accent); color: var(--on-accent); }
html[data-theme="green"] .btn--primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn--ghost { background: transparent; color: var(--ink-2); box-shadow: none; }
.btn--ghost:hover { background: var(--surface-3); box-shadow: none; transform: none; }
.btn--soft { background: var(--accent-soft); color: var(--accent-ink); box-shadow: none; }
.btn--soft:hover { background: color-mix(in srgb, var(--gold) 28%, var(--surface)); color: var(--accent-ink); box-shadow: none; }
.btn--danger { background: var(--urgent); color: #fff; box-shadow: none; }
.btn--danger:hover { background: color-mix(in srgb, var(--urgent) 86%, #000); color: #fff; box-shadow: none; }
.btn--danger-soft { background: var(--urgent-soft); border-color: transparent; color: var(--urgent); box-shadow: none; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn--sm svg { width: 13px; height: 13px; }
.btn--lg { height: 48px; padding: 0 24px; font-size: 14.5px; border-radius: var(--r-sm); }
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 32px; }
.btn--block { width: 100%; }
.btn:disabled, .btn.is-disabled { opacity: .45; pointer-events: none; box-shadow: none; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
.btn-group .btn:hover { transform: none; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

.google-calendar-card { border-color: color-mix(in srgb, var(--accent-2) 22%, var(--line)); }
.google-calendar-card__body {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap;
}
.google-calendar-card__identity { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.google-calendar-card__icon {
  position: relative; width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center;
  border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent-ink);
}
.google-calendar-card__icon svg { width: 18px; height: 18px; }
.google-calendar-card__brand {
  position: absolute; right: -5px; bottom: -4px; width: 17px; height: 17px;
  display: grid; place-items: center; border: 2px solid var(--surface);
  border-radius: 50%; background: conic-gradient(#4285f4 0 25%, #34a853 25% 50%, #fbbc05 50% 75%, #ea4335 75%);
  color: #fff; font-family: Arial, sans-serif; font-size: 10px; font-weight: 800; line-height: 1;
}
.google-calendar-card__copy { min-width: 0; }
.google-calendar-card__copy strong { display: block; color: var(--ink-2); font-size: 13.5px; }
.google-calendar-card__copy .text-mute { margin-top: 2px; }
.google-calendar-card__actions { display: flex; align-items: center; gap: var(--sp-2); flex: 0 0 auto; }

.segmented {
  display: inline-flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 3px; gap: 2px;
}
.segmented a, .segmented button {
  padding: 6px 13px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 600;
  color: var(--ink-3); border: 0; background: transparent; cursor: pointer; font-family: inherit;
  transition: all var(--dur) var(--ease);
}
.segmented a:hover, .segmented button:hover { color: var(--ink); }
.segmented .is-active { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.segmented .is-active:hover { color: var(--on-accent); }

/* ------------------------------------------------------------------- pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-xs);
  font-size: 11px; font-weight: 650; line-height: 1.7; letter-spacing: .02em;
  background: var(--muted-soft); color: var(--muted-tone); white-space: nowrap;
}
.pill svg { width: 12px; height: 12px; }
.pill--urgent  { background: var(--urgent-soft);  color: var(--urgent); }
.pill--caution { background: var(--caution-soft); color: var(--caution); }
.pill--stable  { background: var(--stable-soft);  color: var(--stable); }
.pill--info    { background: var(--info-soft);    color: var(--info); }
.pill--accent  { background: var(--accent-soft);  color: var(--accent-ink); }
.pill--purple  { background: var(--purple-soft);  color: var(--purple); }
.pill--muted   { background: var(--muted-soft);   color: var(--muted-tone); }
.pill--outline { background: transparent; border: 1px solid var(--line-strong); color: var(--ink-3); }
.pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tag-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: var(--r-pill); font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
}
.tag-chip__dot { width: 7px; height: 7px; border-radius: 50%; }

/* ----------------------------------------------------------------- avatars */
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--display);
  font-size: 14px; font-weight: 500;
  background: var(--navy); color: var(--gold-hover);
  overflow: hidden; letter-spacing: .02em;
  box-shadow: none;
}
html[data-theme="dark"] .avatar { background: var(--navy-2); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 30px; height: 30px; flex-basis: 30px; font-size: 12px; }
.avatar--lg { width: 56px; height: 56px; flex-basis: 56px; font-size: 21px; }
.avatar--xl { width: 76px; height: 76px; flex-basis: 76px; font-size: 28px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--gold); }
.avatar--neutral { background: var(--surface-3); color: var(--ink-3); box-shadow: none; border: 1px solid var(--line); }
.avatar--stable { background: var(--stable); color: #fff; }

.text-stable { color: var(--stable) !important; }
.identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.identity__name { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.identity__meta { font-size: 12px; color: var(--ink-4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.data thead th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .18em;
  color: var(--ink-4); font-weight: 650; padding: 13px var(--sp-5) 11px;
  background: var(--surface); border-bottom: 1px solid var(--line-strong);
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
table.data tbody td {
  padding: 0 var(--sp-5); height: var(--row-h);
  border-bottom: 1px solid var(--line-soft); color: var(--ink-2); vertical-align: middle;
  position: relative;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background var(--dur) var(--ease); }
table.data tbody tr:hover { background: var(--accent-softer); }
table.data tbody tr:hover td:first-child::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  border-radius: 0; background: var(--gold);
}
table.data tbody tr.is-clickable { cursor: pointer; }
table.data td.right, table.data th.right { text-align: right; }
table.data td.shrink, table.data th.shrink { width: 1%; white-space: nowrap; }
/* Dates, times, amounts and numbers stay on one line (they wrapped into
   three or four lines in narrow columns: the audit log, the call log). */
table.data td.num { white-space: nowrap; }
table.data .cell-strong { color: var(--ink); font-weight: 600; }
table.data .cell-mute { color: var(--ink-4); font-size: 12.5px; }
.encounter-date-head { width: 132px; }
.encounter-date { width: 132px; white-space: nowrap; }
.encounter-date__day { display: block; color: var(--ink); font-family: var(--mono); font-size: 12px; font-weight: 600; }
.encounter-date__time { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; color: var(--ink-4); font-size: 11px; }
.encounter-date__time svg { width: 12px; height: 12px; }
.dashboard-calls { width: 100%; }
.dashboard-call-sections { display: flex; flex-direction: column; gap: var(--sp-3); }
.dashboard-call-section { padding: 12px 13px 4px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.dashboard-call-section__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); }
.dashboard-call-section__contact { display: inline-flex; align-items: center; gap: 7px; min-width: 0; color: var(--ink); }
.dashboard-call-section__contact svg { width: 15px; height: 15px; color: var(--accent); flex: 0 0 auto; }
.billing-timeline { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.billing-timeline__item { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 0; }
.billing-timeline__item strong, .billing-timeline__item small { display: block; }
.billing-timeline__item strong { color: var(--ink); font-size: 13px; }
.billing-timeline__item small { margin-top: 2px; color: var(--ink-4); font-size: 11px; }
.billing-timeline__icon { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; }
.billing-timeline__icon svg { width: 16px; height: 16px; }
.billing-timeline__icon--issued { background: var(--accent-soft); color: var(--accent); }
.billing-timeline__icon--due { background: var(--caution-soft); color: var(--caution); }
.billing-timeline__icon--overdue { background: var(--urgent-soft); color: var(--urgent); }
.billing-timeline__line { height: 1px; flex: 0 1 56px; background: var(--line-strong); }
.billing-date { width: 112px; white-space: nowrap; }
.billing-date__label, .billing-date__value, .billing-date__state { display: block; }
.billing-date__label { margin-bottom: 3px; color: var(--ink-4); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.billing-date__value { color: var(--ink-2); font-family: var(--mono); font-size: 11.5px; }
.billing-date__state { margin-top: 4px; color: var(--urgent); font-size: 10px; font-weight: 700; }
.billing-date--overdue .billing-date__value { color: var(--urgent); font-weight: 700; }
.billing-date--due .billing-date__value { color: var(--ink); }
.dashboard-call-section__contact strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.dashboard-call-section__date { color: var(--ink-4); font-family: var(--mono); font-size: 10px; white-space: nowrap; }
.dashboard-call-section__link { display: inline-block; margin-top: 7px; font-size: 11px; }
.dashboard-call-section .call-activity-list { padding: 0 var(--sp-2) var(--sp-2); }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 12px var(--sp-5); border-bottom: 1px solid var(--line-soft);
  transition: background var(--dur) var(--ease);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--accent-softer); }
.list-row__main { min-width: 0; flex: 1 1 auto; }
.list-row__title { font-weight: 600; color: var(--ink); font-size: 13.5px; }
.list-row__meta { font-size: 12px; color: var(--ink-4); margin-top: 2px; }
.list-row__tags { display: flex; align-items: center; gap: var(--sp-3); flex: 0 0 auto; }

.kv { display: grid; grid-template-columns: 132px minmax(0,1fr); gap: 9px var(--sp-3); font-size: 13.5px; }
.kv dt { color: var(--ink-4); font-size: 12.5px; font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); }

/* ------------------------------------------------------------------- forms */
.field { margin-bottom: var(--sp-4); }
.field__label {
  display: block; font-size: 13px; font-weight: 600; color: var(--ink);
  margin-bottom: 7px;
}
.field__label .req { color: var(--urgent); margin-left: 3px; }
.field__help { font-size: 11.5px; color: var(--ink-4); margin-top: 5px; }
.field__error { font-size: 11.5px; color: var(--urgent); margin-top: 5px; font-weight: 600; }

.input, input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=number], input[type=date], input[type=time], input[type=datetime-local],
input[type=url], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 10px 13px;
  background-color: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); color: var(--ink);
  font-family: inherit; font-size: 14px; line-height: 1.45;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-field__toggle {
  position: absolute; inset: 0 0 0 auto; width: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--ink-3); cursor: pointer;
}
.password-field__toggle:hover { color: var(--ink); }
.password-field__toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
textarea { min-height: 96px; resize: vertical; }
.input:hover, input:hover, select:hover, textarea:hover { border-color: var(--ink-4); }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink), 0 0 0 4px color-mix(in srgb, var(--gold) 28%, transparent);
  background-color: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input[type=checkbox], input[type=radio] {
  width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); cursor: pointer;
}
select, select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235F6B78' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 16px 16px; padding-right: 34px;
}
select[multiple], select.input[multiple] { background-image: none; padding-right: 13px; }
/* select2 hides the original <select> with position:absolute. With no
   positioned parent (and the 40px minimum height above) it hung off the
   bottom of the document on long forms, so the whole app shell could be
   dragged up past the page, leaving a blank screen. */
select.select2-hidden-accessible { min-height: 0 !important; }
:has(> select.select2-hidden-accessible) { position: relative; }
input[type=color] {
  width: 54px; height: 36px; padding: 3px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface);
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 4px; }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 4px; }
html[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B97A7' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
html[data-theme="green"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235F6B78' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.is-invalid, input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--urgent); }
.checkline { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: var(--ink-2); margin-bottom: 10px; }
.checkline input { margin-top: 2px; flex: 0 0 17px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--sp-4); }
.field-row--3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-section { border-top: 1px solid var(--line-soft); padding-top: var(--sp-5); margin-top: var(--sp-5); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-section__title {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--display); font-size: 19px; font-weight: 500; letter-spacing: 0;
  color: var(--ink); margin-bottom: var(--sp-4);
}
.form-section__title::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--line); }
.form-actions {
  display: flex; gap: var(--sp-2); justify-content: flex-end; align-items: center;
  padding-top: var(--sp-4); margin-top: var(--sp-4); border-top: 1px solid var(--line-soft);
}

.filters {
  display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-soft); background: var(--surface-2);
}
.filters input, .filters select { height: 34px; min-height: 34px; width: auto; min-width: 132px; font-size: 13px; border-radius: var(--r-sm); }
/* 34px is too short for the field padding plus a line of text: the bottom of
   the chosen option was cut off. Selects centre their text without it. */
.filters select { padding-top: 0; padding-bottom: 0; }
.filters .search-input { min-width: 230px; }
/* Search boxes carry a magnifier; the space for it used to be applied to every input. */
input.search-input {
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235F6B78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 15px 15px;
}
html[data-theme="dark"] input.search-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B97A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
}
.pipeline-toolbar {
  display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2); box-shadow: none; overflow: visible;
}
.pipeline-toolbar__label {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  color: var(--ink-2); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.pipeline-toolbar__label svg { width: 15px; height: 15px; color: var(--accent); }
.pipeline-toolbar .filters { flex: 1 1 auto; min-width: 0; padding: 0; border: 0; }
.pipeline-toolbar__summary { color: var(--ink-4); font-size: 12px; white-space: nowrap; }
.pipeline-toolbar__summary .num { color: var(--ink-2); font-weight: 700; }

.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-5); text-align: center; background: var(--surface-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-softer); }
.dropzone svg { width: 30px; height: 30px; color: var(--accent); margin-bottom: 10px; }
.dropzone__hint { font-size: 12px; color: var(--ink-4); margin-top: 5px; }
.dropzone input[type=file] { display: none; }

/* -------------------------------------------------------------- empty/skel */
.empty { padding: var(--sp-10) var(--sp-5); text-align: center; color: var(--ink-3); }
.empty__icon {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto var(--sp-4);
  display: grid; place-items: center; background: var(--gold-soft); color: var(--gold-ink);
  border: 0;
}
.empty__icon svg { width: 23px; height: 23px; }
.empty__title { font-family: var(--display); font-weight: 500; color: var(--ink); margin-bottom: 6px; font-size: 20px; }
.empty__text { font-size: 13px; max-width: 400px; margin: 0 auto var(--sp-4); }

/* ---------------------------------------------------------------- timeline */
.timeline { position: relative; padding-left: 30px; }
.timeline::before {
  content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 2px;
  background: var(--line);
  opacity: 1;
}
.tl-item { position: relative; padding-bottom: var(--sp-5); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item__dot {
  position: absolute; left: -30px; top: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--ink-3); z-index: 1;
  box-shadow: var(--shadow-1);
}
.tl-item__dot svg { width: 13px; height: 13px; }
.tl-item__dot.is-accent { background: var(--navy); border-color: transparent; color: var(--gold); }
.tl-item__dot.is-urgent { background: var(--urgent-soft); border-color: transparent; color: var(--urgent); }
.tl-item__dot.is-stable { background: var(--stable-soft); border-color: transparent; color: var(--stable); }
.tl-item__head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.tl-item__title { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.tl-item__time { font-size: 11.5px; color: var(--ink-4); }
.tl-item__body { font-size: 13px; color: var(--ink-3); margin-top: 4px; white-space: pre-line; }

/* ------------------------------------------------------------------ kanban */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); align-items: start; overflow: visible; padding: var(--sp-1) 2px var(--sp-5); }
.kanban__col { min-width: 0; width: 100%; }
.kanban__head { display: flex; align-items: center; gap: 9px; min-height: 31px; padding: 0 7px var(--sp-3); }
.kanban__dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }
.kanban__title { font-family: var(--display); font-size: 17px; font-weight: 500; color: var(--ink); }
.kanban__count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); background: var(--surface-3); border-radius: var(--r-pill); padding: 2px 9px; font-weight: 600; }
.kanban__rule { height: 1px; flex: 1 1 auto; background: var(--line-soft); margin-left: 2px; }
.kanban__body {
  background: var(--surface-inset); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 8px; min-height: 140px;
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.lead-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 13px; box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  display: block; position: relative; overflow: visible;
}
.lead-card.is-menu-open { z-index: 5; }
.lead-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--gold); opacity: 0; transition: opacity var(--dur) var(--ease);
}
.lead-card:hover { box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.lead-card:hover::before { opacity: 1; }
.lead-card__top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 10px; }
.lead-card__top > .has-menu { display: contents; }
.lead-card__top > .has-menu .menu { grid-column: 1 / -1; }
.lead-card__name { font-weight: 650; font-size: 13.5px; color: var(--ink); }
.lead-card__name a { color: inherit; text-decoration: none; }
.lead-card__name a:hover { color: var(--accent); }
.lead-card__meta { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.lead-card__actions { display: flex; align-items: center; gap: 4px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line-soft); }
.lead-card__actions form { display: contents; }
.lead-card__actions .btn { width: 30px; height: 30px; padding: 0; }
.lead-card__actions .btn svg { width: 14px; height: 14px; }
.lead-card__foot { display: flex; align-items: center; gap: 6px; margin-top: 11px; flex-wrap: wrap; }
.lead-card__stale { color: var(--caution); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; gap: 3px; }

/* ------------------------------------------------------------------ inbox */
.inbox { display: grid; grid-template-columns: 344px minmax(0,1fr); flex: 1 1 auto; min-height: 0; }
.inbox__list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.inbox__list-head { padding: var(--sp-4); border-bottom: 1px solid var(--line-soft); }
.inbox__title { font-size: 22px; }
.inbox__scroll { overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; }
.inbox-search { margin-bottom: var(--sp-3); }
.inbox-search__field { position: relative; }
.inbox-search__field > svg { position: absolute; left: 13px; top: 11px; width: 17px; height: 17px; color: var(--ink-4); pointer-events: none; }
.inbox-search__field input { width: 100%; padding: 10px 40px 10px 40px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--canvas); color: var(--ink); font-size: 13px; }
.inbox-search__field input:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.inbox-search__field input::placeholder { color: var(--ink-4); }
.inbox-search__clear { position: absolute; right: 8px; top: 7px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--r-sm); color: var(--ink-4); }
.inbox-search__clear:hover { background: var(--surface-2); color: var(--ink); }
.inbox-search__clear svg { width: 15px; height: 15px; }
.inbox-search__meta { margin-top: var(--sp-2); }
.convo {
  display: flex; gap: 11px; padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line-soft); cursor: pointer; position: relative;
  transition: background var(--dur) var(--ease);
}
.convo:hover { background: var(--surface-2); }
.convo.is-active { background: var(--accent-softer); }
.convo.is-active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--gold); }
.convo__main { min-width: 0; flex: 1 1 auto; }
.convo__top { display: flex; align-items: baseline; gap: 6px; }
.convo__name { font-weight: 650; font-size: 13.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo__time { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); white-space: nowrap; }
.convo__preview { font-size: 12.5px; color: var(--ink-4); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.convo__badge {
  background: var(--gold); color: var(--navy); border-radius: var(--r-pill);
  font-family: var(--mono); font-size: 10px; font-weight: 700; padding: 2px 7px; min-width: 20px; text-align: center;
}
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--canvas); }
.thread__head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--line);
  background: var(--surface); flex: 0 0 auto;
}
.thread__scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: var(--sp-5) var(--sp-6);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.thread__inner { width: 100%; max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--sp-2); }
.thread__empty { flex: 1 1 auto; display: grid; place-items: center; }
.thread__calls { width: 100%; max-width: 820px; margin: var(--sp-5) auto 0; padding: 12px 13px 4px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.thread__calls-title { display: flex; align-items: center; gap: 7px; margin: 0 0 7px; padding: 0 2px 9px; border-bottom: 1px solid var(--line-soft); color: var(--accent); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.thread__calls-title svg { width: 15px; height: 15px; }
.call-activity-list { padding: 0 var(--sp-4) var(--sp-3); }
.call-activity { display: flex; align-items: center; gap: 9px; min-height: 58px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.call-activity__icon { width: 16px; height: 16px; color: var(--accent); flex: 0 0 auto; }
.call-activity__main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1 1 auto; }
.call-activity__main strong { color: var(--ink); font-size: 14px; font-weight: 700; }
.call-activity__note { margin: -1px 0 8px 25px; color: var(--ink-3); font-size: 12px; line-height: 1.55; }
.voicemail-card { display: flex; align-items: flex-start; gap: 9px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.voicemail-card .avatar { flex: 0 0 auto; }
.voicemail-card .avatar svg { width: 14px; height: 14px; }
.voicemail-card__body { min-width: 0; width: min(100%, 365px); padding: 9px 12px 8px; border-radius: var(--r-md); background: var(--surface-2); }
.voicemail-card__heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; color: var(--ink); }
.voicemail-card__heading strong { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.voicemail-card__heading svg { width: 14px; height: 14px; color: var(--accent); }
.voicemail-card__audio { display: block; width: 100%; height: 39px; accent-color: var(--accent); }
.voicemail-card__missing { display: flex; align-items: center; gap: 6px; min-height: 39px; color: var(--ink-4); font-size: 12px; }
.voicemail-card__missing svg { width: 14px; height: 14px; }
.voicemail-card__meta { display: flex; align-items: center; gap: 5px; margin-top: 5px; color: var(--ink-4); font-family: var(--mono); font-size: 10px; }
@media (max-width: 560px) {
  .thread__calls { margin-left: 0; margin-right: 0; padding-left: 10px; padding-right: 10px; }
  .call-activity { align-items: flex-start; }
  .call-activity .pill { margin-left: auto; }
  .call-activity .num { align-self: center; }
  .call-activity__note { margin-left: 25px; }
}
.bubble-row { display: flex; align-items: flex-end; gap: 8px; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row + .bubble-row { margin-top: 2px; }
.bubble-row.is-turn { margin-top: var(--sp-4); }
.bubble {
  max-width: min(580px, 78%); padding: 11px 15px; border-radius: 14px 14px 14px 3px;
  font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-1);
}
.bubble-row.out .bubble {
  background: var(--grad-cta); border-color: transparent; color: #fff;
  border-radius: 14px 14px 3px 14px; box-shadow: none;
}
.bubble-row.out .bubble.is-automated { background: var(--surface-3); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-1); }
.bubble__meta { font-size: 10.5px; margin-top: 6px; display: flex; align-items: center; gap: 5px; opacity: .78; }
.bubble-row.out .bubble__meta { justify-content: flex-end; }
.thread__composer { border-top: 1px solid var(--line); background: var(--surface); padding: var(--sp-3) var(--sp-6); flex: 0 0 auto; }
.thread__composer form { width: 100%; max-width: 820px; margin: 0 auto; }
.thread__composer textarea { min-height: 66px; resize: none; }
.day-divider { text-align: center; font-size: 11px; color: var(--ink-4); position: relative; margin: var(--sp-2) 0; }
.day-divider span { background: var(--canvas); padding: 0 12px; position: relative; z-index: 1; }
.day-divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line); }

/* --------------------------------------------------------------- calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-1); }
.cal__dow { padding: 10px; text-align: center; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-4); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.cal__day { min-height: 126px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 7px; transition: background var(--dur) var(--ease); }
.cal__day:hover { background: var(--accent-softer); }
.cal__day:nth-child(7n+7) { border-right: 0; }
.cal__day.is-muted { background: var(--surface-2); opacity: .65; }
.cal__day.is-today .cal__num { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.cal__num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink-3); }
.cal__chip {
  display: block; font-size: 11px; padding: 3px 7px; border-radius: var(--r-xs);
  margin-top: 4px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 2px solid var(--gold);
}
.cal__chip--google { background: var(--surface-3); color: var(--ink-2); border-left-color: var(--accent-2); }
.agenda-slot { display: flex; gap: var(--sp-4); padding: var(--sp-4) 0; border-bottom: 1px solid var(--line-soft); }
.agenda-slot__time { flex: 0 0 84px; font-family: var(--mono); font-size: 13px; color: var(--ink-2); font-weight: 600; padding-top: 2px; }
.agenda-slot__body { flex: 1 1 auto; min-width: 0; }

/* ------------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: var(--sp-5); overflow-x: auto; }
.tabs a {
  padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: all var(--dur) var(--ease);
}
.tabs a:hover { color: var(--ink); background: transparent; border-bottom-color: var(--line-strong); }
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--gold); background: transparent; }
.tabs a.is-active svg { color: var(--gold-ink); }
.tabs a svg { width: 15px; height: 15px; }
.tabs__count { font-family: var(--mono); font-size: 10.5px; background: var(--surface-3); border-radius: var(--r-pill); padding: 1px 7px; color: var(--ink-4); font-weight: 600; }

/* ----------------------------------------------------------- modal / drawer */
.overlay {
  position: fixed; inset: 0; background: rgba(21,34,51,.55);
  backdrop-filter: blur(4px); z-index: 90; display: grid; place-items: center; padding: var(--sp-5);
}
.modal {
  background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--gold); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); width: min(580px, 100%); max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal--wide { width: min(900px, 100%); }
.modal__head { padding: var(--sp-6) var(--sp-6) var(--sp-3); display: flex; align-items: flex-start; gap: var(--sp-3); }
.modal__head h2, .modal__head h3 { font-family: var(--display); font-weight: 500; font-size: 22px; letter-spacing: 0; }
.modal__body { padding: 0 var(--sp-6) var(--sp-5); overflow-y: auto; }
.modal__foot { padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--line-soft); background: var(--surface-2); display: flex; gap: var(--sp-2); justify-content: flex-end; }
.delete-confirm__warning {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--urgent) 28%, var(--line));
  border-radius: var(--r-md); background: var(--urgent-soft); color: var(--urgent);
  font-size: 13px; line-height: 1.45;
}
.delete-confirm__warning svg { width: 18px; height: 18px; flex: 0 0 18px; }
.delete-confirm__details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 var(--sp-4); }
.delete-confirm__detail { padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.delete-confirm__detail-label { display: block; margin-bottom: 3px; color: var(--ink-4); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.delete-confirm__detail-value { color: var(--ink); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.delete-confirm__cancel { background: var(--surface); }
.delete-confirm__delete { background: var(--urgent); border-color: var(--urgent); color: #fff; }
.delete-confirm__delete:hover { background: color-mix(in srgb, var(--urgent) 86%, #000); border-color: color-mix(in srgb, var(--urgent) 86%, #000); color: #fff; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-3);
  z-index: 95; display: flex; flex-direction: column;
}

.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-3); min-width: 224px; padding: 6px; overflow: hidden;
}
.menu.menu--up { top: auto; bottom: calc(100% + 8px); }
.lead-card .has-menu { position: static; }
.lead-card .menu { position: static; width: min(260px, 100%); max-width: 100%; max-height: min(420px, 55vh); margin-top: 8px; overflow-y: auto; }
.menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 11px; border-radius: var(--r-sm); font-size: 13px; color: var(--ink-2);
  background: none; border: 0; cursor: pointer; font-family: inherit; text-align: left; font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.menu__item:hover { background: var(--surface-2); color: var(--ink); }
.menu__item svg { width: 15px; height: 15px; color: var(--ink-4); }
.menu__item:hover svg { color: var(--gold-ink); }
.menu__item.is-active { background: var(--accent-softer); color: var(--ink); font-weight: 650; }
.menu__item.is-active svg { color: var(--gold-ink); }
.menu__item.is-active::after { content: "\2713"; margin-left: auto; font-weight: 700; }
.menu__item.is-danger { color: var(--urgent); }
.menu__item.is-danger svg { color: var(--urgent); }
.menu__item.is-danger:hover { background: var(--urgent-soft); color: var(--urgent); }
.menu__sep { height: 1px; background: var(--line-soft); margin: 5px 0; }
.menu__label { display: flex; align-items: center; gap: 7px; font-size: 10px; text-transform: uppercase; letter-spacing: .2em; color: var(--accent-ink); padding: 8px 11px 5px; font-weight: 650; }
.menu__label svg { width: 13px; height: 13px; color: var(--gold-ink); }
.has-menu { position: relative; }

/* ----------------------------------------------------------------- toasts */
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 120; display: flex; flex-direction: column; gap: var(--sp-2); }
.toast {
  display: flex; align-items: flex-start; gap: 11px; min-width: 300px; max-width: 420px;
  background: var(--navy); color: var(--ivory); border: 0; border-left: 3px solid var(--gold);
  border-radius: var(--r-sm); box-shadow: var(--shadow-3); padding: 14px var(--sp-4); font-size: 13.5px;
  animation: toast-in 260ms var(--ease);
}
.toast svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--gold); margin-top: 1px; }
.toast.is-success svg { color: #8CC7A6; }
.toast.is-error   { border-left-color: #F09A90; } .toast.is-error svg { color: #F09A90; }
.toast.is-warning svg { color: #E6C07A; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- misc atoms */
.alert-banner {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px var(--sp-4); border-radius: var(--r-md); font-size: 13px;
  background: var(--caution-soft); color: var(--caution);
  border: 1px solid color-mix(in srgb, var(--caution) 26%, transparent);
}
.alert-banner svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.alert-banner--urgent { background: var(--urgent-soft); color: var(--urgent); border-color: color-mix(in srgb, var(--urgent) 26%, transparent); }
.alert-banner--info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 26%, transparent); }
.alert-banner--accent { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 26%, transparent); }
.alert-banner a { color: inherit; text-decoration: underline; }
.alert-banner code { background: rgba(27,42,65,.07); padding: 1px 5px; border-radius: 4px; }

.meter { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter__fill { height: 100%; border-radius: var(--r-pill); background: var(--grad); transition: width 500ms var(--ease); }
.meter__fill.is-urgent { background: var(--urgent); }
.meter__fill.is-caution { background: var(--caution); }
.meter__fill.is-stable { background: var(--stable); }

.funnel-step { display: flex; align-items: center; gap: var(--sp-3); padding: 10px 0; }
.funnel-step__bar { flex: 1 1 auto; height: 30px; border-radius: var(--r-sm); background: var(--surface-3); position: relative; overflow: hidden; }
.funnel-step__fill { position: absolute; inset: 0 auto 0 0; background: var(--grad); border-radius: var(--r-sm); }
.funnel-step__label { flex: 0 0 138px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.funnel-step__value { flex: 0 0 84px; text-align: right; font-family: var(--mono); font-size: 13px; font-weight: 700; }

.doc-tile {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.doc-tile:hover { border-color: var(--gold); box-shadow: var(--shadow-2); }
.doc-tile__icon { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold-ink); }
.doc-tile__icon svg { width: 19px; height: 19px; }
.doc-tile__name { font-weight: 600; font-size: 13.5px; color: var(--ink); word-break: break-word; }
.doc-tile__meta { font-size: 11.5px; color: var(--ink-4); }

.chart-box { position: relative; height: 268px; }
.chart-box--sm { height: 186px; }

.vital-chip { border: 1px solid var(--line); border-radius: var(--r-md); padding: 11px 13px; background: var(--surface-2); }
.vital-chip__label { font-size: 10px; text-transform: uppercase; letter-spacing: .18em; color: var(--ink-4); font-weight: 650; }
.vital-chip__value { font-family: var(--display); font-size: 24px; font-weight: 500; font-variant-numeric: lining-nums tabular-nums; margin-top: 4px; letter-spacing: 0; color: var(--ink); }
.vital-chip.is-high { border-color: color-mix(in srgb, var(--urgent) 45%, transparent); background: var(--urgent-soft); }
.vital-chip.is-high .vital-chip__value { color: var(--urgent); }
.vital-chip.is-critical { border-color: var(--urgent); background: var(--urgent-soft); }
.vital-chip.is-critical .vital-chip__value { color: var(--urgent); }
.vital-chip.is-low { border-color: color-mix(in srgb, var(--info) 45%, transparent); background: var(--info-soft); }
.vital-chip.is-low .vital-chip__value { color: var(--info); }

.soap-block { border-left: 3px solid var(--line); padding-left: var(--sp-4); margin-bottom: var(--sp-5); }
.soap-block:hover { border-left-color: var(--gold); }
.soap-block__label { font-family: var(--font); font-size: 10.5px; text-transform: uppercase; letter-spacing: .2em; font-weight: 650; color: var(--accent-ink); margin-bottom: 6px; }
.soap-block__text { font-size: 13.5px; color: var(--ink-2); white-space: pre-line; line-height: 1.65; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--ink-3); }
.pagination__links { display: flex; gap: 5px; }

/* utilities */
.text-mute { color: var(--ink-4); }
.text-soft { color: var(--ink-3); }
.text-xs { font-size: 11.5px; } .text-sm { font-size: 12.5px; } .text-lg { font-size: 16px; }
.fw-600 { font-weight: 650; } .fw-500 { font-weight: 550; }
.mt-0{margin-top:0}.mt-1{margin-top:var(--sp-1)}.mt-2{margin-top:var(--sp-2)}.mt-3{margin-top:var(--sp-3)}
.mt-4{margin-top:var(--sp-4)}.mt-5{margin-top:var(--sp-5)}.mt-6{margin-top:var(--sp-6)}
.mb-0{margin-bottom:0}.mb-2{margin-bottom:var(--sp-2)}.mb-3{margin-bottom:var(--sp-3)}.mb-4{margin-bottom:var(--sp-4)}.mb-5{margin-bottom:var(--sp-5)}
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hide { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------------------------------------------------------- public form */
.public-shell { max-width: 700px; margin: 0 auto; padding: var(--sp-10) var(--sp-5) var(--sp-8); }
.public-head { text-align: center; margin-bottom: var(--sp-6); }
.public-head h1 { font-size: 36px; margin-bottom: 8px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1280px) {
  .grid--5 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid--4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid--sidebar, .grid--aside { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 1040px) {
  .grid--3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .encounter-overview { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .inbox { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 340px) minmax(0,1fr); }
  .inbox__list { border-right: 0; border-bottom: 1px solid var(--line); }
  .thread__scroll, .thread__composer { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .kanban { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%);
    transition: transform 240ms var(--ease); box-shadow: var(--shadow-3);
  }
  body.nav-open .sidebar { transform: none; }
  .sidebar__toggle { display: none; }
  body.nav-open .scrim { position: fixed; inset: 0; background: rgba(21,34,51,.55); backdrop-filter: blur(2px); z-index: 39; }
  .page { padding: var(--sp-5) var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); height: 56px; flex-basis: 56px; }
  .topbar .topbar__nav-toggle { display: inline-flex; }
  .topbar { gap: 8px; }
  .topbar__spacer { display: none; }
  .topbar__action-label { display: none; }
  .topbar .topbar__action { width: 34px; height: 34px; padding: 0; }
  .topbar .topbar__search input { padding-right: 12px; }
  .grid--2, .grid--3, .grid--4, .grid--5 { grid-template-columns: minmax(0,1fr); }
  .encounter-overview { grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--sp-3); }
  .stat--compact { padding: var(--sp-3); }
  .stat--compact .stat__value { font-size: 24px; }
  .billing-timeline { align-items: stretch; flex-direction: column; gap: var(--sp-3); }
  .billing-timeline__line { width: 1px; height: 12px; flex: 0 0 12px; margin-left: 16px; }
  .field-row, .field-row--3 { grid-template-columns: minmax(0,1fr); }
  .topbar__search { max-width: none; }
  .topbar__search kbd { display: none; }
  .pipeline-toolbar { align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
  .pipeline-toolbar__label { flex: 1 1 auto; }
  .pipeline-toolbar .filters { flex: 1 1 100%; order: 3; display: flex; flex-wrap: wrap; }
  .pipeline-toolbar .filters select, .pipeline-toolbar .filters .search-input { flex: 1 1 145px; min-width: 0; }
  .pipeline-toolbar__summary { margin-left: auto; }
  .google-calendar-card__body { align-items: flex-start; }
  .google-calendar-card__identity { flex: 1 1 220px; }
  .google-calendar-card__actions { width: 100%; }
  .google-calendar-card__actions .btn,
  .google-calendar-card__actions form { flex: 1 1 auto; }
  .google-calendar-card__actions form .btn { width: 100%; }
  h1 { font-size: 21px; }
  .hero { padding: var(--sp-5); border-radius: var(--r-lg); }
  .hero h1, .hero .hero__title { font-size: 22px; }
  .hero__stats { gap: var(--sp-4); }
  .kanban { grid-template-columns: minmax(0, 1fr); overflow: visible; }
  .modal { border-radius: var(--r-lg); }
  .stat__value { font-size: 27px; }
}
@media (max-width: 420px) {
  .page { padding: var(--sp-3); }
  .card__body { padding: var(--sp-4); }
  .kv { grid-template-columns: minmax(0,1fr); gap: 2px var(--sp-2); }
  .kv dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .sidebar, .topbar, .page-head__actions, .btn, .tabs, .hero { display: none !important; }
  body { background: #fff; background-image: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .stat__value { color: #000; -webkit-text-fill-color: #000; }
  /* Printable pages: the print header in, everything interactive out. */
  .print-only { display: block !important; }
  .no-print, .filters, .pagination, .tabbar, .toasts, .copilot, .breadcrumbs, form button, select, .menu { display: none !important; }
  .page { padding: 0 !important; max-width: none !important; }
  .grid { display: block !important; }
  .grid > * { margin-bottom: 12px; }
  table.data { font-size: 11px; }
  table.data th, table.data td { padding: 4px 6px !important; }
  a { color: #000; text-decoration: none; }
  .print-break { break-before: page; }
}
.print-only { display: none; }
.print-header { border-bottom: 2px solid #1B2A41; padding-bottom: 8px; margin-bottom: 14px; color: #000; }
.print-header__practice, .print-header__title { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.print-header__practice strong { font-size: 15px; }
.print-header__practice span, .print-header__meta { font-size: 11px; color: #333; }
.print-header__title { margin-top: 6px; }
.print-header__title strong { font-size: 17px; }
.print-header__meta { margin-top: 4px; }

/* ==========================================================================
   Copilot — the bar pinned to the bottom of the shell.
   Collapsed it's one line of "what needs you". Expanded it's the full
   briefing plus an ask box. It lives inside .main so it never covers the rail.
   ========================================================================== */
.copilot { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 60; }

/* ---- the launcher ---- */
.copilot__launcher {
  position: relative; width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--navy); cursor: pointer;
  display: grid; place-items: center; padding: 0;
  box-shadow: 0 0 0 3px var(--canvas), 0 0 0 4px var(--gold), 0 14px 30px -12px rgba(21,34,51,.55);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
html[data-theme="dark"] .copilot__launcher { box-shadow: 0 0 0 3px var(--canvas), 0 0 0 4px var(--gold), 0 14px 30px -10px rgba(0,0,0,.72); }
.copilot__launcher:hover { transform: translateY(-2px); }
.copilot__launcher:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.copilot__launcher > * { grid-area: 1 / 1; }
.copilot__mark {
  width: 32px; height: 29px; display: grid; place-items: center;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.copilot__close-mark {
  display: grid; place-items: center; color: var(--gold);
  opacity: 0; transform: scale(.7);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.copilot__close-mark svg { width: 20px; height: 20px; }
.copilot.is-open .copilot__mark { opacity: 0; transform: scale(.7); }
.copilot.is-open .copilot__close-mark { opacity: 1; transform: scale(1); }
.copilot.is-open .copilot__badge { opacity: 0; pointer-events: none; }

.copilot__badge {
  position: absolute; top: -3px; right: -3px; z-index: 2;
  min-width: 20px; height: 20px; padding: 0 5px;
  font-family: var(--mono); font-size: 10.5px; font-weight: 700; line-height: 20px;
  border-radius: var(--r-pill); text-align: center;
  background: var(--gold); color: var(--navy); border: 2px solid var(--canvas);
  transition: opacity var(--dur) var(--ease);
}
.copilot__badge.is-urgent { background: var(--urgent); color: #fff; }

/* ---- the mark: the practice's heart-and-pulse (partials/copilot_robot.html) ---- */
.assist-mark { display: grid; place-items: center; width: 100%; height: 100%; }
.assist-mark .brand-mark { width: 100%; height: auto; }
.copilot__launcher .assist-mark { --bm-cut: var(--navy); }
.copilot__head-mark .assist-mark { --bm-cut: var(--navy); }
.is-thinking .assist-mark .bm-pulse, .is-thinking .assist-mark .bm-pulse-out { animation: bm-beat 1.1s var(--ease) infinite; }
@media (prefers-reduced-motion: reduce) { .is-thinking .assist-mark .bm-pulse, .is-thinking .assist-mark .bm-pulse-out { animation: none; } }

/* ---- the panel: a phone, standing on the launcher ---- */
.copilot__phone {
  position: absolute; right: 0; bottom: calc(54px + 12px);
  width: 384px; height: min(640px, calc(100dvh - var(--sp-5) - 54px - 24px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--r-lg); border: 1px solid var(--line); border-top: 3px solid var(--gold);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform-origin: bottom right;
  animation: copilot-in .18s var(--ease) both;
}
html[data-theme="dark"] .copilot__phone { box-shadow: 0 24px 60px -10px rgba(0,0,0,.76); }
@keyframes copilot-in {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .copilot__phone { animation: none; } }

.copilot__head {
  flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-3);
  padding: 12px var(--sp-4); border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.copilot__head-mark {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; background: var(--navy);
  display: grid; place-items: center; padding: 8px 7px;
}
.copilot__head-text { min-width: 0; flex: 1 1 auto; }
.copilot__head-title { display: block; font-size: 13.5px; font-weight: 700; color: var(--ink); }
.copilot__line {
  display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.copilot__head-btn {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: var(--r-sm);
  border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  display: grid; place-items: center; text-decoration: none;
}
.copilot__head-btn:hover { background: var(--accent-softer); color: var(--accent-ink); }
.copilot__head-btn svg { width: 16px; height: 16px; }

/* Copilot sessions panel */
.copilot__sessions-panel {
  position: absolute;
  top: 55px; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  z-index: 20;
  display: flex; flex-direction: column;
  animation: copilot-in .15s ease-out;
}
.copilot__sessions-panel.hide { display: none !important; }
.copilot__sessions-head {
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.copilot__sessions-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-3);
}
.copilot__sessions-list {
  flex: 1 1 auto; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.copilot__session-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 12px; border-radius: var(--r-md);
  border: 1px solid var(--line-soft); background: var(--surface-2);
  cursor: pointer; text-align: left; transition: background .15s, border-color .15s;
  color: var(--ink); width: 100%;
}
.copilot__session-item:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}
.copilot__session-item.is-active {
  border-color: var(--accent);
  background: var(--accent-softer);
}
.copilot__session-item-title {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.copilot__session-item-meta {
  font-size: 11px; color: var(--ink-3);
  display: flex; justify-content: space-between; align-items: center;
}
.copilot__session-empty {
  padding: 32px 16px; text-align: center; color: var(--ink-3); font-size: 12.5px;
}

/* Copilot New Session Welcome Dashboard */
.copilot__welcome {
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: 4px 0 12px;
  animation: copilot-in .2s ease-out;
}
.copilot__welcome.hide { display: none !important; }

.copilot__welcome-hero {
  text-align: center;
  padding: 16px 14px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  box-shadow: none;
}
.copilot__welcome-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  margin: 0 auto 10px; display: grid; place-items: center;
  background: var(--navy); color: var(--gold);
  box-shadow: none;
}
.copilot__welcome-avatar svg { width: 20px; height: 20px; }
.copilot__welcome-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); background: var(--accent-softer);
  padding: 2px 8px; border-radius: 999px; margin-bottom: 6px;
}
.copilot__welcome-title {
  font-size: 14.5px; font-weight: 700; color: var(--ink);
  margin: 0 0 5px; line-height: 1.3;
}
.copilot__welcome-subtitle {
  font-size: 12px; color: var(--ink-3); margin: 0;
  line-height: 1.45;
}

.copilot__welcome-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-4); font-weight: 700; margin-top: 4px;
  display: flex; align-items: center; gap: 8px;
}
.copilot__welcome-label::after {
  content: ""; flex: 1 1 auto; height: 1px;
  background: var(--line-soft);
}

.copilot__prompt-grid {
  display: grid; grid-template-columns: 1fr; gap: 7px;
}
.copilot__prompt-card {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-md);
  border: 1px solid var(--line-soft); background: var(--surface-2);
  cursor: pointer; text-align: left; transition: all .16s ease;
  width: 100%; color: var(--ink);
}
.copilot__prompt-card:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  transform: translateY(-1.5px);
  box-shadow: 0 4px 12px -2px rgba(0,0,0,0.06);
}
.copilot__prompt-card:active {
  transform: translateY(0);
}
.copilot__prompt-card-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: grid; place-items: center; flex: 0 0 32px;
}
.copilot__prompt-card-icon svg { width: 16px; height: 16px; }
.copilot__prompt-card-body {
  flex: 1 1 auto; min-width: 0;
}
.copilot__prompt-card-title {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--ink);
  margin-bottom: 1px;
}
.copilot__prompt-card-desc {
  display: block; font-size: 11.5px; color: var(--ink-3);
  line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.copilot__scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--sp-4);
}
.copilot__needs { margin-bottom: var(--sp-4); }
.copilot__needs-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-4); font-weight: 700; margin-bottom: var(--sp-2);
}

/* ---- the conversation ---- */
.copilot__thread { display: flex; flex-direction: column; gap: var(--sp-3); }
.copilot-msg {
  max-width: 84%; padding: 9px 12px; border-radius: 16px;
  font-size: 13px; line-height: 1.55;
}
.copilot-msg--me {
  align-self: flex-end; border-bottom-right-radius: 5px;
  background: var(--grad-cta); color: #fff;
}
.copilot-msg--me a { color: #fff; }
.copilot-msg--bot {
  align-self: flex-start; border-bottom-left-radius: 5px;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
}
.copilot-msg--bot.is-past { opacity: .82; }
.copilot-msg__text { white-space: pre-wrap; }
.copilot-msg__dots { display: flex; gap: 4px; padding: 3px 2px; }
.copilot-msg__dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4);
  animation: copilot-dot 1.1s ease-in-out infinite;
}
.copilot-msg__dots i:nth-child(2) { animation-delay: .16s; }
.copilot-msg__dots i:nth-child(3) { animation-delay: .32s; }
@keyframes copilot-dot { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.copilot__foot {
  flex: 0 0 auto; padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--line-soft); background: var(--surface);
}

.copilot-item {
  display: flex; gap: 11px; align-items: flex-start;
  padding: var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface-2);
  margin-bottom: var(--sp-2);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.copilot-item:hover { border-color: var(--line-strong); transform: translateX(2px); }
.copilot-item__icon {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: var(--r-sm);
  display: grid; place-items: center;
}
.copilot-item__icon svg { width: 16px; height: 16px; }
.copilot-item__icon.tone-urgent  { background: var(--urgent-soft);  color: var(--urgent); }
.copilot-item__icon.tone-caution { background: var(--caution-soft); color: var(--caution); }
.copilot-item__icon.tone-stable  { background: var(--stable-soft);  color: var(--stable); }
.copilot-item__icon.tone-info    { background: var(--info-soft);    color: var(--info); }
.copilot-item__icon.tone-accent  { background: var(--accent-soft);  color: var(--accent-ink); }
.copilot-item__body { min-width: 0; flex: 1 1 auto; }
.copilot-item__title { font-weight: 650; font-size: 13.5px; color: var(--ink); }
.copilot-item__detail { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.copilot-item__actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.copilot__ask { position: relative; }
.copilot__ask input {
  width: 100%; height: 42px; padding: 0 46px 0 15px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong);
  background: var(--surface); font-size: 13.5px;
}
.copilot__ask button {
  position: absolute; right: 5px; top: 5px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: var(--grad-cta); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.copilot__ask button svg { width: 15px; height: 15px; }
.copilot__chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--sp-3); }
.copilot__chip {
  font-size: 11.5px; padding: 5px 11px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  cursor: pointer; font-family: inherit; transition: all var(--dur) var(--ease);
}
.copilot__chip:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-softer); }

/* Answer trimmings, shared with the full briefing page. */
.copilot__answer-rows { margin-top: var(--sp-3); display: flex; flex-direction: column; gap: 4px; }
.copilot__answer-row {
  display: flex; justify-content: space-between; gap: var(--sp-3);
  padding: 7px 10px; border-radius: var(--r-sm); background: var(--surface);
  border: 1px solid var(--line-soft); font-size: 12.5px;
}
.copilot__answer-row span:last-child { color: var(--ink-4); white-space: nowrap; }
.copilot__source {
  font-size: 10.5px; color: var(--ink-4); margin-top: var(--sp-2);
  display: flex; align-items: center; gap: 5px;
}
/* Inside a bubble the rows sit on the surface, not on the bubble's own tint. */
.copilot-msg--me .copilot__answer-row,
.copilot-msg--me .copilot__source { color: rgba(255,255,255,.85); }

/* On a phone the panel is the phone: full screen, above everything. */
@media (max-width: 560px) {
  .copilot { right: var(--sp-4); bottom: var(--sp-4); }
  .copilot__phone {
    position: fixed; inset: 0; width: auto; height: auto;
    border-radius: 0; border: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .copilot__head { padding-top: max(12px, env(safe-area-inset-top)); }
}
@media print { .copilot { display: none !important; } .app, .main, .page { height: auto; overflow: visible; } }

/* The composer: one card, its edge coloured by where the message goes. */
.thread__composer form { max-width: 1000px; }
.message-composer { border:1px solid; border-top-width: 2px; border-radius: var(--r-sm); background:var(--surface); overflow: hidden; }
.message-composer[data-active-mode="sms"], .message-composer:not([data-active-mode]) { border-color: var(--line-strong); border-top-color: var(--gold); }
.message-composer[data-active-mode="email"] { border-color: var(--line-strong); border-top-color: var(--info); }
.message-composer[data-active-mode="both"] { border-color: var(--line-strong); border-top-color: var(--navy); }
.message-composer[data-active-mode="internal"] { border-color: var(--line-strong); border-top-color: var(--ink-4); }
.composer-top, .composer-toolbar, .composer-address { display:flex; align-items:center; border-bottom:1px solid var(--line); min-height:42px; padding:6px 12px; gap:12px; }
.composer-top, .composer-toolbar { background: var(--surface-2); }
.composer-mode, .composer-icon, .composer-send-main, .composer-send-options { display:inline-flex; align-items:center; justify-content:center; gap:6px; border:0; background:transparent; color:var(--ink); cursor:pointer; font:inherit; }
.composer-mode { padding:6px 8px; font-size:13px; border-radius:4px; }
.composer-mode.is-selected { background:var(--surface); }
.composer-mode.is-selected { box-shadow: inset 0 -2px 0 currentColor; font-weight: 600; }
.message-composer[data-active-mode="sms"] .composer-mode.is-selected, .message-composer:not([data-active-mode]) .composer-mode.is-selected { color: var(--gold-ink); }
.message-composer[data-active-mode="email"] .composer-mode.is-selected { color: var(--info); }
.message-composer[data-active-mode="both"] .composer-mode.is-selected { color: var(--ink); }
.message-composer[data-active-mode="internal"] .composer-mode.is-selected { color: var(--ink-4); }
.composer-divider { height:24px; border-left:1px solid var(--line); }
.message-composer svg { width:16px; height:16px; flex-shrink:0; }
.composer-window { margin-left:auto; display:flex; gap:4px; }
.composer-icon { width:30px; height:30px; border-radius: var(--r-xs); color: var(--ink-3); }
.composer-icon:hover { background: var(--surface-3); color: var(--ink); }
.message-composer button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.composer-address { min-height:36px; font-size:13px; flex-wrap:wrap; }
.composer-address > span { display:flex; gap:20px; padding-right:24px; }
.composer-address > span + span { border-left:1px solid var(--line); padding-left:20px; }
.composer-address b { font-weight:550; }
.thread__composer .message-composer textarea { display:block; width:100%; min-height:130px; max-height:240px; resize:vertical; border:0; border-radius:0; box-shadow:none; background:transparent; color:var(--ink); padding:14px 12px; font:inherit; outline:none; }
.composer-toolbar { border-top:1px solid var(--line); border-bottom:0; padding:6px; justify-content:space-between; }
.composer-tools { display:flex; gap:3px; flex-wrap:wrap; }
.composer-tools .menu { top:auto; bottom:calc(100% + 8px); left:0; right:auto; max-height:240px; overflow:auto; width:250px; max-width:75vw; }
.composer-tools .menu__item { white-space:normal; }
.composer-send { display:flex; align-items:stretch; border-radius: var(--r-sm); overflow: hidden; }
.message-composer[data-active-mode="sms"] .composer-send, .message-composer:not([data-active-mode]) .composer-send { background: var(--gold); --send-ink: var(--navy); }
.message-composer[data-active-mode="email"] .composer-send { background: var(--info); --send-ink: #fff; }
.message-composer[data-active-mode="both"] .composer-send { background: var(--navy); --send-ink: var(--ivory); }
.message-composer[data-active-mode="internal"] .composer-send { background: var(--ink-4); --send-ink: #fff; }
html[data-theme="dark"] .message-composer[data-active-mode="both"] .composer-send { background: var(--navy-2); }
.composer-send-main { padding:7px 12px; color: var(--send-ink, #fff); font-weight: 600; }
.composer-send-options { padding:7px 5px; color: var(--send-ink, #fff); border-left:1px solid color-mix(in srgb, var(--send-ink, #fff) 25%, transparent); }
.composer-send .menu { top:auto; bottom:calc(100% + 8px); }
.composer-count { text-align:right; color:var(--mute); font-size:11px; padding-top:2px; }
.composer-private, .composer-file { padding:8px 12px; font-size:12px; color: var(--gold-ink); }
.composer-file { display:flex; align-items:center; justify-content:space-between; overflow-wrap:anywhere; }
.message-composer.is-collapsed .composer-content { display:none; }
.message-composer.is-expanded { position:fixed; inset:8vh 6vw; z-index:90; display:flex; flex-direction:column; box-shadow:0 0 0 100vmax rgba(21,34,51,.7); }
.message-composer.is-expanded .composer-content { flex:1; display:flex; flex-direction:column; min-height:0; }
.thread__composer .is-expanded textarea { flex:1; max-height:none; resize:none; }
.message-composer button:disabled { opacity:.4; cursor:not-allowed; }
@media(max-width:600px) { .thread__composer { padding:8px; } .composer-top { gap:4px; padding:6px; } .composer-mode { font-size:11px; } .composer-address > span { padding-right:0; gap:8px; } .composer-address > span + span { padding-left:0; border:0; } }

.thread__scroll .bubble { white-space:normal; }
.bubble-body { white-space:pre-wrap; }

/* Conversation layout: top-aligned history and separate call activity. */
.thread__scroll { justify-content:flex-start; }
.thread__scroll .thread__inner { max-width:1000px; flex-shrink:0; gap:14px; }
.thread__scroll .thread__calls { max-width:1000px; margin:0 auto; flex-shrink:0; }
.thread__scroll .bubble-row { align-items:flex-start; gap:12px; }
.message-content { max-width:min(640px,82%); min-width:0; }
.thread__scroll .bubble { max-width:100%; border-radius:4px 12px 12px 12px; padding:10px 14px; box-shadow:none; font-size:14px; line-height:1.6; }
.thread__scroll .out .bubble { border-radius:12px 4px 12px 12px; background:var(--surface-3); color:var(--ink); border:1px solid var(--line); box-shadow:none; }
.thread__scroll .bubble__meta { padding:0 2px; margin-top:6px; font-size:11px; color:var(--ink-3); opacity:1; flex-wrap:wrap; }
.message-avatar--out { flex-shrink:0; background:var(--surface-3); color:var(--accent); }
@media(max-width:600px) { .message-content { max-width:calc(100% - 42px); } }

.timeline-call { align-self:flex-start; width:min(560px,100%); box-sizing:border-box; padding:4px 14px; margin:8px 0; border:1px solid var(--line); border-radius:12px; background:var(--surface); }
.timeline-call > .call-activity, .timeline-call > .voicemail-card { border-top:0; }
.timeline-call .call-activity__note { overflow-wrap:anywhere; }
.timeline-call--out { align-self:flex-end; background:var(--surface-3); }

.call-recording-state { margin:0 0 10px 25px; }
.call-activity--live .call-activity__icon { animation:call-pulse 1.6s ease-in-out infinite; }
.voicemail-card.is-playing .avatar { animation:call-pulse 1.2s ease-in-out infinite; color:var(--accent); }
@keyframes call-pulse { 0%,100% { opacity:.65; transform:scale(1); } 50% { opacity:1; transform:scale(1.15); } }
@media(prefers-reduced-motion:reduce) { .call-activity--live .call-activity__icon, .voicemail-card.is-playing .avatar { animation:none; } }

/* Animated recording progress; the bars illustrate playback, not sound amplitude. */
.recording-player { display:grid; grid-template-columns:36px minmax(70px,1fr) 28px; gap:9px; align-items:center; padding:10px; border:1px solid var(--line); border-radius:12px; background:var(--surface-3); }
.recording-player__play, .recording-player__mute { display:grid; place-items:center; border:0; cursor:pointer; font:inherit; }
.recording-player__play { width:36px; height:36px; border-radius:50%; background:var(--accent); color:var(--surface); font-size:16px; }
.recording-player__mute { width:28px; height:28px; background:transparent; color:var(--ink); font-size:20px; }
.recording-player__track { position:relative; height:36px; min-width:0; }
.recording-player__bars { display:flex; align-items:center; gap:3px; height:100%; pointer-events:none; }
.recording-player__bars span { height:var(--wave-height); flex:1; min-width:1px; border-radius:3px; background:var(--accent); opacity:.32; transform:scaleY(.75); }
.recording-player__bars .is-played { opacity:1; }
.recording-player.is-playing .recording-player__bars span { animation:recording-wave .85s ease-in-out infinite alternate; animation-delay:var(--wave-delay); }
.recording-player__seek { position:absolute; inset:0; width:100%; height:100%; opacity:0; margin:0; cursor:pointer; }
.recording-player__track:focus-within { outline:2px solid var(--accent); outline-offset:3px; border-radius:4px; }
.recording-player__seek:disabled { cursor:default; }
.recording-player__time { grid-column:2 / 4; font-size:11px; color:var(--ink-3); font-variant-numeric:tabular-nums; }
.recording-player button:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.voicemail-card__audio[hidden] { display:none; }
@keyframes recording-wave { from { transform:scaleY(.35); } to { transform:scaleY(1); } }
@media(prefers-reduced-motion:reduce) { .recording-player.is-playing .recording-player__bars span { animation:none; transform:none; } }

.timeline-call .voicemail-card__body { flex:1; width:auto; }

/* ------------------------------------------------------------- call modal
   One card, two steps: set up, then the live call and its wrap-up. The call
   path is the route Twilio takes — this computer → the practice's Twilio
   number → the contact — and its links light up as the call moves along it.
   data-phase (setup | connecting | ringing | connected | ended) and
   data-device (connecting | ready | offline | unavailable | simulated) on
   .call-modal drive every state below; call-modal.js only sets those two. */
.call-overlay { z-index: 9999; background: color-mix(in srgb, var(--rail-2) 60%, transparent); backdrop-filter: blur(6px); }
/* Computers: the Call window floats top-right with no backdrop and can be
   dragged by its header; the page underneath stays usable during a call. */
@media (min-width: 761px) {
  .call-overlay { background: transparent; backdrop-filter: none; pointer-events: none; display: block; padding: 0; }
  .call-overlay .call-modal {
    pointer-events: auto; position: fixed; top: calc(var(--topbar-h) + 12px); right: 24px;
    width: 440px; max-height: calc(100vh - var(--topbar-h) - 36px);
    box-shadow: 0 30px 80px -24px rgba(21, 34, 51, .5), var(--shadow-3);
  }
  .call-overlay .call-modal[data-floating] { right: auto; }
  .call-modal .call-modal__who.is-drag-handle { cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
  .call-modal.is-dragging { animation: none; }
  .call-modal.is-dragging .call-modal__who { cursor: grabbing; }
}
.call-modal {
  --call-end: #C62828; /* one red for End call in every theme: white text stays above 5:1 */
  position: relative; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 22px 22px 20px; border-radius: var(--r-xl);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-3);
  animation: call-modal-in 220ms var(--ease);
}
@keyframes call-modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.call-modal__close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-3); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.call-modal__close:hover { background: var(--surface-3); color: var(--ink); }
.call-modal__close svg { width: 17px; height: 17px; }

/* who you're calling */
.call-modal__who { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding-right: 34px; }
.call-modal__avatar {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  font-family: var(--display); font-size: 18px; font-weight: 500; letter-spacing: 0;
  color: #fff; background: var(--grad-cta); box-shadow: var(--glow);
}
.call-modal__eyebrow { margin: 0 0 2px; font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-4); }
.call-modal__name {
  margin: 0; font-family: var(--display); font-size: 21px; font-weight: 500; letter-spacing: 0;
  line-height: 1.15; color: var(--ink); overflow-wrap: anywhere;
}
.call-modal__number { margin: 3px 0 0; font-family: var(--mono); font-size: 13px; color: var(--ink-3); letter-spacing: -.01em; }
.call-modal__timer {
  font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; color: var(--ink-4);
}
.call-modal[data-phase="setup"] .call-modal__timer { display: none; }
.call-modal[data-phase="connecting"] .call-modal__timer,
.call-modal[data-phase="ringing"] .call-modal__timer { visibility: hidden; }
.call-modal[data-phase="connected"] .call-modal__timer { color: var(--stable); }

/* the call path — one line from node to node, filled as the call moves along it */
.call-path {
  --path-pad: 10px;
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr);
  align-items: start; margin: 20px 0 0; padding: 16px var(--path-pad) 14px;
  border-radius: var(--r-lg); background: var(--surface-2); border: 1px solid var(--line-soft);
}
.call-path__track {
  /* from the centre of the first node to the centre of the last: the side
     columns are 1fr of 3.3fr, so each centre sits 1/6.6 of the width in */
  position: absolute; top: 35px; height: 2px; overflow: hidden; border-radius: 2px;
  left: calc(var(--path-pad) + (100% - 2 * var(--path-pad)) / 6.6);
  right: calc(var(--path-pad) + (100% - 2 * var(--path-pad)) / 6.6);
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 5px, transparent 5px 10px);
}
.call-path__fill {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--accent);
  transition: width 420ms var(--ease), background var(--dur) var(--ease);
}
.call-path__pulse {
  position: absolute; top: 0; bottom: 0; left: -22%; width: 22%; opacity: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.call-path__stop { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; text-align: center; }
.call-path__node {
  width: 40px; height: 40px; margin-bottom: 5px; display: grid; place-items: center; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--line-strong); color: var(--ink-3);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.call-path__node svg { width: 18px; height: 18px; }
.call-path__label { max-width: 100%; font-size: 12.5px; font-weight: 650; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
.call-path__label--number { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; overflow-wrap: normal; }
.call-path__sub { font-size: 11px; color: var(--ink-4); white-space: nowrap; }
@keyframes call-travel-a { from { left: -22%; } to { left: 50%; } }
@keyframes call-travel-b { from { left: 28%; } to { left: 100%; } }
@keyframes call-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--caution) 42%, transparent); }
  100% { box-shadow: 0 0 0 11px transparent; }
}

/* this computer: is the softphone registered? */
.call-path__device { display: inline-flex; align-items: center; gap: 5px; }
.call-path__device::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); }
.call-modal[data-device="ready"] .call-path__device { color: var(--stable); font-weight: 600; }
.call-modal[data-device="ready"] .call-path__device::before { background: var(--stable); }
.call-modal[data-device="ready"] [data-stop="computer"] .call-path__node {
  border-color: var(--accent); color: var(--accent); background: linear-gradient(var(--accent-softer), var(--accent-softer)), var(--surface);
}
.call-modal[data-device="unavailable"] .call-path__device { color: var(--urgent); font-weight: 600; }
.call-modal[data-device="unavailable"] .call-path__device::before { background: var(--urgent); }
.call-modal[data-device="offline"] .call-path__device,
.call-modal[data-device="simulated"] .call-path__device { color: var(--caution); font-weight: 600; }
.call-modal[data-device="offline"] .call-path__device::before,
.call-modal[data-device="simulated"] .call-path__device::before { background: var(--caution); }
.call-modal[data-device="connecting"] .call-path__device::before { animation: call-pulse 1.2s ease-in-out infinite; }
.call-modal[data-muted="true"] .call-path__device { color: var(--caution); }
.call-modal[data-muted="true"] .call-path__device::before { background: var(--caution); }

/* the call moving along the path (node fills are layered on --surface so
   the line never shows through a translucent dark-theme tint) */
.call-modal[data-phase="connecting"] .call-path__pulse { opacity: 1; animation: call-travel-a 1.1s linear infinite; }
.call-modal[data-phase="ringing"] .call-path__pulse { opacity: 1; animation: call-travel-b 1.1s linear infinite; }
.call-modal[data-phase="ringing"] .call-path__fill { width: 50%; }
.call-modal[data-phase="connected"] .call-path__fill { width: 100%; background: var(--stable); }
.call-modal[data-phase="ringing"] [data-stop="caller-id"] .call-path__node {
  border-color: var(--accent); color: var(--accent); background: linear-gradient(var(--accent-softer), var(--accent-softer)), var(--surface);
}
.call-modal[data-phase="ringing"] [data-stop="contact"] .call-path__node { border-color: var(--caution); color: var(--caution); animation: call-ring 1.4s ease-out infinite; }
.call-modal[data-phase="connected"] .call-path__node {
  border-color: var(--stable); color: var(--stable); background: linear-gradient(var(--stable-soft), var(--stable-soft)), var(--surface);
}
.call-modal[data-phase="connected"] [data-stop="computer"] .call-path__node {
  border-color: var(--stable); color: var(--stable); background: linear-gradient(var(--stable-soft), var(--stable-soft)), var(--surface);
}
.call-modal[data-phase="connected"] [data-stop="contact"] .call-path__node { background: var(--stable); color: var(--surface); }
.call-modal[data-phase="ended"] .call-path__node { border-color: var(--line-strong); color: var(--ink-4); background: var(--surface); }

/* live status */
.call-modal__status {
  display: flex; align-items: center; justify-content: center; gap: 9px; margin: 18px 0 4px;
  font-family: var(--display); font-size: 17px; font-weight: 500; letter-spacing: 0; color: var(--ink);
}
.call-modal__status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-4); }
.call-modal[data-phase="connecting"] .call-modal__status-dot { animation: call-pulse 1.2s ease-in-out infinite; }
.call-modal[data-phase="ringing"] .call-modal__status-dot { background: var(--caution); animation: call-pulse 1.2s ease-in-out infinite; }
.call-modal[data-phase="connected"] .call-modal__status-dot { background: var(--stable); }
.call-modal__message { margin: 0 0 16px; text-align: center; font-size: 13px; line-height: 1.45; color: var(--ink-3); }

/* mute / end */
.call-modal__controls { display: grid; grid-template-columns: 1fr 1.35fr; gap: 10px; margin-bottom: 20px; }
.call-control {
  height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.call-control svg { width: 17px; height: 17px; }
.call-control:hover { background: var(--surface-3); }
.call-control[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.call-control--end { background: var(--call-end); border-color: var(--call-end); color: #fff; }
.call-control--end:hover { background: var(--call-end); filter: brightness(1.12); }
.call-control:disabled { opacity: .4; cursor: default; filter: none; }
.call-modal[data-phase="ended"] .call-modal__controls { display: none; }

/* wrap-up */
.call-wrap { padding-top: 16px; border-top: 1px solid var(--line-soft); }
.call-modal[data-phase="ended"] .call-wrap { border-top: 0; padding-top: 4px; }
.call-wrap__label { display: block; margin: 0 0 8px; padding: 0; font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-4); }
.call-modal .call-wrap__notes { width: 100%; min-height: 76px; padding: 10px 12px; resize: vertical; }
.call-outcomes { min-width: 0; margin: 0 0 16px; padding: 0; border: 0; }
.call-outcomes__list { display: flex; flex-wrap: wrap; gap: 6px; }
.call-outcome { position: relative; display: inline-flex; }
.call-outcome input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.call-outcome span {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.call-outcome:hover span { border-color: var(--ink-4); }
.call-outcome input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.call-outcome input:focus-visible + span { box-shadow: var(--ring); }

/* notices and actions */
.call-modal__notice { margin: 16px 0 0; padding: 10px 12px; border-radius: var(--r-md); font-size: 12.5px; line-height: 1.45; }
.call-modal__notice--setup { background: var(--caution-soft); color: var(--caution); }
.call-modal__notice--error { background: var(--urgent-soft); color: var(--urgent); }
.call-modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.call-modal__dial { min-width: 150px; height: 42px; font-size: 14px; }

@media (max-width: 480px) {
  .call-modal { padding: 18px 16px 16px; border-radius: var(--r-lg); }
  .call-modal__who { gap: 12px; }
  .call-modal__avatar { width: 44px; height: 44px; border-radius: 14px; font-size: 16px; }
  .call-modal__name { font-size: 19px; }
  .call-modal__timer { font-size: 20px; }
  .call-path { --path-pad: 4px; padding-top: 14px; padding-bottom: 12px; }
  .call-path__track { top: 33px; }
  .call-path__label { font-size: 11.5px; }
  .call-path__label--number { font-size: 10.5px; }
  .call-path__sub { font-size: 10.5px; }
  .call-modal__actions .btn { flex: 1 1 0; }
}
@media (prefers-reduced-motion: reduce) {
  .call-modal { animation: none; }
  .call-modal .call-path__pulse, .call-modal .call-path__node,
  .call-modal .call-path__device::before, .call-modal__status-dot { animation: none !important; }
  .call-modal .call-path__pulse { opacity: 0 !important; }
  .call-modal .call-path__fill { transition: none; }
}

/* ----------------------------------------------------------- connection health */
.health-grid {
  list-style: none; margin: 0 0 var(--sp-5); padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--sp-3);
}
.health-card {
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
  padding: 14px 16px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
}
.health-card__top { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.health-card__top strong { font-weight: 650; color: var(--ink); }
.health-card__dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: var(--stable); box-shadow: 0 0 0 3px var(--stable-soft); }
.health-card.is-bad {
  border-color: color-mix(in srgb, var(--urgent) 30%, var(--line));
  background: color-mix(in srgb, var(--urgent-soft) 45%, var(--surface));
}
.health-card.is-bad .health-card__dot { background: var(--urgent); box-shadow: 0 0 0 3px var(--urgent-soft); }
.health-card__status { margin: 5px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.health-card.is-bad .health-card__status { color: var(--urgent); }
.health-card__when { margin: 0; font-size: 12px; color: var(--ink-4); }
.health-card__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 31px; margin-top: 6px; font-size: 12px; color: var(--ink-3);
}
.health-card__foot a { color: var(--accent-ink); font-weight: 600; }
.health-card__foot form { margin: 0; }
.health-table__what strong { display: block; font-weight: 600; color: var(--ink); white-space: normal; }
.health-table__what details { margin-top: 4px; }
.health-table__what summary { cursor: pointer; font-size: 12px; color: var(--ink-3); }
.health-table__what pre {
  margin: 6px 0 0; padding: 8px 10px; max-width: 560px; max-height: 180px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2);
  background: var(--surface-2); border-radius: var(--r-xs);
}
.settings-health { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: 999px; background: var(--urgent); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 1; }

/* The Copilot button floats in the bottom-right corner; on computers the
   message composer keeps a lane clear for it, so it never covers Send. */
@media (min-width: 761px) {
  body:has(#copilot) .thread__composer { padding-right: calc(var(--sp-5) + 66px); }
}
html[data-sidebar="collapsed"] .nav-item__count--soon { display: none; }

/* Lab trends (clinical/services/labs.py trend_svg) */
.lab-trend { display: block; max-width: 100%; height: auto; }
.lab-trend__band { fill: var(--stable-soft); }
.lab-trend__line { stroke: var(--accent); stroke-width: 2; }
.lab-trend__point { fill: var(--accent); }
.lab-trend__point.is-out { fill: var(--urgent); }
.lab-trend__dose { stroke: var(--ink-4); stroke-dasharray: 4 3; }
.lab-trend__axis { font-size: 10px; fill: var(--ink-3); font-family: var(--mono); }
