/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg:       #0d0d0d;
  --panel-bg: #141414;
  --border:   #252525;
  --accent:   #00b4d8;
  --red:      #C41010;
  --text:     #d8d8d8;
  --muted:    #666;
  --btn-bg:   #222;
  --btn-hover:#2e2e2e;
  --panel-w:  248px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── App header ─────────────────────────────────────────── */
.app-header {
  background: #090909;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.app-logo {
  color: var(--red);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 2px;
}
.app-logo-sub {
  color: #2a2a2a;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 2px;
  padding-top: 3px;
}
.app-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  margin-left: 8px;
}
.app-header nav a:hover { color: var(--text); }

/* ── Main ───────────────────────────────────────────────── */
main { flex: 1; overflow: hidden; }

/* ── Search page ────────────────────────────────────────── */
.search-page { padding: 40px; max-width: 820px; }
.search-page h1 { font-size: 18px; margin-bottom: 20px; color: var(--accent); }

.search-box { display: flex; gap: 8px; margin-bottom: 24px; }
.search-box input {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }

.results-list { display: flex; flex-direction: column; gap: 6px; }
.study-card {
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.study-info { display: flex; flex-direction: column; gap: 2px; }
.study-info strong { font-size: 13px; }
.muted { color: var(--muted); font-size: 11px; }
.loading-msg { color: var(--muted); font-style: italic; padding: 8px 0; }
.error-msg   { color: #e74c3c; }

/* ── Buttons (global) ───────────────────────────────────── */
button {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.12s;
  white-space: nowrap;
}
button:hover     { background: var(--btn-hover); }
button:disabled  { opacity: 0.4; cursor: default; }

.load-btn {
  background: var(--accent);
  color: #000;
  border: none;
  font-weight: 600;
  padding: 7px 14px;
}
.load-btn:hover { background: #00cfef; }

.accent-btn {
  background: var(--accent);
  color: #000;
  border: none;
  font-weight: 600;
}
.accent-btn:hover { background: #00cfef; }

/* ── PACS search page ───────────────────────────────────────── */
.pacs-page {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.pacs-left {
  width: 480px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.pacs-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Tab bar ────────────────────────────────────────────── */
.right-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid #1c1c1c;
  background: #0d0d0d;
}
.right-tab {
  flex: 1;
  padding: 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #404040;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.right-tab:hover  { color: #888; }
.right-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge {
  background: #1a3a44;
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  line-height: 1.4;
}

/* ── Tab panels ─────────────────────────────────────────── */
.right-tab-panels {
  flex: 1;
  min-height: 0;
  position: relative;
}
.right-tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 16px 20px;
  position: absolute;
  inset: 0;
  overflow-y: auto;
}
.right-tab-panel::-webkit-scrollbar { width: 4px; }
.right-tab-panel::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
.right-tab-panel.active { display: flex; }

.tab-empty {
  color: #333;
  font-size: 11px;
  text-align: center;
  padding: 24px 0;
  line-height: 1.8;
}
.page-heading { padding: 24px 20px 0; flex-shrink: 0; }
.page-heading h1 { font-size: 17px; font-weight: 700; color: #f0f0f0; margin-bottom: 4px; }
.page-heading p  { color: #383838; font-size: 11px; }

.pacs-section {
  padding: 12px 14px 10px;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.section-label {
  color: var(--red);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  flex-shrink: 0;
}
.search-row { display: flex; gap: 6px; }
.search-row input {
  flex: 1;
  background: #111;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 3px;
  font-size: 12px;
  outline: none;
}
.search-row input:focus { border-color: var(--accent); }
.status-label { font-size: 11px; color: #505050; flex-shrink: 0; }

.result-list {
  flex: 1;
  overflow-y: auto;
  background: #0f0f0f;
  border: 1px solid #1e1e1e;
  border-radius: 4px;
  min-height: 50px;
}
.result-list::-webkit-scrollbar { width: 5px; }
.result-list::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
.result-list::-webkit-scrollbar-thumb:hover { background: var(--red); }

.list-placeholder, .list-loading {
  padding: 10px 12px;
  color: #363636;
  font-size: 11px;
  font-style: italic;
}
.list-loading { color: #E0881A; font-style: normal; }
.list-item {
  padding: 8px 10px;
  border-bottom: 1px solid #191919;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  color: #c0c0c0;
  flex-wrap: wrap;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover:not(.selected) { background: #181818; color: #e8e8e8; }
.list-item.selected { background: #1a0808; color: #ff9090; border-left: 2px solid var(--red); }
.li-date    { color: #666; font-size: 10px; white-space: nowrap; }
.li-patient { font-weight: 600; }
.li-desc    { color: #555; font-size: 10px; }
.li-rec     { font-weight: 600; }
.li-frames  { color: var(--accent); font-size: 10px; }
.li-inst    { color: #555; font-size: 10px; }

.preview-row { display: flex; gap: 12px; align-items: center; justify-content: center; }
.thumb-col   { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.preview-swap-col { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.swap-btn {
  background: rgba(20,20,20,0.8);
  border: 1px solid #2a2a2a;
  color: #555;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  padding: 0;
}
.swap-btn:hover:not(:disabled) { background: #1e1e1e; color: #aaa; border-color: #3a3a3a; }
.swap-btn:disabled { opacity: 0.3; cursor: default; }
.swap-btn.swapped { color: var(--accent); border-color: #1a3a44; background: #0d2028; }
.thumb-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #111;
  border: 1px solid #242424;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #303030;
  font-size: 24px;
  overflow: hidden;
}
.thumb-box img { width: 100%; height: 100%; object-fit: cover; }
.thumb-loading { color: #666; }
.thumb-cap { color: #555; font-size: 11px; font-weight: 600; letter-spacing: 0.5px; }
.preview-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: #888;
  padding-top: 14px;
  border-top: 1px solid #1a1a1a;
  margin-top: 4px;
}
.preview-info div { display: flex; gap: 8px; }
.info-label { color: #444; min-width: 52px; }
/* ── Recent studies ─────────────────────────────────────── */
/* Bookmark label grouping */
.bm-entry-wrap { display: flex; flex-direction: column; }
.bm-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: #444;
  text-transform: uppercase;
  padding: 10px 6px 3px;
  cursor: text;
  border-radius: 3px;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bm-label:hover { color: #666; }
.bm-label.editing {
  color: var(--accent);
  background: #0d1f27;
  border-radius: 3px;
  padding: 2px 6px;
  white-space: nowrap;
  overflow: visible;
}

.recent-list { display: flex; flex-direction: column; gap: 4px; }
.recent-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.recent-row:hover       { background: #1c1c1c; border-color: var(--border); }
.recent-ready           { opacity: 1; }
.recent-badge           { flex-shrink: 0; width: 16px; height: 16px; }
.recent-badge svg       { width: 16px; height: 16px; display: block; }
.recent-info            { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.recent-patient         { font-size: 12px; color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta            { font-size: 10px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-rec             { font-size: 10px; color: #3a7a5a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-right {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.recent-time {
  font-size: 10px;
  color: #444;
  white-space: nowrap;
}
.recent-remove {
  background: none;
  border: none;
  color: #444;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
.recent-row:hover .recent-remove  { opacity: 1; }
.recent-remove:hover               { color: #e05555; }

/* Star / bookmark button */
.star-btn {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 2px;
  color: #333;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
  line-height: 1;
}
.recent-row:hover .star-btn { opacity: 1; }
.star-btn.starred            { opacity: 1; color: #f5c518; }
.star-btn:hover              { color: #f5c518; }

/* Context menu danger item */
.ctx-danger { color: #e05555 !important; }
.ctx-danger:hover { background: #2a1010 !important; }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1e1e1e;
  border: 1px solid #333;
  color: #33cc66;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9999;
}
.toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.launch-area { margin-top: auto; padding-top: 8px; }
.launch-btn {
  width: 100%;
  padding: 11px;
  font-size: 13px;
  font-weight: 700;
  background: var(--red);
  color: #fff;
  border: 1px solid #e02020;
  border-radius: 6px;
}
.launch-btn:hover:not(:disabled) { background: #dd2020; }
.launch-btn:disabled { background: #1a1a1a; border-color: #282828; color: #3a3a3a; cursor: default; }

/* ── Viewer layout ──────────────────────────────────────── */
.viewer-layout {
  display: flex;
  height: 100%;
}
/* Shared/display-only mode — no panel, canvas fills full width */
.viewer-layout--shared .viewer-canvas-wrap {
  width: 100%;
}
/* Push ViewCube down to clear the extra shared controls bar */
.viewer-layout--shared #viewcube-canvas {
  top: 100px; /* 36px header + 28px frame bar + 28px shared bar + 8px gap */
}

/* ── Left panel ─────────────────────────────────────────── */
.viewer-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.viewer-panel::-webkit-scrollbar { width: 4px; }
.viewer-panel::-webkit-scrollbar-thumb { background: #2a2a2a; }

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-bottom: 10px;
  border-bottom: 1px solid #1c1c1c;
}
.panel-section:last-child { border-bottom: none; }

.section-title {
  color: #444;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding-bottom: 2px;
}

.radio-group { display: flex; gap: 12px; }
.radio-group label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* Slider rows */
.slider-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sl-label {
  width: 54px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 11px;
}
.sl-val {
  width: 30px;
  text-align: right;
  font-size: 11px;
  color: #aaa;
  flex-shrink: 0;
}
input[type=color] {
  width: 22px;
  height: 22px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
input[type=range] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 14px;
}

.row-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  flex: 1;
}
.small-btn { padding: 4px 8px; font-size: 10px; }

/* Camera buttons (2×2 grid) */
.cam-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.cam-btn {
  height: 42px;
  font-size: 10px;
  line-height: 1.3;
  text-align: center;
  padding: 4px 2px;
}
.cam-btn span { color: var(--muted); font-size: 9px; display: block; }

.slot-hint {
  color: #2e2e2e;
  font-size: 9px;
  padding: 2px 0;
}

/* 3×3 camera slots */
.slots-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.slot-btn {
  height: 34px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px;
  gap: 0;
}
.slot-btn.filled { color: var(--accent); border-color: #1a3a44; background: #0d2028; }
.slot-btn .dot   { font-size: 7px; line-height: 1; color: var(--accent); }

.btn-stack { display: flex; flex-direction: column; gap: 4px; }

.play-btn { width: 100%; padding: 7px; font-size: 12px; }
.play-btn.active { background: #1a2a1a; color: #4dff80; border-color: #2a4a2a; }

/* ── Canvas area ────────────────────────────────────────── */
.viewer-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#three-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Canvas header bar */
.canvas-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 36px;
  background: rgba(9,9,9,0.82);
  border-bottom: 1px solid #1c1c1c;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
  z-index: 10;
  gap: 12px;
}
#hdr-frame {
  color: #484848;
  font-size: 11px;
  min-width: 90px;
}
.hdr-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
}
.hdr-btn {
  background: rgba(30,30,30,0.8);
  border: 1px solid #2a2a2a;
  color: #aaa;
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s, color 0.12s;
}
.hdr-btn:hover { background: #2e2e2e; color: #e8e8e8; }
.hdr-play-btn  { min-width: 70px; justify-content: center; }
.hdr-play-btn.active { background: #1a2a1a; color: #4dff80; border-color: #2a4a2a; }
.mode-badge {
  background: #1a0808;
  color: var(--red);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  border: 1px solid #3a1010;
  border-radius: 3px;
  padding: 2px 7px;
  min-width: 56px;
  text-align: center;
}

/* Frame slider bar below canvas header */
.canvas-frame-bar {
  position: absolute;
  top: 36px; left: 0; right: 0;
  height: 28px;
  background: rgba(9,9,9,0.65);
  border-bottom: 1px solid #181818;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 10;
  pointer-events: auto;
}
.canvas-frame-bar input[type=range] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 14px;
}
.canvas-frame-bar .sl-val {
  width: 24px;
  text-align: right;
  font-size: 11px;
  color: #555;
  flex-shrink: 0;
}

/* Shared viewer controls bar (display mode + FPS) */
.canvas-shared-bar {
  position: absolute;
  top: 64px; /* 36px header + 28px frame bar */
  left: 0; right: 0;
  height: 28px;
  background: rgba(9,9,9,0.65);
  border-bottom: 1px solid #181818;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
  z-index: 10;
  pointer-events: auto;
}
.shared-bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.shared-bar-label {
  color: #444;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.shared-radio {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #aaa;
  cursor: pointer;
}
.canvas-shared-bar input[type=range] {
  accent-color: var(--accent);
  cursor: pointer;
  height: 14px;
}

/* ViewCube */
#viewcube-canvas {
  position: absolute;
  top: 72px;   /* 36px header + 28px frame bar + 8px gap */
  right: 8px;
  width: 110px;
  height: 110px;
  z-index: 10;
  border-radius: 50%;   /* circular crop matches the orbit ring */
  border: 1px solid #182838;
  pointer-events: auto;
  background: transparent;
}

/* ── Loading overlay ────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13,13,13,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar-wrap {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s ease;
}

/* ── Context menu ───────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px 0;
  min-width: 170px;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-item {
  padding: 6px 14px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text);
}
.ctx-item:hover { background: #2a2a2a; }
.ctx-sep {
  height: 1px;
  background: #2a2a2a;
  margin: 3px 0;
}

/* ── ROI modal ──────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-box {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.modal-hint {
  color: #5050aa;
  font-size: 10px;
  text-align: center;
}
#roi-canvas {
  border: 1px solid #333;
  cursor: crosshair;
  display: block;
}
.modal-btns {
  display: flex;
  gap: 8px;
}
