@import url("/fonts/fonts.css");

@import url("/design-tokens.css?v=1");

/* ===== base.css ===== */
/* =============================================================================
   NutraTech — Base & App Shell
   Reset, typography defaults, and the persistent shell (sidebar + topbar).
   Depends on design-tokens.css.
   ============================================================================= */

/* ---- Fonts ---------------------------------------------------------------- */


/* ---- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv05" 1, "ss01" 1;
}
h1, h2, h3, h4, h5, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }
svg { display: block; }
/* FOCUS MUST BE VISIBLE. This was `box-shadow: var(--ring-focus)` — a 35%-alpha wash
   measuring ~1.5:1, effectively invisible on white and on the dark sidebar, so a
   keyboard user could not tell where they were. Worse, box-shadow is a SINGLE
   non-additive property and this rule carries only 0-1-0 specificity, so every later
   component that sets its own elevation shadow (.btn--primary, .btn--sign,
   .segmented button.is-active, .vtab.is-active) replaced the ring entirely — the
   primary action buttons had NO focus indicator at all.
   `outline` is a separate property, so nothing can overwrite it by setting a shadow,
   and it follows the element's own border-radius (making the radius override here
   unnecessary — pills stay pills). --focus-ring is the solid #2a8782 = 4.30:1 on white. */
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; box-shadow: none; }
/* The sidebar is dark teal; the same ring there is ~1.3:1. White reads 8.9:1 on it. */
.sidebar :focus-visible, .sidebar__foot :focus-visible { outline-color: #ffffff; }
::selection { background: var(--teal-200); }

/* ---- Type helpers --------------------------------------------------------- */
.t-label {
  font-size: var(--text-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.t-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.ic { width: 18px; height: 18px; flex: none; }
.t-num  { font-variant-numeric: tabular-nums; }
.t-muted { color: var(--text-muted); }
.t-secondary { color: var(--text-secondary); }
.t-sm { font-size: var(--text-sm); }
.t-xs { font-size: var(--text-xs); }
.t-lg { font-size: var(--text-lg); }
.section-title {
  font-size: var(--text-md);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}

/* =============================================================================
   APP SHELL
   ============================================================================= */
/* The sidebar is ALWAYS injected by sidebar.js as a position:fixed rail + a body
   margin (no page carries a static <aside class="sidebar"> child). The injected
   CSS sets `.app{display:block!important}` + `body{margin-left:240px!important}`
   — so the FINAL layout is block + a 240px gutter. Mirror that at FIRST PAINT so
   a page never flashes .main squished into a 232px grid column for a split second
   before the deferred script runs (Shmuel 2026-08-03: flashes switching views).
   This changes ONLY the transient pre-JS state; the injected !important rules
   still govern once loaded. Scoped to .app pages, so standalone screens
   (login/privacy) keep their own layout. Desktop only — mobile is full-width. */
.app {
  display: block;
  min-height: 100vh;
}
/* Two page shells inject that same fixed sidebar: the app grid (body > .app) and
   the "utility" pages built as a bare body > main.content (sessions, my-notes,
   readiness, audit, feedback-inbox, my-reports, my-history). Reserve the gutter
   for BOTH at first paint. login/privacy have neither wrapper -> untouched. */
@media (min-width: 901px) { body:has(> .app), body:has(> main.content) { margin-left: 240px; } }

/* ---- Sidebar -------------------------------------------------------------- */
.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-on-teal);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.brandmark {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(150deg, var(--teal-400), var(--teal-600));
  display: grid; place-items: center;
  color: #fff; flex: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.brandmark svg { width: 20px; height: 20px; }
.brand__name { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: -0.02em; color: #fff; }
.brand__sub  { font-size: var(--text-2xs); color: var(--text-on-teal-mut); letter-spacing: 0.02em; }

/* flex:1 + min-height:0 + overflow: the nav scrolls INSIDE the rail, so the
   foot (Sign out) stays pinned on-screen even on pages whose body cannot
   scroll (e.g. chart-review's viewport-filling iframe — mobile, 2026-07-28). */
.nav { padding: var(--space-2) var(--space-3); display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.nav__group-label {
  font-size: var(--text-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-on-teal-mut);
  padding: var(--space-4) var(--space-3) var(--space-2);
}
.nav__item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-on-teal);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease);
  position: relative; white-space: nowrap;
}
.nav__item:hover { background: rgba(255,255,255,0.07); text-decoration: none; }
.nav__item.is-active { background: var(--teal-700); color: #fff; }
.nav__item.is-active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: var(--radius-pill); background: var(--teal-300);
}
.nav__item svg { width: 18px; height: 18px; flex: none; opacity: 0.92; }
.nav__item .nav__count {
  margin-left: auto;
  font-size: var(--text-2xs); font-weight: var(--fw-bold);
  background: rgba(255,255,255,0.14); color: #fff;
  padding: 1px 7px; border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
}
.nav__item .nav__count.is-alert { background: var(--sev-high-500); }

.sidebar__foot { margin-top: auto; padding: var(--space-4); }
.userchip {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2); border-radius: var(--radius-md);
  background: rgba(255,255,255,0.05);
}
.userchip:hover { background: rgba(255,255,255,0.09); }
.avatar {
  width: 32px; height: 32px; border-radius: var(--radius-pill);
  background: var(--teal-500); color: #fff;
  display: grid; place-items: center;
  font-size: var(--text-xs); font-weight: var(--fw-bold);
  flex: none;
}
.userchip__name { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: #fff; }
.userchip__role { font-size: var(--text-2xs); color: var(--text-on-teal-mut); }

/* ---- Main column ---------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6);
  position: sticky; top: 0; z-index: 20;
}
.breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; }
.breadcrumb b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.breadcrumb .sep { color: var(--border-strong); }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-2); }
.topbar__facility {
  height: 34px; max-width: 220px; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 0 var(--space-2); background: var(--bg-surface); color: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.topbar__facility:hover { border-color: var(--text-muted); }

.searchbox {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-3);
  width: 280px; color: var(--text-muted);
}
.searchbox input { border: none; background: none; outline: none; width: 100%; font-size: var(--text-sm); }
.searchbox svg { width: 16px; height: 16px; flex: none; }
.searchbox kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1px 5px; color: var(--text-muted);
}

.iconbtn {
  width: 36px; height: 36px; border-radius: var(--radius-md);
  background: transparent; border: 1px solid transparent;
  display: grid; place-items: center; color: var(--text-secondary);
  position: relative;
}
.iconbtn:hover { background: var(--bg-inset); border-color: var(--border); }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn__dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--sev-high-500); border: 2px solid var(--bg-surface); }

/* ---- Content region ------------------------------------------------------- */
.content { padding: var(--space-6) var(--space-8) var(--space-12); flex: 1; }
/* Long unbroken tokens (pasted URLs, ids) wrap instead of blowing the page into
   horizontal scroll (audit #26). Inherits to everything inside the content region. */
.content { overflow-wrap: anywhere; }
.content--wide { max-width: none; }
/* wrap + a real flex basis on the titles. Previously .page-head was nowrap and
   .page-head__titles defaulted to flex:0 1 auto, so the actions row (facility
   select + date + Refresh, ~480px of intrinsic width) out-competed the heading:
   measured at 924px the titles column was crushed to 107px, breaking the word
   "Facility" mid-word and stacking the page title into 3 lines. The <=720px
   block below already handled phones; this is the 721-1180px band. */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4); margin-bottom: var(--space-5); }
