/* =========================================================================
   REV.health PRD v2 — Shared stylesheet
   - 4-theme token registry (Light, Dark, Hospital, Modern) on body class
   - Tokens are the only place colors are defined; components reference vars
   - Naming convention: --color-* per AGENTS.md
   ========================================================================= */

/* --------- Structural / typographic tokens (theme-independent) ----------- */
:root {
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-serif: 'Source Serif Pro', Georgia, 'Times New Roman', serif;
  --font-mono:  'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

  --header-h:    56px;
  --sidebar-w:   272px;
  --content-max: 1100px;
  --radius:      8px;
  --radius-sm:   5px;
  --radius-lg:   12px;
}

/* =========================================================================
   THEME REGISTRY — 4 themes, all using the same token names.
   Components MUST reference var(--color-*); never hard-code colors.
   ========================================================================= */

/* ----- THEME: Light (default) — warm clinical paper ---------------------- */
:root,
body.theme-light {
  --color-bg:             #faf7f0;
  --color-surface:        #ffffff;
  --color-surface-2:      #f3ede0;
  --color-surface-3:      #ece4d2;
  --color-border:         #d9cfba;
  --color-border-strong:  #b9ad94;
  --color-text:           #1f2328;
  --color-text-dim:       #4a5360;
  --color-text-mute:      #7a8493;
  --color-accent:         #155e6e;
  --color-accent-hover:   #1c7c8e;
  --color-accent-fg:      #ffffff;
  --color-danger:         #b22222;
  --color-warn:           #8c5a2d;
  --color-success:        #2e7d32;
  --color-info:           #1a3a5c;
  --color-focus-ring:     color-mix(in srgb, var(--color-accent) 35%, transparent);
  --color-shadow-sm:      0 1px 2px rgba(31,35,40,0.07);
  --color-shadow-md:      0 4px 16px rgba(31,35,40,0.10);
  --color-shadow-lg:      0 8px 28px rgba(31,35,40,0.13);
  --color-overlay:        rgba(31,35,40,0.45);
  color-scheme: light;
}

/* ----- THEME: Dark — clinical dark, warm professional ------------------- */
body.theme-dark {
  --color-bg:             #0f1418;
  --color-surface:        #161c22;
  --color-surface-2:      #1d242c;
  --color-surface-3:      #242c36;
  --color-border:         #2a333d;
  --color-border-strong:  #3a4552;
  --color-text:           #e7ecef;
  --color-text-dim:       #a3acb6;
  --color-text-mute:      #6f7a86;
  --color-accent:         #5fb1be;
  --color-accent-hover:   #79c4cf;
  --color-accent-fg:      #07121a;
  --color-danger:         #d65a5a;
  --color-warn:           #d49050;
  --color-success:        #6cbfa6;
  --color-info:           #5fb1be;
  --color-focus-ring:     color-mix(in srgb, var(--color-accent) 45%, transparent);
  --color-shadow-sm:      0 1px 2px rgba(0,0,0,0.35);
  --color-shadow-md:      0 4px 16px rgba(0,0,0,0.45);
  --color-shadow-lg:      0 12px 32px rgba(0,0,0,0.55);
  --color-overlay:        rgba(0,0,0,0.65);
  color-scheme: dark;
}

/* ----- THEME: Hospital — sober institutional blues ---------------------- */
body.theme-hospital {
  --color-bg:             #f3f6fb;
  --color-surface:        #ffffff;
  --color-surface-2:      #e8eef7;
  --color-surface-3:      #d8e2f0;
  --color-border:         #c4d0e2;
  --color-border-strong:  #92a5c2;
  --color-text:           #0d2348;
  --color-text-dim:       #3d527a;
  --color-text-mute:      #6b7a96;
  --color-accent:         #1a4d8c;
  --color-accent-hover:   #266ab4;
  --color-accent-fg:      #ffffff;
  --color-danger:         #a82828;
  --color-warn:           #b6731f;
  --color-success:        #1f7a4d;
  --color-info:           #1a4d8c;
  --color-focus-ring:     color-mix(in srgb, var(--color-accent) 30%, transparent);
  --color-shadow-sm:      0 1px 2px rgba(13,35,72,0.07);
  --color-shadow-md:      0 4px 16px rgba(13,35,72,0.10);
  --color-shadow-lg:      0 8px 28px rgba(13,35,72,0.14);
  --color-overlay:        rgba(13,35,72,0.50);
  color-scheme: light;
}

