:root {
  --brand: #315fee;
  --brand-soft: #eef3ff;
  --ink: #111b31;
  --muted: #64718a;
  --faint: #93a0b5;
  --line: #dce5f1;
  --paper: #f4f7fb;
  --white: #ffffff;
  --cyan: #20b9c7;
  --red: #ef5c6c;
  --violet: #7d5ce7;
  --amber: #f2a629;
  --green: #22a879;
  --navy: #13254b;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body { overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--white);
  text-decoration: none;
  font-size: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--white);
  background: linear-gradient(135deg, #315fee 0%, #22c5db 100%);
  border-radius: 8px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(49, 95, 238, 0.2);
}

.brand-lockup > span:last-child { display: grid; gap: 2px; }
.brand-lockup strong { font-size: 15px; }
.brand-lockup small { color: var(--muted); font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }

.case-state {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.case-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(34, 168, 121, 0.11);
}

.case-state b { color: var(--ink); font: 800 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.quiet-button {
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--white);
  font-weight: 700;
  font-size: 11px;
}

.quiet-button:hover { border-color: #a9b9dc; color: var(--brand); }
.synthetic-badge { padding: 6px 9px; color: #9b6214; background: #fff7e6; border: 1px solid #f3d79a; border-radius: 4px; font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace; }

.lab-shell {
  height: calc(100vh - 128px);
  min-height: 620px;
  display: grid;
  grid-template-columns: 230px minmax(650px, 1fr) 280px;
}

.patient-rail,
.state-rail {
  min-width: 0;
  overflow-y: auto;
  background: var(--white);
}

.patient-rail { border-right: 1px solid var(--line); }
.state-rail { border-left: 1px solid var(--line); }
.case-heading, .phase-block, .event-index, .risk-module, .vitals-module, .organs-module, .event-inspector { padding: 19px; border-bottom: 1px solid var(--line); }

.eyebrow,
.section-label {
  color: var(--brand);
  font: 800 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0;
}

.case-heading h1 {
  margin: 8px 0 16px;
  font-size: 25px;
  line-height: 1.18;
}

.patient-meta { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.patient-meta div { padding: 10px 7px; border-right: 1px solid var(--line); }
.patient-meta div:last-child { border-right: 0; }
.patient-meta span { display: block; font-weight: 850; font-size: 13px; }
.patient-meta small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }

.phase-block { background: #f8faff; }
.phase-block strong { display: block; margin: 7px 0 5px; font-size: 15px; }
.phase-block p, .event-inspector p, .risk-module p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.65; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title span { font-weight: 800; font-size: 12px; }
.section-title b { color: var(--faint); font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace; }

#eventList { display: grid; gap: 3px; }
#eventList button {
  min-height: 36px;
  display: grid;
  grid-template-columns: 38px 7px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

#eventList button:hover { background: #f5f8fd; }
#eventList button.active { color: var(--ink); background: var(--brand-soft); border-color: #c8d6ff; }
#eventList button.passed time { color: var(--brand); }
#eventList time { font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
#eventList i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
#eventList span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 650; }

.tone-blue { --tone: var(--brand); }
.tone-cyan { --tone: var(--cyan); }
.tone-red { --tone: var(--red); }
.tone-violet { --tone: var(--violet); }
.tone-amber { --tone: var(--amber); }
.tone-green { --tone: var(--green); }
#eventList i[class*="tone-"] { background: var(--tone); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 13%, transparent); }

.replay-stage {
  min-width: 0;
  padding: 16px 18px 18px;
  overflow-y: auto;
  background: var(--paper);
}

.stage-head { min-height: 52px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.stage-head h2 { margin: 5px 0 0; font-size: 19px; line-height: 1.25; }
.range-presets { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: var(--white); }
.range-presets button { min-width: 44px; height: 31px; padding: 0 9px; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: var(--white); font-size: 10px; font-weight: 800; }
.range-presets button:last-child { border-right: 0; }
.range-presets button.active { color: var(--white); background: var(--brand); }

.monitor-panel,
.timeline-panel,
.window-summary {
  background: var(--white);
  border: 1px solid var(--line);
}

.monitor-toolbar { height: 42px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: 1px solid var(--line); }
.signal-key { display: flex; gap: 13px; }
.signal-key span { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font: 800 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
.signal-key span::before { content: ""; width: 12px; height: 2px; background: var(--signal); }
.cursor-time { display: flex; align-items: baseline; gap: 7px; }
.cursor-time small { color: var(--muted); font-size: 9px; }
.cursor-time strong { font: 850 14px ui-monospace, SFMono-Regular, Menlo, monospace; }

.chart-stack { padding: 7px 10px 4px; }
.signal-row { min-width: 0; display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: stretch; border-bottom: 1px solid #edf2f8; }
.signal-row:last-child { border-bottom: 0; }
.signal-axis { display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #edf2f8; }
.signal-axis strong { font-size: 10px; }
.signal-axis span { margin-top: 2px; color: var(--faint); font-size: 8px; }
.signal-chart { min-width: 0; overflow: hidden; }
.signal-live { display: grid; place-items: center; color: var(--ink); border-left: 1px solid #edf2f8; font: 850 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.uplot { font-family: inherit; }
.uplot .u-cursor-x { border-right: 1px solid var(--navy); }
.uplot .u-cursor-pt { border-color: var(--white) !important; box-shadow: 0 0 0 1px currentColor; }

.timeline-panel { margin-top: 10px; }
.panel-caption { height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: 1px solid var(--line); }
.panel-caption span { font-size: 10px; font-weight: 800; }
.panel-caption b { color: var(--muted); font: 750 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
#clinicalTimeline { height: 224px; }

.vis-timeline { border: 0; color: var(--ink); font-family: inherit; }
.vis-panel.vis-center, .vis-panel.vis-left, .vis-panel.vis-top { border-color: var(--line); }
.vis-time-axis .vis-text { color: var(--muted); font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
.vis-time-axis .vis-grid.vis-minor { border-color: #edf2f8; }
.vis-labelset .vis-label { color: var(--muted); border-color: #edf2f8; background: #fafcff; }
.vis-labelset .vis-label .vis-inner { padding: 8px 9px; font-size: 9px; font-weight: 800; }
.vis-foreground .vis-group { border-color: #edf2f8; }
.vis-item { border-radius: 3px; box-shadow: none; font-size: 9px; }
.vis-item.vis-range { min-height: 22px; }
.vis-item .vis-item-content { padding: 4px 7px; white-space: nowrap; }
.vis-item.clinical-event { color: color-mix(in srgb, var(--tone) 72%, #08142d); background: color-mix(in srgb, var(--tone) 12%, #ffffff); border-color: color-mix(in srgb, var(--tone) 52%, #ffffff); }
.vis-item.clinical-event.vis-selected { color: var(--white); background: var(--tone); border-color: var(--tone); box-shadow: 0 0 0 2px color-mix(in srgb, var(--tone) 22%, transparent); }
.vis-item.vis-point.clinical-event { background: transparent; }
.vis-item.vis-point.clinical-event .vis-dot { border-color: var(--tone); }
.vis-item.risk-window { color: #915b12; background: #fff4d7; border: 1px solid #efc86a; }
.vis-custom-time { width: 2px; background: var(--navy); }
.vis-custom-time::before { content: ""; position: absolute; top: -4px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--navy); }

.window-summary { min-height: 74px; margin-top: 10px; display: grid; grid-template-columns: 145px minmax(340px, 1fr) auto; align-items: center; gap: 14px; padding: 10px 12px; }
.window-summary > div:first-child span { display: block; color: var(--muted); font-size: 9px; }
.window-summary > div:first-child strong { display: block; margin-top: 4px; font: 800 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.window-summary dl { margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); }
.window-summary dl div { padding: 2px 10px; border-left: 1px solid var(--line); }
.window-summary dt { color: var(--muted); font-size: 8px; }
.window-summary dd { margin: 3px 0 0; font: 800 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.window-actions { display: flex; gap: 5px; }
.window-actions button { height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--brand); background: var(--white); font-size: 9px; font-weight: 800; }
.window-actions button:hover { border-color: var(--brand); background: var(--brand-soft); }

.risk-module { text-align: center; padding-top: 21px; }
.risk-orbit {
  --risk-angle: 245deg;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  margin: 13px auto 9px;
  border-radius: 50%;
  background: conic-gradient(var(--red) 0 var(--risk-angle), #edf2f8 var(--risk-angle) 360deg);
  position: relative;
}
.risk-orbit::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--white); }
.risk-orbit span { position: relative; z-index: 1; display: flex; align-items: baseline; }
.risk-orbit b { font: 900 34px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.risk-orbit small { color: var(--muted); font-size: 11px; }
.risk-module > strong { display: block; margin-bottom: 5px; font-size: 13px; }

.vital-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.vital { min-width: 0; padding: 9px; border: 1px solid var(--line); border-left: 3px solid var(--tone); border-radius: 4px; }
.vital span { display: block; color: var(--muted); font-size: 8px; }
.vital b { display: inline-block; margin-top: 3px; font: 850 17px ui-monospace, SFMono-Regular, Menlo, monospace; }
.vital small { margin-left: 3px; color: var(--faint); font-size: 7px; }

.organ-grid { display: grid; gap: 9px; }
.organ-row { display: grid; grid-template-columns: 42px minmax(60px, 1fr) 18px; align-items: center; gap: 8px; font-size: 9px; }
.organ-row i { height: 6px; background: #edf2f8; }
.organ-row i b { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--amber), var(--red)); }
.organ-row strong { text-align: right; font: 800 10px ui-monospace, SFMono-Regular, Menlo, monospace; }

.event-inspector time { display: block; margin-top: 8px; color: var(--brand); font: 800 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.event-inspector h3 { margin: 5px 0; font-size: 13px; line-height: 1.35; }
.safety-note { margin: 14px 18px; padding: 10px; color: #8c641c; background: #fff8e8; border: 1px solid #f1dda9; font-size: 9px; line-height: 1.55; }

.transport {
  height: 60px;
  display: grid;
  grid-template-columns: 38px 82px minmax(260px, 1fr) 300px 130px;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: var(--white);
  border-top: 1px solid var(--line);
}
.play-button { width: 36px; height: 36px; border: 0; border-radius: 50%; color: var(--white); background: var(--brand); font-size: 13px; box-shadow: 0 5px 13px rgba(49, 95, 238, 0.22); }
.play-button.playing { background: var(--red); }
.transport-time { display: flex; align-items: baseline; gap: 4px; }
.transport-time b { font: 850 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.transport-time small { color: var(--faint); font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
#timeScrubber { width: 100%; accent-color: var(--brand); }
.transport-marks { display: flex; justify-content: space-between; color: var(--faint); font-size: 8px; }
.engine-credit { display: flex; justify-content: flex-end; gap: 5px; color: var(--faint); font: 700 8px ui-monospace, SFMono-Regular, Menlo, monospace; }
.engine-credit i { color: var(--brand); font-style: normal; }

@media (max-width: 1180px) {
  .lab-shell { grid-template-columns: minmax(620px, 1fr) 260px; }
  .patient-rail { display: none; }
  .transport { grid-template-columns: 38px 72px minmax(220px, 1fr) 220px; }
  .engine-credit { display: none; }
}

@media (min-width: 1600px) and (min-height: 1200px) {
  #clinicalTimeline { height: 230px; }
  .stage-head { min-height: 62px; }
  .monitor-toolbar { height: 48px; }
  .window-summary { min-height: 86px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 20; padding: 0 12px; }
  .brand-lockup { min-width: 0; }
  .brand-lockup small, .case-state, .synthetic-badge { display: none; }
  .lab-shell { height: auto; min-height: 0; display: block; }
  .replay-stage { overflow: visible; }
  .state-rail { display: grid; grid-template-columns: 1fr 1fr; border: 0; border-top: 1px solid var(--line); }
  .risk-module, .vitals-module, .organs-module, .event-inspector { border-right: 1px solid var(--line); }
  .safety-note { grid-column: 1 / -1; }
  .transport { position: sticky; bottom: 0; z-index: 20; grid-template-columns: 38px 72px minmax(180px, 1fr); }
  .transport-marks, .engine-credit { display: none; }
}

@media (max-width: 620px) {
  .topbar { height: 58px; gap: 9px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-lockup strong { font-size: 13px; }
  .top-actions { margin-left: auto; }
  .quiet-button { width: 34px; padding: 0; font-size: 0; }
  .quiet-button::before { content: "↺"; font-size: 16px; }
  .replay-stage { padding: 13px 8px 10px; }
  .stage-head { display: block; min-height: 88px; }
  .stage-head h2 { font-size: 17px; }
  .range-presets { margin-top: 10px; }
  .monitor-toolbar { padding: 0 8px; }
  .signal-key { gap: 7px; }
  .signal-key span { font-size: 7px; }
  .cursor-time small { display: none; }
  .cursor-time strong { font-size: 11px; }
  .chart-stack { padding: 6px 4px 2px; }
  .signal-row { grid-template-columns: 42px minmax(0, 1fr) 38px; }
  .signal-live { font-size: 9px; }
  #clinicalTimeline { height: 210px; }
  .vis-labelset .vis-label .vis-inner { padding: 7px 5px; font-size: 7px; }
  .vis-item .vis-item-content { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .window-summary { grid-template-columns: 1fr; gap: 8px; }
  .window-summary dl { grid-template-columns: 1fr 1fr; }
  .window-summary dl div { border-left: 0; border-top: 1px solid var(--line); padding: 7px 0; }
  .window-actions { justify-content: flex-start; }
  .state-rail { display: block; }
  .risk-module, .vitals-module, .organs-module, .event-inspector { border-right: 0; }
  .transport { height: 56px; grid-template-columns: 36px 58px minmax(120px, 1fr); padding: 0 9px; gap: 7px; }
  .transport-time small { display: none; }
}