.page-head__titles { min-width: 0; flex: 1 1 260px; }
.page-title { font-size: var(--text-2xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; line-height: var(--lh-tight); }
.page-sub { color: var(--text-secondary); font-size: var(--text-md); margin-top: 2px; }
.page-head__actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* ---- Generic layout utilities -------------------------------------------- */
.stack { display: flex; flex-direction: column; }
.stack-2 > * + * { margin-top: var(--space-2); }
.stack-3 > * + * { margin-top: var(--space-3); }
.stack-4 > * + * { margin-top: var(--space-4); }
.stack-6 > * + * { margin-top: var(--space-6); }
.row { display: flex; align-items: center; }
.row-gap-2 { gap: var(--space-2); }
.row-gap-3 { gap: var(--space-3); }
.row-gap-4 { gap: var(--space-4); }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; }

/* 900px, not 1100px — must match sidebar.js's own @media(min-width:901px),
   which keeps the rail at its full 240px. At 1100px these disagreed: between
   901 and 1100 the rail stayed 240px wide while every label was hidden, giving
   a 240px sidebar of icon-only nav with ~176px of dead space and nine
   unlabelled icons. That band is iPad landscape (1024x768) — the device the
   design brief names for RDs. Change both together or neither. */
@media (max-width: 900px) {
  .app { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  /* Inert at this width by design: sidebar.js turns the rail into an off-canvas
     drawer at <=900 and re-shows these with display:revert!important, because a
     drawer is wide and SHOULD be labelled. The rule is kept, at a breakpoint
     that can no longer produce a 240px icon-only rail, for pages that render
     .app WITHOUT sidebar.js. Do not raise it back above 900. */
  .sidebar__brand .brand__text, .nav__item span:not(.nav__count), .nav__group-label, .userchip__meta { display: none; }
  .nav__item { justify-content: center; }
  .content { padding: var(--space-5) var(--space-5) var(--space-10); }
}

/* MOBILE MUST BE CORRECT ON THE FIRST PAINT. These rules used to live only in the
   CSS that sidebar.js injects at runtime, keyed on a .sb-shell class that JS also
   adds — so until that script ran, a phone got the TABLET grid (a 64px sidebar
   column + 326px content) and the page painted visibly broken: measured at 390px,
   the "Today's worklist" heading was 24px wide and 437px tall (one character per
   line) with 609px of horizontal overflow, then snapped into place. Shmuel caught
   it on a real phone after signing in (2026-07-30) — it is the second of the two
   flashes he screenshotted. A render-blocking stylesheet is the only thing that is
   guaranteed to apply BEFORE the first paint, so the mobile collapse belongs here,
   keyed on .app, which is in the HTML from the start. The equivalent rules remain
   in sidebar.js (harmless, now redundant) so nothing regresses if this file is
   cached from an older build. */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app > *, .content, .main, main, .topbar { min-width: 0; }
  /* overflow-x: CLIP (not hidden). Both stop a stray element from causing a
     horizontal scrollbar, but `hidden` makes html/body a scroll container, which
     BREAKS `position: sticky` for every descendant — so on mobile the topbar and
     the sticky toolbars/name-bar scrolled away. `clip` clips the same overflow
     WITHOUT establishing a scroll container, so sticky works on mobile too
     (Shmuel 2026-08-03). Supported Chrome 90+/FF 81+/Safari 16+. */
  html, body { overflow-x: clip; max-width: 100vw; }
}

/* Mobile density — tighter padding/margins/type so more fits per screen without
   dropping any data (Shmuel 2026-08-03). Moderate: ~25-40% less chrome. */
@media (max-width: 900px) {
  .content { padding: var(--space-3) var(--space-4) var(--space-8); }
  .page-head { margin-bottom: var(--space-3); gap: var(--space-2); }
  .page-title { font-size: var(--text-xl); }
  .page-sub { font-size: var(--text-sm); margin-top: 1px; }
  .stack-6 > * + * { margin-top: var(--space-4); }
  .stack-4 > * + * { margin-top: var(--space-3); }
  .kpi { padding: var(--space-3); }
  .table thead th, .table tbody td { padding: var(--space-2) var(--space-3); }
}

/* ===== components.css ===== */
/* =============================================================================
   NutraTech — Components
   Reusable building blocks. Depends on design-tokens.css + base.css.
   Severity is NEVER color-only: .flag / .pill carry an icon + text label.
   ============================================================================= */