/* ----- THEME: Modern — REV brand, warm minimal -------------------------- */
body.theme-modern {
  --color-bg:             #ffffff;
  --color-surface:        #fbfaf7;
  --color-surface-2:      #f3efe6;
  --color-surface-3:      #e8e2d3;
  --color-border:         #e3ddcd;
  --color-border-strong:  #c8bda4;
  --color-text:           #18181b;
  --color-text-dim:       #4f4f55;
  --color-text-mute:      #84848c;
  --color-accent:         #c84a2d;
  --color-accent-hover:   #e35e3e;
  --color-accent-fg:      #ffffff;
  --color-danger:         #b53d3d;
  --color-warn:           #b07020;
  --color-success:        #2e7d4d;
  --color-info:           #1f5d8a;
  --color-focus-ring:     color-mix(in srgb, var(--color-accent) 30%, transparent);
  --color-shadow-sm:      0 1px 2px rgba(24,24,27,0.05);
  --color-shadow-md:      0 4px 16px rgba(24,24,27,0.08);
  --color-shadow-lg:      0 8px 28px rgba(24,24,27,0.12);
  --color-overlay:        rgba(24,24,27,0.45);
  color-scheme: light;
}

/* =========================================================================
   RESET / BASE
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .2s ease, color .2s ease;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Skip-link — first focusable element on every page */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--color-accent); color: var(--color-accent-fg);
  padding: 0.55rem 1rem; border-radius: var(--radius-sm);
  font-weight: 600; z-index: 1000;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* Main landmark focus indicator — visible when skip-link activates focus */
main#main:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 4px;
  border-radius: 3px;
}

/* =========================================================================
   TYPOGRAPHY
   ========================================================================= */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -0.005em;
  color: var(--color-text);
  margin: 0;
}
h1 { font-size: 2rem;    margin: 0 0 0.75rem; letter-spacing: -0.015em; }
h2 { font-size: 1.45rem; margin: 2rem 0 0.85rem;
     padding-bottom: 0.4rem;
     border-bottom: 1px solid color-mix(in srgb, var(--color-accent) 25%, var(--color-border));
     color: var(--color-accent); }
h3 { font-size: 1.18rem; margin: 1.5rem 0 0.55rem; color: var(--color-text); }
h4 { font-size: 1.02rem; margin: 1.1rem  0 0.4rem;  color: var(--color-text-dim); }
h5 { font-size: 0.92rem; margin: 0.9rem  0 0.3rem; }
h6 { font-family: var(--font-sans); font-size: 0.78rem;
     color: var(--color-text-mute); text-transform: uppercase;
     letter-spacing: 0.08em; font-weight: 700; margin: 0.85rem 0 0.3rem; }

p  { margin: 0 0 0.85rem; }
ul, ol { margin: 0 0 1rem 1.4rem; }
li { margin-bottom: 0.3rem; }

code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: var(--color-surface-2);
  padding: 0.12em 0.38em; border-radius: 4px;
  color: var(--color-text);
  overflow-wrap: anywhere;
}
pre {
  font-family: var(--font-mono); font-size: 0.85rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem; overflow-x: auto; max-width: 100%;
  line-height: 1.55; margin: 0 0 1rem;
}
hr { border: 0; border-top: 1px solid var(--color-border); margin: 2rem 0; }

/* Wide entity-schema tables scroll horizontally within their content column
   instead of forcing the whole page to overflow. Applied at all widths
   because the injected sidebar narrows the content area on tablet too;
   when the table fits, no scrollbar shows. */
/* Form controls never exceed their container (long <option> text was forcing
   <select> wider than the viewport on phones). */
select, input, textarea { max-width: 100%; box-sizing: border-box; }

/* Keep the visit-timeline grid scrollable so it never widens the page; the
   select's own min-width is clamped to the container in its component block. */
.visit-timeline { max-width: 100%; }
.vt-grid { overflow-x: auto; max-width: 100%; }

/* Tables are wrapped in .table-scroll by shell.js (wrapWideTables) so any wide
   table scrolls within its column instead of forcing the whole page to overflow
   on narrow screens. Reliable across all table classes; no scrollbar when the
   table fits. */
.table-scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }

