/* ==========================================================================
   March Health Eval — design tokens
   --------------------------------------------------------------------------
   These values mirror the MarchAgent clinical design system so the evaluation
   sandbox and the clinical workspace read as one product. The rules that
   matter, and why they are rules rather than preferences:

     * Surfaces are solid. Nothing sits behind content, so every contrast
       figure below is a fixed value rather than a range.
     * Text has three levels. The disabled colour styles switched-off controls
       only, never content -- "not recorded" is a clinical fact, not chrome.
     * Borders are named by the job they do, so the contrast requirement
       travels with the choice. Interactive and focus borders clear 3:1 on
       every surface they can appear on.
     * Depth works differently per theme: dark cards are lighter than the page,
       light cards are carried by their border. Do not unify these.
     * Shadows belong to overlays only -- dialogs, popovers, toasts.
     * The monospace face is a safety tool. Manrope does not mark its zero and
       does not separate l from I, so identifiers, codes, doses, lab values and
       timestamps use JetBrains Mono.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Typefaces ------------------------------------------------------------ */
  --font-sans: Manrope, ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    monospace;

  /* Type scale ----------------------------------------------------------- */
  --text-micro: 11px;      /* badges, chart ticks */
  --text-label: 11px;      /* small capital section labels */
  --text-meta: 12px;       /* metadata, table captions, helper text */
  --text-body: 13px;       /* default text, table cells */
  --text-body-lg: 14px;    /* buttons, prominent text */
  --text-heading: 15px;    /* card and section titles */
  --text-title: 20px;      /* page titles */
  --text-display: 24px;    /* measured values and counts */

  --leading-micro: 1.35;
  --leading-label: 1.4;
  --leading-meta: 1.45;
  --leading-body: 1.55;
  --leading-heading: 1.35;
  --leading-title: 1.25;
  --leading-display: 1.15;

  /* Tracking. Small capitals need air; large text needs less of it than the
     face gives it by default. Everything in between is left alone. */
  --tracking-label: 0.06em;   /* uppercase labels and table headers */
  --tracking-wide: 0.10em;    /* the few widest uppercase eyebrows */
  --tracking-title: -0.012em;
  --tracking-display: -0.02em;

  /* Weights. 600 carries every title in the product; 700 is reserved for the
     few places a number has to win against its own label. */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing -------------------------------------------------------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Corner radius -------------------------------------------------------- */
  --radius-sm: 2px;        /* chips, small badges */
  --radius-md: 4px;        /* buttons, inputs, controls */
  --radius-lg: 6px;        /* cards, dialogs, panels */
  --radius-full: 999px;    /* avatars and progress tracks only */

  /* Icon sizes. One scale, mirrored in js/icons.js. An icon that is not one
     of these five sizes is a mistake, not a choice. */
  --icon-xs: 12px;         /* inside a badge */
  --icon-sm: 14px;         /* beside body text, menu affordances */
  --icon-md: 16px;         /* default: buttons, fields, toasts */
  --icon-lg: 20px;         /* dialog headers, empty states */
  --icon-xl: 24px;         /* page-level status */

  /* Control heights. Buttons, inputs and selects share these, so a filter bar
     built from all three lines up without per-component correction. */
  --control-sm: 28px;
  --control-md: 32px;
  --control-lg: 40px;

  /* Layer scale ---------------------------------------------------------- */
  --z-sticky: 10;
  --z-float: 20;
  --z-popover: 30;
  --z-backdrop: 40;
  --z-dialog: 50;
  --z-toast: 60;

  /* Surfaces — solid, no transparency ------------------------------------ */
  --surface-canvas: #f6f9fa;
  --surface-sunken: #edf1f2;
  --surface-raised: #ffffff;
  --surface-overlay: #ffffff;
  --surface-hover: #eef2f3;        /* rows on a card */
  --surface-hover-sunken: #f9fbfb; /* rows on a well — lighter, per theme */
  --surface-active: #e6ebec;       /* pressed: one step past hover */
  --surface-accent: #e2edf7;

  /* Text ----------------------------------------------------------------- */
  --text-primary: #141c21;
  --text-secondary: #42494e;
  --text-tertiary: #646a6e;
  --text-disabled: #767b7f;   /* switched-off controls only, never content */
  --text-inverse: #ffffff;

  /* Borders -------------------------------------------------------------- */
  --border-hairline: #e5e8ea;      /* dividers inside a card — decorative */
  --border-data: #caced0;          /* table grid lines */
  --border-default: #c1c5c6;       /* card edge — carries the card in light */
  --border-interactive: #828789;   /* inputs and controls — 3:1 minimum */
  --border-focus: #4075aa;         /* focus ring, 2px, 2px offset */
  --border-selected: #4075aa;      /* selection — always with a second cue */

  /* Brand ---------------------------------------------------------------- */
  /* The spectrum and the action gradient are brand assets, not surfaces. They
     carry chrome only -- the mark, a page edge, the primary action -- and
     never sit behind content, so every contrast figure below stays a fixed
     value rather than a range that moves with the artwork. */
  --brand-spectrum: linear-gradient(90deg, #c2256c, #e32d20, #ef9f1a, #f2c113,
    #9ac43f, #35b0b0, #2a72b8, #6a2d8f);
  --brand-action: #1a4f7a;
  --brand-action-hover: #143d5f;
  --brand-action-active: #0f2f4a;
  --brand-action-on: #ffffff;

  --brand: #2a5885;
  --brand-strong: #1d436a;
  --brand-soft: #e8f3ff;
  --brand-border: #a9cdec;
  --brand-on: #ffffff;

  /* Status --------------------------------------------------------------- */
  --ok: #005136;
  --ok-bg: #ddf5e9;
  --ok-border: #96d5b8;
  --ok-on: #ffffff;

  --warn: #663e00;
  --warn-bg: #ffebd2;
  --warn-border: #e8bd86;
  --warn-on: #ffffff;

  --bad: #8a0009;
  --bad-bg: #ffe2de;
  --bad-border: #f2a9a2;
  --bad-on: #ffffff;

  --info: #2a5885;
  --info-bg: #e8f3ff;
  --info-border: #a9cdec;

  /* Chart series — deliberately none of them red or amber ---------------- */
  --chart-1: #2a5885;
  --chart-2: #0d6d68;
  --chart-3: #6a47a3;
  --chart-4: #98226f;
  --chart-5: #4e5a66;
  --chart-6: #3b4a9e;

  /* Shadows — overlays only ---------------------------------------------- */
  --shadow-sm: 0 1px 2px rgba(20, 28, 33, 0.06);
  --shadow-md: 0 4px 12px rgba(20, 28, 33, 0.10);
  --shadow-lg: 0 12px 32px rgba(20, 28, 33, 0.16);
  --scrim: rgba(20, 28, 33, 0.55);
}

/* Dark theme.
   Two blocks on purpose: the media query serves anyone who has not chosen,
   the attribute block lets an explicit choice win in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --surface-canvas: #0f1518;
    --surface-sunken: #070c10;
    --surface-raised: #22272b;
    --surface-overlay: #22272b;
    --surface-hover: #191e21;        /* darker in dark mode — not a mistake */
    --surface-hover-sunken: #12181c; /* lighter here, because the well is darker */
    --surface-active: #10161a;
    --surface-accent: #012342;

    --text-primary: #eff2f4;
    --text-secondary: #babec1;
    --text-tertiary: #8e9397;
    --text-disabled: #767b7f;
    --text-inverse: #0f1518;

    --border-hairline: #202527;
    --border-data: #373b3e;
    --border-default: #2d3134;
    --border-interactive: #6d7276;
    --border-focus: #6da9e7;
    --border-selected: #6da9e7;

    --brand-action: #6da9e7;
    --brand-action-hover: #89bcee;
    --brand-action-active: #a5cdf3;
    --brand-action-on: #08131d;

    --brand: #6da9e7;
    --brand-strong: #9ac6f0;
    --brand-soft: #1c2b3a;
    --brand-border: #2f4a63;
    --brand-on: #08131d;

    --ok: #84d1af;
    --ok-bg: #142f24;
    --ok-border: #2b5c45;
    --ok-on: #08130d;

    --warn: #f1c17f;
    --warn-bg: #3c2a0e;
    --warn-border: #6d5222;
    --warn-on: #1a1204;

    --bad: #f7857d;
    --bad-bg: #421c19;
    --bad-border: #77352f;
    --bad-on: #1c0705;

    --info: #6da9e7;
    --info-bg: #1c2b3a;
    --info-border: #2f4a63;

    --chart-1: #6da9e7;
    --chart-2: #4fc0b4;
    --chart-3: #b49bea;
    --chart-4: #f08fc9;
    --chart-5: #9aa5ae;
    --chart-6: #8f9df0;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.38);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.48);
    --scrim: rgba(0, 0, 0, 0.62);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-canvas: #0f1518;
  --surface-sunken: #070c10;
  --surface-raised: #22272b;
  --surface-overlay: #22272b;
  --surface-hover: #191e21;
  --surface-hover-sunken: #12181c;
  --surface-active: #10161a;
  --surface-accent: #012342;

  --text-primary: #eff2f4;
  --text-secondary: #babec1;
  --text-tertiary: #8e9397;
  --text-disabled: #767b7f;
  --text-inverse: #0f1518;

  --border-hairline: #202527;
  --border-data: #373b3e;
  --border-default: #2d3134;
  --border-interactive: #6d7276;
  --border-focus: #6da9e7;
  --border-selected: #6da9e7;

  --brand-action: #6da9e7;
  --brand-action-hover: #89bcee;
  --brand-action-active: #a5cdf3;
  --brand-action-on: #08131d;

  --brand: #6da9e7;
  --brand-strong: #9ac6f0;
  --brand-soft: #1c2b3a;
  --brand-border: #2f4a63;
  --brand-on: #08131d;

  --ok: #84d1af;
  --ok-bg: #142f24;
  --ok-border: #2b5c45;
  --ok-on: #08130d;

  --warn: #f1c17f;
  --warn-bg: #3c2a0e;
  --warn-border: #6d5222;
  --warn-on: #1a1204;

  --bad: #f7857d;
  --bad-bg: #421c19;
  --bad-border: #77352f;
  --bad-on: #1c0705;

  --info: #6da9e7;
  --info-bg: #1c2b3a;
  --info-border: #2f4a63;

  --chart-1: #6da9e7;
  --chart-2: #4fc0b4;
  --chart-3: #b49bea;
  --chart-4: #f08fc9;
  --chart-5: #9aa5ae;
  --chart-6: #8f9df0;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.48);
  --scrim: rgba(0, 0, 0, 0.62);
}

/* Names the rest of this stylesheet still uses, pointed at the tokens above.
   Keeping them is what lets the whole app move theme in one place. */
:root {
  --bg: var(--surface-canvas);
  --surface: var(--surface-raised);
  --surface-soft: var(--surface-sunken);
  --surface-blue: var(--brand-soft);
  --text: var(--text-primary);
  --text-soft: var(--text-secondary);
  --text-muted: var(--text-tertiary);
  --border: var(--border-default);
  --border-strong: var(--border-interactive);
  --primary: var(--brand);
  --primary-dark: var(--brand-strong);
  --primary-soft: var(--brand-soft);
  --success: var(--ok);
  --success-soft: var(--ok-bg);
  --danger: var(--bad);
  --danger-soft: var(--bad-bg);
  --warning: var(--warn);
  --warning-soft: var(--warn-bg);
  --sidebar: var(--surface-raised);
  --sidebar-soft: var(--surface-sunken);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-canvas);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  font-synthesis-weight: none;
}

/* Identifiers, codes, doses, lab values and timestamps. Manrope leaves its
   zero unmarked and gives l and I the same shape, so anything a reader has to
   transcribe or compare down a column is set in the monospace face with
   fixed-width digits. */
code,
kbd,
samp,
.mono,
.mrn,
.code-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.92em;
}

/* Any number that appears in a column lines up, in either face. */
td,
th,
.metric strong,
.run-stats strong,
.rubric-weight,
.score-table td {
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* The rail is a page-level surface, not a dark slab: it carries the same
   canvas colour as the page and separates with a border on its inner edge.
   280px is on the agreed list of panel widths. */
/* The rail stays in view while a long page scrolls -- Judge Settings runs to
   several thousand pixels, and scrolling it used to take the navigation away.
   It is a column, so navigation takes the middle and the account sits at the
   foot. */
aside {
  position: sticky;
  top: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  width: 280px;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-canvas);
  border-right: 1px solid var(--border-default);
  color: var(--text-primary);
  padding: var(--space-5) var(--space-4) var(--space-4);
  box-sizing: border-box;
  flex-shrink: 0;
}

aside > .environment-badge {
  align-self: flex-start;
}

/* The rail's inner edge used to carry a two-pixel rainbow. It meant nothing,
   and a saturated decorative stripe is what a serious clinical tool cannot
   afford: colour here has to be reserved for state. A structural hairline
   does the one job the stripe actually did, which is to separate the rail
   from the content. */
aside::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 1px;
  background: var(--border-default);
}

/* The same lockup the entry screens carry: mark, then owner, then product. */
.rail-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.rail-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.rail-eyebrow {
  margin: 0;
  color: var(--text-tertiary);
  font-size: var(--text-micro);
  line-height: var(--leading-micro);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

aside h1 {
  margin: 0;
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

aside p {
  color: var(--text-tertiary);
  font-size: var(--text-body);
  margin: 0 0 var(--space-5);
  line-height: var(--leading-body);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.menu button {
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  margin: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  font-family: inherit;
  transition: background 0.12s ease, color 0.12s ease;
}

.menu button:hover {
  background: var(--surface-hover-sunken);
  color: var(--text-primary);
}

/* Selection carries a marker on the leading edge as well as a fill, so it
   still reads with colour removed. */
.menu button.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: var(--weight-medium);
  box-shadow: inset 2px 0 0 var(--border-selected);
}

.menu button:active {
  background: var(--surface-active);
}

.menu-group {
  margin-bottom: var(--space-2);
}

.menu-group-title,
.menu-main {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-label);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  font-weight: var(--weight-semibold);
  font-family: inherit;
  cursor: pointer;
}

.menu-group-title:hover,
.menu-main:hover {
  background: var(--surface-active);
}

.menu-subitems {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-2) 0 0 var(--space-3);
  padding-left: var(--space-3);
  border-left: 1px solid var(--border-hairline);
}

/* The collapsed state is defined once, further down, where the animation that
   needs display:flex lives. A second .collapsed rule setting display:none used
   to sit here; it lost to that one and misdescribed the behaviour. */

main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  box-sizing: border-box;
  background: var(--surface-canvas);
}

/* Past this width the margins grow rather than the content. */
main > section {
  max-width: 1760px;
}

section {
  display: none;
}

section.active {
  display: block;
}

.page-title {
  font-weight: var(--weight-bold);
  margin: 0 0 var(--space-2);
  font-size: var(--text-display);
  line-height: var(--leading-display);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-subtitle {
  margin: 0 0 var(--space-5);
  color: var(--text-secondary);
  font-size: var(--text-body-lg);
  max-width: 74ch;
}

.toolbar {
  margin: var(--space-4) 0;
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
}

.compact-toolbar {
  margin: 0;
}

/* One primary action per screen; everything else is quieter. Buttons carry no
   shadow -- depth is reserved for things that genuinely float. */
button.primary,
button.secondary {
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-body);
  transition: background 0.12s ease, border-color 0.12s ease;
}

button.primary {
  background: var(--brand-action);
  border-color: transparent;
  color: var(--brand-action-on);
  font-weight: var(--weight-medium);
}

button.primary:hover {
  background: var(--brand-action-hover);
  border-color: transparent;
}

button.secondary {
  background: var(--surface-raised);
  border-color: var(--border-interactive);
  color: var(--text-primary);
}

button.secondary:hover {
  background: var(--surface-hover);
}

button.primary:active {
  background: var(--brand-action-hover);
}

button.secondary:active {
  background: var(--surface-active);
}

/* Disabled controls keep opacity at 100%: fading them would drag their
   contrast to an unpredictable value. */
button:disabled {
  background: var(--surface-sunken) !important;
  border-color: var(--border-default) !important;
  color: var(--text-disabled) !important;
  box-shadow: none !important;
  opacity: 1;
  cursor: not-allowed;
}

.case-list,
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.grid,
.rubric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* In light mode the border carries the card; in dark mode the lighter surface
   does. Neither gets a shadow -- in a dense layout stacked shadows blur small
   text and read as an unfinished interface. */
.card {
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
}

.case-card,
.result-card {
  width: 100%;
  box-sizing: border-box;
}

.case-header,
.case-selection-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  margin-bottom: var(--space-4);
}

.card h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  letter-spacing: -0.014em;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.card h4 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-body-lg);
  color: var(--text-secondary);
}