/* ---------------------------------------------------------------------------
   CARD / PANEL
   --------------------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card--flush { border-radius: var(--radius-lg); overflow: hidden; }
.card__head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}
.card__head .spacer { flex: 1; }
.card__title { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
.card__title-icon { width: 18px; height: 18px; color: var(--teal-600); flex: none; }
.card__sub { font-size: var(--text-xs); color: var(--text-muted); }
.card__body { padding: var(--space-5); }
.card__body--tight { padding: var(--space-4); }
.card__foot {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-soft);
  background: var(--bg-inset);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Section divider with eyebrow label (used to chunk the long brief) */
.sectionbar {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-1);
}
.sectionbar__num {
  width: 22px; height: 22px; border-radius: var(--radius-pill);
  background: var(--teal-100); color: var(--teal-700);
  font-size: var(--text-2xs); font-weight: var(--fw-bold);
  display: grid; place-items: center; flex: none;
}
.sectionbar h3 { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); white-space: nowrap; }
.sectionbar .spacer { flex: 1; }
.sectionbar .hint { font-size: var(--text-xs); color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   BUTTONS
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-size: var(--text-sm); font-weight: var(--fw-semibold);
  padding: var(--space-2) var(--space-4); height: 38px;
  border-radius: var(--radius-md); border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast), box-shadow var(--dur-fast);
  white-space: nowrap; line-height: 1;
}
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--teal-800); color: #fff; box-shadow: var(--shadow-xs); }
.btn--primary:hover { background: var(--teal-700); }
.btn--primary:active { background: var(--teal-900); }
.btn--secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--bg-inset); border-color: var(--ink-400); }
.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-inset); color: var(--text-primary); }
.btn--danger { background: var(--bg-surface); color: var(--sev-high-700); border-color: var(--sev-high-100); }
.btn--danger:hover { background: var(--sev-high-050); border-color: var(--sev-high-500); }
.btn--sign {
  background: var(--teal-800); color: #fff;
  height: 46px; padding: 0 var(--space-6); font-size: var(--text-md);
  box-shadow: var(--shadow-md);
}
.btn--sign:hover { background: var(--teal-700); }
.btn--sm { height: 30px; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn--lg { height: 46px; padding: 0 var(--space-6); font-size: var(--text-md); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; border-left-width: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); border-left-width: 1px; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }

/* ---------------------------------------------------------------------------
   PILL / BADGE / STATUS
   --------------------------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  padding: 2px 9px 2px 7px; border-radius: var(--radius-pill);
  letter-spacing: 0.01em; white-space: nowrap;
  border: 1px solid transparent;
}
.pill svg { width: 12px; height: 12px; flex: none; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pill--high { background: var(--sev-high-100); color: var(--sev-high-700); border-color: #f3cbc4; }
.pill--high .dot { background: var(--sev-high-600); }
.pill--mod  { background: var(--sev-mod-100); color: var(--sev-mod-700); border-color: #f0d9a8; }
.pill--mod .dot { background: var(--sev-mod-600); }
.pill--low  { background: var(--sev-low-100); color: var(--sev-low-700); border-color: #c8ddf3; }
.pill--low .dot { background: var(--sev-low-600); }
.pill--ok   { background: var(--sev-ok-100); color: var(--sev-ok-700); border-color: #b9e3cb; }
.pill--ok .dot { background: var(--sev-ok-600); }
.pill--neutral { background: var(--ink-100); color: var(--ink-700); border-color: var(--border); }
.pill--neutral .dot { background: var(--ink-400); }
/* OPERATIONAL state (design review 2026-08-21): Due, New data, Stale, No brief —
   things about the WORKFLOW, not the resident. Severity colors are reserved for
   how sick the resident is; everything else is ink. .dot--teal marks "something
   changed" (a webhook landed) without borrowing a severity hue. */
.pill--quiet { background: var(--ink-100); color: var(--ink-700); border-color: var(--border); }
.pill--quiet .dot { background: var(--ink-400); }
.pill .dot--teal { background: var(--teal-500); }
.pill--teal { background: var(--teal-100); color: var(--teal-700); border-color: var(--teal-200); }
.pill--solid-teal { background: var(--teal-800); color: #fff; }

/* Trend chips */
.trend { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend svg { width: 14px; height: 14px; }
.trend--down { color: var(--trend-down); }
.trend--up   { color: var(--trend-up); }
.trend--flat { color: var(--trend-flat); }

/* ---------------------------------------------------------------------------
   SEVERITY FLAG / CALLOUT — the headline component of the brief
   Left severity bar + icon + label + body. Color is reinforced by icon & text.
   --------------------------------------------------------------------------- */
.flag {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-3);
  padding: var(--space-4); padding-left: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-surface); position: relative;
  border-left-width: 4px;
}
.flag__icon {
  width: 30px; height: 30px; border-radius: var(--radius-md);
  display: grid; place-items: center; flex: none;
}
.flag__icon svg { width: 18px; height: 18px; }
.flag__main { min-width: 0; }
.flag__top { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: 3px; }
.flag__title { font-size: var(--text-sm); font-weight: var(--fw-bold); color: var(--text-primary); }
.flag__body { font-size: var(--text-sm); color: var(--text-secondary); line-height: var(--lh-snug); }
.flag__meta { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.flag__meta b { color: var(--text-secondary); font-weight: var(--fw-semibold); }
.flag__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

.flag--high { border-left-color: var(--sev-high-600); background: var(--sev-high-050); }
.flag--high .flag__icon { background: var(--sev-high-100); color: var(--sev-high-700); }
.flag--mod { border-left-color: var(--sev-mod-600); background: var(--sev-mod-050); }
.flag--mod .flag__icon { background: var(--sev-mod-100); color: var(--sev-mod-700); }
.flag--low { border-left-color: var(--sev-low-600); background: var(--sev-low-050); }
.flag--low .flag__icon { background: var(--sev-low-100); color: var(--sev-low-700); }
.flag--ok { border-left-color: var(--sev-ok-600); background: var(--sev-ok-050); }
.flag--ok .flag__icon { background: var(--sev-ok-100); color: var(--sev-ok-700); }

/* ---------------------------------------------------------------------------
   KPI CARD
   --------------------------------------------------------------------------- */
.kpi {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2);
  box-shadow: var(--shadow-xs); position: relative; overflow: hidden;
}
.kpi__label { display: flex; align-items: center; gap: var(--space-2); }
.kpi__label .t-label { color: var(--text-muted); }
.kpi__icon { width: 16px; height: 16px; color: var(--teal-600); }
.kpi__value { font-size: var(--text-3xl); font-weight: var(--fw-bold); letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.kpi__value small { font-size: var(--text-lg); font-weight: var(--fw-semibold); color: var(--text-muted); }
.kpi__foot { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.kpi__spark { margin-top: var(--space-1); }
.kpi--accent { background: linear-gradient(160deg, var(--teal-800), var(--teal-700)); border-color: var(--teal-700); }
.kpi--accent .kpi__value, .kpi--accent .kpi__label .t-label, .kpi--accent .kpi__foot { color: #fff; }
.kpi--accent .kpi__label .t-label, .kpi--accent .kpi__foot { color: var(--text-on-teal-mut); }
.kpi--accent .kpi__icon { color: var(--teal-300); }

/* ---------------------------------------------------------------------------
   DATA TABLE
   --------------------------------------------------------------------------- */
/* The wrap is BOTH the horizontal-overflow guard for wide tables AND the
   sticky-header scrollport. The old top:var(--topbar-h) sticky was DEAD on
   every table (layout audit 2026-08-04): overflow-x:auto made the wrap the
   nearest scrollport, whose height equaled the table — nothing to stick
   against. Cap the wrap instead: long tables scroll INSIDE it and the header
   freezes at its top for real. Short tables are unaffected (no overflow). */
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); }
.table { font-size: var(--text-sm); }
.table thead th {
  text-align: left; font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  color: var(--text-muted); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle; color: var(--text-secondary);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--teal-050); }