/* =========================================================================
   BUTTONS — .btn variants: primary, ghost, danger
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer; user-select: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-strong);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-fg);
}
.btn.primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}
.btn.ghost {
  background: transparent;
  border-color: var(--color-border);
}
.btn.ghost:hover { background: var(--color-surface-2); }
.btn.danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--color-accent-fg);
}
.btn.sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn.lg { padding: 0.75rem 1.25rem; font-size: 1rem; }

/* =========================================================================
   PILLS / BADGES
   ========================================================================= */
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--font-sans);
  font-size: 0.72rem; font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--color-surface-2);
  color: var(--color-text-dim);
  border: 1px solid var(--color-border);
  letter-spacing: 0.04em; text-transform: uppercase;
  line-height: 1.2; white-space: nowrap;
}
.pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.pill.success { color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-success) 35%, var(--color-border)); }
.pill.warn    { color: var(--color-warn);
  background: color-mix(in srgb, var(--color-warn) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-warn) 35%, var(--color-border)); }
.pill.danger  { color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border)); }
.pill.info    { color: var(--color-info);
  background: color-mix(in srgb, var(--color-info) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-info) 35%, var(--color-border)); }
.pill.accent  { color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-accent) 35%, var(--color-border)); }

/* =========================================================================
   CARDS
   ========================================================================= */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--color-shadow-sm);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--color-shadow-md);
}
.card .card-title {
  margin: 0 0 0.4rem;
  font-family: var(--font-serif);
  font-size: 1.08rem;
  color: var(--color-text);
}
.card .card-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-dim);
}
.card-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* =========================================================================
   CALLOUTS — info / warn / danger / success
   ========================================================================= */
.callout {
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  background: var(--color-surface);
  padding: 0.85rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1rem 0;
  font-size: 0.92rem;
  color: var(--color-text);
}
.callout strong {
  display: block; margin-bottom: 0.2rem;
  color: var(--color-text);
  font-family: var(--font-serif); font-size: 1rem;
}
.callout.info    { border-left-color: var(--color-info); }
.callout.warn    { border-left-color: var(--color-warn); }
.callout.danger  { border-left-color: var(--color-danger); }
.callout.success { border-left-color: var(--color-success); }

/* =========================================================================
   TABLES
   ========================================================================= */
.table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85rem 0 1.25rem;
  font-size: 0.88rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
  color: var(--color-text);
}
.table th {
  background: var(--color-surface-2);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: color-mix(in srgb, var(--color-accent) 6%, var(--color-surface)); }

/* =========================================================================
   TABLE-SCROLL — horizontal scroll wrapper for narrow viewports
   Prevents wide tables from overflowing the page layout.
   ========================================================================= */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border-radius: var(--radius);
}
.table-scroll > .table,
.table-scroll > .data-table {
  margin-top: 0;
  margin-bottom: 0;
}

/* ---------- Per-minute visit-type timeline (interactive demo) ----------- */
.visit-timeline {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  padding: 1rem 1.1rem 1.1rem;
  margin: 0.5rem 0 1.25rem;
  box-shadow: var(--color-shadow-sm);
}
.visit-timeline-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.9rem;
}
.visit-timeline-label {
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
}
.visit-timeline-select {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  min-width: min(320px, 100%);
  max-width: 100%;
  cursor: pointer;
}
.visit-timeline-select:focus {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 1px;
}
.visit-timeline-meta {
  font-size: 0.82rem;
  color: var(--color-text-dim);
  margin-left: auto;
}
.visit-timeline-meta strong { color: var(--color-text); font-weight: 600; }

