/* ==========================================================================
   CARDIZIUM v4.1 — Stage 1.2 Stylesheet (index.css)
   Zero-Dependency Clinical Dark & #99CC99 Studio Theme Architecture
   Strict >= 12px (0.75rem) Typography Floor · 100% Local file:// Safe
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. DESIGN TOKENS & DUAL-THEME PALETTE (Exposed to JS 2D/SVG Renderers)
   -------------------------------------------------------------------------- */
:root,
html[data-theme="dark"] {
  color-scheme: dark;

  /* Typography & Numeric Discipline */
  --cz-font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --cz-font-mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Mono", Consolas, monospace;
  --cz-fs-floor: 0.75rem;   /* Strict 12px minimum floor */
  --cz-fs-sm: 0.8125rem;    /* 13px */
  --cz-fs-md: 0.875rem;     /* 14px */
  --cz-fs-lg: 1rem;         /* 16px */
  --cz-fs-xl: 1.1875rem;    /* 19px */
  --cz-fs-2xl: 1.5rem;      /* 24px */

  /* Cockpit Surfaces */
  --cz-bg-app: #070e17;
  --cz-bg-topbar: #0c1724;
  --cz-bg-zone: #0b1522;
  --cz-bg-card: #101f31;
  --cz-bg-card-hover: #15283e;
  --cz-bg-inset: #08111c;
  --cz-bg-control: #13253a;
  --cz-bg-control-hover: #1b334f;
  --cz-bg-hud: rgba(10, 21, 34, 0.88);
  --cz-bg-modal-backdrop: rgba(3, 8, 14, 0.76);

  /* Borders, Elevation & Focus */
  --cz-border-subtle: #1e344d;
  --cz-border-strong: #2d4d70;
  --cz-border-active: #38bdf8;
  --cz-focus-ring: #38bdf8;
  --cz-shadow-zone: 0 6px 20px rgba(0, 0, 0, 0.36);
  --cz-shadow-float: 0 10px 28px rgba(0, 0, 0, 0.55);

  /* Text Hierarchy (WCAG AA/AAA Verified) */
  --cz-text-primary: #eaf2fb;
  --cz-text-secondary: #a8c0da;
  --cz-text-muted: #7e9ab8;
  --cz-text-inverse: #06101a;

  /* ICU Bedside Telemetry Chromatics */
  --cz-vital-hr: #34d399;
  --cz-vital-bp: #fb7185;
  --cz-vital-spo2: #38bdf8;
  --cz-vital-hemo: #fbbf24;
  --cz-accent-ep: #22d3ee;
  --cz-accent-math: #a78bfa;
  --cz-accent-brand: #ef233c;

  /* Clinical Acuity States */
  --cz-status-ok: #10b981;
  --cz-status-ok-bg: rgba(16, 185, 129, 0.14);
  --cz-status-guarded: #38bdf8;
  --cz-status-guarded-bg: rgba(56, 189, 248, 0.14);
  --cz-status-warn: #f59e0b;
  --cz-status-warn-bg: rgba(245, 158, 11, 0.16);
  --cz-status-crit: #ef4444;
  --cz-status-crit-bg: rgba(239, 68, 68, 0.18);

  /* Canvas & SVG Shared Biophysical Tokens (Read by core.js, anatomy.js, ecg.js) */
  --cz-heart-stage-inner: #162a40;
  --cz-heart-stage-mid: #0d1a29;
  --cz-heart-stage-outer: #060d15;
  --cz-ecg-bg: #040b11;
  --cz-ecg-grid-minor: rgba(16, 185, 129, 0.09);
  --cz-ecg-grid-major: rgba(16, 185, 129, 0.22);
  --cz-ecg-trace: #34d399;
  --cz-ecg-phosphor: rgba(52, 211, 153, 0.45);
  --cz-svg-leader: #7cc4fa;
  --cz-svg-label-bg: rgba(9, 19, 31, 0.88);
  --cz-svg-label-text: #eaf2fb;
  --cz-stage-guide-stroke: #294969;
  --cz-stage-guide-title: #9cc0e6;
  --cz-stage-guide-sub: #7096bd;
  --cz-slider-track: #1b3149;
  --cz-slider-thumb: #eaf2fb;
  --cz-slider-thumb-border: #0284c7;
  --cz-gauss-mean-stroke: rgba(255, 255, 255, 0.62);
  --cz-gauss-dot-fill: #ffffff;
  --cz-gauss-dot-stroke: #07111c;
}