.table td .primary { color: var(--text-primary); font-weight: var(--fw-semibold); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; } /* "100 %" was wrapping to two lines in a narrow column (Oversight, sweep 2026-08-21) */
.table th.num { text-align: right; }
.table--zebra tbody tr:nth-child(even) { background: var(--ink-050); }
.table--zebra tbody tr:nth-child(even):hover { background: var(--teal-050); }
.table--compact tbody td, .table--compact thead th { padding: var(--space-2) var(--space-3); }
.cell-name { display: flex; align-items: center; gap: var(--space-3); }
.cell-sub { font-size: var(--text-xs); color: var(--text-muted); }

/* progress meter inside cells (edit %, acceptance, etc.) */
.meter { display: flex; align-items: center; gap: var(--space-2); }
.meter__track { flex: 1; min-width: 60px; height: 6px; border-radius: var(--radius-pill); background: var(--ink-150); overflow: hidden; }
.meter__fill { height: 100%; border-radius: var(--radius-pill); background: var(--teal-500); }
.meter__fill--high { background: var(--sev-high-500); }
.meter__fill--mod { background: var(--sev-mod-500); }
.meter__fill--ok { background: var(--sev-ok-500); }
.meter__val { font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); color: var(--text-primary); min-width: 38px; text-align: right; }

/* ---------------------------------------------------------------------------
   TAB BAR
   --------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tab {
  appearance: none; background: none; border: none;
  padding: var(--space-3) var(--space-4); font-size: var(--text-sm);
  font-weight: var(--fw-semibold); color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--teal-700); border-bottom-color: var(--teal-700); }
.tab svg { width: 16px; height: 16px; }
.tab .tab__count {
  font-size: 11px; font-weight: var(--fw-bold); background: var(--ink-100);
  color: var(--text-secondary); padding: 0 6px; border-radius: var(--radius-pill);
}
.tab.is-active .tab__count { background: var(--teal-100); color: var(--teal-700); }

/* Pill-style segmented control (filters) */
.segmented { display: inline-flex; background: var(--bg-inset); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 2px; gap: 2px; }
.segmented button {
  appearance: none; border: none; background: transparent;
  font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-secondary);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm);
}
.segmented button.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-xs); }

/* ---------------------------------------------------------------------------
   FORM ROW
   --------------------------------------------------------------------------- */
.formrow {
  display: grid; grid-template-columns: 220px 1fr; gap: var(--space-5);
  padding: var(--space-4) 0; border-bottom: 1px solid var(--border-soft);
  align-items: start;
}
.formrow:last-child { border-bottom: none; }
.formrow__label { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-primary); }
.formrow__hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.formrow__control { min-width: 0; }
.input, .select, .textarea {
  width: 100%; background: var(--bg-surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3); font-size: var(--text-sm);
  color: var(--text-primary); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus-ring); box-shadow: var(--ring-focus); outline: none; }
.input::placeholder { color: var(--ink-400); }
.field-max { max-width: 420px; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { width: 40px; height: 23px; border-radius: var(--radius-pill); background: var(--ink-300); transition: background var(--dur); position: relative; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--dur) var(--ease); }
.switch input:checked + .switch__track { background: var(--teal-600); }
.switch input:checked + .switch__track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--ring-focus); }

