/* ECG Hub — clinical design tokens and layout */

/*
 * Direction: the ECG Hub 2 mockups' «Клиника» (docs/design/ecg-hub-2) — light
 * surfaces, a light rail, blue #386097 actions. Type is the mockups' pair,
 * Golos Text + IBM Plex Mono, self-hosted in theme/fonts.css (Cyrillic-first,
 * tabular numerals for clinical figures).
 *
 * The whole previous look — pine rail, teal accent, Inter — survives intact
 * under html[data-accent="original"] and its dark twin, so the switch beside
 * the light/dark toggle reverts every screen with one click. Both accents work
 * in both themes; nothing below hard-codes a hue that a token could carry.
 *
 * Token NAMES are contract: the React islands (frontend/**) read --ecg-primary*,
 * --ecg-brand, --ecg-on-brand, --ecg-bg, --ecg-surface*, --ecg-text*,
 * --ecg-border*, --ecg-radius*, --ecg-good/warn/bad-*, --font-sans/--font-mono
 * off <html> at mount and re-read them when data-theme or data-accent changes.
 * Change the values here; never the names.
 */

:root {
  --font-sans: "Golos Text", "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", "Cascadia Code",
    "Consolas", "Liberation Mono", monospace;

  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  /* Brand = the rail's surface. Light in this direction, so --ecg-on-brand is
     ink, not paper; anything sitting ON the accent uses --ecg-on-primary. */
  --ecg-brand: #ffffff;
  --ecg-brand-2: #f3f5f7;
  --ecg-on-brand: #141b24;

  /* Single accent ramp (blue) */
  --ecg-primary: #386097;
  --ecg-primary-hover: #27446a;
  --ecg-primary-soft: #e5ecf5;
  --ecg-primary-tint: #f1f5fa;
  --ecg-on-primary: #ffffff;

  /* Neutrals — the mockups' cool grey family */
  --ecg-bg: #f3f5f7;
  --ecg-surface: #ffffff;
  --ecg-surface-muted: #eaeef1;
  --ecg-text: #141b24;
  --ecg-text-muted: #5f6b77;
  --ecg-border: #d6dde3;
  --ecg-border-strong: #b7c2cc;
  /* Chart rules sit a step lighter than card borders, as in the mockups. */
  --ecg-grid: #e3e8ec;
  --ecg-row-hover: #f1f5fa;
  --ecg-focus-ring: rgba(56, 96, 151, 0.30);

  /* Semantic status — the mockups' desaturated clinical set */
  --ecg-good-bg: #e8f3ec;
  --ecg-good-fg: #146c3d;
  --ecg-warn-bg: #fbf4e6;
  --ecg-warn-fg: #855612;
  --ecg-bad-bg: #fbeceb;
  --ecg-bad-fg: #9a2a22;
  /* «эксперимент» — its own ochre, never mistaken for a warning. */
  --ecg-exp-fg: #9a6b0e;

  /* The rail, as its own small surface so a light and a dark rail are one
     value swap rather than a fork of every selector. */
  --ecg-rail-bg: #ffffff;
  --ecg-rail-fg: #3b4752;
  --ecg-rail-eyebrow: #5f6b77;
  --ecg-rail-hover: #f1f3f6;
  --ecg-rail-active-bg: #e9edf3;
  --ecg-rail-active-fg: #141b24;
  --ecg-rail-border: #d6dde3;
  --ecg-rail-badge-bg: #eaeef1;
  --ecg-rail-badge-fg: #5f6b77;

  /* Per-channel hues are fixed by BRIEF.md and must not be re-assigned by
     position; they live here so dark mode can restate them. */
  --ecg-ch-ecg: #386097;
  --ecg-ch-ppg: #0d7a6b;
  --ecg-ch-bp: #c2410c;
  --ecg-ch-temp: #6d28d9;
  --ecg-ch-spo2: #0e7490;
  --ecg-ch-sleep: #4b5563;
  --ecg-ch-steps: #3b6d11;
  --ecg-ch-motion: #5f6b77;
  --ecg-ch-stress: #9a6b0e;
  --ecg-ch-neutral: #5f6b77;

  /* The calibrated ECG paper (portal.md §3.2). Paper is paper: the same in
     every theme and accent (no other block restates these), as the app's
     EcgPaperTokens — a clinician reads the grid by its colour. */
  --ecg-paper-bg: #fbfdff;
  --ecg-paper-minor: #d4e2f4;
  --ecg-paper-major: #a9c3e6;
  --ecg-paper-ink: #1f2933;
  --ecg-paper-ppg: #1e6b5a;
  --ecg-paper-seam: #c9d8ec;
  --ecg-paper-label: #5f6b77;
  --ecg-paper-flag: rgba(133, 86, 18, .14);

  --ecg-radius: 12px;
  --ecg-radius-sm: 8px;
  --ecg-header-h: 4rem;

  /* Tinted shadows, matched to the ink (no flat black) */
  --ecg-shadow-sm: 0 1px 2px rgba(20, 27, 36, 0.06);
  --ecg-shadow-md: 0 12px 30px -14px rgba(20, 27, 36, 0.28);
  --ecg-shadow-panel: 0 1px 2px rgba(20, 27, 36, 0.05),
    0 18px 40px -28px rgba(20, 27, 36, 0.32);

  /* What dims the page behind the phone drawer (.ecg-scrim--nav). Dark ink at
     45% reads as a veil on a light page and on a dark one, so no theme block
     restates it. */
  --ecg-scrim: rgba(10, 14, 20, 0.45);
}

/* ——— The previous look, kept whole: pine rail, teal accent, Inter ———
   One attribute on <html> and every screen reverts. */
html[data-accent="original"] {
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Consolas",
    "Liberation Mono", monospace;

  --ecg-brand: #0c3b39;
  --ecg-brand-2: #0f4f47;
  --ecg-on-brand: #f3faf8;

  --ecg-primary: #0d9488;
  --ecg-primary-hover: #0b7c71;
  --ecg-primary-soft: #e0f4f0;
  --ecg-primary-tint: #f2faf8;
  --ecg-on-primary: #ffffff;

  --ecg-bg: #f5f8f8;
  --ecg-surface: #ffffff;
  --ecg-surface-muted: #eef4f3;
  --ecg-text: #102825;
  --ecg-text-muted: #5c706d;
  --ecg-border: #e4ebea;
  --ecg-border-strong: #cdd9d7;
  --ecg-grid: #e4ebea;
  --ecg-row-hover: #f2faf8;
  --ecg-focus-ring: rgba(13, 148, 136, 0.28);

  --ecg-good-bg: #dcf3e5;
  --ecg-good-fg: #146c3d;
  --ecg-warn-bg: #f8edd1;
  --ecg-warn-fg: #855612;
  --ecg-bad-bg: #fbe1de;
  --ecg-bad-fg: #9a2a22;
  --ecg-exp-fg: #9a6b0e;

  /* The pine rail: dark surface, paper ink, washes made of white. */
  --ecg-rail-bg: #0c3b39;
  --ecg-rail-fg: rgba(255, 255, 255, 0.84);
  --ecg-rail-eyebrow: rgba(243, 250, 248, 0.55);
  --ecg-rail-hover: rgba(255, 255, 255, 0.09);
  --ecg-rail-active-bg: rgba(255, 255, 255, 0.14);
  --ecg-rail-active-fg: #ffffff;
  --ecg-rail-border: transparent;
  --ecg-rail-badge-bg: rgba(255, 255, 255, 0.16);
  --ecg-rail-badge-fg: #f3faf8;

  --ecg-ch-ecg: #0d7a6b;
  --ecg-ch-ppg: #3d5a99;

  --ecg-radius: 14px;
  --ecg-radius-sm: 9px;

  --ecg-shadow-sm: 0 1px 2px rgba(16, 40, 38, 0.06);
  --ecg-shadow-md: 0 12px 30px -14px rgba(12, 59, 57, 0.30);
  --ecg-shadow-panel: 0 1px 2px rgba(16, 40, 38, 0.05),
    0 18px 40px -28px rgba(12, 59, 57, 0.35);
}

html {
  font-family: var(--font-sans);
  color-scheme: light;
}

/* ——— Dark mode ——— */

html[data-theme="dark"] {
  color-scheme: dark;
  --ecg-brand: #171d23;
  --ecg-brand-2: #1f262e;
  --ecg-on-brand: #e8edf1;
  --ecg-primary: #90b1df;
  --ecg-primary-hover: #b3cbec;
  --ecg-primary-soft: #213045;
  --ecg-primary-tint: rgba(144, 177, 223, 0.10);
  --ecg-on-primary: #0f1418;
  --ecg-bg: #0f1418;
  --ecg-surface: #171d23;
  --ecg-surface-muted: #1f262e;
  --ecg-text: #e8edf1;
  --ecg-text-muted: #9aa7b3;
  --ecg-border: #26303a;
  --ecg-border-strong: #384454;
  --ecg-grid: #263039;
  --ecg-row-hover: rgba(144, 177, 223, 0.07);
  --ecg-focus-ring: rgba(144, 177, 223, 0.40);
  --ecg-good-bg: #163326;
  --ecg-good-fg: #6fd39a;
  --ecg-warn-bg: #3a2f10;
  --ecg-warn-fg: #f2c14e;
  --ecg-bad-bg: #3d1c1c;
  --ecg-bad-fg: #f47c7c;
  --ecg-exp-fg: #d9a23a;
  --ecg-rail-bg: #171d23;
  --ecg-rail-fg: #c3ccd4;
  --ecg-rail-eyebrow: #9aa7b3;
  --ecg-rail-hover: rgba(255, 255, 255, 0.05);
  --ecg-rail-active-bg: #213045;
  --ecg-rail-active-fg: #e8edf1;
  --ecg-rail-border: #26303a;
  --ecg-rail-badge-bg: #1f262e;
  --ecg-rail-badge-fg: #9aa7b3;
  --ecg-ch-ecg: #90b1df;
  --ecg-ch-ppg: #4fd1a5;
  --ecg-ch-bp: #f0a06a;
  --ecg-ch-temp: #b794f4;
  --ecg-ch-spo2: #5cc8dc;
  --ecg-ch-sleep: #9aa7b3;
  --ecg-ch-steps: #8fd17a;
  --ecg-ch-motion: #9aa7b3;
  --ecg-ch-stress: #d9a23a;
  --ecg-ch-neutral: #9aa7b3;
  --ecg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ecg-shadow-md: 0 12px 30px -14px rgba(0, 0, 0, 0.55);
  --ecg-shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4),
    0 18px 40px -28px rgba(0, 0, 0, 0.6);
}