/* Status is never colour alone: each badge carries a mark before its label, so
   the meaning survives greyscale and colour blindness. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--brand-border);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  line-height: var(--leading-micro);
  margin: var(--space-1) var(--space-1) var(--space-2) 0;
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-label);
}

.badge::before {
  content: "\25CF";
  font-size: 0.8em;
  line-height: var(--leading-body);
}

.badge.pass {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.badge.pass::before {
  content: "\2713";
}

.badge.fail {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad-border);
}

.badge.fail::before {
  content: "\2715";
}

.badge.warning {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.badge.warning::before {
  content: "\26A0";
}

.badge.gray {
  background: var(--surface-sunken);
  color: var(--text-secondary);
  border-color: var(--border-default);
}

.badge.gray::before {
  content: "\2013";
}

.clinical-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  white-space: pre-wrap;
  line-height: var(--leading-body);
  max-height: 520px;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text-secondary);
}

.agent-response {
  background: var(--surface-raised);
  border-left: 3px solid var(--border-selected);
}

details {
  margin-top: var(--space-4);
}

summary {
  cursor: pointer;
  font-weight: var(--weight-medium);
  color: var(--primary-dark);
  margin-bottom: var(--space-3);
}

pre {
  background: var(--surface-sunken);
  color: var(--text-secondary);
  border: 1px solid var(--border-hairline);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 420px;
  font-family: var(--font-mono);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

pre code {
  font-size: inherit;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.metric {
  background: var(--surface);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.metric strong {
  display: block;
  font-size: var(--text-display);
  margin-top: var(--space-2);
  letter-spacing: -0.03em;
}

.pill-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.pill {
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-micro);
  line-height: var(--leading-micro);
  border: 1px solid;
}

.pill.good {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.pill.bad {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad-border);
}

.pill.focus {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--brand-border);
}

.pill.warning {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.empty-note {
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-3) 0;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-3);
  overflow: hidden;
  border-radius: var(--radius-md);
  font-size: var(--text-body-lg);
}

.score-table th,
.score-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.score-table th {
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.score-bar {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  overflow: hidden;
  width: 100%;
}

.score-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
}

.rubric-card {
  border-top: 5px solid var(--primary);
}

.rubric-weight {
  font-size: var(--text-display);
  font-weight: var(--weight-bold);
  color: var(--primary);
  margin: var(--space-3) 0;
  letter-spacing: -0.03em;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field label {
  font-weight: var(--weight-medium);
  font-size: var(--text-body);
  color: var(--text-secondary);
}

/* Form controls had their own typeface -- Inter, falling back to Arial --
   while the rest of the product is set in Manrope. Every field in the
   application was therefore in a different face from its own label, which is
   most of why the forms read as assembled rather than designed. They also
   removed the focus outline and drew a coloured glow instead, giving the
   product two different focus treatments depending on which control you
   reached. Both now follow the shared rule. */
.field input,
.field textarea,
.field select {
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  font-family: var(--font-sans);
  line-height: var(--leading-body);
  color: var(--text-primary);
  background: var(--surface-raised);
}

.field input:hover:not(:disabled),
.field textarea:hover:not(:disabled),
.field select:hover:not(:disabled) {
  border-color: var(--text-tertiary);
}

.field input:focus-visible,
.field textarea:focus-visible,
.field select:focus-visible {
  border-color: var(--border-focus);
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-tertiary);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.full-width {
  grid-column: 1 / -1;
}

.save-status {
  margin-top: var(--space-3);
  color: var(--success);
  font-weight: var(--weight-medium);
}

.generator-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.checkbox-card {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  text-align: left;
}

.checkbox-card:hover {
  background: var(--surface-hover);
  border-color: var(--brand-border);
}

.checkbox-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: var(--space-1) 0 0;
  padding: 0;
  justify-self: start;
  align-self: start;
  accent-color: var(--primary);
}

.checkbox-card div,
.checkbox-card-text {
  min-width: 0;
  text-align: left;
}

.checkbox-card strong,
.checkbox-card-text strong {
  display: block;
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  line-height: var(--leading-body);
  margin-bottom: var(--space-1);
}

.checkbox-card span,
.checkbox-card-text span {
  display: block;
  color: var(--text-soft);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  word-break: break-word;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.difficulty-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.difficulty-card strong {
  font-size: var(--text-body-lg);
}

.difficulty-card p {
  color: var(--text-soft);
  margin: var(--space-2) 0 0;
  line-height: var(--leading-body);
  font-size: var(--text-body-lg);
}

.claims-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.claim-card {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.claim-card h4 {
  margin-top: 0;
}

.small-note {
  color: var(--text-soft);
  font-size: var(--text-body-lg);
  margin-top: -var(--space-1);
}

.status {
  margin: var(--space-3) 0;
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.run-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--space-5);
  align-items: start;
}

.run-case-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  max-height: 560px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: var(--space-1);
}

.run-case-card {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.run-case-card:hover {
  background: var(--surface-hover);
  border-color: var(--brand-border);
}

.run-case-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: var(--space-1) 0 0;
  accent-color: var(--primary);
}

.run-case-card strong {
  display: block;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  font-size: var(--text-body-lg);
}

.run-case-card p {
  margin: var(--space-2) 0 0;
  color: var(--text-secondary);
  line-height: var(--leading-body);
  font-size: var(--text-body-lg);
}

.run-case-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.run-case-meta span {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.progress-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: var(--space-1);
  margin-bottom: var(--space-4);
}

.progress-item {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
  line-height: var(--leading-body);
  font-size: var(--text-body-lg);
}

.progress-item.success {
  border-color: var(--ok-border);
  background: var(--ok-bg);
  color: var(--ok);
}

.progress-item.error {
  border-color: var(--bad-border);
  background: var(--bad-bg);
  color: var(--bad);
}

.progress-item.info {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
}

.trace-details {
  margin-top: var(--space-4);
}

.run-history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

#runsBox {
  margin-bottom: var(--space-5);
}

#runsBox .run-history-grid {
  margin-top: 0;
}

#runsBox::-webkit-scrollbar {
  width: 8px;
}

#runsBox::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

#runsBox::-webkit-scrollbar-track {
  background: transparent;
}
.run-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: all 0.15s ease;
}

.run-card:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.run-card-top {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  margin-bottom: var(--space-4);
}

.run-title {
  font-size: var(--text-heading);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
  font-weight: var(--weight-semibold);
}

.run-date {
  color: var(--text-muted);
  font-size: var(--text-body);
}

.run-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}

.run-stats div {
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
  border: 1px solid var(--border-hairline);
}

.run-stats span {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-label);
  margin-bottom: var(--space-1);
}

.run-stats strong {
  color: var(--text-primary);
  font-size: var(--text-display);
}

.run-card-footer {
  margin-top: var(--space-4);
  color: var(--primary);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

.judge-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

.judge-card {
  background: var(--surface);
  color: var(--text);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.judge-card h3 {
  margin-bottom: var(--space-3);
}

/* The control border is the interactive tier, solved against every surface a
   control can sit on -- not the decorative card border. */
textarea,
select,
input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  margin-bottom: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-interactive);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body-lg);
  line-height: var(--leading-body);
}

textarea:focus,
select:focus,
input:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-color: var(--border-focus);
}

textarea:disabled,
select:disabled,
input:disabled {
  background: var(--surface-sunken);
  color: var(--text-disabled);
  border-color: var(--border-default);
  opacity: 1;
  cursor: not-allowed;
}

button,
select {
  font-family: var(--font-sans);
}

/* Every working control says so. */
button:not(:disabled),
summary,
label,
[role="button"] {
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin-bottom: 0;
  padding: 0;
  accent-color: var(--primary);
}

/* Density is correct in a clinical table: rows stay tight, numbers line up,
   and the header stays put when the table runs past one screen. */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-2);
  background: var(--surface-raised);
  border: 1px solid var(--border-data);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-size: var(--text-body);
}

th,
td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-hairline);
  text-align: left;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--surface-sunken);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  border-bottom: 1px solid var(--border-data);
}

/* Text left, numbers right. */
td.num,
th.num,
td[data-numeric],
th[data-numeric] {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tbody tr:hover td {
  background: var(--surface-hover);
}

@media (max-width: 1100px) {
  .generator-layout,
  .run-layout {
    grid-template-columns: 1fr;
  }

  .difficulty-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1000px) {
  body {
    flex-direction: column;
    height: auto;
  }

  /* #appView is the row that holds the rail and the page, so it is the one
     that has to stack. The rail then sits above the page at its own height
     rather than filling the viewport. */
  .app-view {
    flex-direction: column;
  }

  aside {
    position: static;
    width: 100%;
    height: auto;
    overflow-y: visible;
    border-right: 0;
    border-bottom: 1px solid var(--border-default);
  }

  main {
    padding: var(--space-5);
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .case-header,
  .case-selection-header,
  .run-card-top {
    flex-direction: column;
  }

  .run-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  main {
    padding: var(--space-4);
  }

  .page-title {
    font-size: var(--text-title);
  }

  .card {
    padding: var(--space-4);
  }

  .checkbox-grid,
  .grid,
  .rubric-grid,
  .run-history-grid {
    grid-template-columns: 1fr;
  }
}

.run-layout-single {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  align-items: start;
}

.run-action-bar {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.run-action-bar strong {
  color: var(--text-primary);
  font-size: var(--text-heading);
}

.run-action-bar p {
  margin: var(--space-1) 0 0;
}

.run-main-button {
  min-width: 190px;
  font-weight: var(--weight-medium);
}

@media (max-width: 760px) {
  .run-action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .run-main-button {
    width: 100%;
  }
}

.clinical-review-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.clinical-review-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.clinical-review-row:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.clinical-review-title {
  font-weight: var(--weight-medium);
  color: var(--text);
}

.clinical-review-badges,
.clinical-review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.clinical-review-badges {
  justify-content: flex-end;
}

.clinical-review-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.clinical-review-form-card {
  border: 1px solid var(--primary-soft);
}

.clinical-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  white-space: pre-wrap;
  overflow-x: auto;
}

.agent-response {
  max-height: 520px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* auto-fit, not a fixed pair: two 220px columns plus the gap cannot fit a
   phone, and this rule overrode the responsive one above. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin: var(--space-4) 0;
}

.form-grid label,
.clinical-review-form-card label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.form-grid input,
.form-grid select,
.clinical-review-form-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3);
  font: inherit;
  background: var(--surface-raised);
}

.clinical-checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.checkbox-line {
  flex-direction: row !important;
  align-items: center;
  font-weight: var(--weight-medium) !important;
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.checkbox-line input {
  width: auto;
}

.clinical-alert {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: var(--weight-medium);
}

.success-note {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--success-soft);
  color: var(--success);
  font-weight: var(--weight-medium);
}

.muted {
  color: var(--text-muted);
  font-size: var(--text-body);
  margin-top: var(--space-1);
}

@media (min-width: 1200px) {
  .clinical-review-detail {
    grid-template-columns: 1fr 1fr;
  }

  .clinical-review-form-card {
    grid-column: 1 / -1;
  }
}

#clinicalReviewQueueBox {
  margin-top: var(--space-4);
}

#clinicalReviewDetailBox {
  margin-top: var(--space-5);
}

#clinicalReviewQueueBox::-webkit-scrollbar {
  width: 8px;
}

#clinicalReviewQueueBox::-webkit-scrollbar-track {
  background: var(--surface-soft);
  border-radius: var(--radius-full);
}

#clinicalReviewQueueBox::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

#clinicalReviewQueueBox::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.compact-filter-bar {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin: var(--space-4) 0;
  padding: var(--space-4);
  background: var(--surface-soft);
}

.filter-bar .field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.filter-bar label {
  font-weight: var(--weight-medium);
  color: var(--text);
  font-size: var(--text-body);
}

.filter-bar select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3);
  font: inherit;
  background: var(--surface-raised);
}

@media (max-width: 900px) {
  .filter-bar,
  .compact-filter-bar {
    grid-template-columns: 1fr;
  }
}

#pageHost > section {
  display: none !important;
}

#pageHost > section.active {
  display: block !important;
}

.menu-group-title {
  margin-top: var(--space-2);
}

.menu-group-title.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  box-shadow: inset 2px 0 0 var(--border-selected);
}

.menu-arrow {
  font-size: var(--text-body);
}

.menu-subitems {
  overflow: hidden;
  transition: max-height 0.18s ease, opacity 0.18s ease, visibility 0s;
  max-height: 320px;
  opacity: 1;
  visibility: visible;
}

/* Collapsing has to animate, so the group keeps display:flex and closes by
   height. That left every item in a closed group reachable by Tab and
   announced by a screen reader: focus landed on an invisible control with no
   way to see where it had gone, and pointer-events:none meant a keyboard user
   could focus an item they could not then activate by clicking.

   visibility:hidden takes them out of the tab order and the accessibility
   tree. It is applied at the end of the close (a zero-length transition
   delayed by the animation's duration) and removed instantly on open, so the
   height animation still plays in both directions. */
.menu-subitems.collapsed {
  display: flex;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-left-color: transparent;
  pointer-events: none;
  transition: max-height 0.18s ease, opacity 0.18s ease,
    visibility 0s linear 0.18s;
}

.rubric-card h3,
.judge-card h3,
#rubricPage h3 {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  line-height: var(--leading-body);
}

/* ===== FIX: Rubric title overflow ===== */

#rubricPage .rubric-card h3 {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* critical fix for flexbox */
#rubricPage .rubric-card {
  min-width: 0;
}

#rubricPage .rubric-card h3 {
  min-width: 0;
}

/* ===== FIX: Active Rubric long name overflow ===== */

#rubricPage .metric {
  min-width: 0;
  overflow: hidden;
}

#rubricPage .metric strong {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: var(--leading-body);
}

/* ---------- Loading states ---------- */

.loading-state {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--text-body-lg);
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--border-hairline);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

.loading-spinner.large {
  width: 32px;
  height: 32px;
  border-width: 4px;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.blocking-loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
  z-index: 9999;
}

.blocking-loading-card {
  min-width: 220px;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

.selected-run-card {
  border: 2px solid var(--border-focus);
  background: var(--brand-soft);
}

.selected-clinical-review-row {
  border: 2px solid var(--border-focus);
  background: var(--brand-soft);
}

.agent-response {
  white-space: pre-wrap;
}

.clinical-box {
  max-height: 420px;
  overflow: auto;
  overscroll-behavior: contain;
}

details .clinical-box {
  margin-top: var(--space-3);
}

.log-box {
  background: var(--surface-sunken);
  color: var(--text-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  max-height: 420px;
  overflow: auto;
  overscroll-behavior: contain;
  white-space: pre-wrap;
  font-family: monospace;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  margin-top: var(--space-3);
  border: 1px solid var(--border-hairline);
}

.log-box:empty::before {
  content: "No logs yet.";
  color: var(--text-tertiary);
}

#generatorPatientsBox,
#generatorCaseTypesBox {
}

#generatorPatientsBox::-webkit-scrollbar,
#generatorCaseTypesBox::-webkit-scrollbar {
  width: 8px;
}

#generatorPatientsBox::-webkit-scrollbar-thumb,
#generatorCaseTypesBox::-webkit-scrollbar-thumb {
  background: var(--border-data);
  border-radius: var(--radius-full);
}

#generatorPatientsBox::-webkit-scrollbar-track,
#generatorCaseTypesBox::-webkit-scrollbar-track {
  background: var(--surface-sunken);
}

button.danger {
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: var(--bad);
  color: var(--bad-on);
  cursor: pointer;
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-body);
}

button.danger:hover {
  background: var(--bad);
  filter: brightness(0.92);
}

.generated-file-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.generated-file-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.generated-file-row code {
  font-size: var(--text-body);
  word-break: break-all;
}

.download-link {
  color: var(--brand-on);
  background: var(--primary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  text-decoration: none;
  flex-shrink: 0;
}

.download-link:hover {
  background: var(--primary-dark);
}

.generator-option-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);

  padding: var(--space-4) var(--space-4);

  border: 1px solid var(--border);
  border-radius: var(--radius-md);

  background: linear-gradient(180deg, var(--surface-sunken), var(--surface-sunken));

  min-height: 72px;
}

.generator-option-row:hover {
  border-color: var(--brand-border);
  background: var(--surface-hover);
}

.generator-option-row input[type="checkbox"] {
  width: 18px;
  height: 18px;

  margin-top: var(--space-1);

  accent-color: var(--primary);

  flex-shrink: 0;

  cursor: pointer;
}

.generator-option-content {
  display: flex;
  flex-direction: column;

  cursor: pointer;
}

.generator-option-content strong {
  font-size: var(--text-body-lg);
  line-height: var(--leading-body);

  color: var(--text);
}