/* Checkbox (suggested orders) */
.check { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.check input { position: absolute; opacity: 0; }
.check__box { width: 20px; height: 20px; border-radius: var(--radius-sm); border: 1.5px solid var(--border-strong); background: var(--bg-surface); display: grid; place-items: center; flex: none; transition: all var(--dur-fast); }
.check__box svg { width: 13px; height: 13px; color: #fff; opacity: 0; }
.check input:checked + .check__box { background: var(--teal-600); border-color: var(--teal-600); }
.check input:checked + .check__box svg { opacity: 1; }
.check input:focus-visible + .check__box { box-shadow: var(--ring-focus); }

/* ---------------------------------------------------------------------------
   EDITABLE NOTE BLOCK — the climax of the Pre-Visit Brief
   --------------------------------------------------------------------------- */
.note {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--bg-surface); box-shadow: var(--shadow-sm); overflow: hidden;
}
.note__bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-inset); border-bottom: 1px solid var(--border);
}
.note__bar .spacer { flex: 1; }
.note__doc {
  font-family: var(--font-doc);
  font-size: var(--text-md); line-height: var(--lh-relaxed);
  color: var(--text-primary);
  padding: var(--space-6) var(--space-8);
  background: var(--bg-surface);
  max-width: 70ch;
}
.note__doc:focus { outline: none; }
.note__doc[contenteditable="true"] { box-shadow: inset 0 0 0 2px var(--teal-100); }
.note__doc h4 { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted); margin: var(--space-5) 0 var(--space-1); font-weight: var(--fw-semibold); }
.note__doc h4:first-child { margin-top: 0; }
.note__doc p { margin: 0 0 var(--space-3); }
.note__doc .ai-span { background: var(--teal-050); border-bottom: 1px solid var(--teal-200); border-radius: 2px; padding: 0 1px; }
.note__doc .edited { background: var(--sev-mod-050); border-bottom: 1px solid var(--sev-mod-500); }
.note__foot {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border); background: var(--bg-surface);
}
.note__sigline { display: flex; flex-direction: column; gap: 2px; }
.note__sigline .who { font-size: var(--text-sm); font-weight: var(--fw-semibold); }
.note__sigline .meta { font-size: var(--text-xs); color: var(--text-muted); }
.note.is-signed { border-color: var(--sev-ok-500); box-shadow: 0 0 0 1px var(--sev-ok-500), var(--shadow-sm); }
.note.is-signed .note__bar { background: var(--sev-ok-050); border-bottom-color: var(--sev-ok-100); }

/* ---------------------------------------------------------------------------
   MISC
   --------------------------------------------------------------------------- */
.divider { height: 1px; background: var(--border-soft); border: none; margin: var(--space-4) 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); font-weight: var(--fw-medium); text-align: right; }
.attribution { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-2xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.attribution svg { width: 13px; height: 13px; color: var(--teal-500); }
.source-cite { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-2xs); font-weight: var(--fw-semibold); color: var(--teal-700); background: var(--teal-050); border: 1px solid var(--teal-100); border-radius: var(--radius-sm); padding: 1px 6px; }
.source-cite:hover { background: var(--teal-100); text-decoration: none; }
.empty { text-align: center; padding: var(--space-10); color: var(--text-muted); }

/* ---- Dialog: the ONE popout chrome (design tightening 2026-08-21) ----
   Detail popouts, assessment Q&A, observation entry and the attest step each
   carried their own inline backdrop/panel styles (same 12px radius, a shadow
   that was not a token). One chrome, different bodies. Sizes are the three the
   app actually uses. JS builds these (createElement + className); ids stay
   per-dialog for the tests and handlers. */
.dialog-back { position: fixed; inset: 0; z-index: 2147482300; background: rgba(17, 32, 31, 0.35); display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.dialog { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); padding: var(--space-4); max-height: 85vh; overflow: auto; font-size: var(--text-sm); color: var(--text-primary); }
.dialog--sm { width: min(92vw, 420px); }
.dialog--md { width: min(92vw, 480px); }
.dialog--lg { width: min(94vw, 620px); }
/* STICKY HEAD (Shmuel, live in session 4a 2026-08-24: "it should always show the
   close button even when scrolling down"). .dialog scrolls at max-height 85vh,
   so a long assessment pushed the × off screen and the only ways out were Esc
   or a backdrop click — neither discoverable. The head now rides along, with
   the dialog's own surface behind it so rows don't show through. */
.dialog__head { position: sticky; top: calc(var(--space-4) * -1); z-index: 1; display: flex; align-items: center; gap: var(--space-3); margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) var(--space-2); padding: var(--space-4) var(--space-4) var(--space-2); background: var(--bg-surface); border-bottom: 1px solid var(--border-soft); border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
.dialog__kicker { font-size: var(--text-2xs); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted); }
.dialog__title { font-size: var(--text-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); overflow-wrap: anywhere; }
.dialog__close { margin-left: auto; flex: none; }
.dialog__row { display: grid; grid-template-columns: 38% minmax(0, 1fr); gap: var(--space-3); padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
.dialog__k { font-size: var(--text-2xs); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted); padding-top: 2px; }
.dialog__v { font-size: var(--text-sm); overflow-wrap: anywhere; }
.dialog__v--num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.dialog-back--top { align-items: flex-start; padding-top: 14vh; }   /* pickers drop from the top, like a command palette */
.dialog--sheet { padding: 0; display: flex; flex-direction: column; overflow: hidden; max-height: 70vh; } /* a list-bearing panel: the list scrolls, the chrome does not */
.toast {
  position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink-900); color: #fff; padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: var(--text-sm);
  display: flex; align-items: center; gap: var(--space-2); opacity: 0; pointer-events: none;
  transition: all var(--dur) var(--ease); z-index: 100;
}
/* Visible toasts must be interactive — the base rule's pointer-events:none was
   never undone by .is-on, so the Undo button inside ntUndoToast swallowed every
   click (UI/UX audit HIGH #6). Plain text toasts don't mind; buttons do. */
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast svg { width: 16px; height: 16px; color: var(--teal-300); }

/* ROOT-CLASS FIX (UI/UX audit): the [hidden] attribute loses to ANY author
   display rule (inline style or a class like .btn/.pill setting display) — that
   one mechanic produced highs #3 and #4 and several mediums. Make hidden mean
   hidden, everywhere, unconditionally. */
[hidden] { display: none !important; }

/* ===== pages.css ===== */
/* =============================================================================
   NutraTech — Page layouts (oversight, admin, worklist, review, ask)
   Depends on design-tokens.css + base.css + components.css.
   ============================================================================= */

.page { max-width: var(--content-max); margin: 0 auto; width: 100%; }