/* Signature #99CC99 Studio Theme (Full Parity & High-Contrast Readability) */
html[data-theme="studio"],
html[data-theme="99cc99"],
html[data-theme="light"] {
  color-scheme: light;

  /* Cockpit Surfaces Anchored on #99CC99 */
  --cz-bg-app: #99cc99;
  --cz-bg-topbar: #e4f2e4;
  --cz-bg-zone: #edf7ed;
  --cz-bg-card: #f7fbf7;
  --cz-bg-card-hover: #ffffff;
  --cz-bg-inset: #dcecdc;
  --cz-bg-control: #e2f0e2;
  --cz-bg-control-hover: #d1e7d1;
  --cz-bg-hud: rgba(244, 251, 244, 0.93);
  --cz-bg-modal-backdrop: rgba(18, 38, 22, 0.56);

  /* Borders, Elevation & Focus */
  --cz-border-subtle: #76a87a;
  --cz-border-strong: #49794f;
  --cz-border-active: #0f6cbd;
  --cz-focus-ring: #0b5cab;
  --cz-shadow-zone: 0 4px 14px rgba(20, 52, 26, 0.14);
  --cz-shadow-float: 0 10px 26px rgba(16, 44, 22, 0.24);

  /* High-Contrast Botanical Slate Typography */
  --cz-text-primary: #0f2415;
  --cz-text-secondary: #23442c;
  --cz-text-muted: #3b6145;
  --cz-text-inverse: #f7fcf7;

  /* Studio-Calibrated Bedside Telemetry Chromatics (WCAG Contrast Safe on Pale Sage) */
  --cz-vital-hr: #046c4e;
  --cz-vital-bp: #b91c1c;
  --cz-vital-spo2: #0369a1;
  --cz-vital-hemo: #92400e;
  --cz-accent-ep: #0e7490;
  --cz-accent-math: #5b21b6;
  --cz-accent-brand: #c81e32;

  /* Clinical Acuity States */
  --cz-status-ok: #047857;
  --cz-status-ok-bg: rgba(4, 120, 87, 0.13);
  --cz-status-guarded: #0369a1;
  --cz-status-guarded-bg: rgba(3, 105, 161, 0.13);
  --cz-status-warn: #b45309;
  --cz-status-warn-bg: rgba(180, 83, 9, 0.15);
  --cz-status-crit: #b91c1c;
  --cz-status-crit-bg: rgba(185, 28, 28, 0.16);

  /* Studio Canvas & SVG Tokens */
  --cz-heart-stage-inner: #b8dfb8;
  --cz-heart-stage-mid: #99cc99;
  --cz-heart-stage-outer: #74ab78;
  --cz-ecg-bg: #f2faf2;
  --cz-ecg-grid-minor: rgba(200, 30, 50, 0.12);
  --cz-ecg-grid-major: rgba(200, 30, 50, 0.26);
  --cz-ecg-trace: #0b3b24;
  --cz-ecg-phosphor: rgba(11, 59, 36, 0.22);
  --cz-svg-leader: #14532d;
  --cz-svg-label-bg: rgba(247, 252, 247, 0.94);
  --cz-svg-label-text: #0f2415;
  --cz-stage-guide-stroke: #3f6d45;
  --cz-stage-guide-title: #13331c;
  --cz-stage-guide-sub: #274f32;
  --cz-slider-track: #b2d8b4;
  --cz-slider-thumb: #0f2415;
  --cz-slider-thumb-border: #047857;
  --cz-gauss-mean-stroke: rgba(15, 36, 21, 0.65);
  --cz-gauss-dot-fill: #ffffff;
  --cz-gauss-dot-stroke: #0f2415;
}

/* --------------------------------------------------------------------------
   2. GLOBAL RESET, STRICT 12PX FLOOR & ACCESSIBILITY INVARIANTS
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  font-family: var(--cz-font-sans);
  background-color: var(--cz-bg-app);
  color: var(--cz-text-primary);
  line-height: 1.38;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--cz-bg-app);
  color: var(--cz-text-primary);
  font-size: var(--cz-fs-floor);
  overflow-x: hidden;
  transition: background-color 180ms ease, color 180ms ease;
}

/* Enforce strict >= 12px floor even on small/sub/sup/code elements */
small,
sub,
sup,
code,
kbd,
samp,
button,
input,
select,
textarea,
label,
a {
  font-size: max(var(--cz-fs-floor), 12px);
}

code {
  font-family: var(--cz-font-mono);
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 4px;
  padding: 1px 5px;
}

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