html[data-accent="original"][data-theme="dark"] {
  color-scheme: dark;
  --ecg-brand: #0a201f;
  --ecg-brand-2: #0e302d;
  --ecg-on-brand: #d7eae6;
  --ecg-primary: #2dd4bf;
  --ecg-primary-hover: #5eead4;
  --ecg-primary-soft: rgba(45, 212, 191, 0.14);
  --ecg-primary-tint: rgba(45, 212, 191, 0.07);
  --ecg-on-primary: #04231f;
  --ecg-bg: #0a1413;
  --ecg-surface: #11201e;
  --ecg-surface-muted: #18302d;
  --ecg-text: #e4efed;
  --ecg-text-muted: #8ba39f;
  --ecg-border: #213733;
  --ecg-border-strong: #2e4a45;
  --ecg-grid: #213733;
  --ecg-row-hover: rgba(45, 212, 191, 0.06);
  --ecg-focus-ring: rgba(45, 212, 191, 0.32);
  --ecg-good-bg: rgba(34, 197, 94, 0.16);
  --ecg-good-fg: #86efac;
  --ecg-warn-bg: rgba(245, 158, 11, 0.16);
  --ecg-warn-fg: #fcd97a;
  --ecg-bad-bg: rgba(239, 68, 68, 0.16);
  --ecg-bad-fg: #fca5a5;
  --ecg-exp-fg: #d9a23a;
  --ecg-rail-bg: #0a201f;
  --ecg-rail-fg: rgba(255, 255, 255, 0.84);
  --ecg-rail-eyebrow: rgba(215, 234, 230, 0.55);
  --ecg-rail-hover: rgba(255, 255, 255, 0.09);
  --ecg-rail-active-bg: rgba(255, 255, 255, 0.14);
  --ecg-rail-active-fg: #ffffff;
  --ecg-rail-border: transparent;
  --ecg-rail-badge-bg: rgba(255, 255, 255, 0.16);
  --ecg-rail-badge-fg: #d7eae6;
  --ecg-ch-ecg: #2dd4bf;
  --ecg-ch-ppg: #8fa6e8;
  --ecg-ch-bp: #f0a06a;
  --ecg-ch-temp: #b794f4;
  --ecg-ch-spo2: #5cc8dc;
  --ecg-ch-sleep: #8ba39f;
  --ecg-ch-steps: #8fd17a;
  --ecg-ch-motion: #8ba39f;
  --ecg-ch-stress: #d9a23a;
  --ecg-ch-neutral: #8ba39f;
  --ecg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ecg-shadow-md: 0 12px 30px -14px rgba(0, 0, 0, 0.55);
  --ecg-shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4),
    0 18px 40px -28px rgba(0, 0, 0, 0.6);
}

body.bx--body {
  min-height: 100dvh;
  margin: 0;
}

.ecg-skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 200;
}

.ecg-skip-link:focus {
  position: fixed;
  left: 1rem;
  top: 1rem;
  width: auto;
  height: auto;
  padding: 0.5rem 1rem;
  background: var(--ecg-primary);
  color: #fff;
  border-radius: var(--ecg-radius-sm);
  text-decoration: none;
}

.ecg-main {
  width: min(100%, 78rem);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.ecg-page-header {
  margin-bottom: 1.75rem;
}

.ecg-page-header .ecg-muted {
  margin: 0.25rem 0 0;
  font-size: var(--text-sm);
}

.ecg-muted {
  color: var(--ecg-text-muted);
}

/* ——— Sections grouped by space + hairlines, not boxes ——— */

.ecg-card {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

.ecg-section {
  margin-top: 2.5rem;
}

.ecg-section:first-of-type {
  margin-top: 0;
}

.ecg-section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--ecg-border);
}

/* Caption riding the right end of a section rule. `max-width: none` overrides
   the .ecg-main p measure rule (0,0,1,1), which would otherwise cap this at
   68ch and pull it away from the hairline's right edge. */
.ecg-main .ecg-section__head .ecg-section__sub {
  margin: 0;
  max-width: none;
  font-size: 0.78rem;
  color: var(--ecg-text-muted);
}

/* One genuinely elevated surface: the primary data panel */
.ecg-card--flush {
  background: var(--ecg-surface);
  border-radius: var(--ecg-radius);
  box-shadow: var(--ecg-shadow-panel);
  overflow: hidden;
}

.ecg-stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* Dual analysis: one card per analysis service, side by side on wide screens */
.ecg-analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
  gap: 1rem;
  align-items: start;
}

.ecg-analysis-grid--single {
  grid-template-columns: minmax(0, 1fr);
}

.ecg-analysis-panel {
  border: 1px solid var(--ecg-border, rgba(128, 128, 128, 0.25));
  border-radius: var(--ecg-radius-sm);
  padding: 0.875rem 1rem;
  min-width: 0;
}

.ecg-analysis-grid--single .ecg-analysis-panel {
  border: none;
  padding: 0;
}

/* ---- Header language switcher ---- */
.ecg-lang-switch { display: inline-flex; align-items: center; margin: 0 .1rem 0 .35rem; }
.ecg-lang-select {
  font: inherit; font-size: .82rem; color: inherit; background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 6px;
  padding: .24rem 1.5rem .24rem .55rem; cursor: pointer; line-height: 1.2;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'><path d='M1 1l4 4 4-4' fill='none' stroke='%23c8d6d3' stroke-width='1.4' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right .5rem center;
}
.ecg-lang-select option { color: #10201d; }
.ecg-lang-select:hover { border-color: rgba(255, 255, 255, 0.5); }
.ecg-lang-select:focus-visible { outline: 2px solid var(--ecg-primary, #386097); outline-offset: 1px; }

/* ---- Syndrome hints ("what these findings mean") ---- */
.ecg-syndrome-ref {
  margin-top: 1.5rem;
}
.ecg-syndrome-hint {
  border-left: 3px solid var(--ecg-primary, #0f766e);
  background: var(--ecg-surface-muted, rgba(128, 128, 128, 0.06));
  border-radius: var(--ecg-radius-sm);
  padding: 0.75rem 0.95rem;
  margin-top: 0.75rem;
}
.ecg-syndrome-hint__name {
  margin: 0 0 0.25rem;
}
.ecg-syndrome-hint__name code {
  font-size: 0.75rem;
  color: var(--ecg-text-muted);
  margin-left: 0.35rem;
}
.ecg-syndrome-hint__desc {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ecg-text);
  max-width: 68ch;
}
.ecg-syndrome-hint__link {
  margin: 0.4rem 0 0;
}

/* ---- ECG detail: two-column layout (wide main + sticky info rail) ---- */
.ecg-main--wide {
  width: min(100%, 96rem);
}

/* The theme had no breakpoint above 768px, so a 1728px display rendered exactly
   the same 1536px column as a 1536px one — 192px of screen discarded before the
   rail even took its 352px. A 12-lead trace is the one thing here that gets
   genuinely better with width, so give it the room progressively. */
@media (min-width: 100rem) {
  .ecg-main--wide { width: min(100%, 112rem); }
}
@media (min-width: 128rem) {
  .ecg-main--wide { width: min(100%, 132rem); }
}
@media (min-width: 160rem) {
  .ecg-main--wide { width: calc(100% - 4rem); }
}

/* ...but only the waveform should drink it. Prose at 132rem is unreadable, so
   every other section keeps a comfortable measure. */
.ecg-detail-main > .ecg-section:not(.ecg-section--waveform) {
  max-width: 78rem;
}
.ecg-section--waveform {
  max-width: none;
}
.ecg-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  gap: 2rem;
  align-items: start;
  margin-top: 1.75rem;
}
.ecg-detail-main {
  min-width: 0;
}
/* Docked geometry now lives in the @media (min-width: 60rem) block below,
   together with the drawer it alternates with. */
.ecg-detail-rail .ecg-section {
  margin-top: 0;
}
.ecg-rail-card {
  background: var(--ecg-surface);
  border: 1px solid var(--ecg-border, rgba(128, 128, 128, 0.25));
  border-radius: var(--ecg-radius);
  box-shadow: var(--ecg-shadow-panel);
  padding: 1.1rem 1.15rem 1.25rem;
}
.ecg-rail-card__heading {
  margin: 0 0 0.85rem;
}
.ecg-rail-group + .ecg-rail-group {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--ecg-border, rgba(128, 128, 128, 0.25));
}
.ecg-rail-group__title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ecg-text-muted);
  margin: 0 0 0.7rem;
}
.ecg-rail-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
}
.ecg-rail-list > div {
  min-width: 0;
}
.ecg-rail-list dt {
  font-size: var(--text-xs);
  color: var(--ecg-text-muted);
  font-weight: 500;
  margin-bottom: 0.1rem;
}
.ecg-rail-list dd {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ecg-text);
  word-break: break-word;
}
.ecg-rail-list dd code {
  font-size: 0.75rem;
}
.ecg-subject-eyebrow {
  font-size: var(--text-sm);
  color: var(--ecg-primary);
  font-weight: 600;
  margin: 0 0 0.15rem;
}
/* ---- Details rail: docked column on wide screens, overlay drawer otherwise ----
   The previous rule made the rail `position: static; order: -1` under 60rem,
   i.e. it jumped ABOVE the waveform — you scrolled past a metadata card to
   reach the trace you opened the page for. Replaced by a real drawer. */
.ecg-detail-rail {
  transition: transform 180ms ease, visibility 180ms;
}
@media (prefers-reduced-motion: reduce) {
  .ecg-detail-rail { transition: none; }
}

/* Base state = overlay drawer (mobile-first). Animating only `transform` means
   no layout width changes, so the viewer's ResizeObserver stays quiet. */