.generator-option-content span {
  margin-top: var(--space-1);

  font-size: var(--text-body);
  line-height: var(--leading-body);

  color: var(--text-soft);
}

.clinical-timeline-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: var(--space-5);
  align-items: start;
  margin-top: var(--space-5);
}

.clinical-timeline-list {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  max-height: 720px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: var(--space-2);
}

.clinical-timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: var(--space-3);
}

.clinical-timeline-item::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 22px;
  bottom: -18px;
  width: 2px;
  background: var(--border);
}

.clinical-timeline-item:last-child::before {
  display: none;
}

.clinical-timeline-dot {
  width: 14px;
  height: 14px;
  margin-top: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  z-index: 1;
}

.clinical-timeline-content {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

@media (max-width: 1100px) {
  .clinical-timeline-layout {
    grid-template-columns: 1fr;
  }
}

.patient-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.patient-summary-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.patient-summary-tile span {
  display: block;
  color: var(--text-soft);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

.patient-summary-tile strong {
  display: block;
  color: var(--text);
  font-size: var(--text-body-lg);
  word-break: break-word;
}

.patient-summary-tile.wide {
  grid-column: span 2;
}

.timeline-data-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.timeline-evidence-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-top: var(--space-2);
}

.timeline-evidence-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.timeline-evidence-header h4 {
  margin: 0 0 var(--space-1);
}

.timeline-evidence-panel select {
  width: 100%;
  min-height: 150px;
}

.timeline-clinical-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.timeline-clinical-summary-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.timeline-clinical-summary-panel h4 {
  margin: 0 0 var(--space-3);
}

.timeline-resource-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.timeline-resource-item {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.timeline-resource-item strong {
  display: block;
  color: var(--text);
  font-size: var(--text-body-lg);
  margin-bottom: var(--space-1);
}

.timeline-resource-item span {
  color: var(--text-soft);
  font-size: var(--text-body);
}

.patient-timeline-scroll {
  max-height: 520px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: var(--space-2);
}

.page-header-with-action {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  margin-bottom: var(--space-5);
}

.page-header-with-action .page-subtitle {
  margin-bottom: 0;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.card-title-row h3 {
  margin: 0 0 var(--space-1);
}

.compact-action-button {
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}

.ai-drafted-field {
  border-color: var(--primary) !important;
  background: var(--primary-soft) !important;
}

.ai-drafted-container {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.ai-draft-success {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-weight: var(--weight-medium);
}

.clinical-event-card {
  border-left: 5px solid var(--border-default);
}

.clinical-event-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.clinical-event-type-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.clinical-event-type-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

.clinical-event-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.clinical-event-summary-row {
  border-bottom: 1px solid var(--border-hairline);
  padding: var(--space-3) 0;
}

.clinical-event-summary-row.wide {
  grid-column: 1 / -1;
}

.clinical-event-summary-row span {
  display: block;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.clinical-event-summary-row strong {
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

.clinical-event-technical-details {
  margin-top: var(--space-4);
}

.clinical-event-technical-details > summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: var(--weight-medium);
}

.clinical-event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

.clinical-event-meta span {
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.clinical-event-card {
  border-left: 5px solid var(--border-default);
}

.clinical-event-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.clinical-event-type-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.clinical-event-type-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

.clinical-event-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.clinical-event-summary-row {
  border-bottom: 1px solid var(--border-hairline);
  padding: var(--space-3) 0;
}

.clinical-event-summary-row.wide {
  grid-column: 1 / -1;
}

.clinical-event-summary-row span {
  display: block;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.clinical-event-summary-row strong {
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

.clinical-event-technical-details {
  margin-top: var(--space-4);
}

.clinical-event-technical-details > summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: var(--weight-medium);
}

.clinical-event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

.clinical-event-meta span {
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.patient-snapshot-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-3);
}

.snapshot-reference-list {
  display: grid;
  gap: var(--space-2);
}

.snapshot-reference-list span {
  display: block;
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

.snapshot-reference-list strong {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.clinical-data-focus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.clinical-focus-panel {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.clinical-focus-panel h4 {
  margin: 0 0 var(--space-3) 0;
  font-size: var(--text-body-lg);
  color: var(--text-primary);
}

.clinical-focus-item {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border-hairline);
}

.clinical-focus-item:first-of-type {
  border-top: none;
  padding-top: 0;
}

.clinical-focus-item strong {
  display: block;
  font-size: var(--text-body-lg);
  color: var(--text-primary);
}

.clinical-focus-item span {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-label);
  color: var(--text-tertiary);
}

.clinical-studio-divider {
  height: 1px;
  background: var(--brand-soft);
  margin: var(--space-5) 0;
}

.clinical-timeline-explorer-header {
  margin: var(--space-3) 0 var(--space-3) 0;
}

.clinical-studio-summary-line {
  color: var(--text);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

.clinical-studio-controls.compact {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 180px 200px 160px;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-4);
  align-items: center;
}

.clinical-studio-controls.compact input,
.clinical-studio-controls.compact select,
.clinical-studio-controls.compact button {
  margin: 0;
}

.clinical-studio-controls.compact select {
  height: 44px;
  min-height: 44px;
  width: 100%;
  font-size: var(--text-body);
}

.clinical-studio-search-control {
  position: relative;
  width: 100%;
}

.clinical-studio-search-control input {
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding-right: var(--space-7);
  margin: 0;
  font-size: var(--text-body);
}

.clinical-studio-search-button {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--brand-on);
  cursor: pointer;
  font-size: var(--text-body-lg);
  line-height: 1;
}

.clinical-timeline-explorer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2) var(--space-1) 0;
}

.clinical-studio-tile {
  display: grid;
  gap: var(--space-2);
  min-height: 96px;
  padding: var(--space-3);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
}

.clinical-studio-tile-top {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: center;
}

.clinical-studio-tile-top span:first-child {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
}

.clinical-studio-tile .badge {
  font-size: var(--text-label);
  padding: var(--space-1) var(--space-2);
  margin: 0;
}

.clinical-studio-tile strong {
  font-size: var(--text-body-lg);
  color: var(--text-primary);
  line-height: var(--leading-body);
}

.clinical-studio-tile p {
  margin: 0;
  font-size: var(--text-label);
  color: var(--text-tertiary);
  line-height: var(--leading-label);
}

.clinical-studio-tile-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
}

.clinical-studio-tile.clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.clinical-studio-tile.clickable:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.clinical-studio-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--brand-on);
  font-weight: var(--weight-bold);
  line-height: 1;
}

@media (max-width: 900px) {
  .clinical-studio-controls.compact {
    grid-template-columns: 1fr 1fr;
  }

  .clinical-timeline-explorer-list {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

.clinical-resource-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.clinical-resource-modal {
  width: min(920px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
}

.clinical-resource-modal-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.clinical-resource-modal-header h3 {
  margin: var(--space-2) 0 var(--space-1);
  font-size: var(--text-title);
  line-height: var(--leading-display);
}

.clinical-resource-modal-body {
  display: grid;
  gap: var(--space-4);
  padding-top: var(--space-4);
}

.clinical-resource-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.clinical-resource-section h4 {
  margin: 0 0 var(--space-3);
}

.clinical-resource-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.clinical-resource-detail-row {
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  padding: var(--space-3) var(--space-3);
}

.clinical-resource-detail-row.wide {
  grid-column: 1 / -1;
}

.clinical-resource-detail-row span {
  display: block;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.clinical-resource-detail-row strong {
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.clinical-resource-action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

@media (max-width: 760px) {
  .clinical-resource-modal {
    padding: var(--space-4);
  }

  .clinical-resource-modal-header {
    flex-direction: column;
  }

  .clinical-resource-detail-grid {
    grid-template-columns: 1fr;
  }
}

.clinical-resource-tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-3);
}

.clinical-resource-tab {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--muted);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.clinical-resource-tab.active {
  background: var(--brand);
  color: var(--brand-on);
  border-color: var(--brand);
}

.clinical-resource-tab-panel {
  display: none;
}

.clinical-resource-tab-panel.active {
  display: grid;
  gap: var(--space-4);
}

.clinical-resource-modal.busy {
  position: relative;
}

.clinical-resource-modal-busy {
  position: sticky;
  top: 0;
  z-index: 5;

  display: flex;
  align-items: center;
  gap: var(--space-3);

  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);

  border: 1px solid var(--brand-border);
  border-radius: var(--radius-lg);
  background: var(--brand-soft);
  color: var(--brand);

  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

.result-patient-context-pill {
  cursor: pointer;
  border: none;
  margin-top: 0;
}

.result-patient-context-pill:hover {
  filter: brightness(0.95);
  text-decoration: underline;
}

.result-patient-context-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.result-patient-context-modal {
  width: min(980px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
}

.result-patient-context-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.result-patient-context-header h3 {
  margin: var(--space-2) 0 var(--space-1);
  font-size: var(--text-title);
  line-height: var(--leading-display);
}

.result-patient-context-body {
  display: grid;
  gap: var(--space-4);
  padding-top: var(--space-4);
}

.result-patient-context-tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-3);
}

.result-patient-context-tab {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--muted);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.result-patient-context-tab.active {
  background: var(--brand);
  color: var(--brand-on);
  border-color: var(--brand);
}

.result-patient-context-tab-panel {
  display: none;
}

.result-patient-context-tab-panel.active {
  display: grid;
  gap: var(--space-4);
}

.result-patient-context-grid,
.result-patient-context-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.result-patient-context-tile,
.result-patient-clinical-section,
.result-patient-fhir-record-row {
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  padding: var(--space-3) var(--space-4);
}

.result-patient-context-tile.wide {
  grid-column: 1 / -1;
}

.result-patient-context-tile span,
.result-patient-fhir-record-row span {
  display: block;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.result-patient-context-tile strong,
.result-patient-fhir-record-row strong {
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.result-patient-clinical-section h4 {
  margin: 0 0 var(--space-3);
}

.result-patient-clinical-item {
  border-top: 1px solid var(--border-hairline);
  padding: var(--space-2) 0;
}

.result-patient-clinical-item:first-of-type {
  border-top: none;
}

.result-patient-clinical-item strong {
  display: block;
  font-size: var(--text-body);
  color: var(--text-primary);
}

.result-patient-clinical-item span {
  display: block;
  font-size: var(--text-label);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

.result-patient-fhir-record-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
}

@media (max-width: 760px) {
  .result-patient-context-modal {
    padding: var(--space-4);
  }

  .result-patient-context-header {
    flex-direction: column;
  }

  .result-patient-context-grid,
  .result-patient-context-summary-grid {
    grid-template-columns: 1fr;
  }
}

.event-history-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-3);
}

.event-history-row {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  margin-bottom: var(--space-2);
  overflow: hidden;
}

.event-history-row summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  cursor: pointer;
  list-style: none;
  padding: var(--space-3) var(--space-3);
}

.event-history-row summary::-webkit-details-marker {
  display: none;
}

.event-history-row[open] {
  border-color: var(--border-default);
}

.event-history-main {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.event-history-title {
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-history-meta {
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.event-history-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.event-history-status {
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
}

.event-history-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--brand-on);
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.event-history-row[open] .event-history-chevron {
  transform: rotate(90deg);
}

.event-history-detail {
  border-top: 1px solid var(--border-hairline);
  padding: var(--space-3);
}

.event-history-technical {
  margin-top: var(--space-3);
}

.event-history-technical summary {
  padding: 0;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.ehr-patient-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-5);
}

.ehr-patient-summary h3 {
  margin: 0;
}

.ehr-patient-demographics {
  margin-top: var(--space-2);
  color: var(--text-soft);
  font-size: var(--text-body-lg);
}

.ehr-patient-actions {
  flex-shrink: 0;
}

/* ==========================================================================
   Entry screens
   The one place a brand moment belongs: no dense data, and nothing
   see-through sitting on top of it. The spectrum runs along the card's top
   edge and the mark sits above the wordmark, matching the MarchAgent sign-in.
   ========================================================================== */

.login-view,
.auth-loading-view {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(circle at 14% 6%, var(--brand-soft), transparent 46%),
    radial-gradient(circle at 86% 14%, var(--surface-accent), transparent 48%),
    var(--surface-canvas);
}

.app-view {
  min-height: 100vh;
  width: 100%;
}

.login-card,
.auth-loading-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  overflow: hidden;
}

/* The entry card's top edge. A single brand-coloured rule, not a spectrum:
   it marks the card as ours without competing with the form for attention. */
.login-card::before,
.auth-loading-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--brand);
}

.login-brand,
.auth-loading-card {
  text-align: center;
}

.secure-pill {
  display: inline-block;
  margin-bottom: var(--space-5);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.brand-mark {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
}

.brand-eyebrow {
  margin: 0 0 var(--space-1);
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.brand-wordmark {
  margin: 0 0 var(--space-5);
  color: var(--text-primary);
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

.login-brand h1,
.auth-loading-card h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-display);
  line-height: var(--leading-display);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.login-lede,
.auth-loading-card p {
  margin: 0 0 var(--space-6);
  color: var(--text-secondary);
  font-size: var(--text-body-lg);
  line-height: var(--leading-body);
}

.environment-badge:empty {
  display: none;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  text-align: left;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--text-primary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

/* A leading icon names the field at a glance. The input is padded past it
   rather than the icon sitting over the text. */
.field-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.field-with-icon .field-icon {
  position: absolute;
  left: var(--space-3);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.login-form input:not([type="checkbox"]) {
  width: 100%;
  margin: 0;
  min-height: 44px;
  padding: var(--space-3) var(--space-7) var(--space-3) var(--space-6);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body-lg);
}

.password-reveal {
  position: absolute;
  right: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
}

.password-reveal:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.login-form label.login-remember-row,
.login-remember-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  width: fit-content;
  min-height: 24px;
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.login-remember-row span {
  line-height: var(--leading-body);
}

/* The one primary action on the screen. */
#loginButton {
  width: 100%;
  margin-top: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--brand-action);
  color: var(--brand-action-on);
  font-family: var(--font-sans);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

#loginButton:hover {
  background: var(--brand-action-hover);
}

.login-error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--bad-border);
  border-radius: var(--radius-md);
  background: var(--bad-bg);
  color: var(--bad);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
}

.login-error::before {
  content: "\26A0";
}

/* Restricted-access strip, flush to the foot of the card. */
.login-footnote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin: var(--space-6) calc(-1 * var(--space-6)) calc(-1 * var(--space-6));
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-sunken);
  color: var(--text-tertiary);
  font-size: var(--text-body);
}

.login-footnote svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.grouped-menu {
  flex: 1 1 auto;
  margin-top: var(--space-4);
}

/* The account and the theme: things a person sets once, kept out of the
   navigation path. */
.rail-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-hairline);
}

.sidebar-user-panel {
  color: var(--text-secondary);
}

.sidebar-user-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

.sidebar-user-info {
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-user-name {
  overflow: hidden;
  color: var(--text-primary);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  line-height: var(--leading-body);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-email {
  overflow: hidden;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  line-height: var(--leading-label);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-roles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.sidebar-role-pill {
  padding: 0 var(--space-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  line-height: var(--leading-micro);
}

.sidebar-logout-button {
  flex-shrink: 0;
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.sidebar-logout-button:hover {
  background: var(--surface-hover);
}

.user-management-layout {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.user-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-4);
}

.user-list-box {
  display: grid;
  gap: var(--space-3);
}

.user-list-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  cursor: pointer;
}

.user-list-row:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.user-list-row strong {
  display: block;
  color: var(--text);
  font-size: var(--text-body-lg);
}

.user-list-row span {
  display: block;
  color: var(--text-soft);
  font-size: var(--text-label);
}

@media (max-width: 1100px) {
  .user-management-layout {
    grid-template-columns: 1fr;
  }
}

.selected-user-row {
  border-color: var(--primary);
  background: var(--brand-soft);
}

.user-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-4);
}

.user-role-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.user-role-card {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.user-role-card strong {
  display: block;
  color: var(--text);
  font-size: var(--text-body-lg);
}

.user-role-card span {
  display: block;
  color: var(--text-soft);
  font-size: var(--text-label);
  margin-top: var(--space-1);
}

.role-pill-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.role-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-3);
}

.role-pill button {
  border: none;
  background: transparent;
  color: var(--bad);
  cursor: pointer;
  font-weight: var(--weight-medium);
}

.user-session-list {
  display: grid;
  gap: var(--space-3);
}

.user-session-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}

.user-session-card strong {
  display: block;
}

.user-session-card span {
  display: block;
  color: var(--text-soft);
  margin-top: var(--space-1);
}

.user-session-table-wrapper {
  overflow-x: auto;
  margin-top: var(--space-3);
}

.user-session-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-lg);
}