/* Custom Subtle Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--cz-border-strong) var(--cz-bg-inset);
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: var(--cz-bg-inset);
}
*::-webkit-scrollbar-thumb {
  background: var(--cz-border-strong);
  border-radius: 4px;
}

/* Four-Tier Complexity Progressive Disclosure Hooks */
html[data-tier="1"] .cz-tier-2-up,
html[data-tier="1"] .cz-tier-3-up,
html[data-tier="1"] .cz-tier-4-only {
  display: none !important;
}
html[data-tier="2"] .cz-tier-3-up,
html[data-tier="2"] .cz-tier-4-only {
  display: none !important;
}
html[data-tier="3"] .cz-tier-4-only {
  display: none !important;
}

/* --------------------------------------------------------------------------
   3. BASE CONTROLS, BUTTONS, INPUTS & SHARED UTILITY CLASSES
   -------------------------------------------------------------------------- */
.cz-row-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.cz-card-lite {
  background: var(--cz-bg-card);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: var(--cz-fs-floor);
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

button,
select,
.cz-util-link {
  font-family: inherit;
  font-size: var(--cz-fs-floor);
  font-weight: 500;
  line-height: 1.25;
  color: var(--cz-text-primary);
  background: var(--cz-bg-control);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 6px;
  padding: 5px 9px;
  min-height: 28px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background-color 130ms ease, border-color 130ms ease, transform 90ms ease, box-shadow 130ms ease;
}

select {
  display: inline-block;
  padding-right: 10px;
}

button:hover,
select:hover,
.cz-util-link:hover {
  background: var(--cz-bg-control-hover);
  border-color: var(--cz-border-strong);
}

button:active {
  transform: translateY(1px);
}

button.is-active,
button[aria-pressed="true"],
button[aria-checked="true"],
button[aria-expanded="true"] {
  background: var(--cz-status-guarded-bg);
  border-color: var(--cz-border-active);
  box-shadow: inset 0 0 0 1px var(--cz-border-active);
  font-weight: 600;
}

input[type="number"],
input[type="text"],
input[type="search"] {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-primary);
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 5px;
  padding: 3px 6px;
  min-height: 26px;
}

input[type="search"] {
  font-family: var(--cz-font-sans);
}

input[type="number"]:focus,
input[type="text"]:focus,
input[type="search"]:focus {
  border-color: var(--cz-border-active);
}

/* Tactile Precision Range Sliders (Cross-Browser WebKit + Firefox) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  height: 22px;
  margin: 2px 0;
  vertical-align: middle;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--cz-slider-track);
  border: 1px solid var(--cz-border-subtle);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--cz-slider-thumb);
  border: 2px solid var(--cz-slider-thumb-border);
  margin-top: -5.5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 110ms ease, box-shadow 110ms ease;
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.14);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--cz-slider-track);
  border: 1px solid var(--cz-border-subtle);
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--cz-slider-thumb);
  border: 2px solid var(--cz-slider-thumb-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.cz-inline-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--cz-text-secondary);
  font-size: var(--cz-fs-floor);
  white-space: nowrap;
}

/* Interactive Clinical Math Card Trigger Affordance (ƒ) */
.cz-math-trigger {
  cursor: pointer;
}
.cz-math-trigger:hover {
  border-color: var(--cz-accent-math);
  box-shadow: 0 0 0 1px var(--cz-accent-math);
}

.cz-link-inline {
  padding: 2px 6px;
  min-height: 22px;
  border-radius: 4px;
  background: transparent;
  border: 1px dashed var(--cz-border-strong);
  color: var(--cz-accent-math);
  font-weight: 600;
}

.cz-link-inline:hover {
  background: rgba(167, 139, 250, 0.14);
  border-style: solid;
}

.cz-subhead {
  font-size: var(--cz-fs-floor);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--cz-text-secondary);
}

/* --------------------------------------------------------------------------
   4. FOUR-ZONE ACUTE-CARE ICU COCKPIT SHELL (#cz-app)
   -------------------------------------------------------------------------- */
.cz-app {
  display: grid;
  grid-template-rows: auto auto minmax(440px, 1fr) auto;
  grid-template-columns: minmax(0, 1fr) 376px;
  grid-template-areas:
    "topbar topbar"
    "banner banner"
    "stage  rail"
    "dock   rail";
  gap: 8px;
  padding: 8px;
  min-height: 100vh;
  max-width: 2400px;
  margin: 0 auto;
}