/* ---- KPI strip ------------------------------------------------------------ */
.kpi-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-4); }
.kpi-strip--6 { grid-template-columns: repeat(6, 1fr); }
.kpi-strip--4 { grid-template-columns: repeat(4, 1fr); }

.mini-spark { width: 100%; height: 26px; }

/* ---- Two-column dashboard split ------------------------------------------ */
.split { display: grid; grid-template-columns: minmax(0,1fr) 360px; gap: var(--space-6); align-items: start; }
.split__rail { position: sticky; top: calc(var(--topbar-h) + var(--space-6)); }

/* ---- Activity feed -------------------------------------------------------- */
.feed { display: flex; flex-direction: column; }
.feed__item { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border-soft); }
.feed__item:last-child { border-bottom: none; }
.feed__dot { width: 30px; height: 30px; border-radius: var(--radius-pill); display: grid; place-items: center; flex: none; margin-top: 1px; }
.feed__dot svg { width: 15px; height: 15px; }
.feed__dot--sign { background: var(--sev-ok-100); color: var(--sev-ok-700); }
.feed__dot--edit { background: var(--sev-mod-100); color: var(--sev-mod-700); }
.feed__dot--accept { background: var(--teal-100); color: var(--teal-700); }
.feed__dot--flag { background: var(--sev-high-100); color: var(--sev-high-700); }
.feed__body { min-width: 0; font-size: var(--text-sm); }
.feed__body b { font-weight: var(--fw-semibold); color: var(--text-primary); }
.feed__body .t { color: var(--text-secondary); }
.feed__time { font-size: var(--text-2xs); color: var(--text-muted); margin-top: 2px; }
.feed__diff { font-size: var(--text-xs); margin-top: var(--space-1); background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 4px 8px; color: var(--text-secondary); }
.feed__diff .del { color: var(--sev-high-700); text-decoration: line-through; }
.feed__diff .ins { color: var(--sev-ok-700); }

/* ---- Facility / worklist table extras ------------------------------------ */
.fac-name { display: flex; align-items: center; gap: var(--space-3); }
.fac-badge { width: 32px; height: 32px; border-radius: var(--radius-md); background: var(--teal-100); color: var(--teal-700); display: grid; place-items: center; font-weight: var(--fw-bold); font-size: var(--text-xs); flex: none; }

.toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
/* Opt-in: freeze a toolbar above a long list/table under the topbar (e.g. admin
   Users + Audit). Scoped modifier so the plain .toolbar everywhere else is
   unaffected. bg-canvas so rows scroll cleanly beneath it.
   --topbar-actual is MEASURED by sidebar.js (ResizeObserver on the topbar): the
   token is 60px but the mobile topbar wraps to ~110px, so a token-only offset
   hid this toolbar behind it (layout audit 2026-08-04). */
.toolbar--sticky { position: sticky; top: var(--topbar-actual, var(--topbar-h)); z-index: 6; background: var(--bg-canvas); padding: var(--space-3) 0 var(--space-2); }
.toolbar .spacer { flex: 1; }

/* sortable header affordance */
.th-sort { cursor: pointer; }
.th-sort:hover { color: var(--text-secondary); }

/* ---- Worklist row status -------------------------------------------------- */
/* ---- Worklist row status -------------------------------------------------- */
.wl-summary { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3) var(--space-5); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-width: 120px; }
.wl-summary__n { font-size: var(--text-2xl); font-weight: var(--fw-bold); letter-spacing: -0.03em; line-height: 1; }
.wl-summary__l { font-size: var(--text-xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.wl-summary--high { border-left: 3px solid var(--sev-high-600); }
.wl-summary--high .wl-summary__n { color: var(--sev-high-700); }
.wl-summary--mod { border-left: 3px solid var(--sev-mod-600); }
.wl-summary--ok { border-left: 3px solid var(--sev-ok-600); }
.wl-row { cursor: pointer; }
.wl-row--high td:first-child { box-shadow: inset 3px 0 0 var(--sev-high-600); }
.wl-table td { padding-top: var(--space-3); padding-bottom: var(--space-3); }

.wl-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: var(--fw-semibold); }
.wl-status svg { width: 14px; height: 14px; }
.wl-status--ready { color: var(--teal-700); }
.wl-status--progress { color: var(--sev-mod-700); }
.wl-status--signed { color: var(--sev-ok-700); }

/* ---- Admin layout --------------------------------------------------------- */
.admin-grid { display: grid; grid-template-columns: 220px 1fr; gap: var(--space-8); align-items: start; }
.vtabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + var(--space-6)); }
.vtab { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-3); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); background: none; border: none; text-align: left; }
.vtab:hover { background: var(--bg-inset); color: var(--text-primary); }
.vtab.is-active { background: var(--teal-050); color: var(--teal-800); box-shadow: inset 2px 0 0 var(--teal-700); }
.vtab svg { width: 17px; height: 17px; flex: none; }
.vtab .vtab__count { margin-left: auto; font-size: 11px; font-weight: var(--fw-bold); background: var(--ink-100); color: var(--text-secondary); padding: 0 7px; border-radius: var(--radius-pill); }
.vtab.is-active .vtab__count { background: var(--teal-100); color: var(--teal-700); }