.vt-grid {
  --label-col: 180px;
  --tick-h: 22px;
  --row-h: 26px;
  display: block;
  font-size: 0.8rem;
  overflow-x: auto;
}
.vt-grid-inner {
  min-width: 760px;
}
.vt-axis {
  display: grid;
  grid-template-columns: var(--label-col) 1fr;
  align-items: end;
  margin-bottom: 0.3rem;
}
.vt-axis-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-mute);
  padding-bottom: 4px;
}
.vt-axis-ticks {
  position: relative;
  height: var(--tick-h);
  border-bottom: 1px solid var(--color-border);
}
.vt-axis-ticks span {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: var(--color-text-dim);
  font-variant-numeric: tabular-nums;
}
.vt-axis-ticks span::after {
  content: "";
  display: block;
  width: 1px;
  height: 6px;
  background: var(--color-border-strong);
  margin: 2px auto 0;
}
.vt-row {
  display: grid;
  grid-template-columns: var(--label-col) 1fr;
  align-items: center;
  border-bottom: 1px dashed color-mix(in srgb, var(--color-border) 70%, transparent);
}
.vt-row:last-child { border-bottom: 0; }
.vt-row-label {
  font-size: 0.82rem;
  color: var(--color-text);
  padding: 0.25rem 0.6rem 0.25rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vt-row.is-idle .vt-row-label {
  color: var(--color-text-mute);
}
.vt-row-track {
  position: relative;
  height: var(--row-h);
  background: repeating-linear-gradient(
    to right,
    color-mix(in srgb, var(--color-border) 30%, transparent) 0,
    color-mix(in srgb, var(--color-border) 30%, transparent) 1px,
    transparent 1px,
    transparent calc(100% / var(--vt-minutes, 45) * 5)
  );
}
.vt-stage {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 3px;
  padding: 0 6px;
  font-size: 0.74rem;
  line-height: calc(var(--row-h) - 6px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text);
  border-left: 2px solid var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 22%, var(--color-surface));
}
.stage-checkin {
  background: color-mix(in srgb, var(--color-info) 30%, var(--color-surface));
  border-left-color: var(--color-info);
}
.stage-waiting {
  background: color-mix(in srgb, var(--color-warn) 28%, var(--color-surface));
  border-left-color: var(--color-warn);
}
.stage-rooming {
  background: color-mix(in srgb, var(--color-success) 28%, var(--color-surface));
  border-left-color: var(--color-success);
}
.stage-provider {
  background: color-mix(in srgb, var(--color-accent) 32%, var(--color-surface));
  border-left-color: var(--color-accent);
}
.stage-nurse {
  background: color-mix(in srgb, var(--color-success) 20%, var(--color-surface));
  border-left-color: color-mix(in srgb, var(--color-success) 70%, var(--color-accent));
}
.stage-checkout {
  background: color-mix(in srgb, var(--color-info) 22%, var(--color-surface));
  border-left-color: var(--color-info);
}
.stage-procedure {
  background: color-mix(in srgb, var(--color-danger) 28%, var(--color-surface));
  border-left-color: var(--color-danger);
}
.stage-telehealth {
  background: color-mix(in srgb, var(--color-accent) 30%, var(--color-surface));
  border-left-color: var(--color-accent-hover);
}
.stage-lab {
  background: color-mix(in srgb, var(--color-warn) 22%, var(--color-surface));
  border-left-color: var(--color-warn);
}
.stage-vitals {
  background: color-mix(in srgb, var(--color-success) 22%, var(--color-surface));
  border-left-color: var(--color-success);
}

.visit-timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.85rem;
  font-size: 0.78rem;
  color: var(--color-text-dim);
}
.visit-timeline-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.visit-timeline-legend .swatch {
  display: inline-block;
  width: 14px;
  height: 12px;
  border-radius: 2px;
  border-left: 2px solid currentColor;
}

/* ---------- Resource-graph comparison table (REV vs. competitors) ------- */
.diff-resource-table-wrap {
  overflow-x: auto;
  margin: 0.9rem 0 1.25rem;
  border-radius: var(--radius);
}
.diff-resource-table {
  min-width: 820px;
  font-size: 0.82rem;
  margin: 0;
}
.diff-resource-table th,
.diff-resource-table td {
  padding: 0.45rem 0.65rem;
  line-height: 1.4;
}
.diff-resource-table th:first-child,
.diff-resource-table td:first-child {
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface-2);
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
}
.diff-resource-table .col-rev {
  background: color-mix(in srgb, var(--color-accent) 9%, var(--color-surface));
  border-left: 3px solid var(--color-accent);
  color: var(--color-text);
  font-weight: 500;
}
.diff-resource-table th.col-rev {
  color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface-2));
}
.diff-resource-table caption {
  caption-side: top;
  text-align: left;
  font-size: 0.78rem;
  color: var(--color-text-mute);
  padding: 0 0 0.45rem;
  font-family: var(--font-sans);
  letter-spacing: 0.02em;
}

/* ---------- Phase column styling (L0 pitch + module pages) -------------- */
/* Phase 1 = warm (amber/gold)  ·  Phase 2 = neutral (progress)  ·  Phase 3 = cool (teal/blue) */
/* Each column has a distinct tinted background, colored left border,
   themed header color, and a unique phase-icon shape so the three
   phases are immediately distinguishable even without color vision. */

/* --- Phase 1: warm tint ----------------------------------------------- */
.table th.phase-1,
.table td.phase-1 {
  background: color-mix(in srgb, var(--color-warn) 12%, var(--color-surface));
  border-left: 3px solid color-mix(in srgb, var(--color-warn) 55%, var(--color-border));
}
.table th.phase-1 {
  color: var(--color-warn);
  border-bottom: 2px solid color-mix(in srgb, var(--color-warn) 50%, var(--color-border));
}
.table th.phase-1 .phase-icon {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--color-warn);
  margin-right: 0.45rem;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-warn) 20%, var(--color-surface));
}