.cz-zone {
  background: var(--cz-bg-zone);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 10px;
  box-shadow: var(--cz-shadow-zone);
}

/* --------------------------------------------------------------------------
   5. TOP UTILITY BAR (#cz-topbar) & MOBILE DRAWER SWITCHER (#cz-mobile-nav)
   -------------------------------------------------------------------------- */
#cz-topbar {
  grid-area: topbar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 6px 12px;
  background: var(--cz-bg-topbar);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 10px;
  box-shadow: var(--cz-shadow-zone);
}

.cz-brand {
  gap: 8px;
}

.cz-brand-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(239, 35, 60, 0.45));
}

.cz-brand-title {
  font-size: var(--cz-fs-md);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--cz-text-primary);
}

.cz-version-pill {
  font-family: var(--cz-font-mono);
  font-size: var(--cz-fs-floor);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  color: var(--cz-text-secondary);
}

.cz-bar-label {
  font-weight: 600;
  color: var(--cz-text-secondary);
}

#cz-tier-selector {
  background: var(--cz-bg-inset);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--cz-border-subtle);
}

#cz-tier-selector .cz-tier-btn {
  border-color: transparent;
  background: transparent;
  padding: 4px 8px;
  min-height: 26px;
}

#cz-tier-selector .cz-tier-btn:hover {
  background: var(--cz-bg-control);
}

#cz-tier-selector .cz-tier-btn.is-active,
#cz-tier-selector .cz-tier-btn[aria-checked="true"] {
  background: var(--cz-bg-control-hover);
  border-color: var(--cz-border-active);
  color: var(--cz-text-primary);
}

#cz-audio-bar {
  background: var(--cz-bg-inset);
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid var(--cz-border-subtle);
}

#cz-input-volume {
  width: 68px;
}

.cz-util-link {
  border-color: var(--cz-border-strong);
  font-weight: 600;
}

#cz-mobile-nav {
  display: none;
}

/* --------------------------------------------------------------------------
   6. PRIORITY ZONE 1: TOP MONITOR BANNER (#cz-zone-banner)
   -------------------------------------------------------------------------- */
#cz-zone-banner {
  grid-area: banner;
  display: grid;
  grid-template-columns: minmax(0, 1.68fr) minmax(300px, 1fr) 174px;
  gap: 8px;
  padding: 8px 10px;
  align-items: stretch;
}

/* Scrolling Lead II ECG & Sub-ECG Interval Strip */
.cz-ecg-strip-wrap {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.cz-ecg-header {
  justify-content: space-between;
  gap: 6px 8px;
}

.cz-rhythm-badge {
  font-family: var(--cz-font-mono);
  font-weight: 700;
  font-size: var(--cz-fs-floor);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--cz-status-ok-bg);
  border: 1px solid var(--cz-status-ok);
  color: var(--cz-vital-hr);
}

.cz-rhythm-badge[data-acuity="warn"],
.cz-rhythm-badge[data-rhythm="AFIB"],
.cz-rhythm-badge[data-rhythm="AFL"],
.cz-rhythm-badge[data-rhythm="SVT"] {
  background: var(--cz-status-warn-bg);
  border-color: var(--cz-status-warn);
  color: var(--cz-status-warn);
}

.cz-rhythm-badge[data-acuity="crit"],
.cz-rhythm-badge[data-rhythm="VT"],
.cz-rhythm-badge[data-rhythm="VFIB"],
.cz-rhythm-badge[data-rhythm="ASYSTOLE"],
.cz-rhythm-badge[data-rhythm="PEA"] {
  background: var(--cz-status-crit-bg);
  border-color: var(--cz-status-crit);
  color: var(--cz-status-crit);
}

.cz-telemetry-tag {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-secondary);
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  padding: 3px 7px;
  border-radius: 5px;
}

#cz-input-phase-scrub {
  width: 78px;
}

.cz-ecg-canvas-shell {
  position: relative;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--cz-border-strong);
  background-color: var(--cz-ecg-bg);
  /* Diagnostic millimeter calibration grid sheen prior to & beneath ecg.js canvas */
  background-image:
    linear-gradient(to right, var(--cz-ecg-grid-minor) 1px, transparent 1px),
    linear-gradient(to bottom, var(--cz-ecg-grid-minor) 1px, transparent 1px),
    linear-gradient(to right, var(--cz-ecg-grid-major) 1px, transparent 1px),
    linear-gradient(to bottom, var(--cz-ecg-grid-major) 1px, transparent 1px);
  background-size: 5px 5px, 5px 5px, 25px 25px, 25px 25px;
}

