
:root {
  --ink: #0e1a2b; --ink-2: #1f2d40; --muted: #5b6b80; --muted-2: #889aaf;
  --line: #e3e8ef; --line-2: #eef2f7;
  --bg: #f6f8fb; --panel: #ffffff; --panel-2: #fbfcfe;
  --blue: #1e4d7b; --blue-2: #2f6aa3; --blue-soft: #e8f0f9; --blue-ink: #143a5e;
  --high: #b23a3a; --high-soft: #f7e6e6;
  --med:  #b1801c; --med-soft:  #faf0d8;
  --low:  #2f7a5b; --low-soft:  #e1efe7;
  --pi:   #2f6aa3; --pi-soft:  #e8f0f9;
  --res:  #2f7a5b; --res-soft: #e1efe7;
  --crit: #6b4aa3; --crit-soft:#ece7f6;
  --radius: 8px;
  --shadow: 0 1px 0 rgba(14,26,43,0.04), 0 1px 2px rgba(14,26,43,0.04);
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
             font-family: var(--sans); font-feature-settings: 'tnum' 1;
             -webkit-font-smoothing: antialiased; }

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line);
           padding: 22px 18px 28px; }
.main { padding: 16px 28px 60px; max-width: 1320px; }

.sidebar-h { color: var(--muted); font-size: 11px; font-weight: 600;
             text-transform: uppercase; letter-spacing: 0.08em;
             margin: 0 4px 10px 4px; }
a.patient-card { display: block; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
  transition: border-color .12s, background .12s, box-shadow .12s; }
a.patient-card:hover { border-color: #cfd9e6; background: var(--panel-2); }
a.patient-card.active { border-color: var(--blue-2);
  box-shadow: 0 0 0 3px rgba(47,106,163,0.12); }
.patient-card .card-top { display: flex; justify-content: space-between;
  align-items: center; gap: 10px; margin-bottom: 6px; }
.patient-card .patient-letter { color: var(--ink); font-size: 13.5px; font-weight: 600; }
.patient-card .card-code { color: var(--muted); font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.02em; margin: 2px 0 6px 0; }
.patient-card .card-meta { color: var(--muted); font-size: 11.5px; }
.risk-pill { display: inline-flex; align-items: center; padding: 3px 8px;
  border-radius: 999px; font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.02em; border: 1px solid transparent; }
.risk-pill.high   { color: var(--high); background: var(--high-soft); border-color: #ecd3d3; }
.risk-pill.medium { color: var(--med);  background: var(--med-soft);  border-color: #ecdfbf; }
.risk-pill.low    { color: var(--low);  background: var(--low-soft);  border-color: #c9e0d3; }
.sidebar-foot { color: var(--muted-2); font-family: var(--mono);
  font-size: 10.5px; text-align: center; padding-top: 18px; }

.topbar { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow); }
.topbar .brand { display: flex; gap: 14px; align-items: center; }
.topbar .logo { width: 30px; height: 30px; border-radius: 7px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-2) 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12); }
.topbar .brand-title { color: var(--ink); font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em; }
.topbar .brand-sub   { color: var(--muted); font-size: 12px; margin-top: 1px; }
.topbar .badge { padding: 5px 12px; border-radius: 999px; font-size: 11.5px;
  font-weight: 500; letter-spacing: 0.01em; border: 1px solid #d6e3f1;
  color: var(--blue-ink); background: var(--blue-soft); margin-left: 8px; }

.patient-h1 { color: var(--ink); font-size: 22px; font-weight: 600;
  letter-spacing: -0.015em; margin: 4px 0 16px 0; }
.patient-h1 .code { color: var(--muted); font-family: var(--mono);
  font-size: 12.5px; margin-left: 10px; font-weight: 400; }

.layout-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }

.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 22px; margin-bottom: 16px;
  box-shadow: var(--shadow); }