.user-session-table th {
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
  text-align: left;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.user-session-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.user-session-table tr:hover td {
}

.user-role-checkbox-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.user-role-checkbox-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
}

.user-role-checkbox-row:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.user-role-checkbox-row input {
  margin-top: var(--space-1);
}

.user-role-checkbox-row strong {
  display: block;
  color: var(--text);
  font-size: var(--text-body-lg);
}

.user-role-checkbox-row span {
  display: block;
  color: var(--text-soft);
  font-size: var(--text-label);
  margin-top: var(--space-1);
}

.auth-progress-track {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  overflow: hidden;
}

.auth-progress-bar {
  width: 42%;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--brand-action);
  animation: auth-progress 1.1s ease-in-out infinite;
}

@keyframes auth-progress {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

.patient-studio-tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: var(--space-2);
  flex-wrap: nowrap;
  align-items: center;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  margin: var(--space-4) 0 var(--space-5);
  padding: var(--space-3);
  background: var(--surface-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  backdrop-filter: blur(10px);
}

.patient-studio-tab {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-3);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.patient-studio-tab:hover {
  background: var(--surface-blue);
  color: var(--primary-dark);
  border-color: var(--primary-soft);
}

.patient-studio-tab.active {
  background: var(--surface-raised);
  color: var(--text-primary);
  border-color: var(--border-default);
  box-shadow: inset 0 -2px 0 var(--border-selected);
  font-weight: var(--weight-semibold);
}

.patient-studio-tab-panel {
  display: none;
}

.patient-studio-tab-panel.active {
  display: block;
}

/* The prompt takes the room that is left; the badges take what they need.
   A fixed fraction for the badge column clipped them from the left, which is
   how a difficulty badge came to read "dium". */
.compact-case-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  min-height: 44px;
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
}

.compact-case-row:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.compact-case-prompt {
  min-width: 0;
  max-width: 100%;
  color: var(--text);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-case-side {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-2);
}

.compact-badge {
  flex-shrink: 0;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  margin: 0;
}

.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 10000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: var(--space-6) !important;
  background: var(--scrim) !important;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-panel {
  width: min(1080px, calc(100vw - 56px)) !important;
  max-height: calc(100vh - 56px) !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  background: var(--surface) !important;
  border-radius: var(--radius-lg) !important;
  padding: var(--space-5) !important;
  box-shadow: var(--shadow-lg) !important;
}

#caseDetailModal.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 10000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: var(--space-6) !important;
  background: var(--scrim) !important;
}

#caseDetailModal.hidden {
  display: none !important;
}

#caseDetailModal .case-detail-modal {
  width: min(1040px, calc(100vw - 56px)) !important;
  max-height: calc(100vh - 56px) !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  padding: var(--space-5) !important;
}

#caseDetailModal .modal-header {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  gap: var(--space-4) !important;
  align-items: start !important;
  margin-bottom: var(--space-4) !important;
}

#caseDetailModal .modal-header h3 {
  margin: 0 0 var(--space-1) !important;
  font-size: var(--text-title) !important;
  line-height: var(--leading-display) !important;
  word-break: break-word !important;
}

#caseDetailModal .tab-bar {
  display: flex !important;
  gap: var(--space-2) !important;
  border-bottom: 1px solid var(--border) !important;
  margin-bottom: var(--space-4) !important;
}

#caseDetailModal .tab-button {
  border: none !important;
  background: transparent !important;
  color: var(--text-soft) !important;
  padding: var(--space-3) var(--space-3) !important;
  cursor: pointer !important;
  font-weight: var(--weight-medium) !important;
  border-bottom: 3px solid transparent !important;
  box-shadow: none !important;
}

#caseDetailModal .tab-button.active {
  color: var(--primary-dark) !important;
  border-bottom-color: var(--primary) !important;
}

#caseDetailModal .tab-panel {
  display: none !important;
}

#caseDetailModal .tab-panel.active {
  display: block !important;
}

#caseDetailModal .form-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: var(--space-4) !important;
  margin-top: var(--space-3) !important;
}

#caseDetailModal .field.full-width {
  grid-column: 1 / -1 !important;
}

#caseDetailModal textarea {
  min-height: 120px !important;
}

#caseDetailClinicalPrompt {
  min-height: 180px !important;
}

.case-snapshot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.snapshot-field label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.snapshot-field > div:not(.clinical-box) {
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-weight: var(--weight-medium);
}

.snapshot-field.full-width {
  grid-column: 1 / -1;
}

.page-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.page-title-row .page-subtitle {
  margin-bottom: 0;
}

#sourceCasesBox.case-list {
}

#sourceCasesBox.case-list::-webkit-scrollbar {
  width: 8px;
}

#sourceCasesBox.case-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

#sourceCasesBox.case-list::-webkit-scrollbar-track {
  background: transparent;
}

.compact-run-header {
  justify-content: flex-end !important;
  margin-bottom: var(--space-3) !important;
}

/* The prompt takes the room that is left; the badges take what they need.
   With a fixed fraction for the badge column the prompt ran underneath them,
   which the row's hidden overflow then hid rather than revealed. */
.run-compact-case-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.run-compact-case-row:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.run-compact-case-row input[type="checkbox"] {
  margin: 0;
  accent-color: var(--brand);
}

#runCasesBox.run-case-list {
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.progress-header h3 {
  margin-bottom: var(--space-1);
}

.progress-header .small-note {
  margin-bottom: 0;
}

.config-list {
  display: grid;
  gap: var(--space-3);
}

.config-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.config-row-main {
  min-width: 0;
}

.config-row-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.config-row-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.config-row-actions button:disabled {
  color: var(--text-disabled);
  cursor: not-allowed;
  cursor: not-allowed;
}
/* ── Patient Generator ─────────────────────────────────────────── */
.field-help {
  color: var(--text-muted);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  margin: var(--space-2) 0 0;
}

.generator-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.toggle-line {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  flex: 1 1 260px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.toggle-line input[type="checkbox"] {
  margin-top: var(--space-1);
  flex-shrink: 0;
}

.toggle-line strong {
  display: block;
}

.toggle-line .field-help {
  margin-top: var(--space-1);
}

.hallmark-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

.hallmark-panel-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.patient-card-list {
  display: grid;
  gap: var(--space-4);
}

.patient-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-4);
}

.patient-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.patient-card-name {
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

.patient-card-meta {
  color: var(--text-muted);
  font-size: var(--text-body);
  margin-top: var(--space-1);
}

.patient-card-badges {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.coverage-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.coverage-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  border: 1px solid;
}

.coverage-chip.present {
  background: var(--success-soft);
  color: var(--ok);
  border-color: var(--ok-border);
}

.coverage-chip.absent {
  background: var(--surface-sunken);
  color: var(--text-tertiary);
  border-color: var(--border-hairline);
}

.coverage-count {
  font-weight: var(--weight-medium);
}

.patient-card-foot {
  margin-top: var(--space-4);
}

/* Patient Generator — SDOH domains */
.metric-sub {
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  letter-spacing: 0;
}

.sdoh-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
}

.sdoh-label {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  margin-right: var(--space-1);
}

.chip.sdoh-chip {
  background: var(--brand-soft);
  color: var(--brand);
}


/* ==========================================================================
   Theme control
   The rail carries one control for the theme. The choice is stored per
   browser and applied before first paint, so the page never renders in the
   colours of the theme the reader just left.
   ========================================================================== */

.theme-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--surface-hover);
}

.theme-toggle .theme-toggle-value {
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-secondary);
}

/* The rail's brand block: product name, then environment, then the account. */
.sidebar-brand {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Missing data is content, not chrome: it keeps the normal content colour so
   "not recorded" is as readable as a recorded value. */
.not-recorded,
.empty-note {
  color: var(--text-tertiary);
  font-style: normal;
  opacity: 1;
}

/* Timestamps, durations and measured numbers read in the monospace face with
   fixed-width digits, so they line up and 0 cannot be mistaken for O. */
.run-date,
.metric strong,
.rubric-weight,
.event-history-meta,
.clinical-event-meta span,
.sidebar-user-email {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Hit areas
   The accessibility minimum is 24x24. The graphic stays its own size and the
   clickable area is grown with padding, so a checkbox still looks like a
   checkbox while being large enough to hit.
   ========================================================================== */

/* A native checkbox ignores padding -- the browser draws it as a widget -- so
   the hit area cannot be grown on the input itself. It is grown on the label
   that wraps it, which is what the pointer actually targets. */
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  accent-color: var(--brand);
}

label:has(> input[type="checkbox"]),
label:has(> input[type="radio"]),
.checkbox-line,
.toggle-line,
.login-remember-row {
  min-height: 24px;
}

summary {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

button,
a[href],
[role="button"] {
  min-height: 24px;
}

/* In-page loading: a quiet status line under the page header, not an overlay. */
.page-loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-body);
}

/* A case still carrying a legacy patient key: the name is shown, and the
   badge says it is not linked to a patient record rather than claiming the
   patient is unknown. */
.compact-patient.is-unlinked {
  border-style: dashed;
}

/* How much of a collection a bounded list is showing. */
.list-count {
  margin: 0 0 var(--space-2);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-variant-numeric: tabular-nums;
}

/* The one action of a long form stays reachable: on the case generator the
   form runs to several thousand pixels, and the action used to sit at the
   very bottom of it. */
.sticky-action-bar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0 0;
  padding: var(--space-3) 0 0;
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-raised);
}

.sticky-action-bar .status {
  margin: 0;
  color: var(--text-tertiary);
  font-size: var(--text-body);
}

/* The workspace page opens the four things this product does, in the order
   they are done, rather than describing them in a paragraph. */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.workflow-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
}

.workflow-card:hover {
  border-color: var(--border-selected);
  background: var(--surface-hover);
}

.workflow-step {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.workflow-card strong {
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
}

.workflow-note {
  color: var(--text-secondary);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

/* A8: measured values and file paths are read character by character. */
.clinical-focus-item strong,
#systemParametersPage input[type="text"],
.measured-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Tiles hold a mix: a name reads as prose, a measurement reads character by
   character. Only the measurements take the mono face. */
.patient-summary-tile strong {
  font-variant-numeric: tabular-nums;
}

/* A closed <details> hides everything but its summary -- unless a rule gives a
   child its own `display`, which overrides the browser's own hiding and leaves
   the content painting outside the disclosure. On the rubric page a closed
   details measured 36px while the .pill-list inside it painted 280px, landing
   on the cards below. Hiding non-summary children explicitly restores the
   behaviour whatever display those children are given. */
details:not([open]) > *:not(summary) {
  display: none;
}

/* ==========================================================================
   Workspace page
   The state of the lab, answered on arrival: how much is in it, whether the
   last run worked, and what the next run would use.
   ========================================================================== */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--border-selected);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-sans);
  text-align: left;
}

.stat-tile.is-openable {
  cursor: pointer;
}

.stat-tile.is-openable:hover {
  background: var(--surface-hover);
}

.stat-label {
  color: var(--text-tertiary);
  font-size: var(--text-micro);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.stat-value {
  font-size: var(--text-display);
  line-height: var(--leading-display);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.stat-note {
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.home-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-4);
}

.home-section-title {
  margin: var(--space-5) 0 var(--space-3);
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  font-weight: var(--weight-semibold);
}

.run-headline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.definition-list {
  display: grid;
  gap: var(--space-3);
  margin: 0;
}

.definition-row {
  display: grid;
  grid-template-columns: minmax(0, 120px) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: baseline;
}

.definition-row dt {
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.definition-row dd {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--text-body-lg);
}

/* The chart names its patient, and the tool only above it. */
.page-eyebrow {
  margin: 0 0 var(--space-1);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.patient-identity-line {
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: var(--text-body-lg);
}

.patient-identity-line .mono {
  color: var(--text-primary);
}

/* A tab strip is a row of choices, not a panel: the card around it competed
   with the chart underneath. */
.patient-studio-tabs {
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--border-default);
  border-radius: 0;
  background: var(--surface-canvas);
  gap: 0;
}

.patient-studio-tab {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-4);
}

.patient-studio-tab:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: transparent;
}

.patient-studio-tab.active {
  background: transparent;
  border: 0;
  box-shadow: inset 0 -2px 0 var(--border-selected);
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

/* The summary reads as a row of facts, evenly sized. */
.patient-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* ==========================================================================
   Enterprise layer
   --------------------------------------------------------------------------
   Everything above builds the product's surfaces, colours and pages. This
   section is the pass that makes them read as one system rather than as a
   collection of separately styled screens, and it is deliberately last so it
   refines the rules above instead of replacing them.

   Four things were making a clinical tool look like coursework:

     * Icons came from three sources at four sizes, and half of them were text
       characters whose weight and baseline came from the font.
     * Controls picked their own heights, so a filter row of a button, an input
       and a select lined up on none of its edges.
     * Titles were sized by how important each page felt at the time rather
       than by a hierarchy, and 700 weight was used where 600 was meant.
     * Decoration carried colour that state needed. Colour now means status,
       selection or brand, and nothing else.
   ========================================================================== */

/* Icons --------------------------------------------------------------------
   Every icon is a stroked 16-grid SVG in currentColor. The host span exists so
   markup can ask for an icon by name; it must not add its own box. */
.icon {
  display: block;
  flex: 0 0 auto;
}

.icon-xs { width: var(--icon-xs); height: var(--icon-xs); }
.icon-sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon-md { width: var(--icon-md); height: var(--icon-md); }
.icon-lg { width: var(--icon-lg); height: var(--icon-lg); }
.icon-xl { width: var(--icon-xl); height: var(--icon-xl); }

[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

/* An icon set beside a line of text sits on the text's optical centre, not on
   its baseline: a 16px icon on a 13px line otherwise rides high. */
.interpretation-mark {
  display: inline-block;
  vertical-align: -0.15em;
}

/* Badges -------------------------------------------------------------------
   The status mark was a font character -- a bullet, a tick, a cross, a warning
   sign -- so its size, weight and vertical position were whatever the
   installed face happened to provide, and none of the four agreed with each
   other. They are now the same drawings as the rest of the icon set, painted
   through a mask so they inherit the badge's colour. */
.badge {
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-micro);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  margin: 0 var(--space-1) var(--space-1) 0;
  vertical-align: middle;
}

.badge::before {
  content: "";
  width: var(--icon-xs);
  height: var(--icon-xs);
  flex: 0 0 auto;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-image: var(--badge-mark);
  mask-image: var(--badge-mark);
  --badge-mark: 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='3.4' fill='%23000'/%3E%3C/svg%3E");
}

.badge.pass::before {
  --badge-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8.4 6.3 11.6 13 4.8'/%3E%3C/svg%3E");
}

.badge.fail::before {
  --badge-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 4l8 8M12 4l-8 8'/%3E%3C/svg%3E");
}

.badge.warning::before {
  --badge-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2.6 14.4 13.2H1.6Z'/%3E%3Cpath d='M8 6.6v2.8M8 11.4v.1'/%3E%3C/svg%3E");
}

.badge.gray::before {
  --badge-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3.5 8h9'/%3E%3C/svg%3E");
}

/* The environment badge names a deployment, not a status, so it carries no
   status mark. */
.environment-badge::before {
  --badge-mark: 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='3' fill='%23000'/%3E%3C/svg%3E");
}

/* Typography ---------------------------------------------------------------
   One hierarchy, applied everywhere. A reader should be able to tell a page
   title from a section title from a card title without reading the words. */
.page-title {
  margin: 0;
  font-size: var(--text-title);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-title);
  letter-spacing: var(--tracking-title);
  color: var(--text-primary);
}

.page-subtitle {
  margin: var(--space-2) 0 0;
  max-width: 68ch;
  font-size: var(--text-body);
  font-weight: var(--weight-normal);
  line-height: var(--leading-body);
  color: var(--text-secondary);
}

.page-header,
.page-title-row {
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
}

.page-eyebrow,
.home-section-title {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-label);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.home-section-title {
  margin: var(--space-6) 0 var(--space-3);
}

.card h3,
.card-title-row h3 {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-heading);
  letter-spacing: -0.005em;
  color: var(--text-primary);
}

/* Metadata is secondary by colour and by size, never by opacity: a faded
   element is unreadable at exactly the moment someone needs to read it. */
.muted,
.stat-note,
.workflow-note,
.event-history-meta {
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
  opacity: 1;
}

/* Measured values: tabular figures so a column of numbers aligns on its
   digits, and the mono face so a zero cannot be read as an O. */