#cz-ecg-canvas {
  width: 100%;
  height: 124px;
  display: block;
  background: transparent;
  cursor: crosshair;
}

.cz-ecg-wave-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cz-ecg-wave-overlay > * {
  pointer-events: auto;
}

/* 10-Metric Rate-Corrected Sub-ECG Telemetry Strip */
#cz-ecg-substrip {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
  margin-top: 0;
}

.cz-submetric {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 4px 6px;
  min-height: 44px;
  text-align: left;
  background: var(--cz-bg-card);
}

.cz-submetric-k {
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-secondary);
  font-weight: 600;
}

.cz-submetric strong {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--cz-fs-sm);
  color: var(--cz-text-primary);
  white-space: nowrap;
}

.cz-submetric-qtc {
  grid-column: span 1;
}

#cz-qtc-formula-select {
  padding: 1px 4px;
  min-height: 22px;
  max-width: 78px;
}

/* Acute Five-Second Bedside Vitals Grid (#cz-vitals-readout) */
#cz-vitals-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.cz-vital-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 7px 10px;
  text-align: left;
  background: var(--cz-bg-card);
  border-left-width: 4px;
}

.cz-vital-tile:nth-child(1) {
  border-left-color: var(--cz-vital-hr);
}
.cz-vital-tile:nth-child(1) .cz-vital-main {
  color: var(--cz-vital-hr);
}

.cz-vital-tile:nth-child(2) {
  border-left-color: var(--cz-vital-bp);
}
.cz-vital-tile:nth-child(2) .cz-vital-main {
  color: var(--cz-vital-bp);
}

.cz-vital-tile:nth-child(3) {
  border-left-color: var(--cz-vital-spo2);
}
.cz-vital-tile:nth-child(3) .cz-vital-main {
  color: var(--cz-vital-spo2);
}

.cz-vital-tile:nth-child(4) {
  border-left-color: var(--cz-vital-hemo);
}
.cz-vital-tile:nth-child(4) .cz-vital-main {
  color: var(--cz-vital-hemo);
}

.cz-vital-head {
  font-size: var(--cz-fs-floor);
  font-weight: 700;
  color: var(--cz-text-secondary);
  letter-spacing: 0.02em;
}

.cz-vital-main {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--cz-fs-xl);
  font-weight: 800;
  line-height: 1.15;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
}

.cz-vital-sub {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-secondary);
}

/* Upside-Down Derangement Index Badge (#cz-upside-down-badge) */
#cz-upside-down-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  padding: 8px 10px;
  border-width: 2px;
  border-color: var(--cz-status-ok);
  background: linear-gradient(180deg, var(--cz-status-ok-bg) 0%, var(--cz-bg-card) 100%);
}

#cz-upside-down-badge[data-severity="guarded"] {
  border-color: var(--cz-status-guarded);
  background: linear-gradient(180deg, var(--cz-status-guarded-bg) 0%, var(--cz-bg-card) 100%);
}

#cz-upside-down-badge[data-severity="warning"] {
  border-color: var(--cz-status-warn);
  background: linear-gradient(180deg, var(--cz-status-warn-bg) 0%, var(--cz-bg-card) 100%);
}

#cz-upside-down-badge[data-severity="critical"] {
  border-color: var(--cz-status-crit);
  background: linear-gradient(180deg, var(--cz-status-crit-bg) 0%, var(--cz-bg-card) 100%);
  animation: cz-crit-pulse 1.6s ease-in-out infinite;
}

.cz-ud-header {
  font-size: var(--cz-fs-floor);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cz-text-secondary);
}

.cz-ud-score-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
}

.cz-ud-value {
  font-size: var(--cz-fs-2xl);
  font-weight: 800;
  line-height: 1.05;
}

.cz-ud-scale {
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-secondary);
}

.cz-ud-tier {
  font-family: var(--cz-font-mono);
  font-size: var(--cz-fs-floor);
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
}

#cz-upside-down-meter {
  width: 100%;
  height: 10px;
}

.cz-ud-caption {
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-muted);
}

/* --------------------------------------------------------------------------
   7. PRIORITY ZONE 2: LIVING HEART STAGE & OVERLAYS (#cz-zone-stage)
   -------------------------------------------------------------------------- */
#cz-zone-stage {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px;
  min-height: 460px;
  min-width: 0;
}

#cz-overlay-toolbar {
  justify-content: space-between;
  gap: 6px 10px;
}

.cz-overlay-tab {
  font-weight: 600;
}