.ecg-detail-layout { grid-template-columns: minmax(0, 1fr); }
.ecg-detail-rail {
  position: fixed;
  top: var(--ecg-header-h);
  right: 0;
  width: min(22rem, 92vw);
  height: calc(100dvh - var(--ecg-header-h));
  max-height: none;
  z-index: 160;
  padding: 1rem;
  background: var(--ecg-surface);
  border-left: 1px solid var(--ecg-border, rgba(128, 128, 128, 0.25));
  box-shadow: var(--ecg-shadow-panel);
  transform: translateX(101%);
  visibility: hidden;
}
html[data-ecg-rail="open"] .ecg-detail-rail {
  transform: translateX(0);
  visibility: visible;
}
.ecg-scrim {
  position: fixed;
  inset: 0;
  z-index: 155;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms;
}
html[data-ecg-rail="open"] .ecg-scrim { opacity: 1; visibility: visible; }

/* Wide screens (and not in focus view): dock it back into the grid. */
@media (min-width: 60rem) {
  html:not([data-ecg-focus="1"]) .ecg-detail-layout {
    grid-template-columns: minmax(0, 1fr) 20rem;
  }
  html:not([data-ecg-focus="1"]) .ecg-detail-rail {
    position: sticky;
    top: calc(var(--ecg-header-h) + 1rem);
    right: auto;
    width: auto;
    height: auto;
    max-height: calc(100dvh - var(--ecg-header-h) - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: auto;
    padding: 0;
    background: none;
    border-left: 0;
    box-shadow: none;
    transform: none;
    visibility: visible;
  }
  /* Closed on a wide screen: display:none rather than a transform, so the grid
     column collapses instantly and the width goes to the trace in one reflow. */
  html[data-ecg-rail="closed"]:not([data-ecg-focus="1"]) .ecg-detail-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  html[data-ecg-rail="closed"]:not([data-ecg-focus="1"]) .ecg-detail-rail { display: none; }
  html:not([data-ecg-focus="1"]) .ecg-scrim { display: none; }
  .ecg-rail-close { display: none; }
}

/* ---- Focus view: the waveform section becomes the whole viewport ----
   NB: position:fixed is defeated by transform/filter/contain/will-change on any
   ancestor. Do not add those to .ecg-main, .ecg-detail-layout, .ecg-detail-main
   or .ecg-section without re-testing this. */
html[data-ecg-focus="1"], html[data-ecg-focus="1"] body { overflow: hidden; }
html[data-ecg-focus="1"] .ecg-section--waveform {
  position: fixed;
  inset: 0;
  z-index: 150;
  margin: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.75rem;
  background: var(--ecg-bg);
  overflow: hidden;
}
/* The height chain must be unbroken from the fixed section down to the scroll
   box, or the box sizes to its content and silently stops scrolling — the
   content below the fold is then simply unreachable. Every link needs
   min-height:0, otherwise flex items refuse to shrink below content size. */
html[data-ecg-focus="1"] .ecg-section--waveform > *:not(.ecg-section__head),
html[data-ecg-focus="1"] .ecg-section--waveform [data-react-island="ecg-workspace"],
html[data-ecg-focus="1"] .ecg-section--waveform .ecg-workspace-root {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
/* The live-session bar keeps its natural height; only the viewer stretches. */
html[data-ecg-focus="1"] .ecg-workspace-root > *:not(:last-child) {
  flex: 0 0 auto;
}
html[data-ecg-focus="1"] .ecg-workspace-root > *:last-child {
  flex: 1 1 auto;
  min-height: 0;
}
html[data-ecg-focus="1"] .ecg-section--waveform .ecg-section__head { flex: 0 0 auto; }
.ecg-focus-exit { display: none; }
html[data-ecg-focus="1"] .ecg-focus-exit { display: inline-flex; }
html[data-ecg-focus="1"] .ecg-focus-enter { display: none; }

/* A fixed overlay prints as one viewport-sized page with everything else blank. */
@media print {
  html[data-ecg-focus="1"] .ecg-section--waveform {
    position: static;
    height: auto;
    overflow: visible;
  }
  .ecg-scrim, .ecg-viewer-actions { display: none !important; }
}

/* Faint tinted chips with an accent number — colour, not a slab */
.ecg-stat-tile {
  padding: 0.875rem 1rem;
  background: var(--ecg-primary-tint);
  border-radius: var(--ecg-radius-sm);
}

.ecg-stat-tile__label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ecg-text-muted);
  margin-bottom: 0.3rem;
}

.ecg-stat-tile__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ecg-text);
}

.ecg-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

/* Uniform nav tile: title + one meta line, equal footprint — so a grid of
   count-tiles and descriptor-tiles reads as one even set instead of ragged
   (big teal numbers next to small subtitles). Counts fold in as an accent. */
.ecg-nav-tile {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 5.5rem;
}
.ecg-nav-tile__meta {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ecg-text-muted);
}
.ecg-nav-tile__num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--ecg-primary);
}

/* ——— Filter bar: inline on the canvas, divided by a hairline ——— */

.ecg-filter-toolbar {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--ecg-border);
}

.ecg-filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.875rem 1rem;
  align-items: end;
}

.ecg-filter-row .bx--btn {
  width: 100%;
}

.ecg-table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--ecg-border);
}

.ecg-panel-foot {
  padding: 0 1.25rem 1rem;
}

.ecg-empty-state {
  padding: 2.75rem 1.5rem;
  text-align: center;
}

.ecg-empty-state p {
  margin: 0;
  color: var(--ecg-text-muted);
  font-size: var(--text-sm);
}

/* Auth card — the second legitimate elevated surface */
.ecg-sign-in-wrap {
  max-width: 25rem;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--ecg-surface);
  border-radius: var(--ecg-radius);
  box-shadow: var(--ecg-shadow-panel);
}

.ecg-sign-in-wrap .ecg-page-header {
  margin-bottom: 1.25rem;
}

.ecg-sign-in-wrap .bx--form-item + .bx--form-item {
  margin-top: 1rem;
}

.ecg-sign-in-submit {
  width: 100%;
  margin-top: 1.5rem;
}

.ecg-breadcrumb-wrap {
  margin-bottom: 1.25rem;
}

.ecg-messages {
  margin-bottom: 1rem;
}

.ecg-messages .bx--inline-notification {
  max-width: none;
}

#column-picker label {
  cursor: pointer;
  display: block;
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
  font-size: var(--text-sm);
  white-space: nowrap;
}

#column-picker label:hover {
  background: var(--ecg-surface-muted);
}

.ecg-viewer-section {
  margin-top: 0.5rem;
}

.ecg-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 1.25rem 1.75rem;
}

.ecg-meta-grid dt {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ecg-text-muted);
  margin-bottom: 0.25rem;
}

.ecg-meta-grid dd {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ecg-text);
  word-break: break-word;
}

.ecg-meta-grid code {
  font-size: 0.8125rem;
}

.ecg-billing-note {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--ecg-border);
}

.ecg-billing-note h2 {
  margin-bottom: 0.375rem;
}

.ecg-form-section {
  max-width: 40rem;
}

.ecg-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1rem;
}

.ecg-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  align-items: center;
  margin-top: 2rem;
}

.ecg-inline-form {
  display: inline;
}

.ecg-prose p {
  margin: 0 0 0.75rem;
  font-size: var(--text-sm);
  line-height: 1.6;
  max-width: 65ch;
}

.ecg-prose p:last-child {
  margin-bottom: 0;
}

.ecg-prose h3 {
  margin: 1.5rem 0 0.75rem;
}

/* ——— Upload dropzone: on design tokens, dark-mode aware ———
   (previously an inline <style> in ecg_upload.html that hardcoded Carbon
   blue/green/gray hex and a light dragover box that broke on dark pages). */
.ecg-dropzone {
  display: block;
  position: relative;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--ecg-surface);
  border: 2px dashed var(--ecg-border-strong);
  border-radius: var(--ecg-radius-sm);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ecg-dropzone:hover {
  border-color: var(--ecg-primary);
}
.ecg-dropzone.is-dragover {
  border-color: var(--ecg-primary);
  background: var(--ecg-primary-tint);
}
.ecg-dropzone.has-files {
  border-style: solid;
  border-color: var(--ecg-good-fg);
}
.ecg-dropzone__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.ecg-dropzone__hint {
  pointer-events: none;
  font-size: 0.95rem;
  color: var(--ecg-text-muted);
}
.ecg-dropzone__hint strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--ecg-text);
}
.ecg-dropzone__list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  text-align: left;
}
.ecg-dropzone__list li {
  padding: 0.2rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  border-top: 1px solid var(--ecg-border);
}
.ecg-dropzone__list li:first-child {
  border-top: 0;
}

/* Persistent clinical-safety disclaimer on the analysis surface */
.ecg-analysis-disclaimer {
  margin: 0.25rem 0 1rem;
  padding: 0.6rem 0.8rem;
  max-width: 80ch;
  font-size: var(--text-xs);
  color: var(--ecg-text);
  background: var(--ecg-warn-bg);
  border-left: 3px solid var(--ecg-warn-fg);
  border-radius: var(--ecg-radius-sm);
}

/* ——— Spacing utilities: one scale, replacing ad-hoc inline style margins ——— */
.ecg-mt-1 { margin-top: 0.5rem; }
.ecg-mt-2 { margin-top: 1rem; }
.ecg-mt-3 { margin-top: 1.5rem; }
.ecg-mt-4 { margin-top: 2rem; }
.ecg-mb-1 { margin-bottom: 0.5rem; }
.ecg-mb-2 { margin-bottom: 1rem; }
.ecg-w-full { width: 100%; }

/* Inline table sub-row (recent-changes summary) — token background, not a
   hardcoded #f4f4f4 gray that stayed light on a dark page. */
.ecg-subrow {
  font-size: var(--text-sm);
  background: var(--ecg-surface-muted);
}

/* Checkbox / radio row — a repeated flex label pattern lifted out of inline styles. */
.ecg-check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* Field help text under an input — another repeated inline pattern. */
.ecg-field-hint {
  margin: 0.35rem 0 0;
  max-width: 60ch;
  font-size: var(--text-sm);
}