/* --- Phase 2: neutral with progress indicator ------------------------- */
.table th.phase-2,
.table td.phase-2 {
  background: color-mix(in srgb, var(--color-surface-2) 40%, var(--color-surface));
  border-left: 3px solid var(--color-border-strong);
}
.table th.phase-2 {
  color: var(--color-text-dim);
  border-bottom: 2px solid var(--color-border-strong);
}
.table th.phase-2 .phase-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--color-text-mute);
  margin-right: 0.45rem;
  vertical-align: middle;
  flex-shrink: 0;
  position: relative;
}
.table th.phase-2 .phase-icon::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px; right: 2px; bottom: 2px;
  border-radius: 50%;
  background: var(--color-text-mute);
  opacity: 0.35;
  /* Arc-shaped clip gives a "half-done" progress look */
  clip-path: polygon(50% 0%, 100% 0%, 100% 100%, 50% 100%, 50% 50%);
}

/* --- Phase 3: cool tint ------------------------------------------------ */
.table th.phase-3,
.table td.phase-3 {
  background: color-mix(in srgb, var(--color-info) 12%, var(--color-surface));
  border-left: 3px solid color-mix(in srgb, var(--color-info) 55%, var(--color-border));
}
.table th.phase-3 {
  color: var(--color-info);
  border-bottom: 2px solid color-mix(in srgb, var(--color-info) 50%, var(--color-border));
}
.table th.phase-3 .phase-icon {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  background: var(--color-info);
  margin-right: 0.45rem;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-info) 20%, var(--color-surface));
}

/* Phase column hover should preserve tint, not override with accent mix */
.table tr:hover td.phase-1 { background: color-mix(in srgb, var(--color-warn) 16%, var(--color-surface)); }
.table tr:hover td.phase-2 { background: color-mix(in srgb, var(--color-surface-2) 55%, var(--color-surface)); }
.table tr:hover td.phase-3 { background: color-mix(in srgb, var(--color-info) 16%, var(--color-surface)); }

/* =========================================================================
   INPUTS
   ========================================================================= */
