/* ==========================================================================
   SpineVision V2.0 — clinical design system
   Restrained, high-legibility, desktop-first. No gradients, glass, glow or
   decorative animation. Severity is always text + grade, never colour alone.
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #cdd2da;

  /* text */
  --text: #16202e;
  --text-2: #3d4757;
  --muted: #667085;
  --faint: #98a2b3;

  /* accent — restrained medical blue */
  --accent: #1f5ea8;
  --accent-hover: #184c89;
  --accent-soft: #eaf1fa;
  --accent-border: #b7cde9;
  --navy: #0f2742;

  /* semantic */
  --ok: #1e6b45;       --ok-soft: #e8f4ed;      --ok-border: #b6dcc5;
  --warn: #8a5a00;     --warn-soft: #fdf5e1;    --warn-border: #f0d894;
  --danger: #b3261e;   --danger-soft: #fcebea;  --danger-border: #f2c0bb;
  --info: #1f5ea8;     --info-soft: #eaf1fa;    --info-border: #b7cde9;

  /* Lee severity (ordinal): green → amber → orange → red */
  --sev-normal: #2a7348;   --sev-normal-bg: #e9f4ee;
  --sev-mild: #876400;     --sev-mild-bg: #fbf3d6;
  --sev-moderate: #b04e0c; --sev-moderate-bg: #fcece0;
  --sev-severe: #b3261e;   --sev-severe-bg: #fbe8e6;

  /* clinician (validated) vs AI */
  --clinician: #0f2742;
  --ai: #5b6474;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --sidebar-w: 232px;
  --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); font-feature-settings: "tnum" 1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; color: var(--text); letter-spacing: -.005em; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; }
p { margin: 0 0 8px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
        stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon-lg { width: 20px; height: 20px; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; background: var(--navy); }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--navy); color: #c9d3e0; display: flex; flex-direction: column;
  border-right: 1px solid #0a1d33;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px; color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 6px; background: #fff; color: var(--navy);
              display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: -.02em; }
.brand-text b { display: block; font-size: 13px; letter-spacing: .08em; font-weight: 700; }
.brand-text small { display: block; font-size: 11px; color: #8fa0b6; letter-spacing: .01em; }

.nav { padding: 6px 10px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #7d8ea6;
             padding: 14px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
         color: #c9d3e0; font-weight: 500; font-size: 13.5px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.1); color: #fff; box-shadow: inset 2px 0 0 #7fb1ea; }
.nav a .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.12); color: #fff;
                border-radius: 10px; padding: 0 7px; line-height: 18px; }