.stat-value,
.run-stats strong {
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-display);
  letter-spacing: var(--tracking-display);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.stat-label {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Controls -----------------------------------------------------------------
   Buttons, inputs and selects share a height scale, so a toolbar assembled
   from all three aligns without per-component nudging. */
button.primary,
button.secondary,
button.danger {
  min-height: var(--control-md);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  line-height: 1;
  letter-spacing: 0;
}

button.primary {
  background: var(--brand-action);
  color: var(--brand-action-on);
  border: 1px solid transparent;
}

button.primary:hover {
  background: var(--brand-action-hover);
}

button.primary:active {
  background: var(--brand-action-active);
}

button.secondary {
  background: var(--surface-raised);
  border: 1px solid var(--border-interactive);
  color: var(--text-primary);
}

button.secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-interactive);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

input:not([type="checkbox"]):not([type="radio"]),
select {
  min-height: var(--control-md);
}

/* One focus treatment for everything focusable. */
:is(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* Cards and tables ---------------------------------------------------------
   Density is the point. A clinical reviewer scans a run of twenty rows; rows
   sized for a marketing page turn that into scrolling. */
.card {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: none;
}

table {
  border-radius: var(--radius-md);
  font-size: var(--text-body);
}

th,
td {
  padding: var(--space-2) var(--space-3);
}

th {
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}

tbody tr:hover td {
  background: var(--surface-hover);
}

/* Numeric cells align on their digits. */
td.numeric,
th.numeric {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Navigation ---------------------------------------------------------------
   The workspace entry is a single item with no group to expand, so it needs a
   shape of its own rather than a group title that opens nothing. */
.menu-group-single {
  margin-bottom: var(--space-2);
}

.menu-standalone {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  text-align: left;
  cursor: pointer;
}

.menu-standalone:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.menu-standalone.active {
  background: var(--surface-accent);
  border-color: var(--border-selected);
  color: var(--text-primary);
}

.menu-icon {
  color: var(--text-tertiary);
}

.menu-standalone.active .menu-icon {
  color: var(--brand);
}

/* One chevron, rotated. Two characters swapped by JavaScript could never
   animate and never matched each other's optical weight. */
.menu-arrow {
  color: var(--text-tertiary);
  transition: transform 0.15s ease;
}

.menu-arrow.is-open {
  transform: rotate(90deg);
}

.event-history-chevron,
.clinical-studio-arrow {
  width: var(--control-sm);
  height: var(--control-sm);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  transition: transform 0.15s ease, background 0.12s ease;
}

.event-history-row[open] .event-history-chevron {
  transform: rotate(90deg);
}

/* Entry screen -------------------------------------------------------------
   The field icons are spans wrapping an svg now, so they need to be told to
   centre their contents; as bare svgs they laid out on their own. */
.field-with-icon .field-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-md);
  height: var(--icon-md);
  color: var(--text-tertiary);
}

.login-footnote-icon {
  color: var(--text-tertiary);
}

.password-reveal {
  width: var(--control-md);
  height: var(--control-md);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
}

.password-reveal:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

#loginButton {
  min-height: var(--control-lg);
  border-radius: var(--radius-md);
  background: var(--brand-action);
  color: var(--brand-action-on);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
}

#loginButton:hover {
  background: var(--brand-action-hover);
}

.secure-pill {
  border-radius: var(--radius-sm);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

/* Alerts -------------------------------------------------------------------
   One inline alert, used by the sign-in error, the clinical warnings and
   anywhere else a message belongs in the flow of a page rather than over it.
   The icon is drawn, aligned to the first line of text, and does not move when
   the message wraps to two lines. */
.alert,
.login-error,
.clinical-alert {
  display: grid;
  grid-template-columns: var(--icon-md) 1fr;
  align-items: start;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--text-tertiary);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-body);
  font-weight: var(--weight-normal);
  line-height: var(--leading-body);
  text-align: left;
}

.alert::before,
.login-error::before,
.clinical-alert::before {
  content: "";
  width: var(--icon-md);
  height: var(--icon-md);
  margin-top: 1px;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-image: var(--alert-mark);
  mask-image: var(--alert-mark);
  --alert-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='8' cy='8' r='5.8'/%3E%3Cpath d='M8 7.3v3.6M8 5.2v.1'/%3E%3C/svg%3E");
}

.login-error,
.clinical-alert,
.alert.alert-error {
  border-color: var(--bad-border);
  border-left-color: var(--bad);
  background: var(--bad-bg);
  color: var(--bad);
}

.login-error::before,
.clinical-alert::before,
.alert.alert-error::before {
  --alert-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2.8 14.2 13H1.8Z'/%3E%3Cpath d='M8 6.6v3M8 11.3v.1'/%3E%3C/svg%3E");
}

.alert.alert-warning {
  border-color: var(--warn-border);
  border-left-color: var(--warn);
  background: var(--warn-bg);
  color: var(--warn);
}

.alert.alert-success {
  border-color: var(--ok-border);
  border-left-color: var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
}

.alert.alert-info {
  border-color: var(--info-border);
  border-left-color: var(--info);
  background: var(--info-bg);
  color: var(--info);
}

/* Toasts -------------------------------------------------------------------
   These replaced the browser's alert(). They sit above everything, announce
   themselves to assistive technology, and never take focus -- a toast that
   stole focus would interrupt whatever the operator was typing. */
.toast-host {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(380px, calc(100vw - var(--space-6)));
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: var(--icon-md) 1fr auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--text-tertiary);
  border-radius: var(--radius-md);
  background: var(--surface-overlay);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
}

.toast-icon { margin-top: 1px; }
.toast-error .toast-icon { color: var(--bad); }
.toast-warning .toast-icon { color: var(--warn); }
.toast-success .toast-icon { color: var(--ok); }
.toast-info .toast-icon { color: var(--info); }

.toast-error { border-left-color: var(--bad); }
.toast-warning { border-left-color: var(--warn); }
.toast-success { border-left-color: var(--ok); }
.toast-info { border-left-color: var(--info); }

.toast-body { min-width: 0; }

.toast-title {
  display: block;
  margin-bottom: 2px;
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.toast-message {
  margin: 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-sm);
  height: var(--control-sm);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
}

.toast-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* Confirmation dialog ------------------------------------------------------
   Replaced confirm(). The cancel button is the one that receives focus, so
   Return never commits a destructive action by accident. */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-dialog);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--scrim);
  opacity: 0;
  transition: opacity 0.14s ease;
}

.dialog-backdrop.is-visible { opacity: 1; }

.dialog {
  width: min(440px, 100%);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-overlay);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) 0;
}

.dialog-icon-danger { color: var(--bad); }
.dialog-icon-info { color: var(--info); }

.dialog-title {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-heading);
  color: var(--text-primary);
}

.dialog-body {
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.dialog-message {
  margin: 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-secondary);
}

.dialog-detail {
  margin: var(--space-3) 0 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-meta);
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-sunken);
}

/* Empty states -------------------------------------------------------------
   An empty state says what is missing and what to do about it. It is not an
   error, so it does not borrow the error colour. */
.empty-note {
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-tertiary);
}

.empty-note:last-child { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  .toast,
  .dialog-backdrop,
  .menu-arrow,
  .event-history-chevron,
  .clinical-studio-arrow {
    transition: none;
  }
}

@media (max-width: 640px) {
  .toast-host {
    top: auto;
    right: var(--space-3);
    bottom: var(--space-3);
    left: var(--space-3);
    width: auto;
  }
}

/* Prose detail and identifier detail are different things. */
.dialog-detail {
  margin: var(--space-2) 0 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-secondary);
  background: none;
  padding: 0;
}

.dialog-code {
  margin: var(--space-3) 0 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-meta);
  overflow-wrap: anywhere;
}

/* Dashboard ----------------------------------------------------------------
   The measure row was auto-fit, so at most viewport widths it fitted three
   tiles and dropped the fourth onto a row of its own -- a ragged block that
   reads as a layout accident rather than as a set of four related numbers.
   Four explicit columns keep them as one row, and the two breakpoints below
   fold them in halves so they stay a rectangle at every width. */
.stat-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-5);
}

@media (max-width: 1080px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .stat-row { grid-template-columns: minmax(0, 1fr); }
}

.stat-tile {
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
}

.run-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

@media (max-width: 520px) {
  .run-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.run-stats div {
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 0;
}

.run-stats span {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}

.run-stats strong {
  font-size: var(--text-title);
}

.workflow-step {
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  color: var(--text-tertiary);
}

.workflow-card strong {
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
}

.workflow-card {
  gap: var(--space-2);
  padding: var(--space-4);
}

/* Definition lists carry the "what is this configured to do" panels. A fixed
   label column makes the values line up down the page instead of starting at
   whatever x the longest term happened to reach. */
.definition-row {
  display: grid;
  grid-template-columns: minmax(120px, 160px) 1fr;
  gap: var(--space-3);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-hairline);
}

.definition-row:last-child { border-bottom: 0; }

.definition-row dt {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.definition-row dd {
  margin: 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-primary);
}

@media (max-width: 520px) {
  .definition-row { grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
}

/* Rail ---------------------------------------------------------------------
   Group titles are labels, not headings: small capitals, tertiary colour, and
   the same height as the items they open. */
.menu-group-title {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.menu-subitems button {
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

/* A two-item flex row with no wrap and no min-width on its children cannot get
   narrower than the wider child's longest word, so on a phone it pushed the
   card 25px past the screen. Letting it wrap, and letting each child shrink
   below its content width, is what makes the row responsive rather than just
   narrow. */
.progress-header {
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.progress-header > * {
  min-width: 0;
}

/* Forms --------------------------------------------------------------------
   A long form in one undifferentiated card asks the reader to work out its
   structure from the field names. Named sections carry that structure, and a
   hint under the label carries the instruction that was previously hidden
   inside a placeholder -- where it disappeared the moment anyone typed, and
   was clipped by the control's own height before that. */
.form-section {
  margin-bottom: var(--space-4);
}

.form-section-head {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-hairline);
}

.form-section-head h3 {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-heading);
  color: var(--text-primary);
}

.form-section-note {
  margin: var(--space-1) 0 0;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
}

.field-hint {
  margin: calc(-1 * var(--space-1)) 0 0;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
}

.field label {
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

/* Four list boxes side by side were 96px tall, which clipped their own
   placeholder mid-sentence and put a scrollbar inside every one of them. A
   five-line box holds the example it shows. */
.field textarea {
  min-height: 116px;
  resize: vertical;
}

.form-grid {
  gap: var(--space-4);
  margin-top: 0;
}

/* The action row belongs to the page, not to the last card, and it stays put
   while a long form scrolls past it. */
.form-actions {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
}

.form-actions-status {
  min-width: 0;
  font-size: var(--text-body);
  color: var(--text-secondary);
}

.form-actions-status:empty { display: none; }

.form-actions-buttons {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* A row of three short selects auto-fitted to two columns and left the third
   alone beside an empty cell. Three named columns keep the row a row, and
   collapse together rather than one at a time. */
.form-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 860px) {
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
}

/* Empty states -------------------------------------------------------------
   A card whose entire content is one grey sentence reads as a rendering
   failure rather than as an answer. When the note is all the card holds, it
   becomes a deliberate state: an icon, room around it, and the sentence
   centred so it is obviously the message and not a leftover line.

   The selector does the work, so none of the forty-nine call sites that
   already write .empty-note have to change, and a note used as one line among
   several -- the workspace panels stack two -- keeps its inline treatment. */
.card > .empty-note:only-child,
.card > div > .empty-note:only-child,
.card > dl > .empty-note:only-child {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-secondary);
}

.card > .empty-note:only-child::before,
.card > div > .empty-note:only-child::before,
.card > dl > .empty-note:only-child::before {
  content: "";
  width: var(--icon-lg);
  height: var(--icon-lg);
  background-color: var(--text-tertiary);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-image: var(--empty-mark);
  mask-image: var(--empty-mark);
  --empty-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2.2' y='3.2' width='11.6' height='9.6' rx='1.4'/%3E%3Cpath d='M5 6.4h6M5 9.2h3.4'/%3E%3C/svg%3E");
}

/* A panel that is still loading is not a panel that is empty, and the two
   must not look the same: one resolves on its own and the other will not. */
.is-loading-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--text-body);
}

.is-loading-note::before {
  content: "";
  width: var(--icon-md);
  height: var(--icon-md);
  border: 2px solid var(--border-data);
  border-top-color: var(--brand);
  border-radius: var(--radius-full);
  animation: spinner 0.7s linear infinite;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .is-loading-note::before { animation-duration: 2.4s; }
}

/* The rail on a phone ------------------------------------------------------
   Above the breakpoint this is inert: the toggle is not displayed and every
   rule below is scoped to the narrow layout. */
.rail-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--control-md);
  height: var(--control-md);
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.rail-toggle:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

@media (max-width: 860px) {
  .rail-toggle {
    display: inline-flex;
  }

  .rail-brand {
    margin-bottom: 0;
  }

  /* Which deployment this is stays on screen without a tap. */
  aside > .environment-badge {
    margin: var(--space-2) 0 0;
  }

  /* The rail keeps its brand row and hands the rest of the screen back to the
     page. Height, not display, so the menu can animate and so nothing inside
     it is measured at zero while closed. */
  aside > .menu,
  aside > .rail-footer {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    margin-top: 0;
    transition: max-height 0.2s ease, opacity 0.2s ease,
      visibility 0s linear 0.2s;
  }

  body.rail-open aside > .menu,
  body.rail-open aside > .rail-footer {
    max-height: 80vh;
    overflow-y: auto;
    opacity: 1;
    visibility: visible;
    margin-top: var(--space-3);
    transition: max-height 0.2s ease, opacity 0.2s ease, visibility 0s;
  }

  body.rail-open .rail-toggle {
    transform: rotate(180deg);
  }

  aside {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    padding: var(--space-3) var(--space-4);
  }
}

/* An eyebrow names a section; it is not an identifier, so it does not belong
   in the monospace face reserved for codes and measured values. */
.page-eyebrow {
  font-family: var(--font-sans);
}

/* The full empty state: for the few places where nothing can be shown until
   the reader does something, and the page has to say what. */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  text-align: center;
}

.empty-state-icon {
  color: var(--text-tertiary);
}

.empty-state h3 {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.empty-state-note {
  max-width: 46ch;
  margin: 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-secondary);
}

/* ==========================================================================
   Identity layer — tokens
   --------------------------------------------------------------------------
   The product read as flat because every surface was nearly the same grey and
   colour was only ever used for status badges. This layer gives the interface
   a structure you can see before you read anything:

     canvas     the application ground
     rail       navigation, a tinted plane of its own
     raised     content that is being worked on, lifted by elevation
     highlight  brand-tinted areas that carry the current context
     sunken     wells inside raised content

   Elevation replaces the earlier "shadows on overlays only" rule. Cards on a
   dense clinical dashboard need to separate from the ground without heavy
   borders; a two-layer shadow at low opacity does that and costs no contrast.

   The state palette is the vocabulary for system condition. Each family has a
   foreground that clears 4.5:1 on its own chip and on a card, and an indicator
   dot that clears 3:1 -- checked in both themes before these values were
   written. Brand blue and teal are the two ends of the MarchAgent action
   colour; violet is the spectrum's own and is kept for AI and system work.

   The three blocks mirror the selectors of the base token blocks above so each
   one overrides its counterpart and nothing else.
   ========================================================================== */