#cz-overlay-tray {
  flex: 1 1 100%;
  width: 100%;
  margin-top: 2px;
  padding: 8px 10px;
  background: var(--cz-bg-inset);
  border-color: var(--cz-border-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cz-embolic-strip {
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--cz-border-subtle);
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--cz-text-secondary);
}

.cz-embolic-strip strong {
  color: var(--cz-text-primary);
}

/* Living Elastic Heart Stage (#cz-heart-stage) */
#cz-heart-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 410px;
  border-radius: 9px;
  border: 1px solid var(--cz-border-strong);
  background: radial-gradient(
    circle at 50% 45%,
    var(--cz-heart-stage-inner) 0%,
    var(--cz-heart-stage-mid) 56%,
    var(--cz-heart-stage-outer) 100%
  );
  overflow: hidden;
  user-select: none;
}

#cz-heart-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#cz-heart-canvas:active {
  cursor: grabbing;
}

#cz-heart-svg-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* Theme-Adaptive Pre-Anatomy Reticle Styling */
#cz-svg-stage-placeholder circle,
#cz-svg-stage-placeholder line {
  stroke: var(--cz-stage-guide-stroke);
}
#cz-svg-stage-placeholder text:first-of-type {
  fill: var(--cz-stage-guide-title);
}
#cz-svg-stage-placeholder text:last-of-type {
  fill: var(--cz-stage-guide-sub);
}

/* Five Precordial Auscultation Posts & Draggable Stethoscope */
#cz-auscultation-posts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

#cz-auscultation-posts.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.cz-ausc-post {
  pointer-events: auto;
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 3px 8px;
  min-height: 26px;
  border-radius: 999px;
  font-family: var(--cz-font-mono);
  font-size: var(--cz-fs-floor);
  font-weight: 700;
  background: var(--cz-bg-hud);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1.5px solid var(--cz-border-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.cz-ausc-post:hover {
  transform: translate(-50%, -50%) scale(1.08);
  border-color: var(--cz-accent-ep);
}

.cz-ausc-post.is-active,
.cz-ausc-post[aria-pressed="true"] {
  border-color: var(--cz-vital-hr);
  background: var(--cz-status-ok-bg);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25), 0 3px 10px rgba(0, 0, 0, 0.45);
}

#cz-steth-chestpiece {
  pointer-events: auto;
  position: absolute;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cz-fs-lg);
  background: radial-gradient(circle at 35% 35%, #f8fafc 0%, #94a3b8 58%, #334155 100%);
  border: 2px solid var(--cz-accent-ep);
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.25), var(--cz-shadow-float);
  cursor: grab;
  touch-action: none;
  z-index: 6;
}

#cz-steth-chestpiece:active,
#cz-steth-chestpiece.is-dragging {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.1);
}

/* Floating Viewport Tool Cluster (#cz-canvas-tools) */
#cz-canvas-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px;
  border-radius: 8px;
  background: var(--cz-bg-hud);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--cz-border-subtle);
  box-shadow: var(--cz-shadow-zone);
  z-index: 7;
}

#cz-canvas-tools button {
  padding: 4px 8px;
  min-height: 26px;
}

/* Floating Local Structure Telemetry HUD (#cz-hover-hud) */
#cz-hover-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  width: min(275px, calc(100% - 20px));
  padding: 8px 10px;
  background: var(--cz-bg-hud);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--cz-border-active);
  box-shadow: var(--cz-shadow-float);
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#cz-hover-hud[data-locked="true"],
#cz-hover-hud.is-locked {
  border-color: var(--cz-vital-hemo);
  box-shadow: 0 0 0 1px var(--cz-vital-hemo), var(--cz-shadow-float);
}

.cz-hud-badge {
  font-family: var(--cz-font-mono);
  font-size: var(--cz-fs-floor);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  color: var(--cz-accent-ep);
}

.cz-hud-telemetry {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--cz-text-secondary);
}

.cz-hud-telemetry strong {
  color: var(--cz-text-primary);
}

/* Bottom Colorblind-Safe SpO2 Ramp & Live Chamber Pressure Legend */
#cz-spo2-legend {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 5px 10px;
  background: var(--cz-bg-hud);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 7px;
  font-size: var(--cz-fs-floor);
  z-index: 6;
}

.cz-chamber-pressures {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--cz-text-secondary);
}

.cz-chamber-pressures strong {
  color: var(--cz-text-primary);
}