.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius-sm); color: #fff; }
.user-chip:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #2c4a6e; color: #fff; display: grid;
          place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.user-chip b { display: block; font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip small { display: block; font-size: 11.5px; color: #8fa0b6; }
.sidebar-foot form { margin: 6px 0 0; }
.sidebar-foot .signout { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; color: #aab7c8;
                         background: none; border: 0; font: inherit; font-size: 13px; cursor: pointer; border-radius: var(--radius-sm); }
.sidebar-foot .signout:hover { background: rgba(255,255,255,.06); color: #fff; }
.engine { margin-top: 10px; font-size: 11px; color: #8fa0b6; display: flex; gap: 6px; align-items: center; padding: 0 6px; }
.engine i { width: 7px; height: 7px; border-radius: 50%; background: #5fbf8a; display: inline-block; }
.engine i.off { background: #e0a100; }

.main { min-width: 0; display: flex; flex-direction: column; background: var(--bg); min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); background: var(--surface);
          border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 24px; }
.topbar .menu-btn { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs .sep { color: var(--faint); }
.crumbs .current { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search-mini { position: relative; }
.search-mini input, .search-mini input[type=search] { width: 240px; padding-left: 30px; height: 32px; }
.search-mini .icon { position: absolute; left: 9px; top: 8px; color: var(--faint); }

.page { width: 100%; max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* demo / consult banners */
.sys-banner { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--warn-border);
              padding: 8px 24px; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.consult-banner { background: var(--accent-soft); border: 1px solid var(--accent-border); color: var(--navy);
                  border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 12px; align-items: center;
                  flex-wrap: wrap; margin-bottom: 14px; font-size: 13.5px; }
.consult-banner .actions { margin-left: auto; }

/* ── Patient context banner ────────────────────────────────────────────── */
.patient-banner { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
                  padding: 14px 18px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; box-shadow: var(--shadow); }
.patient-banner.sticky { position: sticky; top: calc(var(--topbar-h) + 8px); z-index: 15; }
.pb-id { min-width: 0; }
.pb-name { font-size: 17px; font-weight: 700; letter-spacing: .01em; text-transform: uppercase; color: var(--text); }
.pb-name a { color: inherit; }
.pb-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; margin-top: 2px; }
.pb-meta b { color: var(--text-2); font-weight: 600; }
.pb-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.patient-banner.compact { padding: 10px 14px; }
.patient-banner.compact .pb-name { font-size: 15px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 14px; }
.card-head .hint { color: var(--muted); font-size: 12.5px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 13px; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }

/* ── Stat cards ────────────────────────────────────────────────────────── */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
        display: block; color: inherit; box-shadow: var(--shadow); }
a.stat:hover { border-color: var(--accent-border); text-decoration: none; }
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.stat .d { color: var(--muted); font-size: 12.5px; }
.stat.attention .v { color: var(--warn); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
       border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
       color: var(--text); font: 500 13.5px/1 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-confirm { background: var(--clinician); border-color: var(--clinician); color: #fff; }
.btn-confirm:hover { background: #09192c; }
.btn-danger { background: var(--surface); border-color: var(--danger-border); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #971f18; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 40px; padding: 0 18px; font-size: 14px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-btn.danger { color: var(--danger); }
.link-btn:hover { text-decoration: underline; }
form.inline { display: inline; margin: 0; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; height: 22px; border-radius: 11px;
         font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; line-height: 1; }
.badge .icon { width: 13px; height: 13px; }
.badge-neutral { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge-outline { background: transparent; color: var(--text-2); border-color: var(--border-strong); }

/* severity: text + grade chip, colour is secondary */
.sev { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.sev .g { font: 600 11px/1 var(--mono); padding: 3px 5px; border-radius: 3px; border: 1px solid currentColor; }
.sev-normal { color: var(--sev-normal); }
.sev-mild { color: var(--sev-mild); }
.sev-moderate { color: var(--sev-moderate); }
.sev-severe { color: var(--sev-severe); }
.sev-pill { padding: 2px 9px 2px 3px; border-radius: 12px; }
.sev-pill.sev-normal { background: var(--sev-normal-bg); }
.sev-pill.sev-mild { background: var(--sev-mild-bg); }
.sev-pill.sev-moderate { background: var(--sev-moderate-bg); }
.sev-pill.sev-severe { background: var(--sev-severe-bg); }
.src { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* validation status — icon + word */
.vstat { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.vstat-pending { color: var(--warn); }
.vstat-partial { color: var(--warn); }
.vstat-confirmed, .vstat-reviewed { color: var(--ok); }
.vstat-corrected { color: #5b3d99; }
.vstat-draft { color: var(--muted); }

/* appointment status */
.ast { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.ast::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.ast-scheduled { color: var(--text-2); }
.ast-checked-in { color: var(--accent); }
.ast-in-consultation { color: #5b3d99; }
.ast-completed { color: var(--ok); }
.ast-cancelled { color: var(--faint); text-decoration: line-through; }
.ast-no-show { color: var(--danger); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase;
            letter-spacing: .04em; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfc; }
.table tr.clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .row-actions { text-align: right; white-space: nowrap; }
.table .row-actions > * + *, .table .row-actions > .cell-v > * + * { margin-left: 6px; }
.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.right { text-align: right; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=time],
input[type=datetime-local], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 34px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: #fff; font: 14px var(--font); color: var(--text);
}
textarea { height: auto; min-height: 84px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,94,168,.15); }
input[readonly] { background: var(--surface-3); }
.field { margin-bottom: 14px; min-width: 0; }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
fieldset { border: 0; margin: 0 0 8px; padding: 0; }
.form-section { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; }
.form-section h3 { margin-bottom: 12px; }
.form-section .section-sub { color: var(--muted); font-size: 12.5px; margin: -8px 0 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; }

/* segmented controls (filters, level selector, viewer modes) */
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.seg > a, .seg > button { border: 0; border-right: 1px solid var(--border); background: transparent; padding: 0 12px; height: 32px;
                          display: inline-flex; align-items: center; gap: 6px; font: 500 13px var(--font); color: var(--text-2); cursor: pointer; }
.seg > :last-child { border-right: 0; }
.seg > a:hover, .seg > button:hover { background: var(--surface-3); text-decoration: none; }
.seg > .on { background: var(--navy); color: #fff; }
.seg > .on:hover { background: var(--navy); }
.seg > button:disabled { color: var(--faint); cursor: not-allowed; background: var(--surface-2); }
.seg .n { font-size: 11px; color: inherit; opacity: .7; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .n { margin-left: 4px; font-size: 11.5px; color: var(--faint); }

/* ── Alerts / flash ────────────────────────────────────────────────────── */
.flashes { margin-bottom: 16px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius); border: 1px solid;
         font-size: 13.5px; margin-bottom: 8px; }
.alert .icon { margin-top: 2px; }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: #183f6e; }
.alert-success { background: var(--ok-soft); border-color: var(--ok-border); color: #174f33; }
.alert-warning { background: var(--warn-soft); border-color: var(--warn-border); color: #6b4700; }
.alert-error { background: var(--danger-soft); border-color: var(--danger-border); color: #8c1d17; }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .6; padding: 0; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty h3 { color: var(--text-2); margin-bottom: 4px; }
.empty .actions { justify-content: center; margin-top: 12px; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); font-weight: 500; }
.kv-4 { grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr); }
@media (max-width: 900px) { .kv-4 { grid-template-columns: max-content minmax(0, 1fr); } }

.disclaimer { font-size: 12.5px; color: var(--muted); border-left: 3px solid var(--border-strong); padding: 6px 10px; background: var(--surface-2); }

/* ── Stepper ───────────────────────────────────────────────────────────── */
.stepper { display: flex; list-style: none; margin: 0 0 16px; padding: 0; background: var(--surface); border: 1px solid var(--border);
           border-radius: var(--radius); overflow-x: auto; }
.stepper li { flex: 1; min-width: 118px; padding: 10px 12px; display: flex; gap: 8px; align-items: center; font-size: 12.5px;
              color: var(--muted); border-right: 1px solid var(--border); white-space: nowrap; }
.stepper li:last-child { border-right: 0; }
.stepper .n { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center;
              font-size: 11px; font-weight: 600; flex: none; }
.stepper li.done { color: var(--text-2); }
.stepper li.done .n { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper li.current { color: var(--text); font-weight: 600; background: var(--accent-soft); }
.stepper li.current .n { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── MRI viewer ────────────────────────────────────────────────────────── */
.viewer-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.viewer-toolbar .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.planes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.plane { background: #0b0f14; border-radius: var(--radius); overflow: hidden; position: relative; border: 1px solid #1b2330; }
.plane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; color: #c7d0dc;
              font-size: 12px; background: #121821; border-bottom: 1px solid #1b2330; }
.plane-head b { color: #fff; font-weight: 600; }
.plane-img { aspect-ratio: 1 / 1; display: grid; place-items: center; background: #000; cursor: zoom-in; }
.plane-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.plane-img { position: relative; }
.disc-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.disc-overlay .disc { pointer-events: all; cursor: pointer; outline: none; }
.disc-overlay .disc .hit { fill: transparent; stroke: none; }
.disc-overlay .lbl { font-family: var(--font); font-weight: 600; paint-order: stroke; stroke: rgba(0,0,0,.8); stroke-linejoin: round; }
/* Original view: minimal markers beside the disc; nothing drawn over the disc itself */
.mode-markers .disc { opacity: .55; }
.mode-markers .disc .leader { stroke: #dfe7f1; stroke-width: 1; vector-effect: non-scaling-stroke; }
.mode-markers .disc .dot { fill: #dfe7f1; }
.mode-markers .disc .lbl { fill: #dfe7f1; }
.mode-markers .disc:hover, .mode-markers .disc:focus-visible { opacity: .9; }
.mode-markers .disc.on { opacity: 1; }
.mode-markers .disc.on .leader { stroke: #ffd24d; stroke-width: 1.5; }
.mode-markers .disc.on .dot { fill: #ffd24d; }
.mode-markers .disc.on .lbl { fill: #ffd24d; font-weight: 700; }
.mode-markers .disc.unavailable { opacity: .35; cursor: not-allowed; }
.mode-markers .disc.unavailable .leader { stroke-dasharray: 2 2; }
.mode-markers .disc.unavailable .dot { fill: none; stroke: #dfe7f1; stroke-width: 1; vector-effect: non-scaling-stroke; }
/* Grad-CAM / ROI / Structures: bounding boxes */
.mode-boxes .disc .frame { fill: rgba(127,177,234,.06); stroke: #7fb1ea; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.mode-boxes .disc .lbl { fill: #cfe2f7; }
.mode-boxes .disc:hover .frame, .mode-boxes .disc:focus-visible .frame { stroke: #fff; stroke-width: 2; }
.mode-boxes .disc.on .frame { stroke: #ffd24d; stroke-width: 3; fill: rgba(255,210,77,.14); }
.mode-boxes .disc.on .lbl { fill: #ffd24d; }
.mode-boxes .disc.unavailable { cursor: not-allowed; }
.mode-boxes .disc.unavailable .frame { stroke: #8e99a8; stroke-dasharray: 4 3; fill: none; }
.mode-boxes .disc.unavailable .lbl { fill: #aab4c2; }
.mode-markers .disc.unassigned, .mode-boxes .disc.unassigned { cursor: help; }
.mode-markers .disc.unassigned { opacity: .6; }
.mode-markers .disc.unassigned .leader { stroke: #e0b64d; stroke-dasharray: 2 2; }
.mode-markers .disc.unassigned .dot { fill: none; stroke: #e0b64d; stroke-width: 1; vector-effect: non-scaling-stroke; }
.mode-markers .disc.unassigned .lbl { fill: #e0b64d; }
.mode-boxes .disc.unassigned .frame { stroke: #e0b64d; stroke-dasharray: 4 3; fill: none; }
.mode-boxes .disc.unassigned .lbl { fill: #e0b64d; }
.mode-boxes .disc.excluded { cursor: default; opacity: .6; }
.mode-boxes .disc.excluded .frame { stroke: #8e99a8; stroke-dasharray: 2 3; fill: none; stroke-width: 1; }
.mode-boxes .disc.excluded .lbl { fill: #aab4c2; font-weight: 500; }
.disc-overlay .disc:focus-visible .dot, .disc-overlay .disc:focus-visible .frame { outline: none; }
.plane-empty { aspect-ratio: 1 / 1; display: grid; place-items: center; color: #7d8898; font-size: 13px; text-align: center; padding: 20px; }
.plane-foot { padding: 6px 10px; font-size: 11.5px; color: #8e99a8; background: #121821; border-top: 1px solid #1b2330; min-height: 30px; }
.plane-foot b { color: #d7dee8; }
.legend { display: inline-flex; gap: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }

.levels-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.level-btn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 5px 10px;
             min-width: 92px; text-align: left; cursor: pointer; font: inherit; color: var(--text); }
.level-btn .lv { font: 600 13px var(--mono); display: block; }
.level-btn .st { font-size: 11.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.level-btn.on { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); background: #f3f6fa; }
.level-btn:disabled { color: var(--faint); background: var(--surface-2); cursor: default; border-style: dashed; }
.level-btn .mark { width: 8px; height: 8px; border-radius: 50%; display: inline-block; border: 1.5px solid currentColor; }
.level-btn .mark.done { background: currentColor; }

/* AI result vs clinician result */
.result-block { border-radius: var(--radius); padding: 14px 16px; }
.ai-block { border: 1px dashed #b9c0cb; background: var(--surface-2); }
.clin-block { border: 1px solid var(--border); border-left: 4px solid var(--clinician); background: #fff; }
.pending-block { border: 1px solid var(--warn-border); background: var(--warn-soft); }
.rb-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
            display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.clin-block .rb-label { color: var(--clinician); }
.rb-level { font: 600 13px var(--mono); color: var(--text-2); }
.rb-finding { font-size: 20px; font-weight: 700; letter-spacing: .01em; text-transform: uppercase; line-height: 1.2; }
.rb-grade { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.rb-conf { display: flex; align-items: baseline; gap: 8px; margin-top: 10px; }
.rb-conf .v { font-size: 22px; font-weight: 600; }
.rb-conf .k { color: var(--muted); font-size: 12.5px; }
.rb-meta { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.rb-note { font-size: 13px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 8px; }

.prob { display: grid; grid-template-columns: 76px minmax(0, 1fr) 52px; gap: 10px; align-items: center; font-size: 13px; margin: 6px 0; }
.prob .bar { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.prob .bar i { display: block; height: 100%; background: #8a95a5; }
.prob.top .bar i { background: var(--navy); }
.prob.top .name { font-weight: 700; }
.prob .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

.grade-choice { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.grade-choice label { margin: 0; }
.grade-choice input { position: absolute; opacity: 0; }
.grade-choice span { display: block; text-align: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
                     padding: 8px 4px; cursor: pointer; font-weight: 600; font-size: 13px; background: #fff; }
.grade-choice span small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.grade-choice input:checked + span { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); background: #f3f6fa; }
.grade-choice input:disabled + span { opacity: .45; cursor: not-allowed; }
.grade-choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

details.ref { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.ref > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 13.5px; list-style: none; display: flex; gap: 8px; align-items: center; }
details.ref > summary::-webkit-details-marker { display: none; }
details.ref > summary::before { content: "▸"; color: var(--muted); font-size: 11px; }
details.ref[open] > summary::before { content: "▾"; }
details.ref .ref-body { padding: 0 14px 14px; font-size: 13.5px; color: var(--text-2); }

/* ── Timeline ──────────────────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 92px 14px minmax(0, 1fr); gap: 10px; padding: 0 0 14px; position: relative; }
.timeline .when { color: var(--muted); font-size: 12.5px; text-align: right; padding-top: 1px; font-variant-numeric: tabular-nums; }
.timeline .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--border-strong); background: #fff; margin-top: 5px; position: relative; z-index: 1; }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 108px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline .t { font-weight: 600; font-size: 13.5px; }
.timeline .d { color: var(--muted); font-size: 12.5px; }
.timeline .k-study .dot, .timeline .k-report .dot { border-color: var(--accent); }
.timeline .k-validation .dot { border-color: var(--clinician); background: var(--clinician); }
.timeline .k-pain .dot, .timeline .k-odi .dot { border-color: var(--sev-mild); }
.timeline .k-appointment .dot { border-color: #5b3d99; }

/* ── Charts (server-rendered SVG) ──────────────────────────────────────── */
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--navy); stroke-width: 2; }
.chart .pt { fill: #fff; stroke: var(--navy); stroke-width: 2; }
.chart .val { fill: var(--text-2); font-size: 10.5px; font-weight: 600; font-family: var(--font); }

/* ── Pain selector (NRS 0–10) ──────────────────────────────────────────── */
.nrs { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; }
.nrs label { margin: 0; }
.nrs input { position: absolute; opacity: 0; }
.nrs span { display: grid; place-items: center; height: 38px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
            font-weight: 600; cursor: pointer; background: #fff; font-variant-numeric: tabular-nums; }
.nrs input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; }
.nrs input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.nrs-bands { display: grid; grid-template-columns: 1fr 3fr 3fr 3fr 1fr; gap: 4px; margin-top: 4px; font-size: 11.5px; color: var(--muted); text-align: center; }
.nrs-bands span { border-top: 2px solid var(--border-strong); padding-top: 3px; }
.nrs-desc { margin-top: 8px; font-size: 13px; color: var(--text-2); min-height: 20px; }

/* ── Upload ────────────────────────────────────────────────────────────── */
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); padding: 22px;
            text-align: center; cursor: pointer; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type=file] { display: none; }
.dropzone .t { font-weight: 600; margin-top: 6px; }
.dropzone .s { color: var(--muted); font-size: 12.5px; }
.file-rows { margin-top: 12px; display: grid; gap: 8px; }
.file-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) 150px; gap: 12px; align-items: center; border: 1px solid var(--border);
            border-radius: var(--radius-sm); padding: 8px; background: #fff; }
.file-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 3px; background: #000; }
.file-row .fname { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row select { height: 32px; }

.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 3px; background: #000; display: block; }

/* ── Calendar ──────────────────────────────────────────────────────────── */
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.cal td { vertical-align: top; height: 108px; border: 1px solid var(--border); padding: 6px; font-size: 12px; }
.cal td.out { background: var(--surface-2); color: var(--faint); }
.cal td.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .dn { font-weight: 600; font-size: 12px; display: flex; justify-content: space-between; }
.cal .ev { display: block; margin-top: 3px; padding: 2px 5px; border-radius: 3px; background: var(--surface-3); color: var(--text);
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--border-strong); }
.cal .ev:hover { text-decoration: none; background: var(--accent-soft); }
.cal .ev.st-completed { border-left-color: var(--ok); }
.cal .ev.st-in-consultation, .cal .ev.st-checked-in { border-left-color: var(--accent); }
.cal .ev.st-cancelled { opacity: .55; text-decoration: line-through; }
.cal .ev.st-no-show { border-left-color: var(--danger); }

/* ── Auth ──────────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--navy); color: #c9d3e0; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { color: #fff; font-size: 22px; margin-top: 28px; }
.auth-side p { max-width: 440px; margin-top: 10px; color: #aab7c8; }
.auth-side ul { padding-left: 18px; color: #aab7c8; max-width: 440px; }
.auth-side .fine { font-size: 12px; color: #7d8ea6; max-width: 460px; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 20px; }

/* ── Misc ──────────────────────────────────────────────────────────────── */
.lightbox { position: fixed; inset: 0; background: rgba(5, 8, 12, .92); z-index: 100; display: none; align-items: center; justify-content: center; padding: 24px; }
.lightbox.on { display: flex; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 80px); }
.lightbox .cap { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; color: #c7d0dc; font-size: 13px; }
.lightbox .x { position: absolute; top: 14px; right: 16px; background: none; border: 1px solid #3a4452; color: #fff; border-radius: 4px; height: 32px; padding: 0 12px; cursor: pointer; }

.modal-bg { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 90; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-bg.on { display: flex; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 440px; }
.modal h3 { padding: 16px 18px 0; font-size: 15px; }
.modal .body { padding: 10px 18px 16px; color: var(--text-2); font-size: 13.5px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 10px 16px; font-size: 13px; color: var(--muted); }

.split { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: 0; }
.mt-0 { margin-top: 0 !important; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-mini input, .search-mini input[type=search] { width: 180px; }
}
@media (max-width: 1199px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .planes { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1199px) {
  :root { --sidebar-w: 64px; }
  .brand-text, .nav a span.lbl, .nav-label, .user-chip .who, .engine span, .sidebar-foot .signout span.lbl, .nav a .count { display: none; }
  .nav a { justify-content: center; padding: 9px; }
  .brand { justify-content: center; padding: 14px 0; }
  .user-chip { justify-content: center; }
  .sidebar-foot .signout { justify-content: center; }
  .engine { justify-content: center; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; width: 248px; transform: translateX(-100%); transition: transform .18s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
  .brand-text, .nav a span.lbl, .nav-label, .user-chip .who, .engine span, .sidebar-foot .signout span.lbl, .nav a .count { display: revert; }
  .nav a { justify-content: flex-start; padding: 8px 10px; }
  .brand { justify-content: flex-start; padding: 16px 18px; }
  .user-chip, .sidebar-foot .signout, .engine { justify-content: flex-start; }
  .topbar { padding: 0 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .search-mini { display: none; }
  .page { padding: 16px 16px 40px; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .patient-banner { gap: 10px; }
  .pb-actions { margin-left: 0; width: 100%; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
  .file-row { grid-template-columns: 48px minmax(0, 1fr); }
  .file-row select { grid-column: 1 / -1; }
  .timeline li { grid-template-columns: 70px 14px minmax(0, 1fr); }
  .timeline li:not(:last-child)::after { left: 86px; }
  .cal td { height: 64px; }
  .cal .ev { font-size: 10.5px; }
  .hide-sm { display: none; }
  .grade-choice { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nrs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .nrs-bands { display: none; }
}

/* ── Print ─────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .sys-banner, .no-print, .flashes { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}

/* Result panel · analysis view switcher (reuses .seg) */
.rp-views { padding: 12px 16px 0; }
.seg-full { display: flex; width: 100%; }
.seg-full > button { flex: 1 1 0; justify-content: center; white-space: nowrap; gap: 6px; }
.seg > button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-st { font-size: 12px; font-weight: 600; }
.tab-st-done { color: var(--ok); }
.tab-st-pending { color: var(--warn); }
.tab-st-na { color: var(--faint); }
.seg > .on .tab-st { color: #fff; }
.rp-sub { margin: 16px 0 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cmp { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); }
.cmp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.cmp-head .rb-label { margin: 0; }
.cmp-kv dd .rb-meta { margin-top: 2px; }
.table tr.is-current td { background: var(--accent-soft); }
.table tr.is-current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* ── Treatment decision support (Patient Workspace) ── */
.mb-0 { margin-bottom: 0 !important; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.tri-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 16px; }
.tri { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.tri label { margin: 0; font-weight: 500; }
.tri input { position: absolute; opacity: 0; }
.tri span { display: block; padding: 0 12px; height: 30px; line-height: 30px; font-size: 13px; color: var(--text-2); cursor: pointer; border-right: 1px solid var(--border); }
.tri label:last-child span { border-right: 0; }
.tri input:checked + span { background: var(--navy); color: #fff; }
.tri input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.level-checks { display: flex; flex-wrap: wrap; gap: 4px 14px; padding-top: 4px; }
.cds-scores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.cds-scores .k, .cds-primary .k { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cds-scores .v { font-size: 22px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.cds-scores .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.cds-scores .v.v-sm { font-size: 15px; padding-top: 5px; }
.cds-primary { border: 1px solid var(--border); border-left: 3px solid var(--navy); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); }
.cds-primary > .v { font-size: 16px; font-weight: 600; color: var(--text); margin-top: 2px; }
.cds-notes { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.cds-notes li + li { margin-top: 3px; }
.cds-evidence { margin: 0; padding-left: 18px; font-size: 13px; }
.cds-evidence li + li { margin-top: 4px; }
.cds-trace td { vertical-align: top; }
.cds-trace .met { color: var(--text); }
.cds-trace .unmet { color: var(--muted); }
.cds-trace tr.o-triggered td:first-child { box-shadow: inset 3px 0 0 var(--navy); }
.cds-trace tr.o-suppressed td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.cds-json { max-height: 360px; overflow: auto; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin: 0; white-space: pre; }
.decision-choice { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 720px) { .cds-scores { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cds-mri .badge { white-space: normal; height: auto; line-height: 1.35; padding: 2px 8px; margin-top: 3px; }
.cds-mri td, .cds-mri th { padding-left: 10px; padding-right: 10px; }

/* ── Decision support: clinician-first layout (engine 1.1) ── */
.cds-body > * + * { margin-top: 16px; }
.cds-status { display: grid; grid-template-columns: minmax(180px, auto) minmax(0, 1fr); gap: 16px; align-items: start; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.cds-status .k, .cds-summary .k { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.cds-status .badge { height: 26px; font-size: 13px; padding: 2px 10px; }
.cds-summary p { font-size: 14px; color: var(--text); }
.cds-safety { border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius); padding: 12px 14px; font-size: 13.5px; }
.cds-safety.s-review { background: var(--warn-soft); border-color: var(--warn-border); border-left-color: var(--warn); }
.cds-safety.s-escalate { background: var(--danger-soft); border-color: var(--danger-border); border-left-color: var(--danger); }
.cds-safety.s-clear { background: var(--surface-2); border-left-color: var(--ok); }
.cds-safety-head { display: flex; gap: 8px; align-items: center; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 12.5px; margin-bottom: 8px; }
.cds-safety.s-review .cds-safety-head { color: var(--warn); }
.cds-safety.s-escalate .cds-safety-head { color: var(--danger); }
.cds-safety.s-clear .cds-safety-head { color: var(--ok); }
.cds-safety-items { border-collapse: collapse; margin-bottom: 8px; }
.cds-safety-items th { text-align: left; font-weight: 600; padding: 3px 18px 3px 0; color: var(--text); white-space: nowrap; }
.cds-safety-items td { padding: 3px 0; color: var(--text-2); }
.cds-more { margin-top: 8px; }
.cds-more > summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.cds-sec { border-top: 1px solid var(--border); padding-top: 14px; }
.cds-sec > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.cds-comp { display: inline-block; margin-right: 12px; }
.cds-target-form { margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.cds-target-form label { margin-bottom: 6px; }
.cds-x { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); }
.cds-x > li + li { border-top: 1px solid var(--border); }
.cds-x summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 170px 18px minmax(0, 1fr); gap: 8px; padding: 7px 12px; font-size: 13.5px; align-items: baseline; }
.cds-x summary::-webkit-details-marker { display: none; }
.cds-x .g { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cds-x .glyph { font-weight: 700; text-align: center; }
.cds-x .m-ok .glyph { color: var(--ok); }
.cds-x .m-warn .glyph { color: var(--warn); }
.cds-x .m-stop .glyph { color: var(--danger); }
.cds-x .m-info .glyph { color: var(--muted); }
.cds-x details[open] summary { background: var(--surface-2); }
.cds-x-body { padding: 6px 12px 10px 190px; }
.cds-x-rule + .cds-x-rule { margin-top: 6px; }
@media (max-width: 720px) {
  .cds-status { grid-template-columns: 1fr; }
  .cds-x summary { grid-template-columns: 18px minmax(0, 1fr); }
  .cds-x .g { grid-column: 1 / -1; }
  .cds-x-body { padding-left: 12px; }
}

/* ── Decision support: clinician-facing result (engine 1.2) ── */
.warn-text { color: var(--warn); }
.cds-overall { display: flex; gap: 14px; align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.cds-overall .badge { height: 28px; font-size: 13.5px; padding: 3px 12px; white-space: nowrap; flex-shrink: 0; }
.cds-overall p { font-size: 14px; color: var(--text); }
.cds-options > h3, .cds-info-needed > h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--navy); margin-bottom: 4px; }
.cds-opt-list { list-style: none; margin: 10px 0; padding: 0; }
.cds-opt { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.cds-opt + .cds-opt { margin-top: 8px; }
.cds-opt.is-primary { border-left: 4px solid var(--navy); background: var(--surface-2); }
.cds-opt .n { font-size: 20px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.cds-opt.is-primary .n { color: var(--navy); }
.cds-opt .t { font-size: 15px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .02em; }
.cds-opt.is-primary .t { font-size: 16.5px; }
.cds-opt-kv { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 4px 12px; margin: 8px 0 0; font-size: 13.5px; }
.cds-opt-kv dt { color: var(--muted); }
.cds-opt-kv dd { margin: 0; }
.cds-opt-detail { padding: 8px 0 0; font-size: 13.5px; }
.cds-info-needed { border: 1px solid var(--warn-border); background: var(--warn-soft); border-radius: var(--radius); padding: 12px 14px; }
.cds-escalation { border: 1px solid var(--danger-border); border-left: 4px solid var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 12px 14px; }
.cds-escalation-head { display: flex; gap: 8px; align-items: center; color: var(--danger); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 13px; margin-bottom: 6px; }
.cds-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.cds-facts dt { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cds-facts dd { margin: 2px 0 0; font-size: 14.5px; font-weight: 600; color: var(--text); }
.cds-mri-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.cds-mri-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13.5px; }
.cds-mri-card .lv { font-weight: 700; margin-bottom: 2px; }
.cds-quote { margin: 0 0 8px; padding: 10px 14px; border-left: 3px solid var(--border-strong); background: var(--surface-2); font-size: 14px; line-height: 1.55; color: var(--text); }
.cds-steps { margin: 0; padding-left: 20px; font-size: 13.5px; }
.cds-steps li + li { margin-top: 3px; }
.cds-x-row { display: grid; grid-template-columns: 170px 18px minmax(0, 1fr); gap: 8px; padding: 6px 12px; font-size: 13.5px; }
#cdsReasoning, #cdsTechnical { margin-top: 12px; }
@media (max-width: 720px) {
  .cds-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cds-opt-kv { grid-template-columns: 1fr; }
  .cds-opt { grid-template-columns: 30px minmax(0, 1fr); }
  .cds-overall { flex-direction: column; }
  .cds-x-row { grid-template-columns: 18px minmax(0, 1fr); }
  .cds-x-row .g { grid-column: 1 / -1; }
}

/* ═══ Treatment decision support — clinical layout (v1.3) ═══
   One surface; sections separated by hairlines, not cards. Colour only for status:
   amber = review, red = escalation, green = clear/confirmed. */
.ds { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; color: var(--text); }
.ds-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ds-title { font-size: 20px; font-weight: 600; margin: 0 0 2px; letter-spacing: -.005em; }
.ds-meta { font-size: 13px; color: var(--muted); line-height: 1.5; }
.ds-status { margin-top: 8px; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ds-when { font-size: 12.5px; color: var(--muted); }
.ds-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.ds-dot.tone-warn { background: var(--warn); } .ds-dot.tone-danger { background: var(--danger); }
.ds-dot.tone-ok { background: var(--ok); } .ds-dot.tone-info { background: var(--accent); }
.ds-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ds-head-actions form { margin: 0; }
.ds-head-actions select { width: auto; height: 32px; font-size: 13px; }
.ds-notice { margin: 0; padding: 8px 20px; font-size: 13px; color: #6b4700; background: var(--warn-soft); border-bottom: 1px solid var(--warn-border); }
.ds-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); border-bottom: 1px solid var(--border); }
.ds-grid > * + * { border-left: 1px solid var(--border); }
.ds-grid-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.ds-col-main > .ds-sec + .ds-sec, .ds-col-side > .ds-sec + .ds-sec { border-top: 1px solid var(--border); }
.ds-sec { padding: 16px 20px; }
.ds > .ds-sec + .ds-sec { border-top: 1px solid var(--border); }
.ds-sec > h3 { font-size: 15.5px; font-weight: 600; margin: 0 0 4px; color: var(--navy); }
.ds-h4 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 12px 0 6px; }
.ds-sub { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.ds-sec p { margin: 0 0 8px; }
.ds .k { color: var(--muted); }
.ds-list { margin: 4px 0 8px; padding-left: 18px; }
.ds-list li + li { margin-top: 3px; }
/* options: numbered rows, hairline between, no cards/badges/ranking */
.ds-options { list-style: none; margin: 8px 0 0; padding: 0; }
.ds-options > li { padding: 10px 0; }
.ds-options > li + li { border-top: 1px solid var(--border); }
.ds-opt-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ds-opt-n { color: var(--muted); font-weight: 600; min-width: 18px; }
.ds-opt-title { font-size: 15px; font-weight: 600; }
.ds-opt-level { font-size: 13.5px; font-weight: 600; color: var(--navy); margin-left: 4px; }
.ds-opt-body { padding-left: 26px; margin-top: 3px; }
.ds-opt-status { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ds-more { margin-top: 6px; font-size: 13.5px; }
.ds-more > summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 500; list-style: none; display: inline-flex; gap: 5px; align-items: center; }
.ds-more > summary::-webkit-details-marker { display: none; }
.ds-more > summary::before { content: "▸"; font-size: 10px; color: var(--muted); }
.ds-more[open] > summary::before { content: "▾"; }
.ds-more[open] > summary { margin-bottom: 6px; }
.ds-levels { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.ds-inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.ds-inline-form select { width: auto; height: 32px; font-size: 13px; }
/* label/value pairs */
.ds-pairs { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 18px; margin: 6px 0 8px; }
.ds-pairs dt { color: var(--muted); font-weight: 400; }
.ds-pairs dd { margin: 0; }
.ds-pairs-wide dt { min-width: 110px; }
.ds-wrap { word-break: break-all; font-size: 12px; }
/* safety: a quiet rule on the left, colour only by state */
.ds-safety { border-left: 3px solid transparent; }
.ds-safety.s-review, .ds-safety.s-incomplete { border-left-color: var(--warn); }
.ds-safety.s-clear { border-left-color: var(--ok); }
.ds-safety-state { font-weight: 600; }
.ds-safety.s-review .ds-safety-state, .ds-safety.s-incomplete .ds-safety-state { color: var(--warn); }
.ds-safety.s-clear .ds-safety-state { color: var(--ok); }
.ds-escalation { border-left: 3px solid var(--danger); background: var(--danger-soft); }
.ds-escalation > h3 { color: var(--danger); }
/* MRI findings: compact rows */
.ds-mri { list-style: none; margin: 6px 0 10px; padding: 0; }
.ds-mri li { display: grid; grid-template-columns: 58px minmax(0, 1fr); column-gap: 10px; padding: 6px 0; }
.ds-mri li + li { border-top: 1px solid var(--border); }
.ds-mri .lv { grid-row: span 3; font-weight: 600; }
.ds-mri .ds-sub { margin: 0; }
/* patient discussion + steps */
.ds-quote { font-size: 14px; line-height: 1.55; padding-left: 10px; border-left: 2px solid var(--border-strong); }
.ds-steps { margin: 4px 0 0; padding-left: 20px; }
.ds-steps li + li { margin-top: 3px; }
/* decision */
.ds-decision { background: var(--surface-2); }
.ds-form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 260px)); gap: 0 16px; }
.ds-decision-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 12px; }
.ds-choice { margin: 0; }
.ds-choice input { position: absolute; opacity: 0; }
.ds-choice span { display: inline-block; min-width: 92px; text-align: center; padding: 6px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); font-weight: 500; cursor: pointer; }
.ds-choice input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; }
.ds-choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.ds-choice-quiet { margin-left: 10px; }
.ds-choice-quiet span { min-width: 0; border-style: dashed; color: var(--text-2); }
.ds-form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.ds-form-foot .ds-sub { margin: 0; }
/* additional information */
.ds-additional > h3 { font-size: 13.5px; color: var(--muted); }
.ds-additional .ds-more { margin-top: 4px; padding: 6px 0; border-top: 1px solid var(--border); }
.ds-additional .ds-more > summary { color: var(--text-2); }
.ds-check { list-style: none; margin: 8px 0; padding: 0; font-size: 13px; }
.ds-check li { display: grid; grid-template-columns: 170px 14px minmax(0, 1fr); gap: 8px; padding: 3px 0; }
.ds-check .g { color: var(--muted); }
.ds-check .m-ok .glyph { color: var(--ok); } .ds-check .m-warn .glyph { color: var(--warn); }
.ds-check .m-stop .glyph { color: var(--danger); } .ds-check .m-info .glyph { color: var(--muted); }
.ds-disclaimer { margin: 12px 0 0; }
@media (max-width: 900px) {
  .ds-grid, .ds-grid-even { grid-template-columns: minmax(0, 1fr); }
  .ds-grid > * + * { border-left: 0; border-top: 1px solid var(--border); }
  .ds-form-row { grid-template-columns: minmax(0, 1fr); }
  .ds-check li { grid-template-columns: 14px minmax(0, 1fr); }
  .ds-check .g { grid-column: 1 / -1; }
  .ds-head, .ds-sec { padding-left: 16px; padding-right: 16px; }
}
.ds-opt-head .ds-opt-status { margin-left: auto; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.ds-options > li { padding: 9px 0; }
.ds-opt-body .ds-more { margin-top: 2px; }
.ds-levels .ds-pairs { margin: 0 0 4px; }
.ds-levels .ds-sub { margin-bottom: 6px; }

/* ==========================================================================
   Clinical workstation (MRI study page) — layout & sidebar refinements.
   Dark imaging area, white clinical panels, restrained semantic colour.
   ========================================================================== */
:root { --ws-dark: #0f1b2d; --ws-dark-2: #13223a; --ws-line: #1d2b42; --ws-canvas: #070c15; --ws-txt: #c9d3e0; --ws-dim: #7d8ea6; }

/* sidebar */
.app, .sidebar { background: var(--ws-dark); }
.sidebar { border-right-color: #0a1424; }
.brand { padding: 18px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 14px; height: 28px; background: none; border-radius: 0; display: flex; flex-direction: column; gap: 3px; align-items: center; justify-content: center; }
.brand-mark i { display: block; width: 8px; height: 4px; border-radius: 1.5px; background: #6a9be0; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { width: 9px; }
.brand-text b { font-size: 16px; letter-spacing: 0; font-weight: 700; }
.brand-text small { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #7fa7d9; margin-top: 1px; }
.nav { padding: 6px 0; }
.nav-label { padding: 16px 18px 6px; }
.nav a { padding: 9px 18px; border-radius: 0; font-size: 14px; }
.nav a.on { background: #1a2b44; box-shadow: inset 3px 0 0 #5b9be6; font-weight: 600; }
.active-patient { margin: 8px 12px 12px; padding: 12px 14px; background: var(--ws-dark-2); border: 1px solid #22385a; border-radius: var(--radius); color: var(--ws-txt); font-size: 13px; line-height: 1.45; }
.active-patient .ap-k { font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #7fa7d9; margin-bottom: 6px; }
.active-patient .ap-name { display: block; color: #fff; font-weight: 600; font-size: 14.5px; }
.active-patient .ap-mrn, .active-patient .ap-date { color: #7fa7d9; font-size: 12.5px; }
.active-patient .ap-k2 { color: #8fa0b6; font-size: 12px; margin-top: 6px; }
.active-patient .ap-study { color: #fff; font-weight: 600; }
.sidebar-foot .signout { justify-content: center; border: 1px solid #2a3b55; margin-top: 8px; }

/* page frame: the study header replaces the generic top bar; the workstation fills the viewport */
body:has(.page.ws) .main { height: 100vh; min-height: 0; }
.page.ws { max-width: none; padding: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.page.ws > .flashes, .page.ws > .consult-banner, .page.ws > .ws-alert { margin: 12px 20px 0; }
.page.ws > .flashes .alert { margin-bottom: 0; }

.ws-top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.ws-header { display: flex; align-items: center; gap: 18px; min-height: 56px; padding: 6px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ws-header .menu-btn { display: none; }
.ws-back { font-size: 13.5px; color: var(--text-2); padding-right: 18px; border-right: 1px solid var(--border); white-space: nowrap; }
.ws-ctx { display: flex; gap: 10px; align-items: baseline; white-space: nowrap; min-width: 0; }
.ws-ctx + .ws-ctx { padding-left: 18px; border-left: 1px solid var(--border); }
.ws-ctx b { font-size: 14.5px; color: var(--text); }
.ws-ctx .ws-name { font-size: 16px; }
.ws-mono { font: 13px var(--mono); color: var(--muted); }
.ws-head-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ws-pill { font: 500 13px var(--font); padding: 5px 10px; border-radius: var(--radius-sm); border: 1px solid; white-space: nowrap; background: none; line-height: 1.3; }
button.ws-pill { cursor: pointer; }
.ws-pill-warn { background: var(--warn-soft); border-color: #ebd27e; color: var(--warn); }
.ws-pill-ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.ws-tabs { display: flex; gap: 4px; padding: 0 20px; overflow-x: auto; }
.ws-tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px 18px 11px; font: 500 14px var(--font); color: var(--text-2); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.ws-tabs button:hover { color: var(--text); }
.ws-tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.ws-tab-dot { width: 7px; height: 7px; border-radius: 50%; background: #d98a12; display: inline-block; }

.ws-panel[data-ws-panel="workstation"] { flex: 1; min-height: 540px; display: flex; }
.ws-panel[data-ws-panel="workstation"].hidden { display: none !important; }
.ws-page { padding: 20px 24px 40px; width: 100%; max-width: 1440px; }
.ws-empty { flex: 1; text-align: center; padding: 56px 16px; color: var(--muted); background: var(--surface); }
.ws-empty h3 { color: var(--text-2); margin-bottom: 6px; }
.ws-empty .actions { justify-content: center; }

.ws-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 200px minmax(0, 1fr) 340px; }

/* spinal level navigation */
.ws-levels { background: var(--ws-dark); border-right: 1px solid var(--ws-line); overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.ws-sec-h { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ws-dim); padding: 14px 16px 10px; border-bottom: 1px solid var(--ws-line); }
.ws-levels .level-btn { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "lv mark" "res res" "st st";
  width: 100%; min-width: 0; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--ws-line);
  border-left: 3px solid transparent; border-radius: 0; box-shadow: none; padding: 14px 16px 14px 15px; color: #e6edf6; cursor: pointer; font: inherit; }
.ws-levels .level-btn .lv { grid-area: lv; font: 600 15px var(--mono); color: #e6edf6; }
.ws-levels .level-btn .mark { grid-area: mark; width: 8px; height: 8px; border-radius: 50%; border: 0; align-self: center; background: transparent; }
.ws-levels .level-btn .mark.pending { background: #e8890c; }
.ws-levels .level-btn .mark.done { background: #3fae6e; }
.ws-levels .level-btn .res { grid-area: res; font-size: 12.5px; color: #9fb0c8; margin-top: 6px; }
.ws-levels .level-btn .st { grid-area: st; font: 12px var(--mono); color: #6f86a6; display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.ws-levels .level-btn:hover { background: #13223a; }
.ws-levels .level-btn.on { background: #142b4d; border-left-color: #4a8ae0; box-shadow: none; }
.ws-levels .level-btn.on .res { color: #d6e2f2; }
.ws-levels .level-btn:disabled { background: transparent; color: #55657d; cursor: default; border-style: solid; border-color: transparent; border-bottom-color: var(--ws-line); }
.ws-levels .level-btn:disabled .lv { color: #55657d; }
.ws-levels .level-btn:disabled .res { color: #4c5b72; }
.ws-levels .level-btn:focus-visible { outline: 2px solid #7fb1ea; outline-offset: -2px; }
.expl { font: 700 10.5px var(--font); color: #d97a06; letter-spacing: .04em; cursor: help; }
.ws-levels-note { margin: 12px; display: flex; gap: 6px; align-items: flex-start; background: rgba(232,137,12,.12); border: 1px solid rgba(232,137,12,.4); color: #f0b45a; font: 500 12.5px var(--font); text-align: left; border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; }

/* MRI viewer */
.ws-viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--ws-canvas); }
.ws-toolbar { display: flex; gap: 14px; align-items: center; padding: 8px 12px; background: var(--ws-dark); border-bottom: 1px solid var(--ws-line); flex-wrap: wrap; }
.tb-group { display: inline-flex; gap: 4px; }
.tb-group button { height: 30px; padding: 0 12px; background: #152238; border: 1px solid #26364f; color: #b8c4d6; border-radius: var(--radius-sm); font: 500 13px var(--font); cursor: pointer; white-space: nowrap; }
.tb-group button:hover { background: #1b2b45; color: #fff; }
.tb-group button.on { background: #1d4b8a; border-color: #3b74c6; color: #fff; font-weight: 600; }
.tb-group button:disabled { opacity: .38; cursor: not-allowed; background: #152238; color: #b8c4d6; }
.tb-group button:focus-visible { outline: 2px solid #7fb1ea; outline-offset: 1px; }
.tb-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.tb-meta { color: var(--ws-dim); font-size: 12.5px; }
.tb-tools button { padding: 0 10px; font-size: 12.5px; }

.ws-canvas { flex: 1; min-height: 0; display: grid; gap: 1px; background: #1a2638; grid-template-columns: minmax(0, 1fr); }
.ws-canvas[data-layout="combined"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.ws-canvas[data-layout="axial"] #sgPlane, .ws-canvas[data-layout="sagittal"] #axPlane { display: none; }
.ws-canvas .plane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ws-canvas); border: 0; border-radius: 0; position: relative; overflow: hidden; margin: 0; }
.plane-label { position: absolute; top: 8px; left: 12px; right: 12px; z-index: 2; display: flex; gap: 10px; align-items: baseline; font-size: 12px; color: #8ea3bf; pointer-events: none; }
.plane-label b { font-weight: 700; color: #7fb1ea; letter-spacing: .08em; text-transform: uppercase; }
.plane-label .lvl { font-family: var(--mono); color: #c7d3e2; }
.plane-label span:last-child { margin-left: auto; color: #6f7f97; }
.ws-canvas .plane-img { flex: 1; min-height: 0; aspect-ratio: auto; background: var(--ws-canvas); position: relative; overflow: hidden; display: block; cursor: zoom-in; }
.zoomer { position: absolute; inset: 0; transform-origin: 0 0; }
.zoomer img { width: 100%; height: 100%; object-fit: contain; display: block; max-width: none; }
.ws-canvas.tool-zoom .plane-img { cursor: zoom-in; }
.ws-canvas.tool-pan .plane-img { cursor: grab; touch-action: none; }
.ws-canvas .plane-img.dragging { cursor: grabbing; }
.ws-canvas.tool-on .disc-overlay .disc { pointer-events: none; }
.ws-canvas .plane-empty { flex: 1; aspect-ratio: auto; }
.ws-canvas .plane-empty a { color: #9cc3f0; }
.ws-canvas .plane-foot { background: #0b1322; border-top: 1px solid var(--ws-line); color: #8e9bb0; min-height: 28px; flex: none; }
.ws-strip { display: flex; gap: 6px; align-items: center; padding: 6px 12px; background: var(--ws-dark); border-top: 1px solid var(--ws-line); color: var(--ws-dim); font-size: 12.5px; flex: none; overflow: hidden; }
.ws-strip .k { margin-right: 4px; white-space: nowrap; }
.ws-strip button { font: 600 12px var(--mono); background: transparent; border: 1px solid transparent; color: #9fb0c8; height: 26px; padding: 0 10px; border-radius: var(--radius-sm); cursor: pointer; }
.ws-strip button:hover { color: #fff; background: #152238; }
.ws-strip button.on { background: #1d4b8a; border-color: #3b74c6; color: #fff; }
.ws-hint { margin-left: auto; color: #6f7f97; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; padding-left: 12px; }

/* clinical findings panel */
.ws-findings { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; min-height: 0; }
.fp-head { padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.fp-head h2 { font: 700 20px var(--font); letter-spacing: .01em; }
.fp-sec { padding: 16px 18px 18px; border-bottom: 1px solid var(--border); }
.fp-title { font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #5e6b80; margin-bottom: 12px; }
.fp-subtitle { font-size: 12px; color: var(--muted); margin: -8px 0 10px; }
.src-chip { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); border: 1px solid var(--border-strong); border-radius: 3px; padding: 2px 7px; background: var(--surface-2); }
.expl-tag { font-size: 11px; font-weight: 700; color: #b0610c; border: 1px solid #f0c48a; background: #fdf3e6; border-radius: 3px; padding: 2px 6px; cursor: help; }
.fp-grade { font-size: 24px; font-weight: 700; color: var(--text); margin-top: 10px; line-height: 1.2; }
.fp-finding { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.fp-conf { margin-top: 10px; }
.fp-conf b { display: inline-block; font: 700 15px var(--font); padding: 3px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-variant-numeric: tabular-nums; }
.fp-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.fp-more { margin-top: 8px; }
.fp-more > summary { font-size: 12.5px; color: var(--accent); cursor: pointer; }
.fp-more .prob { grid-template-columns: 76px minmax(0, 1fr) 48px; font-size: 12.5px; }
.fp-sub { font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: #5e6b80; margin: 18px 0 8px; font-weight: 600; }
.fp-pending { background: var(--warn-soft); border: 1px solid #ebd27e; color: var(--warn); border-radius: var(--radius-sm); padding: 12px; font-size: 13.5px; }
.fp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.fp-actions .btn { height: 38px; font-size: 14px; }
.fp-actions .btn-primary { font-weight: 600; }
.fp-notefield { margin: 10px 0 0; }
.fp-notefield label, .fp-twocol label, #correctPanel label, #sgCorrectPanel label { font-size: 12px; }
#correctPanel, #sgCorrectPanel { margin-top: 10px; }
.fp-twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.fp-twocol .field { margin-bottom: 4px; }
.fp-fine { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.fp-clin { border: 1px solid var(--border); border-left: 3px solid var(--ok); border-radius: var(--radius-sm); padding: 10px 12px; background: #fbfcfd; }
.fp-clin.is-corrected { border-left-color: #5b3d99; }
.fp-row { display: flex; gap: 10px; font-size: 13px; padding: 2px 0; }
.fp-row .k { width: 92px; color: var(--muted); flex: none; }
.fp-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.fp-notebox { font-size: 12.5px; background: var(--surface-2); padding: 6px 8px; border-radius: var(--radius-sm); margin-top: 6px; }
.fp-confbar { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.fp-confbar .bar { flex: 1; height: 4px; background: #e6e9ee; border-radius: 2px; overflow: hidden; }
.fp-confbar .bar i { display: block; height: 100%; background: #42597a; }
.fp-confbar b { font: 700 14px var(--font); font-variant-numeric: tabular-nums; }
.fp-k { font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.fp-groups { list-style: none; margin: 6px 0 0; padding: 0; }
.fp-groups li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--faint); padding: 2px 0; }
.fp-groups li i { width: 6px; height: 6px; border-radius: 50%; background: #c8ced8; flex: none; }
.fp-groups li.on { color: var(--text); font-weight: 600; }
.fp-groups li.on i { background: var(--navy); }
.fp-groups .p { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 500; }
.fp-missing { font-size: 13px; color: var(--muted); }
#discardWrap { margin-top: 10px; }
.fp-details { border-bottom: 1px solid var(--border); }
.fp-details > summary { padding: 12px 18px; font-weight: 600; font-size: 13px; cursor: pointer; list-style: none; display: flex; gap: 8px; }
.fp-details > summary::-webkit-details-marker { display: none; }
.fp-details > summary::before { content: "▸"; color: var(--muted); font-size: 11px; }
.fp-details[open] > summary::before { content: "▾"; }
.fp-details .ref-body { padding: 0 18px 14px; font-size: 13px; color: var(--text-2); }
.fp-disclaimer { font-size: 12px; color: var(--muted); padding: 12px 18px 18px; margin: 0; }
.conf-hi { color: var(--ok); }
.conf-mid { color: #b0610c; }
.conf-lo { color: var(--danger); }

/* status chips (clinical tables) */
.st-chip { display: inline-block; font-size: 12.5px; font-weight: 500; padding: 1px 8px; border-radius: 3px; border: 1px solid; white-space: nowrap; line-height: 1.5; }
.st-confirmed { color: var(--ok); background: #eef8f1; border-color: #9fd3b2; }
.st-pending { color: var(--warn); background: var(--warn-soft); border-color: #ebd27e; }
.st-review { color: var(--danger); background: #fdf0ef; border-color: #f0b7b2; }
.st-corrected { color: #5b3d99; background: #f3effa; border-color: #cdbfe8; }
.st-auto { color: var(--accent); background: #eef4fb; border-color: var(--accent-border); }
.st-na { color: #5e6b80; background: var(--surface-3); border-color: #d5dae2; }

/* disc-level validation */
.dv-card .dv-head { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.dv-card .dv-head h2 { font-size: 17px; }
.dv-card .dv-head p { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }
.dv-table td, .dv-table th { padding: 10px 14px; }
.dv-table tbody td:first-child { font-size: 14px; }
.dv-select { width: auto; min-width: 116px; max-width: 240px; height: 30px; font: 600 13px var(--mono); padding: 2px 8px; }
.dv-reason input { margin-top: 6px; height: 30px; font-size: 13px; min-width: 190px; }
.dv-actions .link-btn { font-weight: 500; margin-right: 16px; font-size: 13.5px; }
.dv-actions .dv-confirm { color: var(--ok); }
.dv-actions .dv-exclude { color: var(--danger); }
.dv-actions .dv-flag { color: var(--warn); }
.dv-actions .link-btn.on { text-decoration: underline; text-underline-offset: 3px; font-weight: 700; }
.link-btn:disabled { opacity: .4; cursor: not-allowed; text-decoration: none; }
.dv-table tr.dv-changed td { background: #fffbea; }
.dv-unsaved { font-size: 11.5px; color: var(--warn); font-style: italic; }
.dv-need { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(179,38,30,.2) !important; }
.dv-dirty { margin-right: auto; align-self: center; }

/* level summary */
.ls-card .ls-title { padding: 14px 20px; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #5e6b80; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.ls-table th { background: var(--surface-2); }
.ls-table th.ls-group { text-align: center; border-left: 1px solid var(--border); }
.ls-table thead tr:first-child th { border-bottom: 1px solid var(--border); }
.ls-table th.ls-review, .ls-table td[data-cell="review"] { border-left: 1px solid var(--border); }
.ls-table thead tr:nth-child(2) th:first-child, .ls-table tbody td:nth-child(2) { border-left: 1px solid var(--border); }
.ls-table .ls-gstart { border-left: 1px solid var(--border); }
.ls-table td.ls-level { white-space: nowrap; font-size: 14px; }
.ls-table td { padding: 11px 12px; }
.ls-delete { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ls-delete label { margin: 0; font-weight: 500; }
.ls-delete input[type=text] { width: 200px; height: 30px; }
.ls-card + .card { margin-top: 16px; }

/* responsive: desktop-first; keep the image and the findings in view */
@media (max-width: 1280px) {
  .ws-grid { grid-template-columns: 172px minmax(0, 1fr) 312px; }
  .ws-hint { display: none; }
  .ws-header { gap: 12px; }
  .ws-ctx + .ws-ctx, .ws-back { padding-left: 12px; padding-right: 0; }
  .ws-back { padding-right: 12px; padding-left: 0; }
}
@media (max-width: 1199px) {
  .ws-grid { grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto minmax(0, 1fr); }
  .ws-levels { grid-column: 1 / -1; flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--ws-line); }
  .ws-sec-h { display: none; }
  #levelBar { display: flex; }
  .ws-levels .level-btn { width: auto; min-width: 128px; border-bottom: 0; border-left: 0; border-right: 1px solid var(--ws-line); border-top: 3px solid transparent; padding: 10px 14px; }
  .ws-levels .level-btn.on { border-top-color: #4a8ae0; }
  .ws-levels-note { margin: 8px; white-space: nowrap; }
  .ws-strip { display: none; }
}
@media (max-width: 1199px) { .active-patient { display: none; } }
@media (max-width: 959px) {
  body:has(.page.ws) .main { height: auto; }
  .page.ws { overflow: visible; }
  .ws-grid { grid-template-columns: minmax(0, 1fr); }
  .ws-canvas { min-height: 62vh; }
  .ws-canvas[data-layout="combined"] { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(52vh, 1fr); }
  .ws-findings { border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .ws-head-right { margin-left: 0; width: 100%; }
}
@media (max-width: 767px) {
  .ws-header .menu-btn { display: inline-flex; }
  .ws-page { padding: 16px; }
  .ws-ctx { flex-wrap: wrap; white-space: normal; }
}
@media print { .ws-top, .ws-levels, .ws-toolbar, .ws-strip { display: none !important; } }

/* refinements after visual check */
.nav a .lbl, .sidebar-foot .signout .lbl { display: inline; color: inherit; font-size: inherit; font-weight: inherit; margin: 0; }
.ws-header { flex-wrap: nowrap; }
.ws-ctx { overflow: hidden; text-overflow: ellipsis; }
.ws-ctx > * { flex: none; }
.ws-head-right { flex-wrap: nowrap; flex: none; }
.ws-pill { font-size: 12.5px; padding: 4px 9px; }
.tb-group { gap: 3px; }
.tb-group button { padding: 0 9px; font-size: 12.5px; }
.ws-toolbar { gap: 10px; }
.ws-grid { grid-template-columns: 184px minmax(0, 1fr) 328px; }
.ws-strip button { white-space: nowrap; flex: none; }
.fp-details > summary { display: block; }
.fp-details > summary::before { margin-right: 8px; }
.fp-details > summary span { font-weight: 500; color: var(--text-2); }
@media (max-width: 1366px) {
  .tb-meta { display: none; }
  .ws-btn-txt { display: none; }
  .tb-group button { padding: 0 8px; }
  .ws-grid { grid-template-columns: 168px minmax(0, 1fr) 312px; }
}
@media (max-width: 1199px) {
  .ws-grid { grid-template-columns: minmax(0, 1fr) 300px; }
  .ws-header { flex-wrap: wrap; }
}
@media (max-width: 959px) { .ws-grid { grid-template-columns: minmax(0, 1fr); } }
.tb-tools button { display: inline-flex; align-items: center; gap: 5px; }
.tb-tools .icon { width: 14px; height: 14px; vertical-align: 0; }
.ws-strip .tb-meta { white-space: nowrap; padding-left: 12px; border-left: 1px solid var(--ws-line); margin-left: 4px; }
.ws-strip .ws-hint + .tb-meta { margin-left: 0; }
@media (max-width: 1366px) {
  .tb-txt { display: none; }
  .tb-tools button { padding: 0 8px; }
  .tb-group button { padding: 0 7px; }
  .ws-strip .tb-meta { display: inline; margin-left: auto; }
}
.ws-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.ws-toolbar > * { flex: none; }
@media (max-width: 1520px) { .tb-txt { display: none; } .tb-tools button { padding: 0 8px; } }
@media (max-width: 1366px) { .ws-grid { grid-template-columns: 160px minmax(0, 1fr) 304px; } }
@media (max-width: 1199px) { .ws-grid { grid-template-columns: minmax(0, 1fr) 300px; } }
@media (max-width: 959px) { .ws-grid { grid-template-columns: minmax(0, 1fr); } }
.dv-table [data-row-status] .cell-sub { white-space: nowrap; font-size: 11.5px; }

/* ==========================================================================
   MRI viewer: image stacks (study / PNG series), slice navigation.
   Restrained palette: navy, white, neutral grey, one clinical blue.
   ========================================================================== */
.ws-canvas .plane { background: var(--ws-canvas); }
.plane-bar { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 4px 10px; background: #0c1626; border-bottom: 1px solid var(--ws-line); flex: none; min-width: 0; }
.plane-bar .pl-name { font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #dbe3ee; white-space: nowrap; }
.plane-bar .pl-lvl { font-size: 12.5px; color: #dbe3ee; white-space: nowrap; }
.pl-src { margin-left: auto; display: inline-flex; border: 1px solid #26364f; border-radius: var(--radius-sm); overflow: hidden; flex: none; }
.pl-src button { background: transparent; border: 0; border-right: 1px solid #26364f; color: #9fb0c8; font: 500 12px var(--font); height: 24px; padding: 0 9px; cursor: pointer; white-space: nowrap; }
.pl-src button:last-child { border-right: 0; }
.pl-src button.on { background: #1d4b8a; color: #fff; }
.pl-src button:disabled { color: #4f5f78; cursor: default; }
.pl-load, .pl-test { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; margin: 0; border: 1px solid #26364f; border-radius: var(--radius-sm);
  background: #152238; color: #c9d3e0; font: 500 12px var(--font); cursor: pointer; white-space: nowrap; flex: none; }
.pl-load:hover, .pl-test:hover { background: #1b2b45; color: #fff; }
.pl-load:focus-within { outline: 2px solid #7fb1ea; outline-offset: 1px; }
.pl-load .icon { width: 13px; height: 13px; vertical-align: 0; }
.pl-test { border-style: dashed; color: #9fb0c8; }
.plane-label { display: none; }
.ws-canvas .plane-img:focus-visible { outline: 2px solid #4a8ae0; outline-offset: -2px; }
.plane-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: #8e9bb0; font-size: 13px; line-height: 1.6; pointer-events: auto; cursor: default; }
.plane-msg a { color: #9cc3f0; }
.slice-bar { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; background: #0c1626; border-top: 1px solid var(--ws-line); flex: none; min-width: 0; }
.slice-bar button { width: 26px; height: 24px; border: 1px solid #26364f; background: #152238; color: #c9d3e0; border-radius: var(--radius-sm); font: 600 15px/1 var(--font); cursor: pointer; flex: none; }
.slice-bar button:hover:not(:disabled) { background: #1b2b45; color: #fff; }
.slice-bar button:disabled { opacity: .35; cursor: default; }
.slice-ct { font: 500 12.5px var(--mono); color: #e6edf6; white-space: nowrap; min-width: 92px; font-variant-numeric: tabular-nums; }
.slice-range { -webkit-appearance: none; appearance: none; flex: 1; min-width: 40px; height: 16px; background: transparent; padding: 0; border: 0; margin: 0; cursor: pointer; }
.slice-range:focus { box-shadow: none; }
.slice-range::-webkit-slider-runnable-track { height: 2px; background: #2a3a54; border-radius: 1px; }
.slice-range::-moz-range-track { height: 2px; background: #2a3a54; border-radius: 1px; }
.slice-range::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 10px; margin-top: -4px; border-radius: 50%; background: #c9d3e0; border: 0; }
.slice-range::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: #c9d3e0; border: 0; }
.slice-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px rgba(74,138,224,.5); }
.slice-range:disabled { opacity: .3; cursor: default; }
.slice-src { font-size: 11.5px; color: #7d8ea6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.slice-bar .pl-mode { margin-left: auto; font-size: 11.5px; color: #7d8ea6; white-space: nowrap; }
.plane.single-slice .slice-range { visibility: hidden; }
.plane.is-series .plane-bar { box-shadow: inset 0 -1px 0 #2f5e9e; }
.ws-canvas .plane-foot { font-size: 11.5px; }

/* calmer colour: numbers and labels neutral; colour only where it carries meaning */
.conf-hi, .conf-mid, .conf-lo { color: inherit; }
.fp-conf b, .fp-confbar b { color: var(--text); }
.ws-levels .level-btn .st { color: #8496b0; }
.dv-actions .dv-confirm, .dv-actions .dv-flag { color: var(--accent); }
.dv-actions .dv-exclude { color: var(--accent); }
.ws-levels-note { color: #e5b766; }

.ws-canvas .plane { container-type: inline-size; }
@container (max-width: 470px) {
  .pl-load span, .slice-src { display: none; }
  .pl-load { padding: 0 7px; }
}
@container (max-width: 380px) { .slice-bar .pl-mode { display: none; } }
.ws-canvas .plane-foot { min-height: 46px; max-height: 46px; overflow: hidden; line-height: 1.45; padding-top: 5px; }

/* ── patient identity (IC number) ── */
.id-status { font-size: 12.5px; margin-top: 4px; min-height: 0; color: var(--muted); }
.id-status.id-ok { color: var(--ok); }
.id-status.id-bad { color: var(--danger); }
.id-status.id-warn { color: var(--warn); }
.id-exists { border: 1px solid var(--warn-border); background: var(--warn-soft); border-radius: var(--radius-sm); padding: 8px 10px; color: var(--text-2); display: grid; gap: 4px; justify-items: start; }
.id-exists > b { color: var(--warn); }
.id-ex-who { color: var(--text); }
.id-dup { border: 1px solid var(--warn-border); border-left: 3px solid var(--warn); background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.id-dup-title { display: flex; gap: 8px; align-items: center; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.id-dup-title .icon { color: var(--warn); }
.id-dup p { color: var(--text-2); font-size: 13.5px; }
.id-dup-kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 4px 0 12px; font-size: 13.5px; }
.id-dup-kv dt { color: var(--muted); }
.id-dup-kv dd { margin: 0; font-weight: 500; }
.pb-ic { color: var(--muted); }
.pb-ic .mono { color: var(--text-2); }

/* ==========================================================================
   Responsive layouts. Desktop ≥ 1200px is the clinical workstation.
   Tablet 768–1199px: icon sidebar, levels on top, findings beside or below
   the viewer. Phone < 768px: one column in clinical-workflow order
   (context → level → MRI → slices → AI findings → clinician review → more).
   ========================================================================== */
.lvl-select, .tb-select, .ws-details, .pb-more, .t-short, .sb-txt, .cal-wd, .cal-empty-m { display: none; }

/* tablet: findings beside the viewer down to 960px, below it under that */
@media (max-width: 1199px) {
  .ws-header { flex-wrap: wrap; row-gap: 6px; }
  .ws-head-right { margin-left: auto; }
}
@media (max-width: 959px) {
  .ws-canvas { min-height: 0; }
  .ws-canvas .plane-img { flex: none; aspect-ratio: 1 / 1; max-height: 72vh; }
  .ws-canvas[data-layout="combined"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-auto-rows: auto; }
  .ws-findings { border-left: 0; border-top: 1px solid var(--border); }
}

/* ── phone ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  body { font-size: 15px; }
  .page { padding: 12px 12px 32px; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 19px; }
  .topbar { height: 52px; padding: 0 8px 0 4px; }
  .topbar .menu-btn { width: 44px; height: 44px; }

  /* touch targets */
  .btn { height: 44px; padding: 0 16px; font-size: 15px; }
  .btn-sm { height: 40px; padding: 0 12px; font-size: 14px; }
  input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=time],
  input[type=datetime-local], input[type=number], input[type=search], select { height: 44px; font-size: 16px; }
  textarea { font-size: 16px; }
  .seg > a, .seg > button { height: 40px; padding: 0 12px; font-size: 14px; }
  .seg { flex-wrap: wrap; }
  .tabs a { padding: 12px 12px; }
  .link-btn { min-height: 32px; }
  .nav a { padding: 12px 18px; }
  .sidebar-foot .signout { height: 44px; }
  .alert .close { width: 36px; height: 36px; }
  .card-head { padding: 12px; }
  .card-body { padding: 12px; }

  /* forms: one column; registration in identity order */
  .form-grid, .form-grid-3, .tri-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .form-section { padding: 14px 12px; }
  .form-actions { flex-direction: column-reverse; align-items: stretch; padding: 12px; }
  .form-actions .btn { width: 100%; }
  .f-name { order: 1; } .f-ic { order: 2; } .f-dob { order: 3; } .f-sex { order: 4; } .f-mrn { order: 5; }
  .grade-choice span { padding: 10px 4px; }

  /* tables → stacked records */
  .table-wrap { overflow-x: visible; }
  table.table-stack, .table-stack > tbody, .table-stack > tbody > tr, .table-stack > tbody > tr > td { display: block; width: 100%; }
  .table-stack > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-stack > tbody > tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table-stack > tbody > tr:last-child { border-bottom: 0; }
  .table-stack > tbody > tr > td { display: grid; grid-template-columns: minmax(92px, 38%) minmax(0, 1fr); gap: 10px; align-items: baseline;
    padding: 3px 0; border: 0; text-align: left !important; white-space: normal !important; }
  .table-stack > tbody > tr > td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; font-weight: 500; }
  .table-stack > tbody > tr > td:first-child { display: block; font-size: 15px; padding-bottom: 4px; }
  .table-stack > tbody > tr > td:first-child::before, .table-stack > tbody > tr > td[data-label=""]::before { content: none; }
  .table-stack > tbody > tr > td[data-label=""] { display: block; }
  .table-stack > tbody > tr > td:empty { display: none; }
  .table-stack .row-actions { padding-top: 8px; }
  .table-stack .row-actions > * + * { margin-left: 10px; }
  .table-stack.ls-table > tbody > tr > td { border-left: 0 !important; }
  .table tbody tr:hover td { background: transparent; }
  .table tr.is-current { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
  .table tr.is-current td { background: transparent; box-shadow: none !important; }
  .dv-select { width: 100%; max-width: none; }
  .dv-actions { display: flex !important; gap: 8px; flex-wrap: wrap; }
  .dv-actions .link-btn { flex: 1; min-height: 40px; margin: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); text-align: center; background: var(--surface); }
  .dv-actions .link-btn.on { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }

  /* patient header: name + MRN; the rest behind "Patient details" */
  .patient-banner { padding: 12px; gap: 10px; }
  .pb-name { font-size: 16px; }
  .pb-sec { display: none; }
  .pb-more { display: block; margin-top: 6px; font-size: 14px; }
  .pb-more > summary, .ws-details > summary { cursor: pointer; color: var(--accent); font-size: 13.5px; min-height: 32px; display: flex; align-items: center; }
  .pb-more dl, .ws-details dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 6px 0 0; }
  .pb-more dt, .ws-details dt { color: var(--muted); }
  .pb-more dd, .ws-details dd { margin: 0; }
  .pb-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .pb-actions .btn { width: 100%; }

  /* appointments calendar → agenda of days that have appointments */
  .cal, .cal tbody, .cal tr { display: block; width: 100%; }
  .cal thead { display: none; }
  .cal td { display: none; height: auto; border: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
  .cal td.has-ev { display: block; }
  .cal td.today { box-shadow: inset 3px 0 0 var(--accent); }
  .cal .cal-wd { display: block; font-weight: 600; margin-bottom: 4px; }
  .cal .dn { display: none; }
  .cal .ev { white-space: normal; font-size: 14px; padding: 8px 10px; margin-top: 6px; }
  .cal-empty-m { display: block; padding: 24px 12px; text-align: center; color: var(--muted); }

  /* ── MRI study page ── */
  .ws-top { position: static; }
  .ws-header { padding: 8px 12px; gap: 4px 10px; min-height: 0; flex-wrap: wrap; }
  .ws-header .menu-btn { display: inline-flex; width: 44px; height: 44px; margin-left: -8px; }
  .ws-back { border-right: 0; padding-right: 0; min-height: 44px; display: inline-flex; align-items: center; }
  .ws-ctx { flex-wrap: wrap; white-space: normal; overflow: visible; }
  .ws-ctx-patient { flex-basis: 100%; order: 3; gap: 4px 10px; }
  .ws-ctx-study { flex-basis: 100%; order: 4; padding-left: 0 !important; border-left: 0 !important; gap: 4px 10px; }
  .ws-ctx .ws-name { font-size: 17px; }
  .ws-wide { display: none; }
  .ws-details { display: block; order: 5; flex-basis: 100%; font-size: 14px; }
  .ws-head-right { order: 6; flex-basis: 100%; margin: 4px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .ws-head-right .ws-pill { grid-column: 1 / -1; text-align: center; padding: 8px; }
  .ws-head-right .btn { width: 100%; }
  .ws-btn-txt { display: inline !important; }
  .ws-tabs { padding: 0 4px; }
  .ws-tabs button { padding: 12px 12px 11px; min-height: 46px; flex: 1; justify-content: center; }
  .t-long { display: none; } .t-short { display: inline; }
  .ws-panel[data-ws-panel="workstation"] { min-height: 0; }
  .ws-page { padding: 12px; }

  .ws-levels { display: block; padding: 10px 12px; border-bottom: 1px solid var(--ws-line); }
  #levelBar, .ws-sec-h { display: none !important; }
  .lvl-select { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px; align-items: center; margin: 0; color: #c9d3e0; font-weight: 600; font-size: 14px; }
  .lvl-select select { background: #152238; color: #fff; border-color: #2c3e5a; font: 600 16px var(--mono); }
  .ws-levels-note { margin: 10px 0 0; width: 100%; white-space: normal; min-height: 40px; }

  .ws-toolbar { flex-wrap: wrap; overflow: visible; gap: 8px; padding: 8px 12px; }
  #viewSeg { flex: 1 1 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  #viewSeg button, .tb-tools button { height: 40px; font-size: 14px; }
  #modeSeg { display: none; }
  .tb-select { display: block; flex: 1 1 140px; margin: 0; }
  .tb-select select { height: 40px; background: #152238; color: #fff; border-color: #2c3e5a; font-size: 15px; }
  .tb-right { margin-left: 0; flex: 0 0 auto; }
  .tb-txt { display: inline !important; }
  .tb-tools button { padding: 0 10px !important; }

  .ws-canvas, .ws-canvas[data-layout="combined"] { grid-template-columns: minmax(0, 1fr) !important; gap: 10px; background: var(--ws-canvas); padding-bottom: 2px; }
  .ws-canvas .plane-img { aspect-ratio: 1 / 1; max-height: 78vh; touch-action: pan-y; }
  .ws-canvas .plane-img.multi, .ws-canvas.tool-on .plane-img { touch-action: none; }
  .plane-bar { min-height: 46px; padding: 4px 8px 4px 12px; }
  .pl-src button { height: 34px; padding: 0 12px; font-size: 13.5px; }
  .pl-load, .pl-test { height: 36px; }
  .slice-bar { height: auto; min-height: 56px; padding: 6px 8px; gap: 8px; }
  .slice-bar button { width: auto; min-width: 44px; height: 44px; padding: 0 12px; font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }
  .slice-bar .sb-txt { display: inline; font: 500 14px var(--font); }
  .slice-ct { min-width: 0; font-size: 14px; }
  .slice-range { height: 32px; }
  .slice-range::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -10px; }
  .slice-range::-moz-range-thumb { width: 22px; height: 22px; }
  .slice-src, .slice-bar .pl-mode { display: none !important; }
  .ws-canvas .plane-foot { max-height: none; min-height: 0; font-size: 12.5px; }
  .ws-strip { display: none; }

  .ws-findings { overflow: visible; }
  .fp-head { padding: 12px; }
  .fp-sec { padding: 14px 12px 16px; }
  .fp-actions .btn { height: 46px; }
  .fp-twocol { grid-template-columns: minmax(0, 1fr); }
  .fp-details > summary { min-height: 44px; display: flex; align-items: center; padding: 10px 12px; }
  .fp-details .ref-body { padding: 0 12px 14px; }
  .fp-disclaimer { padding: 12px; }
  .expl, .expl-tag { cursor: default; }

  .dv-card .dv-head { padding: 14px 12px; }
  .id-dup { padding: 12px; }
}
@media (max-width: 380px) {
  .ws-head-right { grid-template-columns: 1fr; }
  .pb-actions { grid-template-columns: 1fr; }
  .slice-bar .sb-txt { display: none; }
  .tb-tools .tb-txt { display: none !important; }
  .table-stack > tbody > tr > td { grid-template-columns: minmax(84px, 40%) minmax(0, 1fr); }
}
@media (max-width: 767px) {
  select, input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=hidden]) { min-height: 44px !important; }
  .search-mini input, .search-mini input[type=search] { height: 44px; }
  .link-btn { min-height: 40px; }
  .pl-src button { height: 40px; }
  .slice-range { height: 40px; }
}
@media (max-width: 767px) {
  .table-stack > tbody > tr > td::before { font-family: var(--font); }
  /* level summary: one compact record per level — axial row, sagittal row, review */
  .ls-table.table-stack > tbody > tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; }
  .ls-table.table-stack > tbody > tr > td { display: block; padding: 0; }
  .ls-table.table-stack > tbody > tr > td::before { display: block; margin-bottom: 2px; font-size: 11.5px; }
  .ls-table.table-stack > tbody > tr > td:first-child { grid-column: 1 / -1; }
  .ls-table.table-stack > tbody > tr > td[data-cell="review"] { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
  .ls-table.table-stack > tbody > tr > td[data-cell="review"]::before { display: inline; margin: 0; }
  .ls-table .st-chip { white-space: normal; }
  .plane.single-slice .slice-bar button { display: none; }
}
@media (max-width: 380px) { .ws-head-right { grid-template-columns: 1fr 1fr; } }
@media (max-width: 359px) { .ws-head-right { grid-template-columns: 1fr; } }
.cell-v { display: contents; }
@media (max-width: 767px) {
  .table-stack .cell-v { display: block; min-width: 0; }
  .table-stack .cell-v > * + * { margin-left: 4px; }
  .table-stack .row-actions .cell-v { display: flex; gap: 10px; flex-wrap: wrap; }
  .table-stack .row-actions .cell-v > * + * { margin-left: 0; }
}
/* desktop header: keep patient identity + study readable (never truncate the IC) */
.ws-ctx { overflow: visible; }
.ws-ctx > * { white-space: nowrap; }
@media (min-width: 768px) and (max-width: 1599px) {
  .ws-header { gap: 12px; padding: 6px 16px; }
  .ws-back { padding-right: 12px; }
  .ws-ctx + .ws-ctx { padding-left: 12px; }
  .ws-ctx { gap: 8px; }
  .ws-btn-txt { display: none; }
  .pill-long { display: none; }
}
@media (min-width: 768px) and (max-width: 1365px) { .ws-ctx-study .ws-wide { display: none; } }
.ws-header { flex-wrap: wrap; row-gap: 4px; }

/* ── Upload Lumbar MRI ── */
.up-card { max-width: 980px; }
.up-head { padding: 20px 20px 4px; }
.up-head h1 { font-size: 20px; margin-bottom: 4px; }
.up-head p { color: var(--text-2); }
.up-existing { margin: 8px 20px 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13.5px; }
.up-existing a { margin-left: 8px; }
.up-drop { margin: 14px 20px 20px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); padding: 34px 20px; text-align: center; cursor: pointer; color: var(--text-2); }
.up-drop:hover, .up-drop:focus-visible { border-color: var(--accent); }
.up-drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.up-drop .t { font-weight: 600; margin-top: 8px; color: var(--text); }
.up-drop .s { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.link-like { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.up-review-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 8px; border-top: 1px solid var(--border); }
.up-review-head h2 { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: #5e6b80; }
.up-summary { margin: 0 20px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.up-sum { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.up-sum:last-child { border-bottom: 0; }
.up-sum .n { font: 600 20px var(--font); font-variant-numeric: tabular-nums; color: var(--text); text-align: right; }
.up-sum .what { font-weight: 600; }
.up-sum .st { color: var(--muted); font-size: 13px; }
.up-sum.warn .st { color: var(--warn); font-weight: 600; }
.up-group { margin: 12px 20px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.up-group > summary { padding: 10px 14px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.up-warn { color: var(--warn); font-size: 12.5px; }
.up-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; border-top: 1px solid var(--border); }
.up-row { display: grid; grid-template-columns: 44px 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 6px 14px; border-bottom: 1px solid var(--border); }
.up-row:last-child { border-bottom: 0; }
.up-row img { width: 44px; height: 44px; object-fit: cover; background: #000; border-radius: 3px; }
.up-row.is-dup { opacity: .7; }
.up-idx { font-size: 13px; }
.up-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-tag { font-size: 11.5px; color: var(--accent); }
.up-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.up-note { font-size: 12.5px; color: var(--muted); }
.up-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 16px 20px 20px; flex-wrap: wrap; }
.up-msg { margin-right: auto; color: var(--text-2); font-size: 13.5px; }
@media (max-width: 767px) {
  .up-head, .up-review-head { padding-left: 12px; padding-right: 12px; }
  .up-drop, .up-summary, .up-group, .up-existing { margin-left: 12px; margin-right: 12px; }
  .up-sum { grid-template-columns: 44px minmax(0, 1fr); }
  .up-sum .st, .up-sum .link-btn { grid-column: 2; }
  .up-row { grid-template-columns: 44px minmax(0, 1fr); }
  .up-row .up-idx { grid-column: 2; }
  .up-row .up-name { grid-column: 1 / -1; white-space: normal; overflow-wrap: anywhere; }
  .up-acts { grid-column: 1 / -1; justify-content: flex-start; }
  .up-acts .btn { flex: 1; }
  .up-actions { flex-direction: column-reverse; align-items: stretch; padding: 12px; }
  .up-msg { margin: 0; }
}

/* ── Stored-series image selection (manual; no automatic slice/level choice) ── */
a.pl-load { text-decoration: none; }
.sel-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 10px; background: #0c1626; border-top: 1px solid var(--ws-line); color: #c9d3e0; font-size: 12.5px; flex: none; }
.sel-bar.hidden { display: none; }
.sel-used { color: #8fb6e8; margin-right: auto; min-width: 0; overflow-wrap: anywhere; }
.sel-used:empty { display: none; }
.sel-used:empty + .sel-lvl { margin-left: auto; }
.sel-lvl { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: #c9d3e0; font-size: 12.5px; white-space: nowrap; }
.sel-lvl select { height: 28px; padding: 0 24px 0 8px; background-color: #13213a; color: #e6edf6; border: 1px solid #26364f; border-radius: var(--radius-sm); font-size: 12.5px; }
.sel-bar .btn { white-space: nowrap; }
@media (max-width: 767px) {
  .sel-bar { padding: 8px 12px; }
  .sel-used { flex-basis: 100%; }
  .sel-lvl select, .sel-bar .btn { height: 40px; min-height: 40px; }
  .sel-bar .btn { flex: 1; }
}

.ws-findings.no-analysis #axSection, .ws-findings.no-analysis #sgSection { display: none; }
.fp-empty p { color: var(--text-2); font-size: 13.5px; margin: 6px 0 0; }

/* ── Prepare AI analysis: axial → disc levels (clinician); sagittal → one Pfirrmann input ── */
.prep-head h1 { font-size: 20px; }
.prep-card { max-width: 1180px; }
.prep-note { padding: 12px 16px 0; color: var(--text-2); font-size: 13.5px; }
.prep-note p { margin: 0 0 6px; }
.prep-pad { padding: 0 16px; }
.prep-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 16px 0; }
.prep-status { font-size: 12.5px; color: var(--muted); margin-left: auto; }
.prep-grid { list-style: none; margin: 0; padding: 12px 16px; display: grid; gap: 10px; border: 0; min-width: 0;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
.prep-grid.dense { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.prep-item { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; min-width: 0; margin: 0; }
.prep-item.is-set { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.prep-thumb { display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; border: 0; border-radius: 3px; background: #000; overflow: hidden; cursor: zoom-in; }
.prep-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.prep-thumb.lg { width: 260px; max-width: 100%; }
.prep-meta { display: flex; gap: 6px; align-items: baseline; min-width: 0; font-size: 12.5px; }
.prep-file { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.prep-lvl { display: flex; flex-direction: column; gap: 3px; margin: 0; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.prep-lvl select { height: 34px; font-size: 13.5px; text-transform: none; letter-spacing: 0; }
.prep-lvl select.dup { border-color: var(--danger, #c0392b); box-shadow: 0 0 0 1px var(--danger, #c0392b); }
.prep-badge { position: absolute; top: 12px; left: 12px; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 3px; background: rgba(12, 22, 38, .85); color: #dbe7f6; }
.prep-badge.ok { background: #1f6b45; color: #fff; }
.prep-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.prep-msg { margin-right: auto; font-size: 13px; color: var(--text-2); }
.prep-msg.err { color: var(--danger, #c0392b); font-weight: 600; }
.prep-single { display: flex; gap: 16px; align-items: flex-start; padding: 12px 16px; flex-wrap: wrap; }
.prep-ready { margin: 8px 0 0; font-weight: 600; color: #1f6b45; }
.prep-pick { cursor: pointer; }
.prep-pick .prep-thumb { cursor: pointer; }
.prep-pick:hover { border-color: var(--border-strong); }
.prep-pick:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
.prep-pick:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
fieldset[disabled] .prep-pick { cursor: default; opacity: .75; }
@media (max-width: 767px) {
  .prep-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px 12px; }
  .prep-grid.dense { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .prep-grid.dense.sg { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .prep-note, .prep-tools, .prep-pad { padding-left: 12px; padding-right: 12px; }
  .prep-actions { padding: 12px; }
  .prep-actions .btn-primary { flex: 1 1 100%; min-height: 44px; }
  .prep-lvl select { height: 40px; }
  .prep-thumb.lg { width: 100%; }
}
@media (max-width: 380px) { .prep-grid.dense.sg { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.sel-prep { font-size: 12px; color: #8fb6e8; white-space: nowrap; }
.sel-prep:hover { color: #fff; }