:root {
  --brand: #1c5f92;
  --brand-strong: #134a73;
  --brand-soft: #e8f1f9;
  --brand-border: #b3d0ec;
  --brand-on: #ffffff;
  --accent: #0e7c6f;
  --accent-soft: #e2f3ef;

  --brand-action: #1c5f92;
  --brand-action-hover: #174f7c;
  --brand-action-active: #103e63;
  --brand-action-on: #ffffff;
  --brand-sheen: linear-gradient(135deg, #1c5f92 0%, #17614f 100%);

  --surface-canvas: #f2f5f8;
  --surface-rail: #e9eff4;
  --surface-raised: #ffffff;
  --surface-overlay: #ffffff;
  --surface-sunken: #eef2f5;
  --surface-highlight: #eef5fb;
  --surface-hover: #eef2f6;
  --surface-accent: #e3eef8;

  --border-hairline: #e6ebf0;
  --border-default: #d6dde4;
  --border-data: #d0d8e0;

  --elevation-0: 0 0 0 transparent;
  --elevation-1: 0 1px 2px rgba(16, 38, 58, 0.06), 0 1px 3px rgba(16, 38, 58, 0.05);
  --elevation-2: 0 6px 16px rgba(16, 38, 58, 0.08), 0 2px 4px rgba(16, 38, 58, 0.05);
  --elevation-3: 0 18px 40px rgba(16, 38, 58, 0.14), 0 4px 10px rgba(16, 38, 58, 0.06);

  --ease-out: cubic-bezier(0.22, 0.8, 0.26, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.25, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 320ms;

  /* State families: foreground / chip / indicator / border */
  --state-live: #0b6b5e;   --state-live-bg: #e2f3ef;   --state-live-dot: #16a085;   --state-live-border: #a8dccf;
  --state-done: #1d6b32;   --state-done-bg: #e5f4e8;   --state-done-dot: #2e9e4c;   --state-done-border: #b1dcba;
  --state-work: #1c5f92;   --state-work-bg: #e6f0f9;   --state-work-dot: #2a72b8;   --state-work-border: #b3d0ec;
  --state-attn: #8a4d00;   --state-attn-bg: #fff2dc;   --state-attn-dot: #b86f00;   --state-attn-border: #f0cc8e;
  --state-crit: #a3121c;   --state-crit-bg: #fde8e7;   --state-crit-dot: #d93a31;   --state-crit-border: #f3b3ae;
  --state-idle: #4b5561;   --state-idle-bg: #eef1f4;   --state-idle-dot: #78838f;   --state-idle-border: #cdd4db;
  --state-lock: #4a4677;   --state-lock-bg: #eeedf6;   --state-lock-dot: #7e79b3;   --state-lock-border: #cfcce6;
  --state-ai: #6a2d8f;     --state-ai-bg: #f3eaf8;     --state-ai-dot: #9a55c6;     --state-ai-border: #d9bfea;

  /* Data visualisation */
  --viz-grid: #e6ebf0;
  --viz-track: #e8edf2;
  --viz-1: #1c5f92;
  --viz-2: #0e8a7a;
  --viz-3: #7a44a8;
  --viz-4: #b02a6a;
  --viz-5: #b86f00;
  --viz-6: #6b7785;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #6da9e7;
    --brand-strong: #9ac6f0;
    --brand-soft: #16283a;
    --brand-border: #2c4a68;
    --brand-on: #08131d;
    --accent: #4fc4b0;
    --accent-soft: #0f2c27;

    --brand-action: #6da9e7;
    --brand-action-hover: #89bcee;
    --brand-action-active: #a5cdf3;
    --brand-action-on: #08131d;
    --brand-sheen: linear-gradient(135deg, #2a6aa3 0%, #1f7a69 100%);

    --surface-canvas: #0d1317;
    --surface-rail: #0a0f13;
    --surface-raised: #1b2227;
    --surface-overlay: #222a30;
    --surface-sunken: #11171b;
    --surface-highlight: #14263a;
    --surface-hover: #232b31;
    --surface-accent: #15283b;

    --border-hairline: #1f262c;
    --border-default: #283037;
    --border-data: #2e373e;

    --elevation-1: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 1px 2px rgba(0, 0, 0, 0.40);
    --elevation-2: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 20px rgba(0, 0, 0, 0.45);
    --elevation-3: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 20px 44px rgba(0, 0, 0, 0.55);

    --state-live: #6fd5bf;   --state-live-bg: #0f2c27;   --state-live-dot: #3cc3a6;   --state-live-border: #1f5048;
    --state-done: #86d49a;   --state-done-bg: #13291a;   --state-done-dot: #4fb96a;   --state-done-border: #264d30;
    --state-work: #7fb6ec;   --state-work-bg: #12263a;   --state-work-dot: #5a9be0;   --state-work-border: #24486b;
    --state-attn: #f2c27a;   --state-attn-bg: #33240c;   --state-attn-dot: #e7a33c;   --state-attn-border: #5f4418;
    --state-crit: #f68c84;   --state-crit-bg: #3a1917;   --state-crit-dot: #ec5d53;   --state-crit-border: #6b2f2a;
    --state-idle: #aeb6be;   --state-idle-bg: #20262b;   --state-idle-dot: #7d8791;   --state-idle-border: #363d43;
    --state-lock: #b8b3e6;   --state-lock-bg: #232135;   --state-lock-dot: #9791cf;   --state-lock-border: #3c3a5c;
    --state-ai: #cc9cec;     --state-ai-bg: #2a1b35;     --state-ai-dot: #b877e0;     --state-ai-border: #4a3160;

    --viz-grid: #232b31;
    --viz-track: #242c33;
    --viz-1: #6da9e7;
    --viz-2: #4fc4b0;
    --viz-3: #b88ae0;
    --viz-4: #e98ab8;
    --viz-5: #e7a33c;
    --viz-6: #93a0ab;
  }
}

:root[data-theme="dark"] {
  --brand: #6da9e7;
  --brand-strong: #9ac6f0;
  --brand-soft: #16283a;
  --brand-border: #2c4a68;
  --brand-on: #08131d;
  --accent: #4fc4b0;
  --accent-soft: #0f2c27;

  --brand-action: #6da9e7;
  --brand-action-hover: #89bcee;
  --brand-action-active: #a5cdf3;
  --brand-action-on: #08131d;
  --brand-sheen: linear-gradient(135deg, #2a6aa3 0%, #1f7a69 100%);

  --surface-canvas: #0d1317;
  --surface-rail: #0a0f13;
  --surface-raised: #1b2227;
  --surface-overlay: #222a30;
  --surface-sunken: #11171b;
  --surface-highlight: #14263a;
  --surface-hover: #232b31;
  --surface-accent: #15283b;

  --border-hairline: #1f262c;
  --border-default: #283037;
  --border-data: #2e373e;

  --elevation-1: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 1px 2px rgba(0, 0, 0, 0.40);
  --elevation-2: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 20px rgba(0, 0, 0, 0.45);
  --elevation-3: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 20px 44px rgba(0, 0, 0, 0.55);

  --state-live: #6fd5bf;   --state-live-bg: #0f2c27;   --state-live-dot: #3cc3a6;   --state-live-border: #1f5048;
  --state-done: #86d49a;   --state-done-bg: #13291a;   --state-done-dot: #4fb96a;   --state-done-border: #264d30;
  --state-work: #7fb6ec;   --state-work-bg: #12263a;   --state-work-dot: #5a9be0;   --state-work-border: #24486b;
  --state-attn: #f2c27a;   --state-attn-bg: #33240c;   --state-attn-dot: #e7a33c;   --state-attn-border: #5f4418;
  --state-crit: #f68c84;   --state-crit-bg: #3a1917;   --state-crit-dot: #ec5d53;   --state-crit-border: #6b2f2a;
  --state-idle: #aeb6be;   --state-idle-bg: #20262b;   --state-idle-dot: #7d8791;   --state-idle-border: #363d43;
  --state-lock: #b8b3e6;   --state-lock-bg: #232135;   --state-lock-dot: #9791cf;   --state-lock-border: #3c3a5c;
  --state-ai: #cc9cec;     --state-ai-bg: #2a1b35;     --state-ai-dot: #b877e0;     --state-ai-border: #4a3160;

  --viz-grid: #232b31;
  --viz-track: #242c33;
  --viz-1: #6da9e7;
  --viz-2: #4fc4b0;
  --viz-3: #b88ae0;
  --viz-4: #e98ab8;
  --viz-5: #e7a33c;
  --viz-6: #93a0ab;
}

/* ==========================================================================
   Identity layer — surfaces and components
   ========================================================================== */

/* Surfaces ------------------------------------------------------------------ */
body,
.app-view,
main {
  background: var(--surface-canvas);
}

aside {
  background: var(--surface-rail);
}

.card,
.panel,
.kpi {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--elevation-1);
}

/* Tones ----------------------------------------------------------------------
   One set of classes for every place a colour carries meaning: chart marks,
   legend swatches and the tinted icon tiles. Each tone sets three properties
   and the component decides which it needs. */
.tone-live { --tone: var(--state-live-dot); --tone-fg: var(--state-live); --tone-bg: var(--state-live-bg); }
.tone-done { --tone: var(--state-done-dot); --tone-fg: var(--state-done); --tone-bg: var(--state-done-bg); }
.tone-work { --tone: var(--state-work-dot); --tone-fg: var(--state-work); --tone-bg: var(--state-work-bg); }
.tone-attn { --tone: var(--state-attn-dot); --tone-fg: var(--state-attn); --tone-bg: var(--state-attn-bg); }
.tone-crit { --tone: var(--state-crit-dot); --tone-fg: var(--state-crit); --tone-bg: var(--state-crit-bg); }
.tone-idle { --tone: var(--state-idle-dot); --tone-fg: var(--state-idle); --tone-bg: var(--state-idle-bg); }
.tone-lock { --tone: var(--state-lock-dot); --tone-fg: var(--state-lock); --tone-bg: var(--state-lock-bg); }
.tone-ai   { --tone: var(--state-ai-dot);   --tone-fg: var(--state-ai);   --tone-bg: var(--state-ai-bg); }
.tone-viz-1 { --tone: var(--viz-1); --tone-fg: var(--state-work); --tone-bg: var(--state-work-bg); }
.tone-viz-2 { --tone: var(--viz-2); --tone-fg: var(--state-live); --tone-bg: var(--state-live-bg); }
.tone-viz-3 { --tone: var(--viz-3); --tone-fg: var(--state-ai);   --tone-bg: var(--state-ai-bg); }
.tone-viz-4 { --tone: var(--viz-4); --tone-fg: var(--viz-4);      --tone-bg: color-mix(in srgb, var(--viz-4) 12%, var(--surface-raised)); }
.tone-viz-5 { --tone: var(--viz-5); --tone-fg: var(--state-attn); --tone-bg: var(--state-attn-bg); }
.tone-viz-6 { --tone: var(--viz-6); --tone-fg: var(--state-idle); --tone-bg: var(--state-idle-bg); }

/* A hatch says "absent" without a colour of its own, so "no response" never
   borrows a status hue it has not earned. */
.is-patterned {
  background-color: var(--tone-bg) !important;
  background-image: repeating-linear-gradient(
    135deg, var(--tone) 0 1.5px, transparent 1.5px 5px) !important;
}

/* States ---------------------------------------------------------------------- */
.state {
  --state-fg: var(--state-idle);
  --state-bg: var(--state-idle-bg);
  --state-dot: var(--state-idle-dot);
  --state-border: var(--state-idle-border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  color: var(--state-fg);
  font-size: var(--text-meta);
  font-weight: var(--weight-medium);
  line-height: var(--leading-meta);
  white-space: nowrap;
  vertical-align: middle;
}

.state-live { --state-fg: var(--state-live); --state-bg: var(--state-live-bg); --state-dot: var(--state-live-dot); --state-border: var(--state-live-border); }
.state-done { --state-fg: var(--state-done); --state-bg: var(--state-done-bg); --state-dot: var(--state-done-dot); --state-border: var(--state-done-border); }
.state-work { --state-fg: var(--state-work); --state-bg: var(--state-work-bg); --state-dot: var(--state-work-dot); --state-border: var(--state-work-border); }
.state-attn { --state-fg: var(--state-attn); --state-bg: var(--state-attn-bg); --state-dot: var(--state-attn-dot); --state-border: var(--state-attn-border); }
.state-crit { --state-fg: var(--state-crit); --state-bg: var(--state-crit-bg); --state-dot: var(--state-crit-dot); --state-border: var(--state-crit-border); }
.state-idle { --state-fg: var(--state-idle); --state-bg: var(--state-idle-bg); --state-dot: var(--state-idle-dot); --state-border: var(--state-idle-border); }
.state-lock { --state-fg: var(--state-lock); --state-bg: var(--state-lock-bg); --state-dot: var(--state-lock-dot); --state-border: var(--state-lock-border); }
.state-ai   { --state-fg: var(--state-ai);   --state-bg: var(--state-ai-bg);   --state-dot: var(--state-ai-dot);   --state-border: var(--state-ai-border); }

.state-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.state--chip {
  padding: 2px var(--space-2) 2px 6px;
  border: 1px solid var(--state-border);
  border-radius: var(--radius-full);
  background: var(--state-bg);
}

.state-glyph {
  flex: 0 0 auto;
}

.state-dot {
  position: relative;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--state-dot);
}

/* The live ring. It says "this is being measured now", so it only ever appears
   on states that are. */
.state[data-live] .state-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  border: 2px solid var(--state-dot);
  opacity: 0;
  animation: state-pulse 2.4s var(--ease-out) infinite;
}

.state[data-spin] .state-dot {
  background: transparent;
  border: 2px solid color-mix(in srgb, var(--state-dot) 30%, transparent);
  border-top-color: var(--state-dot);
  animation: state-spin 0.9s linear infinite;
}

.state[data-spin] .state-glyph {
  animation: state-spin 1.2s linear infinite;
}

.state--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--state-bg);
  color: var(--state-fg);
}

@keyframes state-pulse {
  0%   { transform: scale(0.6); opacity: 0.55; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

@keyframes state-spin {
  to { transform: rotate(360deg); }
}

/* Buttons that feel pressed ---------------------------------------------------- */
button.primary,
button.secondary,
button.danger,
.link-button,
.icon-button {
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

button.primary {
  box-shadow: 0 1px 2px rgba(16, 38, 58, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

button.primary:hover {
  box-shadow: 0 3px 8px rgba(28, 95, 146, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

button.primary:active,
button.secondary:active,
button.danger:active,
.icon-button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.link-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--brand);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
}

.link-button:hover {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.link-button .icon {
  transition: transform var(--dur-fast) var(--ease-out);
}

.link-button:hover .icon {
  transform: translateX(2px);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-md);
  min-height: var(--control-md);
  padding: 0 !important;
}

.icon-button.is-spinning .icon {
  animation: state-spin 0.9s linear infinite;
}

/* Workspace ------------------------------------------------------------------- */
.workspace {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.workspace-heading .page-subtitle {
  margin-top: var(--space-1);
}

.workspace-live {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.live-indicator .state {
  color: var(--text-secondary);
}

/* The status strip is an open band on a tinted surface: one row of the four
   things a reader checks first, divided rather than boxed. */
.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-highlight);
  overflow: hidden;
}

.status-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-right: 1px solid var(--border-default);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.status-item:last-child {
  border-right: 0;
}

.status-item.is-openable {
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}

.status-item.is-openable:hover {
  background: color-mix(in srgb, var(--brand) 7%, transparent);
}

.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--elevation-1);
  color: var(--brand);
}

.status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.status-label {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.status-text .state {
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
}

.status-detail {
  overflow: hidden;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-secondary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Attention: the one place on the workspace allowed to raise its voice. */
.attention {
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--state-crit-dot);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--elevation-1);
  overflow: hidden;
}

.attention-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
}

.attention-header h3 {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
}

.attention-bell {
  color: var(--state-crit);
}

.attention-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.attention-header .state {
  margin-left: auto;
}

.attention-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.attention-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
  animation: rise-in var(--dur-slow) var(--ease-out) both;
}

.attention-item:last-child {
  border-bottom: 0;
}

.attention-item.severity-crit {
  background: color-mix(in srgb, var(--state-crit-bg) 45%, transparent);
}

.attention-text strong {
  display: block;
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.attention-text p {
  margin: 2px 0 0;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-secondary);
}

/* Measures */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4);
  color: inherit;
  font: inherit;
  text-align: left;
  overflow: hidden;
  animation: rise-in var(--dur-slow) var(--ease-out) both;
}

.kpi:nth-child(2) { animation-delay: 40ms; }
.kpi:nth-child(3) { animation-delay: 80ms; }
.kpi:nth-child(4) { animation-delay: 120ms; }

.kpi.is-openable {
  cursor: pointer;
  transition: box-shadow var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
}

.kpi.is-openable:hover {
  border-color: var(--brand-border);
  box-shadow: var(--elevation-2);
  transform: translateY(-1px);
}

.kpi-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.kpi-icon,
.panel-icon,
.activity-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: var(--radius-md);
  background: var(--tone-bg, var(--surface-sunken));
  color: var(--tone-fg, var(--text-secondary));
}

.kpi-icon { width: 24px; height: 24px; }

.kpi-label {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: var(--weight-semibold);
  line-height: 1.1;
  letter-spacing: var(--tracking-display);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.kpi-unit {
  margin-left: 2px;
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  letter-spacing: 0;
  color: var(--text-tertiary);
}

.kpi-visual {
  display: block;
  min-height: 22px;
}

.kpi-note {
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-secondary);
}

/* Panels */
.workspace-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  align-items: stretch;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.panel-span-2 {
  grid-column: span 2;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
}

.panel-icon { width: 32px; height: 32px; }

.panel-heading {
  min-width: 0;
  flex: 1 1 auto;
}

.panel-heading h3 {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-heading);
  color: var(--text-primary);
}

.panel-subtitle {
  margin: 0;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
}

.panel-body {
  flex: 1 1 auto;
  padding: var(--space-4);
}

.panel-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
}

.panel-note .icon {
  flex: 0 0 auto;
  margin-top: 1px;
}

.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 180px;
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.panel-empty strong {
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.panel-empty p {
  max-width: 40ch;
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-secondary);
}

/* The empty-state art: the panel's own icon on a concentric tinted plate, so
   an empty panel still reads as that panel and not as a generic blank. */