@media (min-width: 768px) {
  .ecg-main {
    padding: 2.25rem 1.75rem 3.5rem;
  }

  .ecg-filter-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
    --ecg-brand: #171d23;
    --ecg-brand-2: #1f262e;
    --ecg-on-brand: #e8edf1;
    --ecg-primary: #90b1df;
    --ecg-primary-hover: #b3cbec;
    --ecg-primary-soft: #213045;
    --ecg-primary-tint: rgba(144, 177, 223, 0.10);
    --ecg-on-primary: #0f1418;
    --ecg-bg: #0f1418;
    --ecg-surface: #171d23;
    --ecg-surface-muted: #1f262e;
    --ecg-text: #e8edf1;
    --ecg-text-muted: #9aa7b3;
    --ecg-border: #26303a;
    --ecg-border-strong: #384454;
    --ecg-grid: #263039;
    --ecg-row-hover: rgba(144, 177, 223, 0.07);
    --ecg-focus-ring: rgba(144, 177, 223, 0.40);
    --ecg-good-bg: #163326;
    --ecg-good-fg: #6fd39a;
    --ecg-warn-bg: #3a2f10;
    --ecg-warn-fg: #f2c14e;
    --ecg-bad-bg: #3d1c1c;
    --ecg-bad-fg: #f47c7c;
    --ecg-exp-fg: #d9a23a;
    --ecg-rail-bg: #171d23;
    --ecg-rail-fg: #c3ccd4;
    --ecg-rail-eyebrow: #9aa7b3;
    --ecg-rail-hover: rgba(255, 255, 255, 0.05);
    --ecg-rail-active-bg: #213045;
    --ecg-rail-active-fg: #e8edf1;
    --ecg-rail-border: #26303a;
    --ecg-rail-badge-bg: #1f262e;
    --ecg-rail-badge-fg: #9aa7b3;
    --ecg-ch-ecg: #90b1df;
    --ecg-ch-ppg: #4fd1a5;
    --ecg-ch-bp: #f0a06a;
    --ecg-ch-temp: #b794f4;
    --ecg-ch-spo2: #5cc8dc;
    --ecg-ch-sleep: #9aa7b3;
    --ecg-ch-steps: #8fd17a;
    --ecg-ch-motion: #9aa7b3;
    --ecg-ch-stress: #d9a23a;
    --ecg-ch-neutral: #9aa7b3;
    --ecg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --ecg-shadow-md: 0 12px 30px -14px rgba(0, 0, 0, 0.55);
    --ecg-shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4),
      0 18px 40px -28px rgba(0, 0, 0, 0.6);
  }
  html[data-accent="original"]:not([data-theme="light"]) {
    color-scheme: dark;
    --ecg-brand: #0a201f;
    --ecg-brand-2: #0e302d;
    --ecg-on-brand: #d7eae6;
    --ecg-primary: #2dd4bf;
    --ecg-primary-hover: #5eead4;
    --ecg-primary-soft: rgba(45, 212, 191, 0.14);
    --ecg-primary-tint: rgba(45, 212, 191, 0.07);
    --ecg-on-primary: #04231f;
    --ecg-bg: #0a1413;
    --ecg-surface: #11201e;
    --ecg-surface-muted: #18302d;
    --ecg-text: #e4efed;
    --ecg-text-muted: #8ba39f;
    --ecg-border: #213733;
    --ecg-border-strong: #2e4a45;
    --ecg-grid: #213733;
    --ecg-row-hover: rgba(45, 212, 191, 0.06);
    --ecg-focus-ring: rgba(45, 212, 191, 0.32);
    --ecg-good-bg: rgba(34, 197, 94, 0.16);
    --ecg-good-fg: #86efac;
    --ecg-warn-bg: rgba(245, 158, 11, 0.16);
    --ecg-warn-fg: #fcd97a;
    --ecg-bad-bg: rgba(239, 68, 68, 0.16);
    --ecg-bad-fg: #fca5a5;
    --ecg-exp-fg: #d9a23a;
    --ecg-rail-bg: #0a201f;
    --ecg-rail-fg: rgba(255, 255, 255, 0.84);
    --ecg-rail-eyebrow: rgba(215, 234, 230, 0.55);
    --ecg-rail-hover: rgba(255, 255, 255, 0.09);
    --ecg-rail-active-bg: rgba(255, 255, 255, 0.14);
    --ecg-rail-active-fg: #ffffff;
    --ecg-rail-border: transparent;
    --ecg-rail-badge-bg: rgba(255, 255, 255, 0.16);
    --ecg-rail-badge-fg: #d7eae6;
    --ecg-ch-ecg: #2dd4bf;
    --ecg-ch-ppg: #8fa6e8;
    --ecg-ch-bp: #f0a06a;
    --ecg-ch-temp: #b794f4;
    --ecg-ch-spo2: #5cc8dc;
    --ecg-ch-sleep: #8ba39f;
    --ecg-ch-steps: #8fd17a;
    --ecg-ch-motion: #8ba39f;
    --ecg-ch-stress: #d9a23a;
    --ecg-ch-neutral: #8ba39f;
    --ecg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --ecg-shadow-md: 0 12px 30px -14px rgba(0, 0, 0, 0.55);
    --ecg-shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4),
      0 18px 40px -28px rgba(0, 0, 0, 0.6);
  }
}


/* ---- Billing ------------------------------------------------------------
   Money is read in columns, so every figure is tabular and right-aligned:
   the eye compares digits by position, and a ragged column defeats that. */
.ecg-billing-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ecg-billing-cur {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ecg-text-muted);
}

.ecg-billing-note {
  font-size: var(--text-xs);
  margin: 0.5rem 0 0;
  max-width: 78ch;
}

/* Direction of travel, encoded in more than a minus sign */
.ecg-billing-debit { color: var(--ecg-bad-fg); }
.ecg-billing-credit { color: var(--ecg-good-fg); }

/* Quota meter: a bar reads at a glance in a way "4 / 20" does not */
.ecg-meter {
  display: block;
  width: min(180px, 100%);
  height: 5px;
  border-radius: 999px;
  background: var(--ecg-surface-muted);
  overflow: hidden;
}

.ecg-meter__fill {
  display: block;
  height: 100%;
  background: var(--ecg-primary);
  border-radius: inherit;
}

.ecg-meter__fill--full { background: var(--ecg-bad-fg); }

.ecg-billing-meterlabel {
  font-size: var(--text-xs);
  color: var(--ecg-text-muted);
}

/* ---- Billing: period picker + drill-down layout ---- */
.ecg-billing-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.ecg-period-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.ecg-period-picker__label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ecg-text-muted);
}

.ecg-period-select {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--ecg-border-strong);
  border-radius: var(--ecg-radius-sm);
  background: var(--ecg-surface);
  color: var(--ecg-text);
  cursor: pointer;
}

/* two side-by-side breakdowns (API client / user) that stack on narrow screens */
.ecg-billing-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem 2rem;
  align-items: start;
}

/* ---- Mobile app download (login line + profile card) ---- */
.ecg-app-download--line {
  margin: 1.25rem 0 0;
  font-size: var(--text-sm, 0.9rem);
}

.ecg-app-download--card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.15rem;
  background: var(--ecg-primary-tint);
  border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm);
  max-width: 640px;
}

.ecg-app-download__title { font-weight: 640; }
.ecg-app-download__ver { color: var(--ecg-primary); font-weight: 700; }
.ecg-app-download__meta {
  font-size: var(--text-xs);
  color: var(--ecg-text-muted);
  margin-top: 0.2rem;
}
.ecg-app-download__notes {
  font-size: var(--text-xs);
  color: var(--ecg-text-muted);
  margin-top: 0.5rem;
  max-width: 46ch;
}

/* ---- Method hints: a "?" disclosure revealing how a finding/measurement is computed ---- */
.ecg-hint {
  display: inline-block;
  position: relative;
  vertical-align: middle;
}