.input,
input[type="text"].input,
input[type="search"].input,
input[type="email"].input,
input[type="number"].input,
textarea.input,
select.input {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--color-text-mute); }
.input:focus,
input[type="text"].input:focus,
input[type="search"].input:focus,
textarea.input:focus,
select.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}
.label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-dim);
  margin-bottom: 0.3rem;
  font-family: var(--font-sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* =========================================================================
   KPI TILE — used on persona dashboards & module pages
   ========================================================================= */
.kpi {
  display: flex; flex-direction: column; gap: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--color-shadow-sm);
  min-width: 0;
}
.kpi .kpi-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-mute);
}
.kpi .kpi-value {
  font-family: var(--font-serif);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--color-text);
  letter-spacing: -0.01em;
}
.kpi .kpi-delta {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-dim);
}
.kpi .kpi-delta.up      { color: var(--color-success); }
.kpi .kpi-delta.down    { color: var(--color-danger); }
.kpi-grid {
  display: grid; gap: 0.85rem;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

/* =========================================================================
   THEME PICKER (used in header and on theme-matrix.html)
   ========================================================================= */
.theme-picker {
  display: inline-flex; gap: 0.3rem; flex-wrap: wrap;
  padding: 0.3rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.theme-picker .tp-btn {
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--color-text-dim);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background .15s, color .15s, border-color .15s;
}
.theme-picker .tp-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.theme-picker .tp-btn.active {
  background: var(--color-surface-2);
  border-color: color-mix(in srgb, var(--color-accent) 50%, var(--color-border));
  color: var(--color-text);
}
.theme-picker .tp-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}
.theme-picker .tp-swatch.tp-light    { background: linear-gradient(135deg, #faf7f0 0%, #155e6e 100%); }
.theme-picker .tp-swatch.tp-dark     { background: linear-gradient(135deg, #0f1418 0%, #5fb1be 100%); }
.theme-picker .tp-swatch.tp-hospital { background: linear-gradient(135deg, #f3f6fb 0%, #1a4d8c 100%); }
.theme-picker .tp-swatch.tp-modern   { background: linear-gradient(135deg, #ffffff 0%, #c84a2d 100%); }

/* =========================================================================
   SITE SHELL — header / sidebar / main / footer
   Rendered on every walkthrough page by assets/shell.js. Pages opt out by
   setting <body data-shell="off"> (e.g. theme-matrix.html test page).
   ========================================================================= */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

body.has-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--header-h) 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}
body.has-shell > .skip-link { grid-column: 1 / -1; }
body.has-shell > .site-header  { grid-area: header; }
body.has-shell > .site-sidebar { grid-area: sidebar; }
body.has-shell > .site-main    { grid-area: main; padding: 1.25rem 2rem 3rem; min-width: 0; }
body.has-shell > .site-footer  { grid-area: footer; }

/* Prose fills the content column. Legacy readable-measure caps (inline
   max-width:720px, per-page .lede max-width:70ch, narrow callouts, etc.)
   left the right half of wide screens empty; override them site-wide.
   Fixed-width UI (receipts, modals, input grids, diagrams) is deliberately
   NOT targeted, so it keeps its intended size. */
.site-main :is(p, ul, ol, dl, .lede, .callout, blockquote) {
  max-width: none !important;
}

/* ---------- Header --------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0 1rem;
  z-index: 100;
}
@supports not (backdrop-filter: blur(10px)) {
  .site-header { background: var(--color-bg); }
}

.hamburger {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 1.05rem; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}
.hamburger:hover { background: var(--color-surface-2); }
.hamburger[aria-expanded="true"] {
  background: var(--color-surface-2);
  border-color: var(--color-border-strong);
}

.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  padding: 0.25rem 0.35rem;
  border-radius: var(--radius-sm);
}
.brand:hover { color: var(--color-accent); text-decoration: none; }
.brand .brand-mark {
  display: inline-flex;
  width: 26px; height: 26px;
  color: var(--color-accent);
  flex-shrink: 0;
}
.brand .brand-mark > svg { width: 100%; height: 100%; }
.brand .brand-text {
  font-weight: 700;
  white-space: nowrap;
}
.brand .brand-text-sub {
  color: var(--color-text-mute);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-sans);
  margin-left: 0.25rem;
}

.site-search {
  flex: 1 1 220px;
  min-width: 0; max-width: 480px;
  display: flex; align-items: center;
  margin: 0;
}
.site-search > .input {
  height: 36px;
  padding-top: 0.4rem; padding-bottom: 0.4rem;
}

.header-actions {
  display: flex; align-items: center; gap: 0.4rem;
  flex-shrink: 0;
  margin-left: auto;
}
.header-link {
  display: inline-flex; align-items: center;
  font-size: 0.88rem; font-weight: 600;
  padding: 0.4rem 0.7rem;
  color: var(--color-text-dim);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid transparent;
}
.header-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  text-decoration: none;
}
.header-link.external::after {
  content: " ↗";
  font-weight: 400;
  color: var(--color-text-mute);
  margin-left: 0.15rem;
}
.header-link.demo-link {
  border-color: color-mix(in srgb, var(--color-accent) 35%, var(--color-border));
  color: var(--color-accent);
}
.header-link.demo-link:hover {
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
  color: var(--color-accent);
}

/* ---------- Environment toggle (Local | Online) --------------------------- */
.header-env-toggle {
  display: inline-flex; align-items: center; gap: 0;
  font-size: .78rem; font-weight: 600;
  margin-left: .5rem;
}
.header-env-opt {
  padding: .25rem .45rem;
  border-radius: var(--radius-sm);
  color: var(--color-text-mute);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.header-env-opt:hover { background: var(--color-surface-2); color: var(--color-text); }
.header-env-opt.active {
  background: var(--color-accent);
  color: #fff;
}
.header-env-sep {
  color: var(--color-text-mute);
  font-weight: 400;
  margin: 0 .15rem;
}

/* ---------- Settings button + User display -------------------------------- */
.header-settings-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.header-settings-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.header-settings-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.header-user {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ---------- Settings Modal ------------------------------------------------ */
.settings-overlay {
  position: fixed; inset: 0;
  background: var(--color-overlay);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.settings-overlay[hidden] { display: none; }
.settings-modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--color-shadow-lg);
  width: 90vw; max-width: 420px;
  padding: 0;
  color: var(--color-text);
}
.settings-modal[open] { display: block; }
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.settings-title {
  margin: 0; font-size: 1.05rem; font-weight: 700;
}
.settings-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 1.4rem; line-height: 1; color: var(--color-text-dim);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
.settings-close:hover { background: var(--color-surface-2); color: var(--color-text); }
.settings-body {
  padding: 1.25rem;
}
.settings-section {
  border: none; margin: 0; padding: 0;
}
.settings-section legend {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--color-text-mute);
  margin-bottom: 0.75rem; padding: 0;
}
.settings-theme-picker.theme-picker {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  padding: 0; border: none; background: transparent;
}
.settings-theme-picker .tp-btn {
  flex: 1 1 0; min-width: 0;
  justify-content: center;
  padding: 0.6rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.settings-theme-picker .tp-btn.active {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-surface));
}

/* ---------- Sidebar -------------------------------------------------------- */
.site-sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.1rem 0.75rem 2rem;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
}
.sidebar-title {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-mute);
  padding: 0 0.55rem 0.5rem;
  margin: 0;
}
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav > li { margin: 0; }
.sidebar-nav .sb-row {
  display: flex; align-items: center; gap: 0.5rem;
}
.sidebar-nav .sb-item {
  display: flex; align-items: center; gap: 0.55rem;
  flex: 1 1 auto;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--color-text-dim);
  text-decoration: none;
  position: relative;
  min-width: 0;
}
/* Top-level section labels get more weight than children */
.sidebar-nav > li > .sb-row > .sb-item {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
}
.sidebar-nav .sb-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  text-decoration: none;
}
.sidebar-nav .sb-level {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--color-text-mute);
  background: var(--color-surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.sidebar-nav [aria-current="page"] {
  background: color-mix(in srgb, var(--color-accent) 12%, var(--color-surface));
  color: var(--color-text);
  font-weight: 700;
}
.sidebar-nav [aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -0.05rem; top: 0.4rem; bottom: 0.4rem;
  width: 3px;
  background: var(--color-accent);
  border-radius: 2px;
}
.sidebar-nav [aria-current="page"] .sb-level {
  background: color-mix(in srgb, var(--color-accent) 22%, var(--color-surface));
  color: var(--color-accent);
}
.sb-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--color-text-mute);
  cursor: pointer;
  font-size: 0.78rem;
  margin-right: 0.15rem;
}
.sb-toggle:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.sb-toggle .chev {
  display: inline-block;
  transition: transform .15s ease;
}
.sb-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.sidebar-sub {
  list-style: none;
  padding: 0 0 0.4rem 1.6rem;
  margin: 0.1rem 0 0.4rem;
  border-left: 1px dashed var(--color-border);
}
.sidebar-sub .sb-item {
  font-size: 0.85rem;
  padding: 0.35rem 0.55rem;
}
.sidebar-section-collapsed .sidebar-sub { display: none; }