.statusline { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.statusline .light { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.statusline .light--ok { background: var(--sev-ok-500); box-shadow: 0 0 0 3px var(--sev-ok-100); }
.statusline .light--warn { background: var(--sev-mod-500); box-shadow: 0 0 0 3px var(--sev-mod-100); }

.rolepill { font-size: var(--text-2xs); font-weight: var(--fw-semibold); padding: 2px 8px; border-radius: var(--radius-sm); }
.rolepill--rd { background: var(--teal-100); color: var(--teal-700); }
.rolepill--md { background: var(--sev-low-100); color: var(--sev-low-700); }
.rolepill--admin { background: var(--ink-100); color: var(--ink-700); }
.rolepill--mgr { background: var(--sev-mod-100); color: var(--sev-mod-700); }

/* ---- Ask the Chart (chat) ------------------------------------------------- */
.chat { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: var(--space-6); align-items: start; }
.chat__main { display: flex; flex-direction: column; min-height: calc(100vh - var(--topbar-h) - 200px); }
.chat__stream { display: flex; flex-direction: column; gap: var(--space-5); padding-bottom: var(--space-6); }
.msg { display: grid; grid-template-columns: 34px 1fr; gap: var(--space-3); max-width: 760px; }
.msg--user { display: flex; justify-content: flex-end; align-items: flex-start; max-width: 760px; margin-left: auto; }
.msg--user .msg__bubble.user { max-width: 480px; }
.msg__av { width: 34px; height: 34px; border-radius: var(--radius-md); display: grid; place-items: center; flex: none; }
.msg__av--ai { background: linear-gradient(155deg, var(--teal-500), var(--teal-700)); color: #fff; }
.msg__av--rd { background: var(--ink-200); color: var(--ink-700); font-size: var(--text-xs); font-weight: var(--fw-bold); }
.msg__who { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-muted); margin-bottom: 3px; }
.msg__bubble { font-size: var(--text-md); color: var(--text-primary); line-height: var(--lh-normal); }
.msg__bubble.user { background: var(--teal-050); border: 1px solid var(--teal-100); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); display: inline-block; }
.msg__cites { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.msg__answerblock { background: var(--bg-surface); border: 1px solid var(--border); border-left: 3px solid var(--teal-600); border-radius: var(--radius-md); padding: var(--space-4); }

.composer { display: flex; align-items: flex-end; gap: var(--space-3); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: var(--space-3); background: var(--bg-surface); box-shadow: var(--shadow-sm); }
.composer textarea { flex: 1; border: none; outline: none; resize: none; font-size: var(--text-md); min-height: 24px; max-height: 160px; }
.composer .btn { flex: none; }
.suggest-chip { font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-secondary); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 6px 12px; text-align: left; }
.suggest-chip:hover { border-color: var(--teal-400); color: var(--teal-700); background: var(--teal-050); }
.answer-list { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.answer-list li { position: relative; padding-left: 16px; font-size: var(--text-md); color: var(--text-secondary); }
.answer-list li::before { content: ""; position: absolute; left: 2px; top: 9px; width: 5px; height: 5px; border-radius: 50%; background: var(--teal-500); }
.answer-list b { color: var(--text-primary); }
.ask-tips { display: flex; flex-direction: column; gap: var(--space-3); }
.ask-tips li { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-secondary); }
.ask-tips svg { width: 16px; height: 16px; color: var(--teal-500); flex: none; }

/* ---- Diff (review screen) ------------------------------------------------- */
.diffline { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.diffcol { font-family: var(--font-doc); font-size: var(--text-sm); line-height: var(--lh-relaxed); }
.diffcol h5 { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted); font-weight: var(--fw-semibold); margin: 0 0 var(--space-2); }
.ins-mark { background: var(--sev-ok-100); border-radius: 2px; }
.del-mark { background: var(--sev-high-100); text-decoration: line-through; border-radius: 2px; }
.diff-h { font-size: var(--text-xs); font-weight: var(--fw-bold); color: var(--text-primary); margin: 0 0 var(--space-2); }

/* ---- Decision mix bar (oversight) ---------------------------------------- */
.decision-bar { display: flex; height: 28px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.decision-seg { height: 100%; }
.decision-seg + .decision-seg { border-left: 2px solid var(--bg-surface); }
.legend { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-secondary); }
.legend b { color: var(--text-primary); font-weight: var(--fw-bold); }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.row-gap-6 { gap: var(--space-6); }

/* QA distribution rows */
.qa-row { display: grid; grid-template-columns: 40px 1fr 42px; gap: var(--space-3); align-items: center; }
.qa-row__label { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-secondary); }
.qa-row .meter__track { height: 8px; }
.qa-row__val { font-size: var(--text-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; text-align: right; color: var(--text-primary); }

/* ---- Section heading inside content -------------------------------------- */
.block-head { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-2) 0 var(--space-3); }
.block-head h3 { font-size: var(--text-lg); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.block-head .spacer { flex: 1; }

/* ---- Responsive ----------------------------------------------------------- */
@media (max-width: 1180px) {
  .kpi-strip, .kpi-strip--6 { grid-template-columns: repeat(3, 1fr); }
  .kpi-strip--4 { grid-template-columns: repeat(2, 1fr); }
  .split, .chat { grid-template-columns: 1fr; }
  .split__rail { position: static; }
  .admin-grid { grid-template-columns: 1fr; }
  .vtabs { flex-direction: row; overflow-x: auto; position: static; }
}
@media (max-width: 720px) {
  .kpi-strip, .kpi-strip--6, .kpi-strip--4 { grid-template-columns: repeat(2, 1fr); }
  .diffline { grid-template-columns: 1fr; }
}

/* Phone (RD on the floor): the page-head actions row (date + Refresh) used to
   sit margin-left:auto next to the title and overflow/wrap awkwardly at 390px.
   Stack it under the title, full width, with the primary action reachable. */
@media (max-width: 480px) {
  .page-head { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  /* In COLUMN flex the titles' `flex: 1 1 260px` basis becomes its HEIGHT, so the
     header rendered ~150px taller than its text — a blank band above the content
     on EVERY .content page (Shmuel 2026-08-06, seen on Notes + Chart & Brief).
     Reset the basis to auto so the header height hugs the title + description;
     desktop keeps the 260px width-basis anti-crush. */
  .page-head__titles { flex: 1 1 auto; }
  .page-head__actions { margin-left: 0; flex-wrap: wrap; }
  .page-head__actions .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
}



/* iOS Safari's floating toolbar overlaps content pinned to the bottom of a
   100vh box, making the sidebar's Sign out intermittently untappable (Shmuel,
   2026-07-28). Root cause: 100vh on iOS measures BEHIND the dynamic toolbar;
   100dvh tracks the actually-visible viewport as the toolbar shows/hides.
   Older browsers ignore the dvh line and keep the vh one. The safe-area
   padding is the belt for viewport-fit/standalone contexts (0 on desktop). */
.sidebar { height: 100dvh; }
.sidebar__foot { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); }
.ntum { bottom: calc(env(safe-area-inset-bottom, 0px) + 60px) !important; }


/* =============================================================================
   FACILITY IDENTITY TINT
   -----------------------------------------------------------------------------
   The top banner takes the current facility's hue, so switching buildings is
   visible at a glance instead of being one word in the breadcrumb.

   Rules of the system:
   - Hue comes from NTUI.facilityTheme() and arrives as --fac-h on .topbar.
   - The palette lives in the blue->magenta arc only. Red / amber / green belong
     to the clinical severity scale and are never spent on "which building".
   - Hue is scoped to ONE USER'S facilities, not the org's 300+. See the long
     comment in nt-ui.js before changing the palette.
   - Colour is never the only signal: the facility name stays in the breadcrumb
     and .fac-chip shows its initials.

   WASH STRENGTH — measured, do not "tidy" it paler.
   The first cut used hsl(H 42% 97%). That is only deltaE 0.7 between the
   palette's hues: the same colour to the eye, so the background carried no
   information at all and the whole feature rested on the 3px ribbon. The wash
   is now hsl(H 72% 91%) — deltaE 3.8 (clearly perceptible) while primary text
   still measures 12.09:1 on the worst hue.
   The cost: --text-muted is NOT readable on a wash this strong, so muted text
   inside a tinted topbar is promoted to --text-secondary (4.91:1 worst case).
   That promotion is load-bearing; if you lighten the wash, keep it.
   ============================================================================= */
.topbar[data-facility] {
  background: hsl(var(--fac-h) 72% 91%);
  border-bottom-color: hsl(var(--fac-h) 34% 78%);
  box-shadow: inset 0 3px 0 0 hsl(var(--fac-h) 46% 52%);
  transition: background var(--dur, 200ms) var(--ease, cubic-bezier(0.2, 0.6, 0.2, 1)), border-color var(--dur, 200ms) var(--ease, cubic-bezier(0.2, 0.6, 0.2, 1)), box-shadow var(--dur, 200ms) var(--ease, cubic-bezier(0.2, 0.6, 0.2, 1));
}
/* Muted greys go illegible on the tint — promote them. Worst hue: 4.91:1. */
.topbar[data-facility] .breadcrumb,
.topbar[data-facility] .t-muted,
.topbar[data-facility] .muted { color: var(--text-secondary); }
.topbar[data-facility] .breadcrumb .sep { color: hsl(var(--fac-h) 30% 60%); }
.topbar[data-facility] .searchbox {
  background: rgba(255, 255, 255, 0.72);
  border-color: hsl(var(--fac-h) 30% 76%);
}

/* Facility chip — initials + name, tinted to match. The redundant cue. */
/* Initials only — the breadcrumb next to it owns the facility NAME, so the chip
   carries just the hue + initials. Sized as a badge, not a name pill. */
.fac-chip {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px; border-radius: var(--radius-pill);
  background: hsl(var(--fac-h) 50% 88%);
  border: 1px solid hsl(var(--fac-h) 36% 74%);
  color: hsl(var(--fac-h) 52% 27%);            /* 6.27:1 on the chip fill */
  white-space: nowrap; flex: none;
}
.fac-chip__badge {
  width: 20px; height: 20px; border-radius: var(--radius-pill); flex: none;
  display: grid; place-items: center;
  /* 38%, not 42%: at 42% white-on-badge measured 4.23:1 on hue 195 (sub-AA).
     38% is 5.04:1 on the worst hue. 10px bold is normal-size text for WCAG. */
  background: hsl(var(--fac-h) 46% 38%); color: #fff;
  font-size: 10px; font-weight: var(--fw-bold); letter-spacing: .02em;
}

/* One-shot confirmation that the building changed. Motion-safe. */
@keyframes fac-switch {
  0%   { box-shadow: inset 0 3px 0 0 hsl(var(--fac-h) 46% 52%); }
  22%  { box-shadow: inset 0 44px 0 0 hsl(var(--fac-h) 60% 82%); }
  100% { box-shadow: inset 0 3px 0 0 hsl(var(--fac-h) 46% 52%); }
}
.topbar.fac-switched { animation: fac-switch 900ms var(--ease, cubic-bezier(0.2, 0.6, 0.2, 1)) 1 }
@media (prefers-reduced-motion: reduce) {
  .topbar.fac-switched { animation: none }
  .topbar[data-facility] { transition: none }
}

/* The sidebar rail picks up a matching edge so the identity reads on both. */
.sidebar[data-facility] { box-shadow: inset -3px 0 0 0 hsl(var(--fac-h) 40% 45%) }

/* .fac-chip__name was removed 2026-07-31 — the chip is initials-only, so it
   needs no responsive rule; it is already the same size at every width. */

/* ---- "Updated in PCC" badge ------------------------------------------------
   Shown on a worklist row when PointClickCare pushed a change event for that
   resident. Amber while the refresh pull is still queued, teal once the chart has
   actually been re-pulled — the distinction is what lets an RD (or a PCC validator
   watching a demo) tell "we heard about it" from "we have the new data". */
.pcc-chg {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 3px;
  padding: 1px 7px; border-radius: 999px;
  font-size: var(--text-xs, 0.8125rem); font-weight: 700; line-height: 1.5;
  background: var(--sev-mod-050, #fdf7ec); color: var(--sev-mod-700, #9a5b00);
  box-shadow: inset 0 0 0 1px var(--sev-mod-200, #f2d6a6);
}
.pcc-chg--done {
  background: var(--teal-050, #f1f8f7); color: var(--teal-800, #0f3d3e);
  box-shadow: inset 0 0 0 1px var(--teal-200, #bce0dd);
}