.ecg-hint__q {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  margin-left: 0.35rem;
  border-radius: 50%;
  border: 1px solid var(--ecg-border-strong);
  background: var(--ecg-surface);
  color: var(--ecg-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  list-style: none;
  user-select: none;
}
.ecg-hint__q::-webkit-details-marker { display: none; }
.ecg-hint__q:hover { border-color: var(--ecg-primary); color: var(--ecg-primary); }
.ecg-hint[open] .ecg-hint__q { background: var(--ecg-primary); color: var(--ecg-on-primary, #fff); border-color: var(--ecg-primary); }

.ecg-hint__body {
  /* fixed, not absolute: the rule-findings table lives in a scrolling
     .bx--data-table-container, and an absolutely-positioned popover is clipped
     by it — the hint was cut off by the panel edge. Coordinates are set on open
     by static/web/theme/ecg-hints.js; these are only the pre-placement values.
     z-index clears the focus-view overlay (150). */
  position: fixed;
  z-index: 400;
  top: 0;
  left: 0;
  width: min(30rem, 78vw);
  padding: 0.8rem 0.95rem;
  background: var(--ecg-surface);
  color: var(--ecg-text);
  border: 1px solid var(--ecg-border-strong);
  border-radius: var(--ecg-radius-sm);
  box-shadow: var(--ecg-shadow-md, 0 6px 24px rgba(0,0,0,0.16));
  font-size: var(--text-xs);
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  text-align: left;
}
/* Edge flipping and the small-screen case are both handled by the placement
   script now, so the old right-align and fixed overrides are gone. */
@media (max-width: 560px) {
  .ecg-hint__body { width: min(30rem, calc(100vw - 2rem)); }
}


/* Waveform section head: title left, reading controls right. */
.ecg-viewer-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.ecg-rail-close {
  display: inline-flex;
  margin: 0 0 0.75rem auto;
}


/* ---- Checkboxes and fieldsets ----
   The templates use Carbon's class names (bx--checkbox, bx--checkbox-label,
   bx--checkbox-wrapper, bx--fieldset) but this stylesheet is a bespoke
   look-alike and never defined ANY of them. The reviewer picker was therefore
   raw unstyled inputs: the box floated away from its label and the text wrapped
   underneath it. Define them here rather than pull in Carbon. */
.bx--fieldset {
  border: 1px solid var(--ecg-border, rgba(128, 128, 128, 0.25));
  border-radius: var(--ecg-radius-sm);
  padding: 0.9rem 1rem 1rem;
  margin: 0;
  min-width: 0;
}
.bx--fieldset > .bx--label,
.bx--fieldset > legend {
  padding: 0 0.35rem;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ecg-text-muted);
}
.bx--checkbox-wrapper {
  display: flex;
  /* The wrapper also carries .bx--form-item, which is `flex-direction: column`
     (clinical-ui.css:278) for stacked label-over-input fields. A checkbox is
     the one field where the control sits BESIDE its label, so the direction has
     to be restated — declaring only `display:flex` inherited the column and
     dropped the label underneath the box. */
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  min-height: 2rem;
  margin: 0;
}
.bx--checkbox {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--ecg-primary);
  cursor: pointer;
}
.bx--checkbox-label {
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.bx--checkbox:focus-visible {
  outline: 2px solid var(--ecg-primary);
  outline-offset: 2px;
}

/* A long reviewer roster is a list of short strings — one per row wastes the
   screen and makes scanning it harder than it should be. */
.ecg-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.15rem 1.25rem;
}

/* Forms stay a comfortable single-column measure, but a form that CONTAINS a
   roster needs room for it. */
.ecg-form-section--roomy {
  max-width: min(100%, 72rem);
}


/* Billing is tabular, so it earns the wide container — but the XL/XXL tiers are
   for the ECG trace, not for tables of numbers. Cap it at a width where a row
   is still scannable left-to-right. */
.ecg-main--wide:has(.ecg-billing-header) {
  width: min(100%, 100rem);
}
/* Four stat tiles hugging the left of a 2000px screen reads as a broken page.
   Let them share the row instead. */
.ecg-billing-header ~ .ecg-stat-tiles,
.ecg-stat-tiles {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

/* ══════════════════════════════════════════════════════════════════════════
   PANELS — a section that is a card
   The ECG Hub 2 mockups put a section's heading INSIDE its panel. The portal
   had the heading floating above a full-bleed table with a hairline under it,
   which reads as a page of loose rules rather than a page of objects, and let
   a 420px chart sit alone in 1400px of empty background.
   ══════════════════════════════════════════════════════════════════════════ */
.ecg-panel { background: var(--ecg-surface); border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius); padding: .95rem 1.15rem 1.1rem; min-width: 0; }
.ecg-panel > .ecg-section__head { border-bottom: 0; padding-bottom: 0; margin-bottom: .8rem; }
.ecg-panel > .ecg-section__head h2 { font-size: 1.0625rem; font-weight: 600; margin: 0; }
/* The table is the panel's floor: flush to the edges, its own header band the
   only rule it needs. */
.ecg-panel .bx--data-table-container { border: 0; border-radius: 0; background: transparent;
  margin: 0 -1.15rem; width: calc(100% + 2.3rem); }
.ecg-panel .bx--data-table th:first-child,
.ecg-panel .bx--data-table td:first-child { padding-left: 1.15rem; }
.ecg-panel .bx--data-table th:last-child,
.ecg-panel .bx--data-table td:last-child { padding-right: 1.15rem; }
.ecg-panel > :last-child { margin-bottom: 0; }
.ecg-panel > .ecg-section__head .ecg-section__sub { margin: 0; }
/* A panel that owns a figure band keeps the same inner rhythm as one that owns
   a table, so a page of both does not read as two grids. */
.ecg-panel .ecg-stat-tiles, .ecg-panel .ops-tiles { margin-top: .25rem; }
/* A bordered fieldset inside a bordered panel is a box in a box in a box. In
   the panel the legend alone groups the controls, as it does in the mockups. */
.ecg-panel .bx--fieldset { border: 0; padding: 0; }
.ecg-panel .bx--fieldset > .bx--label,
.ecg-panel .bx--fieldset > legend { padding: 0 0 .35rem; }
.ecg-panel .ecg-checkbox-grid { grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }

/* The wide thing and its companion. */
.ecg-duo { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr);
  gap: 1.15rem; align-items: start; }
/* …and the form-and-its-consequences pairing, where the form is the narrower. */
.ecg-duo--form { grid-template-columns: minmax(0, 36rem) minmax(0, 1fr); }
@media (max-width: 68rem) { .ecg-duo, .ecg-duo--form { grid-template-columns: minmax(0, 1fr); } }
.ecg-stack { display: flex; flex-direction: column; gap: 1.15rem; min-width: 0; }
.ecg-consent-count { font-size: 1rem; }
.ecg-consent-count strong { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Numeric columns are as wide as their own headings; the naming column absorbs
   the rest. Four counts spread evenly over 1400px put each number most of a
   screen away from the row it belongs to. */
.ecg-table--measured th.ecg-billing-num,
.ecg-table--measured td.ecg-billing-num { width: 1%; white-space: nowrap; }

/* A short list of events: time, what, state. */
.ecg-feed { list-style: none; margin: 0; padding: 0; }
.ecg-feed__row { display: flex; align-items: baseline; gap: .6rem; padding: .5rem 0;
  border-top: 1px solid var(--ecg-border); font-size: .875rem; }
.ecg-feed__row:first-child { border-top: 0; padding-top: 0; }
.ecg-feed__time { font-size: .75rem; color: var(--ecg-text-muted); flex: none; }
.ecg-feed__body { flex: 1; min-width: 0; }
.ecg-swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px;
  margin-right: .35rem; vertical-align: -1px; }

/* ══════════════════════════════════════════════════════════════════════════
   SHELL — rail + utility bar
   Replaces the horizontal header. The old bar held twelve equal-weight links
   and wrapped to nine rows / 316px at 1024px; a fixed rail cannot wrap, so
   chrome cost is constant at every viewport.
   ══════════════════════════════════════════════════════════════════════════ */
:root { --ecg-rail-w: 240px; --ecg-utility-h: 48px; }

.ecg-shell { display: grid; grid-template-columns: var(--ecg-rail-w) 1fr; min-height: 100vh; }
.ecg-shell__col { min-width: 0; display: flex; flex-direction: column; }

/* The rail reads its own small palette (--ecg-rail-*) instead of white-on-pine
   literals, so the light rail of the «Клиника» direction and the pine rail of
   the original accent are the same selectors with different values. */
.ecg-rail {
  background: var(--ecg-rail-bg); color: var(--ecg-rail-fg);
  border-right: 1px solid var(--ecg-rail-border);
  padding: .9rem .6rem 1rem; display: flex; flex-direction: column; gap: .05rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.ecg-rail__brand { display: flex; align-items: center; gap: .5rem;
  padding: .3rem .5rem 1.1rem; text-decoration: none; color: var(--ecg-rail-active-fg); }
.ecg-rail__badge { font-family: var(--font-mono); font-size: .6rem; font-weight: 500;
  letter-spacing: .04em; background: var(--ecg-primary); color: var(--ecg-on-primary);
  padding: .22rem .34rem; border-radius: 4px; }
.ecg-rail__name { font-weight: 600; letter-spacing: -0.014em; font-size: 1.0625rem; }

.ecg-rail__label { font-family: var(--font-mono); font-size: .625rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ecg-rail-eyebrow); margin: 1rem 0 .3rem; padding: 0 .55rem; }
.ecg-rail__item {
  display: flex; align-items: center; gap: .6rem; padding: .44rem .55rem;
  border-radius: var(--ecg-radius-sm); color: var(--ecg-rail-fg);
  text-decoration: none; font-size: .9rem; line-height: 1.3;
}
.ecg-rail__item:hover { background: var(--ecg-rail-hover); color: var(--ecg-rail-active-fg); }
.ecg-rail__item.is-current { background: var(--ecg-rail-active-bg);
  color: var(--ecg-rail-active-fg); font-weight: 500; }
.ecg-rail__item.is-current .ecg-rail__ico { color: var(--ecg-primary); opacity: 1; }
.ecg-rail__item:focus-visible { outline: 2px solid var(--ecg-primary); outline-offset: 1px; }
.ecg-rail__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Fixed-width count so labels stop shifting as data changes. */
.ecg-rail__count { font-family: var(--font-mono); font-size: .68rem; min-width: 1.55rem;
  text-align: center; background: var(--ecg-rail-badge-bg); color: var(--ecg-rail-badge-fg);
  padding: .06rem .3rem; border-radius: 999px; }
.ecg-rail__item.is-current .ecg-rail__count { background: var(--ecg-primary);
  color: var(--ecg-on-primary); font-weight: 500; }

.ecg-rail__sub { display: flex; flex-direction: column; gap: .05rem;
  margin: .1rem 0 .35rem 1.2rem; padding-left: .6rem; border-left: 1px solid var(--ecg-border); }
.ecg-rail__subitem { padding: .3rem .5rem; border-radius: var(--ecg-radius-sm);
  color: var(--ecg-rail-eyebrow); text-decoration: none; font-size: .84rem; }
.ecg-rail__subitem:hover { background: var(--ecg-rail-hover); color: var(--ecg-rail-active-fg); }
.ecg-rail__subitem.is-current { color: var(--ecg-primary); font-weight: 500;
  background: var(--ecg-rail-active-bg); }
.ecg-rail__spacer { flex: 1; min-height: .75rem; }

.ecg-rail__ico { width: 1.05rem; height: 1.05rem; flex: none; opacity: .7;
  color: var(--ecg-rail-eyebrow);
  background: currentColor; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center; }