/* ---------- Sidebar mobile/backdrop --------------------------------------- */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: var(--header-h) 0 0 0;
  background: var(--color-overlay);
  z-index: 90;
}

/* ---------- Breadcrumb (in main) ------------------------------------------ */
.breadcrumb {
  list-style: none;
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--color-text-mute);
  margin: 0 0 0.85rem; padding: 0;
}
.breadcrumb li {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin: 0;
}
.breadcrumb li + li::before {
  content: "/"; color: var(--color-text-mute);
}
.breadcrumb a {
  color: var(--color-text-dim);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--color-accent); text-decoration: underline; }
.breadcrumb [aria-current="page"] {
  color: var(--color-text);
  font-weight: 600;
}

/* ---------- Footer --------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.1rem 1.5rem;
  font-size: 0.8rem;
  color: var(--color-text-dim);
  background: var(--color-surface);
  display: flex;
  gap: 1rem; flex-wrap: wrap;
  justify-content: space-between; align-items: center;
}
.site-footer .footer-version,
.site-footer .footer-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.site-footer .footer-meta {
  display: inline-flex; gap: 0.85rem; flex-wrap: wrap;
  align-items: center;
}

/* ---------- Mobile (≤720px) ----------------------------------------------- */
@media (max-width: 720px) {
  body.has-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main"
      "footer";
  }
  body.has-shell > .site-main { padding: 1rem 1rem 2rem; }
  .hamburger { display: inline-flex; }
  .site-sidebar {
    position: fixed;
    top: var(--header-h); left: 0; bottom: 0;
    width: 280px; max-width: 82vw;
    height: calc(100vh - var(--header-h));
    z-index: 95;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--color-shadow-lg);
  }
  body.sidebar-open .site-sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .site-search { display: none; }
  .header-actions { gap: 0.25rem; }
  .header-link.demo-link .header-link-text-full { display: none; }
  .header-link.demo-link .header-link-text-short { display: inline; }
  .header-user { font-size: 0.78rem; padding: 0.25rem 0.45rem; }
  .brand .brand-text-sub { display: none; }
}
@media (min-width: 721px) {
  .header-link.demo-link .header-link-text-short { display: none; }
  .header-link.demo-link .header-link-text-full { display: inline; }
}
@media (max-width: 480px) {
  .site-header { padding: 0 0.5rem; gap: 0.35rem; }
  .brand { padding: 0.25rem 0.2rem; gap: 0.4rem; }
  .brand .brand-text,
  .brand .brand-text-sub { display: none; }
  .header-link { padding: 0.35rem 0.45rem; font-size: 0.78rem; }
  .header-link.external::after { content: ""; margin: 0; }
  .header-actions { gap: 0.2rem; }
  .header-user { display: none; }
}

