/* ZhaoYi Peri-Implant ROI Manual Review Studio — Clinical Dark Workstation Theme */
:root {
  --bg-0: #090d14;
  --bg-1: #0f1520;
  --bg-2: #151e2e;
  --bg-3: #1c283d;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.30);
  --text-0: #f1f5f9;
  --text-1: #cbd5e1;
  --text-2: #8a9bb2;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.15);
  --cyan: #00e5ff;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.16);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.16);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.18);
  --magenta: #ec4899;
  --purple: #a855f7;
  --radius: 8px;
  --radius-sm: 5px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg-0); color: var(--text-0);
  font-family: var(--font); font-size: 13px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.42); }

/* Login Screen */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; width: 100vw;
  background:
    radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.10), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(34, 197, 94, 0.08), transparent 45%),
    var(--bg-0);
  overflow: auto;
}
.login-card {
  width: 410px; max-width: 92vw;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 32px 30px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.login-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--green-dim); color: #86efac;
  font-size: 11px; font-weight: 600; margin-bottom: 14px;
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.login-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.2px; }
.login-sub { font-size: 12.5px; color: var(--text-2); margin: 0 0 22px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; color: var(--text-1); margin-bottom: 5px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; background: var(--bg-0); color: var(--text-0);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; font-family: inherit; font-size: 13px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18); }
textarea.input { resize: vertical; min-height: 58px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-2); color: var(--text-0);
  font-family: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all 0.14s; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-3); border-color: rgba(148, 163, 184, 0.5); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: #0284c7; border-color: #38bdf8; color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #0369a1; }
