/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1d23;
  --bg2: #21252e;
  --bg3: #2a2f3b;
  --border: #343a48;
  --accent: #4a9eff;
  --accent-h: #6abaff;
  --text: #dce1ec;
  --text-dim: #7a8399;
  --success: #3ecf8e;
  --warn: #f5a623;
  --panel-w: 300px;
  --topbar-h: 44px;
  --statusbar-h: 26px;
  --radius: 6px;
  --font: 'Segoe UI', 'Noto Sans KR', sans-serif;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 8px;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.app-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.app-version {
  font-size: 11px;
  color: var(--text-dim);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12.5px;
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== LAYOUT ===== */
.layout {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
}

/* ===== LEFT PANEL ===== */
.panel-left {
  width: var(--panel-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-section {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* Info table */
.info-table {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-label {
  color: var(--text-dim);
  font-size: 12px;
}

.info-val {
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Toggles */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  cursor: pointer;
}

.toggle-label {
  font-size: 12.5px;
}

/* Color picker */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

input[type="color"] {
  width: 36px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px;
  background: var(--bg3);
  cursor: pointer;
}

/* Slider */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Step list */
.next-step-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-item {
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  font-size: 12px;
  color: var(--text-dim);
  cursor: not-allowed;
  transition: background 0.15s, color 0.15s;
}

.step-item.active {
  border-color: var(--accent);
  color: var(--accent);
  cursor: pointer;
  background: rgba(74, 158, 255, 0.1);
}

.step-item.done {
  border-color: var(--success);
  color: var(--success);
  background: rgba(62, 207, 142, 0.08);
}

/* ===== VIEWPORT ===== */
.viewport-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
}

/* Drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  z-index: 5;
  pointer-events: none;
  /* clicks pass through to canvas */
  transition: opacity 0.25s;
}

.drop-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  opacity: 0.45;
}

.drop-text {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

.drop-sub {
  font-size: 11.5px;
  color: #555;
}

.drop-overlay.dragover {
  background: rgba(74, 158, 255, 0.06);
  border: 2px dashed var(--accent);
}

/* HUD labels */
.hud-bottom-left,
.hud-bottom-right {
  position: absolute;
  bottom: 10px;
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.hud-bottom-left {
  left: 12px;
}

.hud-bottom-right {
  right: 12px;
}

/* ===== STATUS BAR ===== */
.statusbar {
  height: var(--statusbar-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* Drag-hover highlight on entire page */
body.dragging .drop-overlay {
  background: rgba(74, 158, 255, 0.05);
}

/* ===== TOPBAR ICON TOGGLE BUTTONS ===== */
.btn-icon {
  background: var(--bg3);
  border-color: var(--border);
  color: var(--text-dim);
  padding: 5px 7px;
  opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
}

.btn-icon.active {
  opacity: 1;
  color: var(--text);
  background: var(--bg3);
  border-color: var(--accent);
}

.btn-icon:hover {
  opacity: 1;
}

.btn-persp {
  font-size: 11.5px;
  padding: 5px 10px;
  min-width: 46px;
  text-align: center;
}

/* ===== SECOND PRIMARY BUTTON (Distal Femur) ===== */
.btn-distal {
  background: #3a78b5;
  border-color: #3a78b5;
  color: #fff;
}

.btn-distal:hover {
  background: #5a98d5;
  border-color: #5a98d5;
}

/* ===== MODEL SECTION ===== */
.model-badge {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  flex-shrink: 0;
}

.section-title {
  display: flex;
  align-items: center;
}

.model-status {
  margin-left: auto;
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.model-status.loaded {
  color: var(--success);
  border-color: var(--success);
  background: rgba(62, 207, 142, 0.08);
}

/* ===== SIDE BADGES (Step 2 Left/Right) ===== */
.side-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg);
  user-select: none;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.side-badge.active {
  color: var(--success);
  border-color: var(--success);
  background: rgba(62, 207, 142, 0.10);
}

.model-controls {
  margin-top: 10px;
}

/* ===== DROP BADGES ===== */
.drop-badges {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.drop-badge {
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid;
  font-size: 11.5px;
  color: var(--text-dim);
}

/* ===== DROP TARGET MODAL ===== */
.drop-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.drop-modal.hidden {
  display: none;
}

.drop-modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.drop-modal-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
}

.drop-modal-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.btn-modal-hip {
  background: #a0603a;
  border-color: #a0603a;
  color: #fff;
  padding: 7px 20px;
}

.btn-modal-hip:hover {
  background: #c07848;
  border-color: #c07848;
}

.btn-modal-distal {
  background: #3a78b5;
  border-color: #3a78b5;
  color: #fff;
  padding: 7px 20px;
}

.btn-modal-distal:hover {
  background: #5a98d5;
  border-color: #5a98d5;
}

/* ===== STEP BODY CONTENT ===== */
.step-desc {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.55;
  margin-bottom: 8px;
}

.pt-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  max-height: 160px;
  overflow-y: auto;
}

.pt-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px 3px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  gap: 4px;
}

.pt-list li .pt-idx {
  color: var(--accent);
  font-weight: 600;
  min-width: 14px;
}

.pt-list li button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}

.pt-list li button:hover {
  color: #e06060;
}

.step-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11.5px;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

.sphere-result {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sphere-result.hidden {
  display: none;
}

.result-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
}

.result-label {
  color: var(--text-dim);
}

.result-val {
  color: var(--success);
  font-variant-numeric: tabular-nums;
}

/* ===== WORKFLOW NAV STEPS ===== */
.nav-step {
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.nav-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: default;
  user-select: none;
}

.nav-step.locked .nav-step-header {
  opacity: 0.38;
}

.nav-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.nav-step.active .nav-step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.nav-step.done .nav-step-num {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.nav-step-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  flex: 1;
}

.nav-step.active .nav-step-title {
  color: var(--text);
}

.nav-step.done .nav-step-title {
  color: var(--success);
}

/* Inline action buttons inside step header */
.step-actions-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.step-actions-inline .btn-sm {
  padding: 2px 7px;
  font-size: 11px;
  min-width: 54px;
  text-align: center;
  justify-content: center;
}

.nav-step-body {
  padding: 0 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-step.locked .nav-step-body {
  display: none;
}

/* ===== MODEL ROW ===== */
.model-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: var(--bg3);
  border: 1px solid var(--border);
  min-height: 34px;
}

.model-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.model-row-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  cursor: default;
}

/* visibility toggle (eye icon) */
.vis-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.vis-toggle input {
  display: none;
}

.vis-icon {
  font-size: 14px;
  opacity: 0.75;
  transition: opacity 0.15s;
  line-height: 1;
  filter: grayscale(0);
}

.vis-toggle input:not(:checked)+.vis-icon {
  opacity: 0.25;
  filter: grayscale(1);
}

/* mini load button */
.btn-load-mini {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.btn-load-mini:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* transparency active state */
.btn-load-mini.transp-on {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  opacity: 0.55;
}

.btn-load-mini.transp-on:hover {
  opacity: 0.8;
}

/* display options inside step 1 */
.display-opts {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ===== PANEL RESIZER ===== */
.panel-resizer {
  width: 4px;
  flex-shrink: 0;
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.panel-resizer:hover,
.panel-resizer.dragging {
  background: var(--accent);
}

.panel-resizer::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}

/* ===== RIGHT PANEL: MRI / CT ===== */
:root {
  --panel-right-w: 680px;
}

.panel-right {
  width: var(--panel-right-w);
  min-width: 180px;
  max-width: 900px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.panel-right-header {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-right-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#mri-canvas {
  flex: 1;
  width: 100%;
  display: block;
}

/* ===== DICOM SERIES LIST ===== */
.dicom-series-box {
  min-width: 360px;
  max-width: 480px;
}

.series-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.series-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.series-item:hover {
  border-color: var(--accent);
  background: rgba(74, 158, 255, 0.08);
}

.series-item-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.series-item-sub {
  font-size: 11px;
  color: var(--text-dim);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg2);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}