/* ---------- Print ---------------------------------------------------------- */
@media print {
  .skip-link,
  .site-header,
  .site-sidebar,
  .sidebar-backdrop,
  .hamburger { display: none !important; }
  body.has-shell {
    display: block;
    grid-template: none;
  }
  body.has-shell > .site-main { padding: 0; }
  .site-footer {
    border-top: 1px solid #888;
    background: transparent;
  }
}

/* =========================================================================
   THEME-MATRIX page layout
   ========================================================================= */
.matrix-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
}
.matrix-wrap header.matrix-head {
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 5;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.matrix-wrap header.matrix-head h1 { margin: 0; font-size: 1.35rem; }
.matrix-wrap section.component-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}
.matrix-wrap section.component-block > h2 {
  margin-top: 0;
  font-size: 1rem;
  border-bottom: none;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-sans);
  font-weight: 700;
  padding-bottom: 0;
}
.demo-row {
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center;
  margin: 0.5rem 0;
}
.swatch-row {
  display: grid; gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  margin-top: 0.5rem;
}
.swatch-row .sw {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
}
.swatch-row .sw .sw-color { height: 44px; width: 100%; }
.swatch-row .sw .sw-meta {
  padding: 0.4rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-text-dim);
}
.swatch-row .sw .sw-name {
  display: block;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--color-text);
}

/* =========================================================================
   PER-PAGE FILTER (injected by filter.js via shell.js)
   ========================================================================= */

.page-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 1.25rem;
  max-width: 600px;
  flex-wrap: wrap;
}

.page-filter-label {
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--color-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}

.page-filter-input-wrap {
  position: relative;
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  align-items: center;
}

.page-filter-input {
  padding-right: 1.8rem !important;  /* space for clear button */
}

.page-filter-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--color-text-mute);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.page-filter-clear:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.page-filter-regex {
  font-family: var(--font-mono) !important;
  font-size: 0.78rem !important;
  padding: 0.3rem 0.55rem !important;
  letter-spacing: -0.02em;
  color: var(--color-text-mute);
  flex-shrink: 0;
}
.page-filter-regex.active,
.page-filter-regex[aria-pressed="true"] {
  background: color-mix(in srgb, var(--color-accent) 15%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-accent) 50%, var(--color-border));
  color: var(--color-accent);
}

.page-filter-count {
  font-size: 0.78rem;
  color: var(--color-text-mute);
  white-space: nowrap;
  flex-shrink: 0;
}
.page-filter-error {
  color: var(--color-danger);
}

.page-filter-hint {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--color-text-mute);
  opacity: 0.55;
  white-space: nowrap;
  flex-shrink: 0;
}

/* --- Match highlights --- */
mark.page-filter-match {
  background: color-mix(in srgb, var(--color-accent) 30%, var(--color-surface));
  color: var(--color-text);
  padding: 0.05em 0.12em;
  border-radius: 2px;
}

mark.page-filter-first {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  background: color-mix(in srgb, var(--color-accent) 45%, var(--color-surface));
}

/* Mobile adjustments */
@media (max-width: 720px) {
  .page-filter-bar {
    max-width: 100%;
    gap: 0.4rem;
  }
  .page-filter-hint { display: none; }
}

/* Print: hide filter bar and un-highlight marks */
@media print {
  .page-filter-bar { display: none !important; }
  mark.page-filter-match {
    background: transparent;
    outline: none;
    padding: 0;
  }
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 720px) {
  body { font-size: 14px; }
  .matrix-wrap { padding: 1rem 1rem 3rem; }
}