.card-h { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.card-h h3 { margin: 0; color: var(--ink); font-size: 16px; font-weight: 600; }
.card-h .num-tag { color: var(--muted-2); font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.card-h .card-stats { margin-left: auto; display: flex; gap: 22px; }
.card-h .stat { display: flex; flex-direction: column; }
.card-h .stat .k { color: var(--muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.card-h .stat .v { color: var(--ink); font-family: var(--mono);
  font-size: 15px; font-weight: 500; margin-top: 2px; }

.kv-grid { display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px 22px; }
.kv .k { color: var(--muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.kv .v { color: var(--ink); font-size: 14px; margin-top: 3px; }

.chart-img { width: 100%; display: block; margin: 6px 0 0 0; }

details.agent { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
  border-left-width: 3px; }
details.agent.pi   { border-left-color: var(--pi); }
details.agent.res  { border-left-color: var(--res); }
details.agent.crit { border-left-color: var(--crit); }
details.agent summary { cursor: pointer; display: flex; gap: 12px;
  align-items: center; padding: 14px 18px; list-style: none; }
details.agent summary::-webkit-details-marker { display: none; }
details.agent summary:hover { background: var(--panel-2); }
.agent-icon { width: 30px; height: 30px; border-radius: 7px;
  display: grid; place-items: center; font-family: var(--mono);
  font-size: 11px; font-weight: 600; flex-shrink: 0; }
.pi-icon   { background: var(--pi-soft);   color: var(--pi); }
.res-icon  { background: var(--res-soft);  color: var(--res); }
.crit-icon { background: var(--crit-soft); color: var(--crit); }
.agent-title { display: flex; flex-direction: column; flex: 1; }
.agent-role { font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.1em; font-weight: 600; }
details.agent.pi   .agent-role { color: var(--pi); }
details.agent.res  .agent-role { color: var(--res); }
details.agent.crit .agent-role { color: var(--crit); }
.agent-name { color: var(--ink); font-size: 14px; font-weight: 600; margin-top: 1px; }
.agent-chev { color: var(--muted-2); transition: transform .2s ease; }
details.agent[open] .agent-chev { transform: rotate(180deg); }
.agent-body { padding: 0 18px 18px 60px; color: var(--ink-2);
  font-size: 13px; line-height: 1.6; }
.weights { margin-top: 14px; border-collapse: collapse; }
.weights td { padding: 4px 18px 4px 0; font-size: 12.5px; }
.weights td.m { color: var(--ink-2); }
.weights td.w { color: var(--muted); font-family: var(--mono); }
.critic-row { padding: 9px 0; border-top: 1px dashed var(--line); }
.critic-row:first-child { border-top: none; padding-top: 0; }
.critic-title { color: var(--low); font-family: var(--mono); font-size: 11px;
  font-weight: 600; letter-spacing: 0.06em; margin-bottom: 4px; }
.critic-body { color: var(--ink-2); font-size: 13px; }

.summary-card { border-left: 3px solid var(--blue-2); }
.summary-body { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.65; }
.footer { color: var(--muted); font-family: var(--mono); font-size: 11px;
  text-align: center; padding-top: 12px; margin-top: 14px;
  border-top: 1px solid var(--line-2); }

.patient-content { display: none; }
.patient-content.active { display: block; }

/* MRI viewer (in-page, not iframe) */
.mri-card .hdr { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.mri-card .hdr h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); }
.mri-card .hdr .tag { font-family: var(--mono); font-size: 11px;
  color: var(--muted-2); letter-spacing: 0.08em; text-transform: uppercase; }
.mri-card .controls { display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 18px; align-items: center; margin-bottom: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line-2); }
.seg { display: inline-flex; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px; gap: 2px; }
.seg label { cursor: pointer; padding: 5px 11px;
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  letter-spacing: 0.04em; border-radius: 4px; user-select: none; }
.seg input { display: none; }
.seg label:hover { color: var(--ink-2); background: rgba(47,106,163,0.06); }
.seg input:checked + .lbl { background: var(--blue-2); color: #fff; }
.toggle { display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
  font-family: var(--sans); font-size: 12.5px; color: var(--ink-2); }
.toggle input { accent-color: var(--blue-2); width: 14px; height: 14px; }
.slider-row { grid-column: 1 / -1;
  display: grid; grid-template-columns: 60px 1fr 80px;
  gap: 12px; align-items: center;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
  letter-spacing: 0.04em; }
.slider-row .label { text-align: left; }
.slider-row .val { text-align: right; color: var(--blue-2); }
input[type="range"] { -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; background: var(--line);
  border-radius: 2px; outline: none; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none;
  appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--blue-2); border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; transition: transform 0.1s; }
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px;
  border-radius: 50%; background: var(--blue-2); border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.canvas { border-radius: 6px;
  background: radial-gradient(ellipse at 50% 52%, #1a2a3d 0%, #0c1622 45%, #07101a 100%);
  border: 1px solid #0c1622; padding: 10px;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; height: 420px; }
.canvas img { max-height: 100%; height: 100%; width: auto;
  display: block; border-radius: 4px;
  image-rendering: -webkit-optimize-contrast; }
.canvas .seg-img { position: absolute; pointer-events: none; }
.mri-meta { margin-top: 8px;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
  letter-spacing: 0.08em; text-align: right; }

@media (max-width: 1100px) {
  .layout-grid { grid-template-columns: 1fr; }
}
