:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #172033;
  --border: #243047;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-border: rgba(245, 158, 11, 0.45);
  --warn-text: #fcd34d;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-line {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.study-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.study-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.study-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.study-tab.active {
  background: var(--accent-strong);
  color: #fff;
}

.tab-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
}

.tab-count {
  font-size: 11px;
  opacity: 0.85;
}

.ai-toggle-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.ai-toggle-btn:hover,
.ai-toggle-btn.active {
  background: var(--accent-strong);
  color: #fff;
  border-color: var(--accent);
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 230px 1fr 400px;
  min-height: 0;
  overflow: hidden;
}

.workspace.ai-collapsed {
  grid-template-columns: 230px 1fr 0px;
}

.workspace.ai-collapsed .ai-panel {
  display: none;
}

/* Sidebar */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.series-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.series-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.series-item:hover {
  border-color: var(--border);
}

.series-item.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

.series-thumb {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: #000;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.series-info {
  min-width: 0;
  flex: 1;
}

.series-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.series-sub {
  font-size: 11px;
  color: var(--muted);
}

/* Viewer Section */
.viewer-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #05070b;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.tool-btn:hover {
  border-color: var(--accent);
}

.tool-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
}

.slice-indicator,
.zoom-indicator {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  min-width: 52px;
  text-align: center;
}

.sliders-group {
  gap: 12px;
}

.mini-slider {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}

.mini-slider input[type="range"] {
  width: 78px;
  accent-color: var(--accent);
}

/* Viewport */
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  outline: none;
}

.viewport:active {
  cursor: grabbing;
}

.canvas-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
}

#main-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
  will-change: transform, filter;
}

.dicom-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: rgba(226, 232, 240, 0.85);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
}

.dicom-overlay.hidden {
  display: none;
}

.dicom-overlay > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.overlay-tl, .overlay-bl {
  display: block !important;
}

.overlay-tr, .overlay-br {
  text-align: right;
  display: block !important;
}

/* Scrubber & Thumbnails */
.scrubber-bar {
  padding: 6px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.scrubber-bar input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.thumb-strip {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.thumb-btn {
  position: relative;
  flex-shrink: 0;
  width: 54px;
  height: 54px;
  border-radius: 6px;
  border: 2px solid transparent;
  background: #000;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-btn.active {
  border-color: var(--accent);
}

.thumb-num {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 0 4px;
  border-radius: 3px;
}

/* AI Panel */
.ai-panel {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-panel-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.icon-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
}

.icon-close:hover {
  color: var(--text);
  border-color: var(--text);
}

.ai-gate {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-card {
  background: var(--panel-2);
  border: 1px solid var(--warn-border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gate-icon {
  font-size: 28px;
}

.gate-card h3 {
  font-size: 16px;
  color: var(--warn-text);
}

.gate-desc {
  font-size: 13px;
  color: var(--text);
}

.consent-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text);
}

.consent-label input[type="checkbox"] {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.unlock-btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent-strong);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.unlock-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hidden {
  display: none !important;
}

.sticky-warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.patient-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.patient-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.report-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.report-card h3 {
  font-size: 14px;
  margin-bottom: 6px;
}

.finding-card {
  border-color: var(--warn-border);
  background: rgba(245, 158, 11, 0.06);
}

.finding-card h3 {
  color: var(--warn-text);
}

.jump-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.jump-btn {
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  font-size: 11.5px;
  cursor: pointer;
}

.jump-btn:hover {
  background: var(--accent-strong);
  color: #fff;
}

.ai-sections {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.section-badge {
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 7px;
  border-radius: 999px;
}

.report-card ul {
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #d1d5db;
}

/* Responsive */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 180px 1fr;
  }
  .ai-panel {
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: min(420px, 100vw);
    z-index: 50;
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.6);
  }
  .workspace.ai-collapsed {
    grid-template-columns: 180px 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 8px 10px;
  }
  .workspace,
  .workspace.ai-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .series-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 8px;
  }
  .series-item {
    width: auto;
    min-width: 145px;
  }
  .sliders-group {
    display: none;
  }
  .ai-panel {
    top: 0;
    width: 100vw;
  }
}