.ecg-ico--records { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 8h3l2-5 3 10 2-5h4' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 8h3l2-5 3 10 2-5h4' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E"); }
.ecg-ico--upload { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 12V3m0 0L4.5 6.5M8 3l3.5 3.5M2 13h12' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 12V3m0 0L4.5 6.5M8 3l3.5 3.5M2 13h12' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E"); }
.ecg-ico--reviews { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='5.5' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3Ccircle cx='8' cy='8' r='2' fill='%23000'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='5.5' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3Ccircle cx='8' cy='8' r='2' fill='%23000'/%3E%3C/svg%3E"); }
.ecg-ico--bell { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 11V7a4 4 0 018 0v4l1 2H3l1-2zM6.5 14.5h3' fill='none' stroke='%23000' stroke-width='1.4'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 11V7a4 4 0 018 0v4l1 2H3l1-2zM6.5 14.5h3' fill='none' stroke='%23000' stroke-width='1.4'/%3E%3C/svg%3E"); }

/* ── Utility bar ─────────────────────────────────────────────────────────── */
.ecg-utility {
  display: flex; align-items: center; gap: .6rem; min-height: var(--ecg-utility-h);
  padding: .4rem 1.5rem; background: var(--ecg-surface);
  border-bottom: 1px solid var(--ecg-border); position: sticky; top: 0; z-index: 30;
}
.ecg-utility__search { flex: 1; max-width: 30rem; margin: 0; }
.ecg-utility__search input {
  width: 100%; font: inherit; font-size: .875rem; padding: .32rem .7rem;
  border: 1px solid var(--ecg-border-strong); border-radius: var(--ecg-radius-sm);
  background: var(--ecg-bg); color: var(--ecg-text);
}
.ecg-orgpick, .ecg-usermenu { position: relative; }
.ecg-orgpick__button, .ecg-usermenu__button {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; list-style: none;
  font-size: .875rem; font-weight: 560; padding: .28rem .6rem;
  border: 1px solid var(--ecg-border); border-radius: 999px; background: var(--ecg-surface-muted);
  color: var(--ecg-text); white-space: nowrap;
}
.ecg-orgpick__button.is-static { cursor: default; }
.ecg-orgpick__button::-webkit-details-marker, .ecg-usermenu__button::-webkit-details-marker { display: none; }
.ecg-orgpick__role { font-size: .6rem; text-transform: uppercase; letter-spacing: .06em;
  background: var(--ecg-primary); color: var(--ecg-on-primary); padding: 0 .3rem; border-radius: 3px; }
.ecg-orgpick__caret { font-size: .6rem; opacity: .7; }
.ecg-orgpick__menu, .ecg-usermenu__menu {
  position: absolute; top: calc(100% + 6px); z-index: 500; min-width: 16.5rem;
  padding: .3rem; background: var(--ecg-surface); border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm); box-shadow: var(--ecg-shadow-md);
}
.ecg-usermenu { margin-left: auto; }
.ecg-usermenu__menu { right: 0; }
.ecg-orgpick__item, .ecg-usermenu__item {
  display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left;
  padding: .4rem .55rem; border: 0; border-radius: var(--ecg-radius-sm);
  background: transparent; color: var(--ecg-text); font: inherit; font-size: .875rem;
  cursor: pointer; text-decoration: none;
}
.ecg-orgpick__item:hover, .ecg-usermenu__item:hover { background: var(--ecg-row-hover); }
.ecg-orgpick__item.is-current::before { content: "\2713"; color: var(--ecg-primary); }
.ecg-orgpick__itemname { flex: 1; }
.ecg-orgpick__badge { font-size: .62rem; text-transform: uppercase; letter-spacing: .04em;
  padding: .05rem .35rem; border-radius: 999px; background: var(--ecg-warn-bg); color: var(--ecg-warn-fg); }
.ecg-usermenu__avatar { width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--ecg-primary); color: var(--ecg-on-primary); display: grid; place-items: center;
  font-size: .64rem; font-weight: 600; }
.ecg-usermenu__sep { height: 1px; background: var(--ecg-border); margin: .3rem 0; }
.ecg-usermenu__row { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem;
  padding: .3rem .55rem; }
.ecg-usermenu__icon { display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--ecg-border); background: var(--ecg-surface);
  border-radius: var(--ecg-radius-sm); cursor: pointer; padding: .2rem .45rem;
  color: var(--ecg-text); font: inherit; font-size: .8125rem; line-height: 1.5; }
.ecg-usermenu__icon:hover { border-color: var(--ecg-border-strong); background: var(--ecg-row-hover); }
/* The accent switch shows the accent it is currently on, as a swatch of the
   live token — so it cannot drift out of step with the theme it describes. */
.ecg-accent-toggle__dot { width: .7rem; height: .7rem; border-radius: 3px; flex: none;
  background: var(--ecg-primary); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.ecg-usermenu__menu form { margin: 0; }

/* ══════════════════════════════════════════════════════════════════════════
   MEASURE — prose is capped, data is not.
   The old shell capped EVERY page at 78rem, so content stayed 1192px wide on a
   4K display (31% of the viewport) while its own table cells wrapped to two
   lines. Reading measure is a typographic constant; a record table is not.
   ══════════════════════════════════════════════════════════════════════════ */
.ecg-main { padding: 1.25rem 1.5rem 3rem; width: 100%; }
.ecg-main > * { max-width: none; }
/* …except the auth card, which is a form of six controls and not data. This
   blanket rule was overriding its own 25rem cap (same specificity, declared
   later), so the sign-in box spanned 1870px at 1080p. */
.ecg-main > .ecg-sign-in-wrap { max-width: 25rem; }
/* Prose keeps a measure. */
.ecg-main p, .ecg-main .ecg-prose, .ecg-main .ecg-empty-state p { max-width: 68ch; }

/* ══════════════════════════════════════════════════════════════════════════
   PHONE SHELL — below 60rem the rail is a drawer behind a 48px bar
   (portal.md §2.0). The old rule wrapped every link into 553px of rows above the
   page's own title; now the page starts under one 48px bar: ☰ · ECG Hub ·
   «Оповещения N». shell-nav.js toggles html[data-ecg-nav="open"]; the rail
   (#ecg-rail) becomes a fixed panel of min(20rem, 88vw) over .ecg-scrim--nav.
   Not to be confused with .ecg-scrim, the record page's «Details» rail veil
   (html[data-ecg-rail]) — its own element, its own attribute, both left alone.
   The wide shell is untouched: everything phone-only is display:none from 60rem up.
   ══════════════════════════════════════════════════════════════════════════ */
.ecg-phonebar, .ecg-scrim--nav, .ecg-rail__phone, .ecg-rail__phonefoot { display: none; }

/* «время клиники UTC+03:00». Hidden in the markup; clinic-time.js shows it when the
   viewer's computer is on another zone than the clinic. */
.ecg-clinic-time { font-size: .75rem; color: var(--ecg-text-muted); white-space: nowrap; }
.ecg-utility .ecg-clinic-time { margin-left: auto; }
.ecg-utility .ecg-clinic-time:not([hidden]) + .ecg-usermenu { margin-left: 0; }

@media (max-width: 59.99rem) {
  .ecg-shell { display: block; }
  .ecg-utility { display: none; }
  .ecg-main { padding: 1rem .9rem 2.5rem; }
  /* An in-page link (the dossier's #plan) must not land under the sticky bar. */
  html { scroll-padding-top: calc(var(--ecg-utility-h) + .5rem); }

  /* The bar. A sticky child of the (now block) shell, so it stays while the page
     scrolls; one token with the utility bar it replaces (--ecg-utility-h, 48px). */
  .ecg-phonebar {
    display: flex; align-items: center; gap: .1rem;
    position: sticky; top: 0; z-index: 30; height: var(--ecg-utility-h);
    padding-right: .35rem; background: var(--ecg-surface);
    box-shadow: 0 1px 0 var(--ecg-border);
  }
  .ecg-phonebar__menu {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 48px; height: 48px; padding: 0; border: 0; border-radius: var(--ecg-radius-sm);
    background: transparent; color: var(--ecg-text); cursor: pointer;
  }
  .ecg-phonebar__menu:hover { background: var(--ecg-row-hover); }
  .ecg-phonebar__menu:focus-visible { outline: 2px solid var(--ecg-primary); outline-offset: -4px; }
  /* Three bars from one element and its shadows: no icon font, no glyph that some
     system font lacks, and it takes the text colour in every theme. */
  .ecg-phonebar__bars { display: block; width: 1.25rem; height: 2px; border-radius: 1px;
    background: currentColor; box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor; }
  .ecg-phonebar__label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .ecg-phonebar__brand, .ecg-phonebar__alerts {
    display: inline-flex; align-items: center; min-height: 48px; color: var(--ecg-text);
    text-decoration: none; border-radius: var(--ecg-radius-sm);
  }
  .ecg-phonebar__brand { padding: 0 .4rem; font-weight: 600; letter-spacing: -0.014em;
    font-size: 1.0625rem; }
  .ecg-phonebar__alerts { margin-left: auto; gap: .4rem; padding: 0 .5rem; font-size: .9rem;
    font-weight: 500; }
  .ecg-phonebar__brand:focus-visible, .ecg-phonebar__alerts:focus-visible {
    outline: 2px solid var(--ecg-primary); outline-offset: -2px; }
  .ecg-phonebar__count { font-family: var(--font-mono); font-size: .75rem; min-width: 1.55rem;
    text-align: center; padding: .08rem .35rem; border-radius: 999px;
    background: var(--ecg-bad-bg); color: var(--ecg-bad-fg); }

  /* The rail, as a drawer. Closed: off-screen AND visibility:hidden, so nothing in
     it can be tabbed to or read. The visibility flip is instant on open and waits
     out the slide on close (a transitioned visibility would leave the drawer
     unfocusable for the first frames, and the close button is focused at once). */
  .ecg-rail {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 190; height: auto;
    width: min(20rem, 88vw); padding-bottom: 1.5rem;
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(-101%); visibility: hidden;
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }
  html[data-ecg-nav="open"] .ecg-rail {
    transform: none; visibility: visible; box-shadow: var(--ecg-shadow-md);
    transition: transform 180ms ease, visibility 0s;
  }
  .ecg-scrim--nav {
    display: block; position: fixed; inset: 0; z-index: 180;
    background: var(--ecg-scrim); opacity: 0; visibility: hidden;
    transition: opacity 180ms ease, visibility 0s linear 180ms;
  }
  html[data-ecg-nav="open"] .ecg-scrim--nav {
    opacity: 1; visibility: visible; transition: opacity 180ms ease, visibility 0s;
  }
  html[data-ecg-nav="open"] body { overflow: hidden; }

  /* The drawer says «ECG Hub» in the bar already; its group headings and the open
     section's sub-items, which the old wrapped bar had to drop, fit a column. */
  .ecg-rail__brand { display: none; }
  .ecg-rail__item { min-height: 48px; font-size: .95rem; }
  .ecg-rail__subitem { display: flex; align-items: center; min-height: 44px; }

  /* Its top block: what the utility bar carries on a wide screen. */
  .ecg-rail__phone {
    display: flex; flex-direction: column; gap: .55rem;
    padding: 0 .1rem .85rem; margin-bottom: .35rem;
    border-bottom: 1px solid var(--ecg-rail-active-bg);
  }
  .ecg-rail__phonehead { display: flex; align-items: flex-start; gap: .5rem; min-height: 48px; }
  .ecg-rail__phone .ecg-orgpick { flex: 1 1 auto; min-width: 0; }
  .ecg-rail__phone .ecg-orgpick__button { min-height: 44px; max-width: 100%; }
  .ecg-rail__phone .ecg-orgpick__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* The list sits in the flow under its button instead of floating over the
     drawer's own scroll box, where it would be clipped. */
  .ecg-rail__phone .ecg-orgpick__menu { position: static; min-width: 0; margin-top: .4rem;
    max-height: 40vh; overflow-y: auto; box-shadow: none; }
  .ecg-rail__phone .ecg-orgpick__item { min-height: 44px; }
  .ecg-rail__close {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    margin-left: auto; width: 48px; height: 48px; padding: 0; border: 0;
    border-radius: var(--ecg-radius-sm); background: transparent;
    color: var(--ecg-rail-fg); font-size: 1.75rem; line-height: 1; cursor: pointer;
  }
  .ecg-rail__close:hover { background: var(--ecg-rail-hover); color: var(--ecg-rail-active-fg); }
  .ecg-rail__close:focus-visible { outline: 2px solid var(--ecg-primary); outline-offset: -4px; }
  .ecg-rail__search { margin: 0; }
  /* 16px: anything smaller makes iOS zoom the page when the field takes focus. */
  .ecg-rail__search input {
    width: 100%; min-height: 44px; font: inherit; font-size: 1rem; padding: .4rem .75rem;
    border: 1px solid var(--ecg-border-strong); border-radius: var(--ecg-radius-sm);
    background: var(--ecg-bg); color: var(--ecg-text);
  }
  /* name · Профиль · Выйти on one line, the name giving way (an e-mail can be long). */
  .ecg-rail__who { display: flex; align-items: center; gap: .15rem; }
  .ecg-rail__who form { margin: 0; flex: none; }
  .ecg-rail__whoname { flex: 1 1 auto; min-width: 0; padding: 0 .55rem; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; font-weight: 560;
    color: var(--ecg-rail-active-fg); }
  .ecg-rail__whoitem, .ecg-rail__phonelink {
    display: inline-flex; align-items: center; flex: none; min-height: 44px; padding: 0 .55rem;
    border: 0; border-radius: var(--ecg-radius-sm); background: transparent;
    color: var(--ecg-rail-fg); font: inherit; font-size: .9rem; text-decoration: none; cursor: pointer;
  }
  .ecg-rail__whoitem:hover, .ecg-rail__phonelink:hover { background: var(--ecg-rail-hover); color: var(--ecg-rail-active-fg); }
  .ecg-rail__whoitem:focus-visible, .ecg-rail__phonelink:focus-visible {
    outline: 2px solid var(--ecg-primary); outline-offset: 1px; }
  /* The identity menu's other entries, at the drawer's foot: quiet, after everything else. */
  .ecg-rail__phonefoot { display: flex; flex-wrap: wrap; gap: 0 .15rem; margin-top: .6rem;
    padding-top: .5rem; border-top: 1px solid var(--ecg-rail-active-bg); }
  .ecg-rail__phonelink { color: var(--ecg-rail-eyebrow); }
  .ecg-rail__phone .ecg-clinic-time { padding: 0 .55rem; color: var(--ecg-rail-eyebrow); }
}
@media (prefers-reduced-motion: reduce) {
  .ecg-rail, .ecg-scrim--nav { transition: none !important; }
}
/* A sheet of paper is narrower than 60rem, so it gets the phone shell: the bar has
   no business on a printout (the closed drawer is off-screen and prints nothing). */
@media print {
  .ecg-phonebar, .ecg-scrim--nav { display: none !important; }
}

/* ── Page header: one title block, three slots ───────────────────────────── */
.ecg-page-header { margin-bottom: 1rem; }
.ecg-page-header__back { font-size: .82rem; color: var(--ecg-text-muted);
  text-decoration: none; display: inline-block; margin-bottom: .25rem; }
.ecg-page-header__back:hover { color: var(--ecg-primary); }
.ecg-page-header__row { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; }
.ecg-page-header__lede { min-width: 0; }
.ecg-page-header h1 { font-size: 1.625rem; font-weight: 600; letter-spacing: -0.018em;
  margin: 0; line-height: 1.2; }
/* An identifier that belongs to the title: mono, muted, one size down — the
   mockups' «Иванов А. П. …9f3c». */
.ecg-page-header__meta { font-family: var(--font-mono); font-size: .875rem;
  font-weight: 400; color: var(--ecg-text-muted); letter-spacing: 0; }
/* Live data, never a glossary sentence. */
.ecg-page-header__summary { color: var(--ecg-text-muted); font-size: .875rem;
  margin: .2rem 0 0; max-width: none; font-variant-numeric: tabular-nums; }
.ecg-page-header__actions { display: flex; gap: .45rem; align-items: center; flex: none; }

/* Below 100rem the rail costs more width than it earns — a dense 8-column table
   wraps and rows grow from 48px to 68px. Collapse to icons: destinations stay one
   click away and the content column gets 168px back. Labels survive as the
   accessible name and a native tooltip. */
/* The icon-only rail collapse was REMOVED (2026-07-28) after two independent
   failures, both found by measuring rather than eyeballing:

   1. It creates a content cliff. Expanding the rail costs 168px the instant the
      query fires, so crossing the threshold makes content SHRINK as the window
      grows — the records table went 1478px -> 1320px between 1600 and 1610, and
      moving the threshold to 112rem only moved the cliff (1670 -> 1510).
   2. Collapsed, it is illegible. Only the three clinical items have icons; the
      nine Organisation destinations fall back to their first letter, giving a
      column of U G V P A D P B I A — with TWO "P" (Patient assignments, Problem
      reports) and TWO "A" (Assign reviewers, All payers).

   A constant 240px labelled rail is predictable, always legible, and has no
   discontinuity at any width. If the width is ever wanted back, it should be a
   user-controlled toggle persisted in localStorage — a choice, not an inference.
*/


/* ── Reading screen ──────────────────────────────────────────────────────── */
.ecg-record-key { font-family: var(--font-mono); font-size: 1.375rem; font-weight: 640;
  letter-spacing: -0.01em; margin: 0; word-break: break-all; }

/* The metadata that was hidden behind the Details ghost button. */
.ecg-facts { display: flex; flex-wrap: wrap; gap: .1rem 1.6rem; margin: .55rem 0 0; }
.ecg-facts > div { display: flex; flex-direction: column; }
.ecg-facts dt { font-family: var(--font-mono); font-size: .6rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ecg-text-muted); }
.ecg-facts dd { margin: 0; font-size: .875rem; font-weight: 560; }

/* The clinical answer, at answer scale. It used to be one of three identical
   body-copy lines, the other two being provenance. */
.ecg-result { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap;
  background: var(--ecg-surface); border: 1px solid var(--ecg-border);
  border-left: 3px solid var(--ecg-bad-fg); border-radius: var(--ecg-radius-sm);
  padding: .7rem .95rem; margin: .1rem 0 .6rem; }
.ecg-result__code { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700;
  line-height: 1; color: var(--ecg-bad-fg); }
.ecg-result__codes { font-size: .875rem; color: var(--ecg-text-muted); }
.ecg-result__prov { margin-left: auto; text-align: right; font-size: .7rem;
  color: var(--ecg-text-muted); line-height: 1.45; }

/* A platform-admin form has no business framing a clinical read; keep it
   reachable but visually subordinate. */
.ecg-section--admin { opacity: .72; border-top: 1px dashed var(--ecg-border-strong); margin-top: 2rem; }
.ecg-section--admin:hover, .ecg-section--admin:focus-within { opacity: 1; }
.ecg-admin-heading { font-size: .875rem !important; color: var(--ecg-text-muted); }

/* ── Organisation overview (replaces the 9-tile nav grid) ────────────────── */
.ecg-overview { margin-top: 1.4rem; }
.ecg-overview__label { font-family: var(--font-mono); font-size: .64rem; letter-spacing: .11em;
  text-transform: uppercase; color: var(--ecg-text-muted); font-weight: 400; margin: 0 0 .5rem; }
.ecg-overview__cards { display: grid; gap: .6rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.ecg-overview__card { display: flex; flex-direction: column; gap: .1rem;
  background: var(--ecg-surface); border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm); padding: .7rem .85rem; text-decoration: none;
  color: var(--ecg-text); min-height: 78px; }
.ecg-overview__card:hover { border-color: var(--ecg-primary); }
.ecg-overview__cardlabel { font-size: .8rem; font-weight: 600; }
.ecg-overview__value { font-size: 1.4rem; font-weight: 640; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1.2; }
.ecg-overview__hint { font-size: .72rem; color: var(--ecg-text-muted); margin-top: auto; }

/* ── Findings as chips ───────────────────────────────────────────────────── */
/* Replaces one glossary card per finding. A card cost ~65px; with the classical
   engine expanding toward ~200 syndromes a multi-finding record would otherwise
   push the review section a full screen down. The explanation moves into the
   existing `?` hint popover. */
.ecg-findings { display: flex; flex-wrap: wrap; gap: .4rem; margin: .2rem 0 .3rem; }
.ecg-finding { display: inline-flex; align-items: center; gap: .4rem;
  background: var(--ecg-surface); border: 1px solid var(--ecg-border);
  border-left: 2px solid var(--ecg-primary); border-radius: var(--ecg-radius-sm);
  padding: .25rem .55rem; font-size: .8125rem; max-width: 100%; }
.ecg-finding__code { font-family: var(--font-mono); font-size: .72rem; font-weight: 700;
  color: var(--ecg-primary-hover); }
.ecg-finding__name { color: var(--ecg-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:root[data-theme="dark"] .ecg-finding__code { color: var(--ecg-primary); }
@media (prefers-color-scheme: dark) { .ecg-finding__code { color: var(--ecg-primary); } }
.ecg-finding .ecg-hint { margin-left: .1rem; }

/* Human-readable name beside the bare code in the rule-findings table, so the
   table needs no companion glossary block. */
.ecg-finding-name { display: block; font-size: .78rem; color: var(--ecg-text-muted); margin-top: .1rem; }

/* The result band says what the code means, not just the code. */
.ecg-result__say { display: block; font-size: .9375rem; font-weight: 620; line-height: 1.3; }
.ecg-result__also { display: block; font-size: .8125rem; color: var(--ecg-text-muted); margin-top: .15rem; }
.ecg-result__alsocode { font-family: var(--font-mono); font-size: .68rem; opacity: .75; }

/* The safety banner is a BAR, not a paragraph.
   It carried its own max-width:80ch, and the generic `.ecg-main p` measure rule
   (68ch) then beat it on specificity — so on a wide monitor the notice ended
   ~600px short of every other element, giving the page a third right edge. A
   banner should span the column; the SENTENCE keeps the measure. */
.ecg-main p.ecg-analysis-disclaimer { max-width: none; }
.ecg-analysis-disclaimer__text { display: block; max-width: 92ch; }

/* ── One right edge on the reading page ─────────────────────────────────────
   `.ecg-detail-main > .ecg-section:not(.ecg-section--waveform)` pinned every
   section below the trace to 78rem/1248px at ANY viewport while the waveform
   stayed uncapped, so the two diverged as the screen grew: the gap between the
   trace's right edge and the analysis's measured 132px at 1500 and 564px at
   2100. That cap predates the rail — the rail already reserves its own width,
   and prose is capped by the `.ecg-main p` measure rule, so the container does
   not need a second cap to stay readable. */
.ecg-detail-main > .ecg-section:not(.ecg-section--waveform) { max-width: none; }

/* ——— Link subject: a real form crammed into a 320px rail ——————————————
   Stacked blocks with their own gap. The first cut let the checkbox label and
   the submit button sit as inline siblings, so on a narrow rail the label
   wrapped and the button landed on top of its second line. */
.ecg-linkform { margin-top: .75rem; }
.ecg-linkform > summary {
  cursor: pointer;
  font-size: .8125rem;
  color: var(--ecg-primary);
}
.ecg-linkform form {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: .5rem;
}
.ecg-linkform__hint {
  margin: 0;
  font-size: .75rem;
  line-height: 1.4;
  color: var(--ecg-text-muted);
}
.ecg-linkform__field { display: flex; flex-direction: column; gap: .2rem; }
.ecg-linkform__field .bx--select-input,
.ecg-linkform__field .bx--text-input { width: 100%; }
/* The hash is 64 chars in a narrow column — let it shrink rather than overflow. */
.ecg-linkform__field .ecg-mono { font-size: .72rem; }
.ecg-linkform__check {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: .4rem;
  font-size: .75rem;
  line-height: 1.35;
  color: var(--ecg-text-muted);
}
.ecg-linkform__submit { align-self: flex-start; }

/* Engine diagnostics, folded away — superuser only. */
.ecg-skipped { margin-top: .75rem; }
.ecg-skipped > summary {
  cursor: pointer;
  font-size: .8125rem;
  color: var(--ecg-text-muted);
}
.ecg-skipped > summary:hover { color: var(--ecg-text); }

/* ══════════════════════════════════════════════════════════════════════════
   ONBOARDING — the organisation wizard and the per-organisation setup page.
   A long form the operator fills top-down once; steps are numbered because
   the chain really is ordered (nothing downstream works without the policy
   and the payer). Density matches the billing tables, not the ECG viewer.
   ══════════════════════════════════════════════════════════════════════════ */
.ecg-onb { display: flex; flex-direction: column; gap: 2.25rem; }
.ecg-onb-step { padding-top: 1.5rem; border-top: 1px solid var(--ecg-border); }
.ecg-onb-step:first-of-type { border-top: 0; padding-top: 0; }
.ecg-onb-step__head { display: flex; align-items: center; gap: .7rem; margin-bottom: .9rem; }
.ecg-onb-step__num { flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: .78rem; font-weight: 600;
  background: var(--ecg-primary); color: var(--ecg-on-primary, #fff); }
.ecg-onb-step__lede { margin: -.35rem 0 1rem; max-width: 62ch; font-size: var(--text-sm); }
.ecg-onb-optional { font-size: .8rem; font-weight: 400; margin-left: .35rem; }
.ecg-onb-fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.ecg-onb-fieldset > legend { padding: 0; margin-bottom: .5rem; }
.ecg-onb-radios { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: .6rem; }
.ecg-onb-radio { display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; align-items: start;
  padding: .7rem .85rem; border: 1px solid var(--ecg-border); border-radius: var(--ecg-radius-sm);
  background: var(--ecg-surface); cursor: pointer; }
.ecg-onb-radio input { grid-row: span 2; margin-top: .2rem; }
.ecg-onb-radio.is-selected { border-color: var(--ecg-primary); box-shadow: inset 0 0 0 1px var(--ecg-primary); }
.ecg-onb-radio__label { font-weight: 600; font-size: var(--text-sm); }
.ecg-onb-radio__hint { grid-column: 2; color: var(--ecg-text-muted); font-size: var(--text-xs); line-height: 1.4; }
.ecg-onb-checks { display: flex; flex-direction: column; gap: .55rem; }
.ecg-onb-limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 14rem)); gap: 1rem; align-items: end; margin-bottom: 1rem; }
.ecg-onb-limits__hint { grid-column: 1 / -1; margin: 0; }
.ecg-onb-limits.is-off { opacity: .45; }
.ecg-onb-limits.is-off input { pointer-events: none; }
.ecg-onb-pricetable { max-width: 44rem; }
.ecg-onb-pricetable td, .ecg-onb-pricetable th { vertical-align: middle; }
.ecg-onb-price { width: 7rem; text-align: right; font-family: var(--font-mono); }
.ecg-onb-prices.is-trial .ecg-onb-price { color: var(--ecg-text-muted); }
.ecg-onb-sku { font-family: var(--font-mono); font-size: .7rem; }
.ecg-onb-people td { vertical-align: top; }
.ecg-onb-people input, .ecg-onb-people .bx--select { min-width: 12rem; }
.ecg-onb-people tr.has-error input[type=email] { border-color: var(--ecg-bad-fg); }
.ecg-onb-people__foot { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-top: .5rem; }
.ecg-onb-roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .3rem 1.5rem; margin: 1rem 0 0; }
.ecg-onb-roles dt { font-size: var(--text-xs); font-weight: 600; }
.ecg-onb-roles dd { margin: 0; font-size: var(--text-xs); color: var(--ecg-text-muted); }
.ecg-onb-client__fields.is-off { display: none; }
.ecg-onb-error { display: block; color: var(--ecg-bad-fg); font-size: var(--text-xs); margin-top: .3rem; }
.ecg-onb-submit { display: flex; gap: .6rem; align-items: center; padding-top: .5rem; }
.ecg-onb-inline { margin-top: .5rem; }
.ecg-onb-slugchip { font-size: .8rem; font-weight: 400; margin-left: .5rem; }
.ecg-onb-failing { font-size: var(--text-xs); margin-left: .4rem; }
/* Readiness: one line per check, the mark carries state, text carries detail. */
.ecg-onb-checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; max-width: 62rem; }
.ecg-onb-check { display: grid; grid-template-columns: 1.4rem 1fr auto; gap: .5rem; align-items: baseline;
  padding: .45rem .7rem; border-radius: var(--ecg-radius-sm); background: var(--ecg-surface); border: 1px solid var(--ecg-border); }