.panel-empty-art {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--brand-soft) 45%, transparent);
  color: var(--brand);
}

.panel-empty.is-quiet {
  min-height: 140px;
}

/* Legends */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
}

.chart-legend.is-inline {
  margin: 0 0 var(--space-3);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--tone);
}

.legend-line {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: var(--tone);
}

.legend-value {
  font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.legend-share {
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Segment bar */
.segment-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--viz-track);
}

.segment-chart.is-compact .segment-bar {
  height: 6px;
}

.segment {
  min-width: 3px;
  background: var(--tone);
  transform-origin: left center;
  animation: grow-x var(--dur-slow) var(--ease-out) both;
}

/* Bar list */
.bar-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-6);
  row-gap: var(--space-2);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(60px, 40%) 24px;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-meta);
}

.bar-label {
  overflow: hidden;
  color: var(--text-secondary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  position: relative;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--viz-track);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar);
  border-radius: inherit;
  background: var(--tone);
  transform-origin: left center;
  animation: grow-x var(--dur-slow) var(--ease-out) both;
}

.bar-value {
  font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  text-align: right;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Ring */
.ring {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
}

.ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg) scaleY(-1);
}

.ring circle {
  fill: none;
  stroke-width: 3.2;
}

.ring-track {
  stroke: var(--viz-track);
}

.ring-fill {
  stroke: var(--tone);
  stroke-linecap: round;
  transition: stroke-dasharray var(--dur-slow) var(--ease-out);
}

.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.ring-value small {
  font-size: var(--text-label);
  color: var(--text-tertiary);
}

/* Sparkline */
.sparkline {
  position: relative;
  display: block;
  height: 22px;
}

.sparkline svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sparkline polyline {
  fill: none;
  stroke: var(--tone);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.sparkline-end {
  position: absolute;
  width: 7px;
  height: 7px;
  border: 2px solid var(--surface-raised);
  border-radius: var(--radius-full);
  background: var(--tone);
  transform: translate(-50%, -50%);
  box-sizing: content-box;
}

/* Run chart */
.run-chart {
  --axis-w: 28px;
  display: grid;
  gap: var(--space-2);
}

.run-track {
  display: grid;
  grid-template-columns: var(--axis-w) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  column-gap: var(--space-2);
}

.track-label {
  grid-column: 2;
  margin-bottom: var(--space-1);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.track-axis {
  position: relative;
  grid-row: 2;
}

.axis-tick {
  position: absolute;
  right: 0;
  font-family: var(--font-mono);
  font-size: var(--text-label);
  color: var(--text-tertiary);
  transform: translateY(-50%);
  font-variant-numeric: tabular-nums;
}

.track-plot {
  position: relative;
  grid-row: 2;
  grid-column: 2;
}

.run-track-score .track-plot { height: 96px; }
.run-track-cases .track-plot { height: 110px; }

.grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed var(--viz-grid);
}

.grid-line.is-base {
  border-top-style: solid;
  border-top-color: var(--border-data);
}

.run-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.run-line polyline {
  fill: none;
  stroke: var(--state-work-dot);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.run-marker {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid var(--surface-raised);
  border-radius: var(--radius-full);
  background: var(--state-work-dot);
  box-sizing: content-box;
  transform: translate(-50%, -50%);
  animation: fade-in var(--dur-slow) var(--ease-out) both;
}

.run-marker.is-missing {
  width: 6px;
  height: 6px;
  border: 1.5px dashed var(--state-idle-dot);
  background: var(--surface-raised);
}

.run-columns {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--runs), minmax(0, 1fr));
}

.run-column {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  outline: none;
  cursor: default;
}

.run-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: min(28px, 62%);
  min-height: 3px;
  border-radius: 3px 3px 1px 1px;
  overflow: hidden;
  transform-origin: bottom center;
  animation: grow-y var(--dur-slow) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 30ms);
  transition: filter var(--dur-fast) var(--ease-out);
}

.run-seg { display: block; min-height: 2px; }
.seg-pass { background: var(--state-done-dot); }
.seg-fail { background: var(--state-attn-dot); }
.seg-none {
  --tone: var(--state-idle-dot);
  --tone-bg: var(--state-idle-bg);
  background-color: var(--state-idle-bg);
  background-image: repeating-linear-gradient(135deg, var(--state-idle-dot) 0 1.5px, transparent 1.5px 5px);
}

.run-column:hover .run-stack,
.run-column:focus-visible .run-stack {
  filter: brightness(1.08) saturate(1.1);
}

.run-column:focus-visible::before,
.run-column:hover::before {
  content: "";
  position: absolute;
  inset: -2px 10%;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}

.chart-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: var(--z-popover);
  display: grid;
  gap: 2px;
  min-width: 176px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-overlay);
  box-shadow: var(--elevation-3);
  color: var(--text-primary);
  font-size: var(--text-meta);
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.run-column:first-child .chart-tip { left: 0; transform: translate(0, 4px); }
.run-column:last-child .chart-tip { left: auto; right: 0; transform: translate(0, 4px); }

.run-column:hover .chart-tip,
.run-column:focus-visible .chart-tip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.run-column:first-child:hover .chart-tip,
.run-column:first-child:focus-visible .chart-tip,
.run-column:last-child:hover .chart-tip,
.run-column:last-child:focus-visible .chart-tip {
  transform: translate(0, 0);
}

.chart-tip strong {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
}

.chart-tip-meta {
  margin-bottom: 4px;
  color: var(--text-tertiary);
}

.chart-tip-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--text-secondary);
}

.chart-tip-row b {
  font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.run-dates {
  position: relative;
  height: 16px;
  margin-left: calc(var(--axis-w) + var(--space-2));
}

.axis-date {
  position: absolute;
  top: 0;
  font-size: var(--text-label);
  color: var(--text-tertiary);
  white-space: nowrap;
  transform: translateX(-50%);
}

/* Quality */
.quality-headline {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.quality-figure {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-display);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.quality-figure small {
  font-size: var(--text-body-lg);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
}

.quality-caption {
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.quality-facts {
  display: grid;
  gap: 0;
  margin: var(--space-4) 0 0;
  border-top: 1px solid var(--border-hairline);
}

.quality-fact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-hairline);
}

.quality-fact dt .state {
  color: var(--text-secondary);
  font-size: var(--text-body);
  font-weight: var(--weight-normal);
}

.quality-fact dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

/* Coverage */
.coverage-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
}

.coverage-figure {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-display);
  color: var(--text-primary);
}

