:root {
  --bg-0: #070d19;
  --bg-1: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --border: #27354d;
  --text-0: #f8fafc;
  --text-1: #cbd5e1;
  --text-2: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --emerald: #10b981;
  --amber: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 25%, #172554 0%, #070d19 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  width: 410px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  font-size: 15px;
  border-radius: 8px;
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--text-2);
  font-size: 12.5px;
}

.login-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-2);
}

/* Shell & Topbar */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  min-height: 52px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 14px;
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.topbar-title {
  font-weight: 700;
  font-size: 15px;
}

.topbar-badge {
  font-size: 11px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  margin-left: 16px;
  background: var(--bg-0);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.mode-tab {
  background: transparent;
  color: var(--text-1);
  border: none;
  padding: 6px 13px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}

.mode-tab.active {
  background: var(--bg-2);
  color: var(--accent);
}

/* Workspace Grids */
.workspace-grid {
  flex: 1;
  display: grid;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.studio-grid {
  grid-template-columns: clamp(200px, 18vw, 265px) minmax(380px, 1fr) clamp(235px, 22vw, 335px);
}

.capture-grid {
  grid-template-columns: minmax(420px, 1fr) clamp(280px, 28vw, 385px);
}

@media (max-width: 980px) {
  html, body {
    overflow: auto;
  }
  .app-shell {
    height: auto;
    min-height: 100vh;
  }
  .studio-grid,
  .capture-grid,
  .live-preview-grid {
    grid-template-columns: 1fr;
  }
  .canvas-wrap {
    min-height: 440px;
  }
}

.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.panel-body {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.slim-pad {
  padding: 8px;
}

/* Inputs & Buttons */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-1);
  margin: 10px 0 4px;
}

.field-label-xs {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  margin-bottom: 3px;
}

.form-error {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid var(--danger);
  color: #fca5a5;
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-0);
  background: var(--bg-2);
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--bg-3);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #0369a1;
}

.btn-accent {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-2);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-1);
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.btn-lg {
  padding: 11px 16px;
  font-size: 14px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11.5px;
}

/* Study List */
.study-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.study-card {
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.study-card:hover {
  border-color: var(--bg-3);
}

.study-card.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.study-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.study-card-meta {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-2);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Viewport & Toolbar */
.viewport-panel {
  position: relative;
}

.viewport-toolbar {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toolbar-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--bg-2);
  color: var(--accent);
}

.chk-inline, .slider-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-1);
  cursor: pointer;
}

.slider-inline input[type="range"] {
  width: 68px;
}

.select-xs {
  width: auto;
  padding: 3px 6px;
  font-size: 11.5px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at center, #111c33 0%, #050912 100%);
  overflow: hidden;
}

.empty-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-2);
  pointer-events: none;
}

.cursor-readout {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(7, 13, 25, 0.85);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11.5px;
  color: var(--accent);
  pointer-events: none;
  z-index: 20;
}

.heatmap-legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: rgba(7, 13, 25, 0.86);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  z-index: 20;
}

.hm-gradient {
  width: 90px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 50%, #10b981 100%);
}

/* 3D Floating CSS2D Labels */
.label-3d {
  background: rgba(7, 13, 25, 0.9);
  border: 1px solid var(--accent);
  color: #f8fafc;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

/* 2D View */
.canvas-2d-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #05080f;
}

.image-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.image-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.stack-scrubber-bar {
  padding: 8px 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.stack-scrubber-bar input[type="range"] {
  flex: 1;
}

/* Inspector & Metrics */
.subcard {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.accent-border {
  border-color: var(--accent);
}

.subcard-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.metric-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
}

.metric-box.highlight {
  border-color: rgba(56, 189, 248, 0.5);
}

.m-label {
  font-size: 10.5px;
  color: var(--text-2);
}

.m-val {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 2px;
}

.m-sub {
  font-size: 11px;
  color: var(--text-1);
}

.profile-chart-wrap {
  margin-bottom: 8px;
}

.chart-caption {
  font-size: 10.5px;
  color: var(--text-2);
  margin-bottom: 3px;
}

#profile-canvas {
  width: 100%;
  height: 92px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.compact-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.align-end {
  display: flex;
  align-items: flex-end;
}

.hint-banner {
  padding: 8px 10px;
  border-radius: 7px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.35);
  color: var(--text-1);
  font-size: 12px;
  margin-bottom: 12px;
}

.section-block {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.section-header h3, .section-header h4 {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--text-1);
}

.annotations-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
}

.ann-item {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 9px;
  cursor: pointer;
}

.ann-item:hover {
  border-color: var(--accent);
}

.ann-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.color-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.clinical-summary {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px;
  font-size: 12px;
  color: var(--text-1);
  line-height: 1.5;
}

/* Live Wand Capture Tab */
.wand-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.wand-card {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
}

.wand-card.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.live-preview-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 12px;
}

.preview-stage-card {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.preview-overlay-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.mjpeg-frame {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #030712;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mjpeg-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.wand-sd-queue {
  margin-top: 10px;
}

.wand-datasets-list {
  max-height: 135px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.wand-ds-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11.5px;
}

.ctrl-slider {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 9px;
  font-size: 12px;
}

.assessment-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* Pills, Spinner & Utilities */
.pill {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
}

.pill-ok {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
}

.pill-warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.pill-muted {
  background: var(--bg-2);
  color: var(--text-2);
}

.job-banner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(2, 132, 199, 0.2);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(56, 189, 248, 0.35);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.row-gap-xs { display: flex; align-items: center; gap: 6px; }
.row-gap-md { display: flex; align-items: center; gap: 14px; }
.top-gap-xs { margin-top: 6px; }
.top-gap-sm { margin-top: 10px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.mono-text { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