.ecg-onb-check__mark { font-family: var(--font-mono); font-weight: 700; }
.ecg-onb-check.is-ok .ecg-onb-check__mark { color: var(--ecg-good-fg, #0d7a6b); }
.ecg-onb-check.is-bad { border-color: var(--ecg-bad-fg); }
.ecg-onb-check.is-bad .ecg-onb-check__mark { color: var(--ecg-bad-fg); }
.ecg-onb-check__body { display: flex; flex-wrap: wrap; gap: .15rem .7rem; }
.ecg-onb-check__label { font-weight: 600; font-size: var(--text-sm); }
.ecg-onb-check__detail { color: var(--ecg-text-muted); font-size: var(--text-xs); }
.ecg-onb-check__fix { font-size: var(--text-xs); white-space: nowrap; }
/* Secrets: unmistakably one-off. */
.ecg-onb-reveal { margin: 0 0 2rem; padding: 1rem 1.2rem; border: 1px solid var(--ecg-warn-fg, #9a6b0e);
  border-left-width: 4px; border-radius: var(--ecg-radius-sm); background: var(--ecg-surface); }
.ecg-onb-reveal__table { margin: .75rem 0 .4rem; max-width: 48rem; }
.ecg-onb-reveal__client { margin-top: .9rem; }
.ecg-onb-secret { font-family: var(--font-mono); font-size: .95rem; user-select: all; }
.ecg-onb-tariff__prices { font-size: .78rem; }
.ecg-onb-recipes { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.ecg-onb-filters { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.ecg-onb-filters .bx--text-input { max-width: 18rem; }
.ecg-onb-pagination { display: flex; gap: 1rem; align-items: center; margin-top: .75rem; }

/* Superadmin navigation: stable platform entry, expandable administration. */
.ecg-rail__group { margin: .25rem 0; }
.ecg-rail__group > summary { padding: .65rem .55rem; font-size: .75rem; font-weight: 500; color: var(--ecg-rail-eyebrow); cursor: pointer; }
.ecg-rail__group > summary:hover { color: var(--ecg-rail-active-fg); background: var(--ecg-rail-hover); border-radius: var(--ecg-radius-sm); }
.ecg-rail__group > summary:focus-visible { outline: 2px solid var(--ecg-primary); outline-offset: -2px; }
.ecg-rail__group-items { margin: .25rem 0; }