.coverage-caption {
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.coverage-difficulty .section-label {
  display: block;
  margin-bottom: var(--space-2);
}

.section-label {
  margin: 0;
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Activity: a timeline, with a rail joining the events. */
.activity-list {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.activity-list::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 13px;
  width: 1px;
  background: var(--border-hairline);
}

.activity-item {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  animation: rise-in var(--dur-slow) var(--ease-out) both;
}

.activity-item:nth-child(2) { animation-delay: 30ms; }
.activity-item:nth-child(3) { animation-delay: 60ms; }
.activity-item:nth-child(4) { animation-delay: 90ms; }
.activity-item:nth-child(n+5) { animation-delay: 120ms; }

.activity-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  box-shadow: 0 0 0 3px var(--surface-raised);
}

.activity-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.activity-title {
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.activity-detail {
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.activity-body .state {
  margin-top: 2px;
}

.activity-time {
  padding-top: 2px;
  font-size: var(--text-meta);
  color: var(--text-tertiary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Workflows: a row of links, not another set of cards. */
.workflow-strip {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.workflow-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border-default);
  border-bottom: 1px solid var(--border-default);
}

.workflow-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-3) var(--space-3);
  border: 0;
  border-right: 1px solid var(--border-hairline);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}

.workflow-link:last-child { border-right: 0; }

.workflow-link:hover {
  background: var(--surface-raised);
}

.workflow-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.workflow-link:hover .workflow-icon {
  background: var(--brand);
  color: var(--brand-on);
}

.workflow-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.workflow-text strong {
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.workflow-text span {
  overflow: hidden;
  font-size: var(--text-meta);
  color: var(--text-tertiary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-arrow {
  margin-left: auto;
  color: var(--text-tertiary);
  transition: transform var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.workflow-link:hover .workflow-arrow {
  color: var(--brand);
  transform: translateX(3px);
}

/* Skeletons: the shape of what is coming, instead of the word "Loading". */
.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    var(--surface-sunken) 0%,
    color-mix(in srgb, var(--surface-sunken) 55%, var(--surface-raised)) 50%,
    var(--surface-sunken) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton-icon { width: 32px; height: 32px; border-radius: var(--radius-md); flex: 0 0 auto; }
.skeleton-line { height: 10px; width: 100%; margin: 4px 0; }
.skeleton-line.is-short { width: 45%; }
.skeleton-figure { height: 28px; width: 55%; margin: 6px 0; }
.skeleton-chart { height: 140px; width: 100%; margin-bottom: var(--space-3); border-radius: var(--radius-md); }
.skeleton-panel { padding: var(--space-1) 0; }

/* Motion ----------------------------------------------------------------------- */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes grow-x {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

@keyframes grow-y {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Motion that carries meaning -- a spinner saying "working" -- slows rather
   than stops, so the meaning survives. Everything decorative stops. */
@media (prefers-reduced-motion: reduce) {
  .kpi, .attention-item, .activity-item, .segment, .bar-fill, .run-stack,
  .run-marker, .kpi.is-openable, .workflow-link, .workflow-arrow,
  .link-button .icon, button.primary, button.secondary, button.danger {
    animation: none !important;
    transition: none !important;
  }

  .kpi.is-openable:hover { transform: none; }

  .state[data-live] .state-dot::after { animation: none; opacity: 0; }
  .skeleton { animation: none; }
  .state[data-spin] .state-dot,
  .state[data-spin] .state-glyph,
  .icon-button.is-spinning .icon { animation-duration: 3s; }
}

/* Responsive ------------------------------------------------------------------- */
@media (max-width: 1240px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .panel-span-2 { grid-column: 1 / -1; }
  .bar-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .status-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-item:nth-child(2) { border-right: 0; }
  .status-item:nth-child(-n+2) { border-bottom: 1px solid var(--border-default); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workflow-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workflow-link:nth-child(2) { border-right: 0; }
  .workflow-link:nth-child(-n+2) { border-bottom: 1px solid var(--border-hairline); }
}

@media (max-width: 760px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .bar-list { grid-template-columns: minmax(0, 1fr); }
  .coverage-summary { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .attention-item { grid-template-columns: auto minmax(0, 1fr); }
  .attention-item .link-button { grid-column: 2; justify-self: start; margin-left: calc(-1 * var(--space-2)); }
}

@media (max-width: 560px) {
  .status-strip { grid-template-columns: minmax(0, 1fr); }
  .status-item { border-right: 0; border-bottom: 1px solid var(--border-default); }
  .status-item:last-child { border-bottom: 0; }
  .kpi-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2); }
  .kpi { padding: var(--space-3); }
  .kpi-value { font-size: 22px; }
  .workflow-row { grid-template-columns: minmax(0, 1fr); }
  .workflow-link { border-right: 0; border-bottom: 1px solid var(--border-hairline); }
  .workflow-link:last-child { border-bottom: 0; }
  .workspace-header { align-items: flex-start; }
  .run-chart { --axis-w: 20px; }
  .chart-tip { min-width: 150px; }
  .attention-header .state { display: none; }
}

/* Workspace grid, by named area -------------------------------------------------
   Wide:    runs runs quality / coverage coverage activity
   Medium:  runs across, then quality beside activity, then coverage across
   Narrow:  one column, in reading order of importance
   Each layout keeps every row full, so no panel sits beside an empty column. */
.workspace-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    "runs runs quality"
    "coverage coverage activity";
}

.area-runs { grid-area: runs; }
.area-quality { grid-area: quality; }
.area-coverage { grid-area: coverage; }
.area-activity { grid-area: activity; }

@media (max-width: 1240px) {
  .workspace-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "runs runs"
      "quality activity"
      "coverage coverage";
  }
}

@media (max-width: 760px) {
  .workspace-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "runs" "quality" "activity" "coverage";
  }
}

/* When the live indicator wraps under the heading it stays on the right. */
.workspace-live {
  margin-left: auto;
}

.axis-date.is-day {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

/* Navigation -------------------------------------------------------------------
   The rail is a tinted plane; the page you are on is lifted out of it. An
   active item differs from its neighbours in five ways at once -- raised
   surface, elevation, a brand indicator, weight, and icon colour -- because a
   selection signalled by a slight tint alone is the difference between "I can
   see where I am" and "I have to look". */
aside .menu {
  gap: 2px;
}

.menu .menu-subitems {
  gap: 2px;
  margin: var(--space-1) 0 var(--space-2) 0;
  padding-left: 0;
  border-left: 0;
}

.menu .menu-subitems button,
.menu .menu-standalone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px var(--space-3) 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.menu .menu-icon {
  display: inline-flex;
  color: var(--text-tertiary);
  transition: color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.menu .menu-subitems button:hover,
.menu .menu-standalone:hover {
  background: color-mix(in srgb, var(--text-primary) 5%, transparent);
  color: var(--text-primary);
}

.menu .menu-subitems button:hover .menu-icon,
.menu .menu-standalone:hover .menu-icon {
  color: var(--text-secondary);
}

.menu .menu-subitems button.active,
.menu .menu-standalone.active {
  border-color: var(--border-default);
  background: var(--surface-raised);
  box-shadow: var(--elevation-1);
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

.menu .menu-subitems button.active::before,
.menu .menu-standalone.active::before {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: -1px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}

.menu .menu-subitems button.active .menu-icon,
.menu .menu-standalone.active .menu-icon {
  color: var(--brand);
}

/* Group titles are section labels. The one holding the current page is
   brighter, so the location reads even with every group collapsed. */
.menu .menu-group-title {
  min-height: 30px;
  margin-top: var(--space-2);
  padding: 4px var(--space-2) 4px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  box-shadow: none;
  color: var(--text-tertiary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
}

.menu .menu-group-title:hover {
  background: transparent;
  color: var(--text-primary);
}

.menu .menu-group-title.active {
  background: transparent;
  box-shadow: none;
  color: var(--text-primary);
}

.menu .menu-group-title.active .menu-arrow {
  color: var(--brand);
}

.menu-group-single {
  margin-bottom: 0;
}

/* The rail's brand block and footer sit on the same tinted plane. */
aside .rail-footer {
  border-top-color: var(--border-default);
}

aside .theme-toggle,
aside .sidebar-user-panel button {
  background: var(--surface-raised);
}

/* A closed group takes no vertical room: the open-group margin above also
   matched closed groups and left a gap under every collapsed title. */
.menu .menu-subitems.collapsed {
  margin: 0;
}

/* Run history cards -------------------------------------------------------------
   A card that opens a run is a button, so it is reachable and operable from the
   keyboard; these rules undo the browser's button defaults. */
button.run-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--elevation-1);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: box-shadow var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
}

button.run-card:hover {
  border-color: var(--brand-border);
  box-shadow: var(--elevation-2);
  transform: translateY(-1px);
}

button.run-card.selected-run-card {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand), var(--elevation-2);
}

button.run-card .run-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0;
}

button.run-card .run-stats {
  margin: 0;
}

.run-stats-outcome {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.run-stats-outcome div {
  padding: var(--space-2) var(--space-1);
}

.run-stats-outcome strong {
  font-size: var(--text-heading);
}

.run-stats .is-muted-stat strong {
  color: var(--state-idle);
}

button.run-card .run-card-footer {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
  color: var(--brand);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

button.run-card:hover .run-card-footer .icon {
  transform: translateX(2px);
}

button.run-card .run-card-footer .icon {
  transition: transform var(--dur-fast) var(--ease-out);
}

button.run-card.outcome-noResponse .run-title {
  color: var(--text-secondary);
}

@media (max-width: 560px) {
  .run-stats-outcome { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  button.run-card, button.run-card:hover { transition: none; transform: none; }
}

/* The stats respond to the card's width, not the window's: the same card sits
   in a two-column grid on a laptop and a one-column grid on a phone, and five
   labels that fit one layout clipped in the other. */
button.run-card {
  container-type: inline-size;
}

button.run-card .run-card-top {
  flex-wrap: wrap;
}

button.run-card .run-title {
  font-size: var(--text-body-lg);
}

.run-stats-outcome span {
  overflow-wrap: anywhere;
  hyphens: auto;
  letter-spacing: 0.02em;
}

@container (max-width: 380px) {
  .run-stats-outcome { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Sign-in: brand panel and form ------------------------------------------------
   Scoped with :has() to the page that carries the panel, so the EHR sign-in,
   which has its own identity, keeps its centred card unchanged.

   The panel deliberately has one look in both themes: a deep clinical navy.
   It is the product's signature surface, not content, and every text colour on
   it was checked against it directly rather than inherited from a theme. */
.login-view:has(> .login-showcase) {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  background: var(--surface-canvas);
}

.login-showcase {
  position: relative;
  display: flex;
  flex: 0 0 44%;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-6);
  max-width: 640px;
  min-height: 100vh;
  padding: var(--space-7) var(--space-7) var(--space-6);
  overflow: hidden;
  box-sizing: border-box;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(42, 106, 163, 0.55), transparent 60%),
    radial-gradient(90% 70% at 100% 100%, rgba(31, 122, 105, 0.45), transparent 60%),
    #0b1d2e;
  color: #eef4fa;
}

.showcase-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: rgba(164, 196, 226, 0.09);
  pointer-events: none;
}

.showcase-pulse {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: pulse-draw 2.2s var(--ease-out) 0.3s forwards;
}

@keyframes pulse-draw {
  to { stroke-dashoffset: 0; }
}

.showcase-brand,
.showcase-copy,
.showcase-points,
.showcase-foot {
  position: relative;
}

.showcase-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.showcase-eyebrow {
  margin: 0;
  color: #b8cbdd;
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.showcase-wordmark {
  margin: 0;
  color: #ffffff;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
}

.showcase-copy {
  max-width: 30rem;
}

.showcase-kicker {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  color: #7fd3c1;
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.showcase-kicker::before {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.showcase-title {
  margin: 0;
  color: #ffffff;
  font-size: clamp(22px, 2.3vw, 30px);
  font-weight: var(--weight-semibold);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.showcase-points {
  display: grid;
  gap: var(--space-4);
  max-width: 30rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.showcase-points li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.showcase-point-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(164, 196, 226, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  color: #a9d4f5;
}

.showcase-points strong {
  display: block;
  color: #ffffff;
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
}

.showcase-points li > span:last-child {
  color: #b7c7d7;
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

.showcase-foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding-top: var(--space-4);
  border-top: 1px solid rgba(164, 196, 226, 0.16);
  color: #b8cbdd;
  font-size: var(--text-meta);
}

.showcase-foot [data-icon] {
  color: #7fd3c1;
}

/* The form side. The panel already names the product, so the card drops its
   own logo and wordmark and leads with the task. */
.login-view:has(> .login-showcase) .login-card {
  align-self: center;
  margin: auto;
  max-width: 420px;
  box-shadow: var(--elevation-2);
}

.login-view:has(> .login-showcase) .login-brand {
  text-align: left;
}

.login-view:has(> .login-showcase) .brand-mark,
.login-view:has(> .login-showcase) .brand-eyebrow,
.login-view:has(> .login-showcase) .brand-wordmark,
.login-view:has(> .login-showcase) .login-footnote {
  display: none;
}

.login-view:has(> .login-showcase) .secure-pill {
  margin-bottom: var(--space-4);
}

.login-view:has(> .login-showcase) .login-brand h1 {
  font-size: 24px;
  font-weight: var(--weight-semibold);
}

.login-view:has(> .login-showcase) .login-lede {
  margin-bottom: var(--space-5);
}

@media (max-width: 960px) {
  .login-view:has(> .login-showcase) {
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
  }

  .login-showcase {
    display: none;
  }

  .login-view:has(> .login-showcase) .login-brand {
    text-align: center;
  }

  .login-view:has(> .login-showcase) .brand-mark,
  .login-view:has(> .login-showcase) .brand-eyebrow,
  .login-view:has(> .login-showcase) .brand-wordmark {
    display: block;
  }

  .login-view:has(> .login-showcase) .login-footnote {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  .showcase-pulse { animation: none; stroke-dashoffset: 0; }
}

/* Tabs ------------------------------------------------------------------------
   Four tab components had grown four looks: a pill, an inset shadow, a border
   and a background. They are one component now. The current tab is marked by
   colour, weight and a brand indicator that grows in from its centre, so the
   change of tab is visible as movement rather than a flicker of tint. */
:is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab) {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-md);
  padding: 6px var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

:is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab)::after {
  content: "";
  position: absolute;
  right: var(--space-3);
  bottom: 0;
  left: var(--space-3);
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
  transform: scaleX(0);
  transition: transform var(--dur-base) var(--ease-out);
}

:is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab):hover {
  border-color: transparent;
  background: color-mix(in srgb, var(--text-primary) 5%, transparent);
  color: var(--text-primary);
}

:is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab).active {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

:is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab).active::after {
  transform: scaleX(1);
}

/* The studio's tab bar is a raised strip that stays pinned while the chart
   scrolls beneath it. */
.patient-studio-tabs {
  gap: 2px;
  padding: var(--space-1) var(--space-2) 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--elevation-1);
}

.patient-studio-tabs .patient-studio-tab {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  min-height: 40px;
}

@media (prefers-reduced-motion: reduce) {
  :is(.patient-studio-tab, .tab-button, .clinical-resource-tab, .result-patient-context-tab)::after {
    transition: none;
  }
}

/* A judge score as a compact figure: the number carries the weight, the scale
   stays quiet. */
.score-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  padding: 1px var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.score-pill-value {
  color: var(--text-primary);
  font-size: var(--text-meta);
  font-weight: var(--weight-semibold);
}

.score-pill-max {
  color: var(--text-tertiary);
  font-size: var(--text-label);
}

.clinical-review-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.showcase-trace {
  position: relative;
  display: block;
  width: 100%;
  max-width: 30rem;
  height: 72px;
  margin: calc(-1 * var(--space-4)) 0;
  overflow: visible;
}

/* On the tinted rail a hairline border disappears, so the role pills take the
   structural border and a raised fill. */
aside .sidebar-role-pill {
  border: 1px solid var(--border-default);
  background: var(--surface-raised);
  color: var(--text-secondary);
}

/* Run chart on narrow plots -----------------------------------------------------
   The chart measures its own width, not the window's: it is full width on a
   phone and a third of the page on a wide screen. Below the width at which
   every label fits, times are dropped first and dates kept, so the axis still
   says when things happened. */
.run-chart {
  container-type: inline-size;
}

.run-column .chart-tip {
  left: 50%;
}

.run-column.tip-start .chart-tip {
  left: 0;
  right: auto;
  transform: translate(0, 4px);
}

.run-column.tip-end .chart-tip {
  left: auto;
  right: 0;
  transform: translate(0, 4px);
}

.run-column.tip-start:is(:hover, :focus-visible) .chart-tip,
.run-column.tip-end:is(:hover, :focus-visible) .chart-tip {
  transform: translate(0, 0);
}

/* A tooltip that is not showing takes no part in layout or in the tab order. */
.chart-tip {
  visibility: hidden;
}

.run-column:is(:hover, :focus-visible) .chart-tip {
  visibility: visible;
}

.area-runs {
  overflow: visible;
}

@container (max-width: 560px) {
  .axis-date:not(.is-day):not(.is-last) { visibility: hidden; }
}

@container (max-width: 360px) {
  .axis-date:not(.is-first):not(.is-last) { visibility: hidden; }
}

.axis-date.is-first { transform: translateX(-25%); }
.axis-date.is-last { transform: translateX(-75%); }

/* Case rows on narrow screens ----------------------------------------------------
   The list's single track was "1fr", which grows to its widest row, and the
   badge column neither shrank nor wrapped, so on a phone every row ran 74px
   past the screen with its badges cut off. */
.case-list,
.results-grid {
  grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 640px) {
  .compact-case-row {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .compact-case-side {
    flex-wrap: wrap;
  }

  .compact-badge {
    flex-shrink: 1;
    max-width: 100%;
  }
}

/* Endpoints and identifiers have no spaces to break at, so on a phone a single
   base URL pushed its row past the screen. They may break anywhere. */
.config-row-main,
.config-row-main .small-note {
  min-width: 0;
  overflow-wrap: anywhere;
}

.bar-list {
  row-gap: var(--space-3);
}

.bar-stack {
  position: absolute;
  inset: 0 auto 0 0;
  display: flex;
  gap: 1px;
  width: var(--bar);
  border-radius: inherit;
  overflow: hidden;
  transform-origin: left center;
  animation: grow-x var(--dur-slow) var(--ease-out) both;
}

.bar-part {
  min-width: 2px;
  background: var(--tone);
}

.coverage-difficulty .chart-legend {
  margin-top: var(--space-2);
}

@media (prefers-reduced-motion: reduce) {
  .bar-stack { animation: none; }
}

/* The activity feed takes the height of the row it sits in rather than setting
   it. Left to size itself, eight events made the row 250px taller than the
   panel beside it and left that panel standing over empty space. Size
   containment removes the feed from the row's height calculation; the feed
   then fills what the neighbouring panel needs and scrolls the rest, with a
   fade at the foot to say there is more. In one column there is no neighbour,
   so the feed returns to its natural height. */
@media (min-width: 761px) {
  .area-activity {
    contain: size;
    min-height: 320px;
  }

  .area-activity .panel-body {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-data) transparent;
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
  }

  .area-activity .activity-list {
    padding-bottom: var(--space-4);
  }
}

/* Patient summary ---------------------------------------------------------------
   Built around what a clinician scans first. Clinical load is three figures a
   reader can take in at once; body metrics carry their own scale; the rest are
   facts in a list rather than five identical boxes. */
.clinical-load {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-bottom: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--border-hairline);
  overflow: hidden;
}

.clinical-load-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 0;
  background: var(--surface-raised);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}

.clinical-load-item:hover {
  background: var(--surface-hover);
}

.clinical-load-icon {
  grid-row: span 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--tone-bg);
  color: var(--tone-fg);
}

.clinical-load-figure {
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-display);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.clinical-load-label {
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.body-metrics {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-hairline);
  border-bottom: 1px solid var(--border-hairline);
}

.body-metric {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.body-metric-label {
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.body-metric-value {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.bmi-scale {
  position: relative;
  display: block;
  height: 6px;
  margin-top: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--viz-track);
}

.bmi-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--tone) 55%, transparent);
}

.bmi-band:first-child { border-radius: var(--radius-full) 0 0 var(--radius-full); }
.bmi-band:nth-child(4) { border-radius: 0 var(--radius-full) var(--radius-full) 0; }

.bmi-marker {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid var(--surface-raised);
  border-radius: var(--radius-full);
  background: var(--text-primary);
  box-shadow: var(--elevation-1);
  transform: translate(-50%, -50%);
}

.bmi-ticks {
  position: relative;
  display: block;
  height: 14px;
}

.bmi-ticks span {
  position: absolute;
  font-family: var(--font-mono);
  font-size: var(--text-label);
  color: var(--text-tertiary);
  transform: translateX(-50%);
}

.summary-facts {
  display: grid;
  margin: 0;
}

.summary-fact {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr);
  align-items: start;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-hairline);
}

.summary-fact:last-child {
  border-bottom: 0;
}

.summary-fact dt {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-meta);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
}

.summary-fact dd {
  margin: 0;
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text-primary);
}

.summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.fact-chip {
  padding: 2px var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-size: var(--text-meta);
  color: var(--text-secondary);
}

.fact-chip.is-more {
  border-style: dashed;
  background: transparent;
  color: var(--text-tertiary);
}

@media (max-width: 640px) {
  .clinical-load { grid-template-columns: minmax(0, 1fr); }
  .body-metrics { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
  .summary-fact { grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
}

/* Studio controls ------------------------------------------------------------------
   Four fixed columns added up to 896px and were placed in a card 631px wide, so
   the last two filters ran out of the card. The search takes the most room and
   every control can shrink; the row wraps before anything is cut off. Controls
   share the product's control height rather than a local 44px. */
.clinical-studio-controls.compact {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
}

.clinical-studio-controls.compact .clinical-studio-search-control {
  flex: 2 1 240px;
  min-width: 0;
}

.clinical-studio-controls.compact select {
  flex: 1 1 150px;
  min-width: 0;
  width: auto;
  height: var(--control-md);
  min-height: var(--control-md);
}

.clinical-studio-search-control input {
  min-height: var(--control-md);
}

/* One height for the whole control row. The search keeps its button inside the
   field as a quiet icon rather than a filled disc, which at this size put a
   dark glyph on a blue circle nobody could read. */
.clinical-studio-controls.compact .clinical-studio-search-control input,
.clinical-studio-controls.compact select {
  height: var(--control-md);
  min-height: var(--control-md);
  padding-top: 0;
  padding-bottom: 0;
  line-height: normal;
}

.clinical-studio-controls.compact .clinical-studio-search-control input {
  padding-right: 36px;
}

.clinical-studio-controls.compact .clinical-studio-search-control {
  flex: 2 1 200px;
}

.clinical-studio-controls.compact select {
  flex: 1 1 120px;
}

.clinical-studio-search-button {
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-sm);
  height: var(--control-sm);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-tertiary);
}

.clinical-studio-search-button:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

.button-with-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

@media (max-width: 560px) {
  .clinical-studio-controls.compact select {
    flex-basis: 100%;
  }
}

/* Workspace vertical rhythm -----------------------------------------------------
   The page switcher shows the active page with display:block !important, which
   overrides the workspace's display:flex -- and a flex gap does nothing on a
   block. Every section sat about two pixels from the next. Spacing between the
   workspace's direct children is margin, which holds whatever display the page
   switcher gives the section. */
.workspace > * + * {
  margin-top: var(--space-4);
}

.workspace > .workspace-header {
  margin-bottom: var(--space-1);
}

.workspace > .workflow-strip {
  margin-top: var(--space-5);
}

/* Studio header actions ---------------------------------------------------------- */
.page-header-with-action {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.page-actions {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.launch-action {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

/* The launch button is the page's main action: brand fill, a mark that ties it
   to March Assistant, and an out-arrow that says it opens somewhere else. It is
   taller than the secondary action beside it so it is found first. */
button.primary.launch-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-lg);
  padding: 0 var(--space-4) 0 var(--space-3);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-semibold);
  box-shadow: 0 1px 2px rgba(16, 38, 58, 0.18), 0 4px 12px rgba(28, 95, 146, 0.22);
}

button.primary.launch-button:hover:not(:disabled) {
  box-shadow: 0 2px 4px rgba(16, 38, 58, 0.2), 0 8px 20px rgba(28, 95, 146, 0.3);
  transform: translateY(-1px);
}

.launch-button-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.16);
}

.launch-button-out {
  opacity: 0.85;
  transition: transform var(--dur-fast) var(--ease-out);
}

button.primary.launch-button:hover:not(:disabled) .launch-button-out {
  transform: translate(1px, -1px);
}

/* Not ready: still clearly the launch button, with the reason beneath it, so a
   person who is looking for it knows why it cannot be used yet. The label takes
   the system's disabled colour from the global button:disabled rule -- that
   colour exists for switched-off controls -- and the reason is carried by the
   status line, which is ordinary readable text. */
button.primary.launch-button:disabled {
  background: var(--surface-sunken);
  border-color: var(--border-default);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 1;
}

button.primary.launch-button:disabled .launch-button-mark {
  background: var(--surface-raised);
  color: var(--state-ai);
}

button.primary.launch-button.is-preparing .launch-button-mark .icon {
  animation: state-spin 1.2s linear infinite;
}

.launch-status {
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
  color: var(--text-tertiary);
  text-align: right;
}

.launch-status[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .page-actions {
    width: 100%;
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .launch-action {
    align-items: stretch;
  }

  button.primary.launch-button {
    justify-content: center;
  }

  .launch-status {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  button.primary.launch-button:hover:not(:disabled) { transform: none; }
  button.primary.launch-button.is-preparing .launch-button-mark .icon { animation: none; }
}

/* Patient summary rhythm ----------------------------------------------------------
   The card lost its in-title button; its heading block now sits closer to the
   figures it introduces, and the fact labels take less of the row so values
   start nearer to them. */
#patientStudioSummaryPanel .card-title-row {
  margin-bottom: var(--space-4);
}

#patientStudioSummaryPanel .card-title-row .small-note {
  margin: var(--space-1) 0 0;
}

.summary-fact {
  grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
}

.patient-studio-tabs {
  margin: 0 0 var(--space-4);
}

/* Page rhythm --------------------------------------------------------------------
   Pages are stacks of headers, filter bars, cards and lists placed directly in
   the page section, and several pages had two of them touching -- the March
   Agent profiles card on its connection card, the run case list on the
   progress card. Every block in a page is at least 16px from the one before.
   Pages are normal flow, so these margins collapse with any larger margin an
   element already has: the 24px under a page header stays 24px. */
#pageHost > section > * + * {
  margin-top: var(--space-4);
}

/* Header actions share one height, so the pair lines up on both edges. */
.page-actions > button.secondary {
  min-height: var(--control-lg);
  padding: 0 var(--space-3);
}