#cz-cycle-phase-badge {
  font-family: var(--cz-font-sans);
  font-weight: 700;
  color: var(--cz-accent-ep);
}

/* Collapsible 12-Lead ECG & Wiggers / PV Loop Drawers */
.cz-stage-drawer {
  padding: 8px 10px;
  background: var(--cz-bg-inset);
  border-color: var(--cz-border-strong);
}

#cz-12lead-canvas,
#cz-axis-vector-canvas,
#cz-wiggers-canvas,
#cz-pvloop-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: var(--cz-ecg-bg);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 6px;
}

/* --------------------------------------------------------------------------
   8. PRIORITY ZONE 3: SLIDERS, GAUSSIAN LABS & ANTHROPOMETRICS (#cz-zone-dock)
   -------------------------------------------------------------------------- */
#cz-zone-dock {
  grid-area: dock;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px;
}

.cz-primary-sliders-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.cz-slider-card,
.cz-lab-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  padding: 7px 9px;
}

.cz-detent-btn {
  padding: 2px 6px;
  min-height: 24px;
  font-weight: 700;
}

.cz-slider-sub {
  font-size: var(--cz-fs-floor);
  color: var(--cz-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Gaussian Bell-Curve Vector Tracks */
.cz-gauss-track {
  width: 100%;
  height: 26px;
  display: block;
  background: var(--cz-bg-inset);
  border-radius: 5px;
  border: 1px solid var(--cz-border-subtle);
}

.cz-gauss-track line {
  stroke: var(--cz-gauss-mean-stroke);
}

.cz-gauss-dot {
  fill: var(--cz-gauss-dot-fill);
  stroke: var(--cz-gauss-dot-stroke);
  stroke-width: 1.5px;
  transition: cx 120ms ease-out, cy 120ms ease-out;
}

.cz-lab-card[data-zone="warn"] {
  border-color: var(--cz-status-warn);
  background: linear-gradient(180deg, var(--cz-status-warn-bg) 0%, var(--cz-bg-card) 100%);
}

.cz-lab-card[data-zone="critical"] {
  border-color: var(--cz-status-crit);
  background: linear-gradient(180deg, var(--cz-status-crit-bg) 0%, var(--cz-bg-card) 100%);
}

/* Anthropometrics Bar & Optional Labs Drawer */
#cz-anthropometrics-bar {
  padding: 6px 10px;
  background: var(--cz-bg-card);
}

.cz-anthro-pill {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
}

#cz-optional-labs-drawer {
  padding-top: 2px;
}

.cz-optional-labs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 7px;
}

/* --------------------------------------------------------------------------
   9. PRIORITY ZONE 4: CLINICAL PHARMA, TRIAGE & MATH RAIL (#cz-zone-rail)
   -------------------------------------------------------------------------- */
#cz-zone-rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  position: relative;
}

.cz-rail-block {
  padding: 8px 10px;
}

.cz-risk-pill {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 3px 7px;
  min-height: 24px;
}

#cz-differential-summary {
  color: var(--cz-text-secondary);
  line-height: 1.42;
}

/* ISMP Tall-Man Medication Safety Highlighting */
.cz-pump-row {
  padding: 4px 6px;
  border-radius: 5px;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
}

.cz-pump-row span strong {
  font-family: var(--cz-font-mono);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--cz-vital-hemo);
  background: var(--cz-status-warn-bg);
  padding: 0 3px;
  border-radius: 3px;
}

/* Initialed & Time-Stamped Emergency Triage Checklist */
.cz-check-item {
  padding: 5px 7px;
  margin-bottom: 4px;
  border-radius: 5px;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  border-left-width: 3px;
}

#cz-checklist-immediate .cz-check-item {
  border-left-color: var(--cz-status-crit);
}

#cz-checklist-stabilization .cz-check-item {
  border-left-color: var(--cz-status-guarded);
}

.cz-check-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--cz-status-ok);
  cursor: pointer;
}

.cz-check-item label {
  cursor: pointer;
  flex: 1 1 auto;
}

#cz-checklist-log-list {
  font-family: var(--cz-font-mono);
  font-variant-numeric: tabular-nums;
  background: var(--cz-bg-inset);
  border: 1px solid var(--cz-border-subtle);
  border-radius: 5px;
  padding: 5px 7px !important;
  max-height: 120px;
  overflow-y: auto;
}

#cz-checklist-log-list li {
  padding: 2px 0;
  color: var(--cz-text-secondary);
}