.btn-success { background: #15803d; border-color: #22c55e; color: #fff; font-weight: 600; }
.btn-success:hover:not(:disabled) { background: #166534; }
.btn-amber { background: #b45309; border-color: #f59e0b; color: #fff; font-weight: 600; }
.btn-amber:hover:not(:disabled) { background: #92400e; }
.btn-danger { background: #991b1b; border-color: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #7f1d1d; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; padding: 10px 14px; font-size: 14px; }
.btn.active { background: var(--accent-dim); border-color: var(--accent); color: #e0f2fe; }
.btn.active-red { background: var(--red-dim); border-color: var(--red); color: #fecaca; }
.btn.active-amber { background: var(--amber-dim); border-color: var(--amber); color: #fde68a; }
.btn.active-green { background: var(--green-dim); border-color: var(--green); color: #bbf7d0; }

.alert-err {
  background: var(--red-dim); border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca; padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 12px; margin-bottom: 12px; display: none;
}
.alert-warn {
  background: var(--amber-dim); border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a; padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 11.5px; line-height: 1.4;
}
.alert-info {
  background: var(--accent-dim); border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd; padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 11.5px; line-height: 1.4;
}

/* Main Workstation Shell */
.app-shell {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh; width: 100vw;
}

/* Top Bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; gap: 10px;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  z-index: 20;
}
.topbar-left, .topbar-center, .topbar-right {
  display: flex; align-items: center; gap: 8px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 13.5px; letter-spacing: -0.2px;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.6);
}
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-1);
}
.pill-green { background: var(--green-dim); color: #86efac; border-color: rgba(34,197,94,0.35); }
.pill-red { background: var(--red-dim); color: #fca5a5; border-color: rgba(239,68,68,0.4); }
.pill-amber { background: var(--amber-dim); color: #fcd34d; border-color: rgba(245,158,11,0.4); }
.pill-cyan { background: rgba(0,229,255,0.12); color: #67e8f9; border-color: rgba(0,229,255,0.35); }
.pill-purple { background: rgba(168,85,247,0.16); color: #d8b4fe; border-color: rgba(168,85,247,0.4); }

.segmented {
  display: inline-flex; background: var(--bg-0); padding: 2px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.segmented button {
  background: transparent; border: none; color: var(--text-2);
  padding: 4px 10px; border-radius: 4px; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.14s;
}
.segmented button:hover { color: var(--text-0); }
.segmented button.active { background: #0284c7; color: #fff; font-weight: 600; }

/* Main 3-Column Body */
.workspace {
  display: grid;
  grid-template-columns: 272px 1fr 376px;
  min-height: 0; overflow: hidden;
}
.workspace.queue-collapsed {
  grid-template-columns: 0px 1fr 376px;
}

/* Left Cohort Queue */
.queue-panel {
  background: var(--bg-1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.queue-header {
  padding: 10px 10px 8px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 7px;
}
.queue-stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
}
.stat-mini {
  background: var(--bg-0); border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 5px; text-align: center;
}
.stat-mini .val { font-size: 13px; font-weight: 700; font-family: var(--mono); color: var(--text-0); }
.stat-mini .lbl { font-size: 10px; color: var(--text-2); }
.filter-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  padding: 2px 7px; border-radius: 4px; font-size: 11px;
  background: var(--bg-0); border: 1px solid var(--border); color: var(--text-2);
  cursor: pointer; transition: all 0.12s;
}
.chip:hover { color: var(--text-0); border-color: var(--border-strong); }
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: #e0f2fe; font-weight: 600; }

.queue-list { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.case-item {
  padding: 7px 9px; border-radius: 6px;
  border: 1px solid transparent; background: var(--bg-0);
  cursor: pointer; transition: all 0.12s;
}
.case-item:hover { background: var(--bg-2); border-color: var(--border); }
.case-item.active { background: rgba(2, 132, 199, 0.18); border-color: var(--accent); }
.case-item.held { opacity: 0.72; }
.case-item-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.case-id { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.case-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; font-size: 10.5px; color: var(--text-2); }

/* Center MPR Stage */
.center-stage {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: #06090f; overflow: hidden;
}
.viewer-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--bg-1); border-bottom: 1px solid var(--border);
}
.toolbar-sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 2px; }
.sub-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 5px 10px; background: #111a2a; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.sub-toolbar.hidden { display: none; }
.implant-strip {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 5px 10px; background: #0c121c; border-bottom: 1px solid var(--border);
}
.imp-tab {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 5px; font-size: 12px; font-family: var(--mono);
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text-1);
  cursor: pointer;
}
.imp-tab:hover { border-color: var(--border-strong); color: #fff; }
.imp-tab.active { background: #0369a1; border-color: var(--cyan); color: #fff; font-weight: 700; }
.imp-tab .dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-ok { background: var(--green); }
.dot-warn { background: var(--amber); }
.dot-fail { background: var(--red); }
.dot-excl { background: #64748b; }

/* 2x2 MPR Grid */
.mpr-grid {
  flex: 1; min-height: 0; padding: 6px; gap: 6px;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
}
.mpr-grid.single-mode {
  grid-template-columns: 1fr; grid-template-rows: 1fr;
}
.mpr-grid.single-mode .mpr-pane:not(.maximized) { display: none; }

.mpr-pane {
  position: relative; background: #000; border: 1px solid var(--border);
  border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
.mpr-pane.focused { border-color: rgba(56, 189, 248, 0.55); }
.pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 8px; background: rgba(15, 21, 32, 0.92);
  border-bottom: 1px solid var(--border); font-size: 11.5px; z-index: 4;
}
.pane-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pane-title .tag {
  font-size: 10px; font-family: var(--mono); padding: 1px 5px; border-radius: 3px;
  background: var(--bg-3); color: var(--accent);
}
.pane-canvas-wrap {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  user-select: none; touch-action: none;
}
.pane-canvas-wrap canvas {
  display: block; width: 100%; height: 100%;
}
.pane-slider-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; background: rgba(15, 21, 32, 0.92);
  border-top: 1px solid var(--border); font-size: 11px; font-family: var(--mono);
}
.pane-slider-row input[type=range] { flex: 1; accent-color: var(--accent); height: 4px; }

/* 4th Quadrant: Info & Telemetry Tile */
.info-tile {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
.metric-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.metric-box {
  background: var(--bg-0); border: 1px solid var(--border); border-radius: 5px;
  padding: 6px 8px;
}
.metric-box .k { font-size: 10.5px; color: var(--text-2); }
.metric-box .v { font-size: 13px; font-weight: 700; font-family: var(--mono); margin-top: 1px; }
.v-ok { color: #86efac; }
.v-warn { color: #fcd34d; }
.v-bad { color: #fca5a5; }

.legend-row { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--text-1); }
.legend-chip { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* Held / Alias Center Placeholder */
.held-view {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 28px;
  overflow-y: auto;
}
.held-card {
  max-width: 580px; width: 100%; background: var(--bg-1);
  border: 1px solid var(--border-strong); border-radius: 12px; padding: 24px;
  overflow: hidden;
}
.held-card .kv-line { gap: 12px; align-items: flex-start; }
.held-card .kv-line .k { flex-shrink: 0; }
.held-card .kv-line .v {
  overflow-wrap: anywhere; word-break: break-word; text-align: right; min-width: 0;
}

/* Right Clinical Review Panel */
.review-panel {
  background: var(--bg-1); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.review-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border); background: var(--bg-0);
}
.review-tab {
  padding: 9px 6px; text-align: center; font-size: 12px; font-weight: 600;
  color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent;
  background: transparent; border-top: none; border-left: none; border-right: none;
}
.review-tab:hover { color: var(--text-0); }
.review-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--bg-1); }
.review-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.review-section {
  background: var(--bg-0); border: 1px solid var(--border); border-radius: 7px;
  padding: 10px; display: flex; flex-direction: column; gap: 7px;
}
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 700; color: var(--text-0);
}
.section-head .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent); font-size: 11px; margin-right: 5px;
}
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.check-item {
  display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-1);
  cursor: pointer; padding: 3px 5px; border-radius: 4px; background: var(--bg-1);
}
.check-item input { accent-color: var(--green); }
.review-footer {
  padding: 9px 12px; border-top: 1px solid var(--border); background: var(--bg-0);
  display: flex; gap: 8px; align-items: center;
}

/* Gallery & Lightbox */
.gallery-grid { display: flex; flex-direction: column; gap: 10px; }
.gallery-card {
  background: var(--bg-0); border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
.gallery-card-head {
  padding: 6px 9px; font-size: 11.5px; font-weight: 600;
  border-bottom: 1px solid var(--border); display: flex; justify-content: space-between;
}
.gallery-card img { width: 100%; min-height: 110px; display: block; cursor: zoom-in; background: #000; object-fit: contain; }

/* Modal / Lightbox / Toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: none; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(3px);
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--bg-1); border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 20px; width: 460px; max-width: 94vw; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}
.lightbox-img { max-width: 94vw; max-height: 90vh; border-radius: 6px; border: 1px solid var(--border-strong); }

.toast-stack {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  padding: 8px 16px; border-radius: 7px; font-size: 12.5px; font-weight: 500;
  background: #1e293b; border: 1px solid var(--border-strong); color: #f8fafc;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}
.toast.ok { border-color: var(--green); background: #0f291c; color: #bbf7d0; }
.toast.err { border-color: var(--red); background: #2c1014; color: #fecaca; }
.toast.warn { border-color: var(--amber); background: #2b1f0b; color: #fde68a; }

.loading-overlay {
  position: absolute; inset: 0; background: rgba(6, 9, 15, 0.68);
  display: none; align-items: center; justify-content: center; z-index: 15;
  flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--text-1);
}
.loading-overlay.show { display: flex; }
.spinner {
  width: 24px; height: 24px; border: 3px solid rgba(56,189,248,0.22);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.kv-line { display: flex; justify-content: space-between; font-size: 11.5px; padding: 2px 0; }
.kv-line .k { color: var(--text-2); }
.kv-line .v { font-family: var(--mono); color: var(--text-0); }
.mono { font-family: var(--mono); }
.muted { color: var(--text-2); font-size: 11.5px; }
.row { display: flex; align-items: center; gap: 6px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
