:root {
  /* Brand color */
  --bamboo:        #2DB146;
  --bamboo-deep:   #1f8c36;
  --bamboo-soft:   #e8f5ec;
  --bamboo-line:   #cfe8d6;
  /* Neutrals */
  --accent:        #1A1A1A;
  --muted:         #6b7280;
  --line:          #e5e7eb;
  --bg:            #f7faf8;
  --panel:         #ffffff;
  /* Semantic */
  --danger:        #c0392b;
  --warning:       #c98a16;
  /* Type */
  --font:          ui-sans-serif, system-ui, -apple-system, "PingFang SC",
                   "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  --mono:          ui-monospace, "JetBrains Mono", "SF Mono", Consolas, "Courier New", monospace;
  /* Shape & motion */
  --radius:        10px;
  --radius-sm:     6px;
  --radius-pill:   999px;
  --shadow:        0 1px 3px rgba(15,30,20,.06), 0 2px 12px rgba(15,30,20,.04);
  --transition:    .15s ease;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--accent);
  background: var(--bg);
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 14px; }
.muted { color: var(--muted); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-img { width: 22px; height: 48px; object-fit: contain; display: block; }
.brand-text { line-height: 1.15; }
.brand-title { font-weight: 700; font-size: 15px; color: var(--accent); }
.brand-title .latin { color: var(--muted); font-weight: 500; margin-left: 6px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  gap: 14px; padding: 14px;
  min-height: calc(100vh - 64px);
}
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-center { min-height: 60vh; }
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .col-center { min-height: 60vh; order: -1; }
}

/* ---------- Card ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 500; border: 1px solid var(--line);
}
.badge-muted { color: var(--muted); background: #f3f4f6; }
.badge-ok { color: var(--bamboo-deep); background: var(--bamboo-soft); border-color: var(--bamboo-line); }

/* ---------- Patient-ID pill ---------- */
.patient-id {
  font-family: var(--mono); font-size: 14px;
  background: var(--bamboo-soft); color: var(--bamboo-deep);
  padding: 8px 10px; border-radius: var(--radius-sm);
  word-break: break-all; letter-spacing: .01em;
}

/* ---------- KV list ---------- */
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- Button ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}
.btn-primary { background: var(--bamboo); color: #fff; }
.btn-primary:hover { background: var(--bamboo-deep); }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn-ghost:hover { background: #f3f4f6; border-color: #d1d5db; }
.btn-sm { padding: 4px 8px; font-size: 12px; }

/* ---------- Chip ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  cursor: pointer; font-size: 12px; background: #fff; user-select: none;
}
.chip:has(input:checked) { border-color: var(--bamboo); background: var(--bamboo-soft); color: var(--bamboo-deep); }
.chip input { display: none; }
.chip-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Controls ---------- */
.ctrl-row { display: flex; align-items: center; gap: 10px; }
.ctrl-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
input[type=range] { width: 100%; accent-color: var(--bamboo); cursor: pointer; }
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Viewer toolbar + canvas ---------- */
.viewer-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.structure-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.map-readout { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.viewer {
  flex: 1; position: relative; overflow: hidden; min-height: 420px;
  background: linear-gradient(180deg, #fafdfb 0%, #eef5f1 100%);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.viewer canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.viewer-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  gap: 6px; align-items: center; justify-content: center; color: var(--muted);
  pointer-events: none; text-align: center; padding: 24px;
}
.viewer-empty .big { font-size: 16px; color: var(--accent); font-weight: 600; }

/* ---------- CT stage (right rail) ---------- */
.ct-stage {
  position: relative; line-height: 0; border-radius: var(--radius-sm);
  overflow: hidden; background: #000; cursor: crosshair;
}
.ct-stage img { width: 100%; height: auto; display: block; image-rendering: auto; }
.ct-marker {
  position: absolute; display: none; width: 16px; height: 16px;
  border: 2px solid var(--bamboo); border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0,0,0,.5), 0 0 8px rgba(45,177,70,.9);
  transform: translate(-50%, -50%); pointer-events: none;
}
.ct-marker::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 2px; height: 2px; background: var(--bamboo);
  transform: translate(-50%, -50%); border-radius: 50%;
}
.slice-readout { font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 6px; text-align: center; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--bamboo);
  border-radius: 8px; padding: 10px 14px; font-size: 13px;
  box-shadow: 0 4px 18px rgba(0,0,0,.08); pointer-events: auto; max-width: 320px;
  animation: toast-in .25s ease;
}
.toast.toast-err { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