/* Slide-Out Interactive Clinical Math & IV Dosing Appendix (#cz-math-drawer) */
#cz-math-drawer {
  position: fixed;
  top: 58px;
  right: 10px;
  bottom: 10px;
  width: min(460px, calc(100vw - 20px));
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--cz-bg-zone);
  border: 2px solid var(--cz-accent-math);
  border-radius: 10px;
  box-shadow: var(--cz-shadow-float);
  overflow-y: auto;
  animation: cz-drawer-slide-in 160ms ease-out;
}

.cz-math-cards-host {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
}

.cz-math-card-placeholder,
.cz-math-card {
  padding: 10px;
  border-radius: 7px;
  background: var(--cz-bg-card);
  border: 1px solid var(--cz-border-subtle);
}

/* --------------------------------------------------------------------------
   10. GLOBAL ACCESSIBLE MODAL & NON-BLOCKING TOAST STACK
   -------------------------------------------------------------------------- */
.cz-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--cz-bg-modal-backdrop);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.cz-modal-dialog {
  width: min(720px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--cz-bg-zone);
  border: 1px solid var(--cz-border-strong);
  border-radius: 12px;
  box-shadow: var(--cz-shadow-float);
}

.cz-modal-body p {
  line-height: 1.5;
  color: var(--cz-text-secondary);
}

.cz-modal-body strong {
  color: var(--cz-text-primary);
}

#cz-toast-stack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(370px, calc(100vw - 28px));
  pointer-events: none;
}

#cz-toast-stack > * {
  pointer-events: auto;
  background: var(--cz-bg-hud);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--cz-border-strong);
  box-shadow: var(--cz-shadow-float);
  padding: 8px 10px;
}

/* --------------------------------------------------------------------------
   11. KEYFRAME ANIMATIONS & REDUCED-MOTION COMPLIANCE
   -------------------------------------------------------------------------- */
@keyframes cz-crit-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.0);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.32);
  }
}

@keyframes cz-drawer-slide-in {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   12. RESPONSIVE COCKPIT GRIDS & MOBILE ZONE DRAWERS
   -------------------------------------------------------------------------- */
@media (max-width: 1440px) {
  #cz-ecg-substrip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .cz-primary-sliders-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .cz-app {
    grid-template-rows: auto auto auto auto auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "banner"
      "stage"
      "dock"
      "rail";
  }

  #cz-zone-banner {
    grid-template-columns: minmax(0, 1fr) 174px;
  }

  #cz-ecg-strip-wrap {
    grid-column: 1 / -1;
  }

  #cz-zone-rail {
    max-height: none;
    overflow-y: visible;
  }
}

@media (max-width: 960px) {
  .cz-app {
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas:
      "topbar"
      "mobnav"
      "banner"
      "stage"
      "dock"
      "rail";
  }

  #cz-mobile-nav {
    grid-area: mobnav;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 5px;
    background: var(--cz-bg-topbar);
    border: 1px solid var(--cz-border-subtle);
    border-radius: 9px;
  }

  .cz-mob-tab {
    width: 100%;
    font-weight: 700;
  }

  /* Responsive override for inline split-grid styles inside Stage 1.1 drawers */
  .cz-12lead-grid,
  .cz-hemo-drawer-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .cz-primary-sliders-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Active Mobile Zone Drawer Switching (Driven by html[data-mobile-zone] in core.js) */
  html[data-mobile-zone="stage"] #cz-zone-dock,
  html[data-mobile-zone="stage"] #cz-zone-rail {
    display: none;
  }

  html[data-mobile-zone="dock"] #cz-zone-stage,
  html[data-mobile-zone="dock"] #cz-zone-rail {
    display: none;
  }

  html[data-mobile-zone="rail"] #cz-zone-stage,
  html[data-mobile-zone="rail"] #cz-zone-dock {
    display: none;
  }

  html[data-mobile-zone="math"] #cz-zone-stage,
  html[data-mobile-zone="math"] #cz-zone-dock,
  html[data-mobile-zone="math"] #cz-zone-rail > :not(#cz-math-drawer) {
    display: none;
  }

  html[data-mobile-zone="math"] #cz-math-drawer {
    position: static;
    width: 100%;
    display: flex !important;
  }
}

@media (max-width: 640px) {
  #cz-zone-banner {
    grid-template-columns: minmax(0, 1fr);
  }

  #cz-vitals-readout {
    grid-template-columns: minmax(0, 1fr);
  }

  #cz-ecg-substrip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cz-primary-sliders-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #cz-mobile-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #cz-heart-stage {
    min-height: 330px;
  }
}