/* ============================================================
   IRIBHM Microscopy Platform — Viewer Styles
   ============================================================ */

body {
  overflow: hidden; /* Prevent page scrolling when using viewer */
}

.viewer-layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  z-index: var(--z-viewer-base); /* Above everything else */
}

/* ── Minimal Header ──────────────────────────────────────── */
.viewer-header {
  position: relative;
  min-height: 56px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.hamburger-menu-btn {
  display: none;
  z-index: var(--z-viewer-raised);
}

@keyframes slideDownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Hamburger collapse: triggered by JS ResizeObserver ─────── */
/* Applied when the toolbar wraps to a second line (height > 56px) */

.viewer-header.toolbar-collapsed .hamburger-menu-btn {
  display: flex !important;
}

.viewer-header.toolbar-collapsed .viewer-toolbar {
  display: none !important;
  position: absolute;
  top: calc(100% - 4px);
  right: var(--space-4);
  background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: var(--space-4);
  z-index: var(--z-viewer-elevated);
  flex-direction: column !important;
  align-items: stretch !important;
  gap: var(--space-3) !important;
  min-width: 260px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  max-height: 80vh;
  overflow-y: auto;
}

.viewer-header.toolbar-collapsed .viewer-toolbar.menu-open {
  display: flex !important;
  animation: slideDownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.viewer-header.toolbar-collapsed .viewer-toolbar.menu-open .toolbar-cluster {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  border-left: none !important;
  padding-left: 0 !important;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: var(--space-2);
  gap: 6px !important;
  width: 100%;
}

.viewer-header.toolbar-collapsed .viewer-toolbar.menu-open .toolbar-cluster:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.viewer-header.toolbar-collapsed .viewer-toolbar.menu-open .toolbar-label {
  display: block !important;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.viewer-header.toolbar-collapsed .viewer-toolbar.menu-open .toolbar-actions {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: var(--space-2) !important;
}

.viewer-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.viewer-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  color: var(--text-primary);
}

.viewer-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── Main Workspace ──────────────────────────────────────── */
.viewer-workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ── Sidebar collapse: smooth width slide ────────────────── */
.viewer-sidebar {
  width: 320px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  /* Animate the collapse with width + opacity */
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              border-color 0.25s ease;
}

.viewer-sidebar.sidebar-hidden {
  width: 0;
  border-right: none;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ── Sidebar topbar (title + collapse button) ─────────────── */
.sidebar-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  min-height: 40px;
  background: color-mix(in srgb, var(--bg-surface) 80%, var(--bg-base));
}

.sidebar-topbar-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Floating reopen button (visible on canvas left edge when sidebar hidden) */
.sidebar-reopen-btn {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 56px;
  padding: 0;
  background: color-mix(in srgb, var(--bg-surface) 90%, transparent);
  border: 1px solid var(--border-light);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease, color 0.15s ease, width 0.15s ease;
}

.sidebar-reopen-btn:hover {
  background: var(--bg-active);
  color: var(--color-primary);
  width: 34px;
}

.sidebar-reopen-btn i,
.sidebar-reopen-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}



.panel-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Channel Controls ────────────────────────────────────── */
.channel-item {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.channel-item.is-disabled {
  opacity: 0.55;
}

.channel-header-row {
  display: grid;
  gap: 8px;
}

.channel-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.channel-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.channel-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

.channel-quick {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.channel-summary {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.channel-advanced {
  display: none;
  margin-top: var(--space-3);
}

.channel-item.expanded .channel-advanced {
  display: block;
}

.channel-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
}

.histogram-editor {
  position: relative;
  height: 144px;
  padding: 10px 0 16px;
  border-radius: var(--radius-sm);
  overflow: visible;
}

.histogram-band {
  position: absolute;
  top: 12px;
  bottom: 18px;
  background: color-mix(in srgb, var(--color-primary) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-primary) 34%, transparent);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 1;
}

.channel-item .mini-histogram,
.studio-channel-item .mini-histogram {
  position: absolute;
  top: 12px;
  right: 0;
  bottom: 18px;
  left: 0;
  z-index: 2;
  display: block;
  height: auto;
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.channel-item .mini-histogram svg,
.studio-channel-item .mini-histogram svg {
  display: block;
  width: 100%;
  height: 100%;
}

.hist-handle {
  position: absolute;
  top: 6px;
  width: 12px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
  z-index: 3;
}

.hist-handle::after {
  content: "";
  position: absolute;
  inset: 14px 4px;
  border-radius: 999px;
  background: var(--text-primary);
}

.hist-handle.handle-mid {
  height: 54px;
  top: 3px;
  background: color-mix(in srgb, var(--color-primary) 26%, var(--bg-surface));
}

.channel-advanced-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.channel-color-picker {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  appearance: none;
  padding: 0;
  background: transparent;
}
.channel-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.channel-color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

.slider-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

input[type="range"] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 16px;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  border-radius: var(--radius-full);
  outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 0;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
}

/* ── Canvas Area ─────────────────────────────────────────── */
.viewer-canvas-container {
  flex: 1;
  min-width: 0;
  position: relative;
  background: #000;
  overflow: hidden;
}

#webgl-canvas,
#tracking-canvas canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none; /* Let clicks pass through to canvas */
}

.canvas-overlay > * {
  pointer-events: auto; /* Re-enable clicks for buttons */
}

.quality-stream-progress {
  position: absolute;
  left: var(--space-4);
  bottom: var(--space-4);
  z-index: 14;
  min-width: 172px;
  max-width: min(240px, 48vw);
  padding: var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.quality-stream-progress.hidden {
  display: none;
}

.quality-stream-progress-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.quality-stream-progress-track {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--border-strong) 65%, transparent);
  overflow: hidden;
}

.quality-stream-progress-fill {
  width: 0%;
  height: 100%;
  background: var(--color-primary);
  transition: width 0.15s linear;
}

/* ── Gaussian blur progress toast (bottom-right) ─────────────── */
.blur-progress-toast {
  position: absolute;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 148px;
  max-width: 200px;
  padding: 7px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(6px);
  pointer-events: none;
  /* Appear with a gentle fade+slide */
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.blur-progress-toast.hidden {
  display: none;
}

.blur-progress-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--color-primary);
  opacity: 0.85;
  animation: blur-icon-pulse 1.4s ease-in-out infinite;
}

@keyframes blur-icon-pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%       { opacity: 1;   transform: scale(1.15); }
}

.blur-progress-body {
  flex: 1;
  min-width: 0;
}

.blur-progress-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.blur-progress-track {
  width: 100%;
  height: 3px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--border-strong) 65%, transparent);
  overflow: hidden;
}

.blur-progress-fill {
  width: 0%;
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 0.12s linear;
  position: relative;
  overflow: hidden;
}
/* PERF-034: indeterminate shimmer via a transform-animated highlight overlay
   (compositor) instead of animating background-position (repaint every frame). The
   fill keeps its solid primary background; the lighter band slides across it. */
.blur-progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--color-primary) 60%, white), transparent);
  transform: translateX(-100%);
  animation: blur-shimmer 1.2s linear infinite;
  will-change: transform;
}

@keyframes blur-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.viewer-legend {
  position: absolute;
  left: var(--space-4);
  bottom: var(--space-4);
  z-index: 12;
  min-width: 184px;
  max-width: min(280px, 36vw);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg-surface) 90%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-md);
}

.viewer-legend.hidden {
  display: none;
}

.viewer-legend-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.viewer-legend-range {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.viewer-legend-gradient {
  display: flex;
  gap: 0;
  margin-top: var(--space-2);
  height: 10px;
  overflow: hidden;
  border-radius: var(--radius-full);
}

.viewer-legend-gradient span {
  flex: 1;
}

/* SEC-021: colormap menu hover/selection moved off inline onmouseover/onmouseout
   (CSP hygiene) onto CSS state. .selected marks the active map. */
.colormap-option {
  background: transparent;
}
.colormap-option:hover {
  background: var(--bg-hover);
}
.colormap-option.selected {
  background: var(--bg-active);
}

.viewer-legend-items {
  display: grid;
  gap: 6px;
  margin-top: var(--space-2);
}

.viewer-legend-item {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.viewer-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

body.viewer-iframe .canvas-overlay {
  top: calc(var(--space-4) + 44px);
}

.quality-status {
  margin-top: var(--space-2);
  min-height: 16px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.physical-status {
  margin-top: var(--space-3);
  min-height: 30px;
  font-size: var(--text-xs);
  line-height: 1.45;
  color: var(--text-muted);
}

.physical-status strong {
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.related-link {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-base);
  color: var(--text-primary);
  text-decoration: none;
  min-width: 0;
}

.related-link:hover {
  border-color: var(--color-primary);
  background: var(--bg-hover);
}

.related-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.related-link-title {
  min-width: 0;
  overflow: hidden;
}

.related-link-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.related-link-meta {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.related-type {
  min-width: 54px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  text-align: center;
}

.related-type.fixed {
  background: var(--badge-fixed-bg);
  color: var(--badge-fixed-text);
}

.related-type.live {
  background: var(--badge-live-bg);
  color: var(--badge-live-text);
}

.related-type.tracking {
  background: var(--badge-track-bg);
  color: var(--badge-track-text);
}

.axis-helper {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-4);
  width: 100px;
  height: 100px;
  pointer-events: none;
}

/* ── Timeline (LiveImaging) ──────────────────────────────── */
.viewer-timeline {
  height: 80px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-4);
  flex-shrink: 0;
}

.play-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.scrubber-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.scrubber-track {
  height: 24px;
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  position: relative;
  cursor: pointer;
}

.scrubber-track.scrubber-stepped {
  background-color: var(--bg-base);
  background-image: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.28) 0,
    rgba(255, 255, 255, 0.28) 1px,
    transparent 1px,
    transparent 100%
  );
  background-size: var(--tick-size, 8%) 100%;
  background-repeat: repeat-x;
}

.scrubber-buffer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
}

.scrubber-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  width: 0%;
}

.scrubber-handle {
  position: absolute;
  top: 50%;
  width: 4px;
  height: 32px;
  background: white;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  box-shadow: var(--shadow-sm);
}

/* ── Loader ──────────────────────────────────────────────── */
.viewer-loader {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: white;
  backdrop-filter: blur(4px);
}

.progress-bar-container {
  width: 300px;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  margin-top: var(--space-4);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.3s ease;
}

/* ── Studio Editor Mode ──────────────────────────────────── */
.studio-layout {
  position: fixed;
  inset: 0;
  z-index: var(--z-viewer-modal);
  background: var(--bg-body);
  display: flex;
  flex-direction: column;
}

.studio-layout.hidden {
  display: none !important;
}

.studio-header {
  min-height: 56px;
  height: auto;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.studio-header-left h2 {
  margin: 0;
  font-size: var(--text-base);
}

.studio-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.studio-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.studio-sidebar-left {
  width: 240px;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.studio-sidebar-right {
  width: 280px;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.studio-workspace {
  flex: 1;
  background: var(--bg-base);
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.studio-workspace canvas {
  box-shadow: var(--shadow-xl);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
}

.studio-tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
}

.studio-tools-grid .btn {
  width: 100%;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.studio-tools-grid .btn.active {
  background: var(--bg-active);
  color: var(--color-primary);
}

.studio-layers-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.studio-layer-item {
  display: flex;
  align-items: center;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.studio-layer-item:hover {
  background: var(--bg-hover);
}

.studio-layer-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.flex-row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.mt-1 { margin-top: var(--space-1); }

.studio-layer-item .icon {
  width: 16px;
  height: 16px;
  margin-right: var(--space-2);
  color: var(--text-muted);
}

.studio-properties-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.studio-properties-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
}

.studio-properties-form input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.studio-channels-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

.studio-channel-item {
  padding: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.studio-channel-item .ch-color {
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
}

#studio-rotation-control {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 228px;
  flex: 0 0 auto;
  pointer-events: auto;
}

#studio-rotation-slider {
  accent-color: var(--color-primary);
  width: 148px;
  flex: 0 0 148px;
  margin: 0;
  position: relative;
  top: 0;
  vertical-align: middle;
}

/* Production Studio refinements */
.studio-header {
  gap: var(--space-3);
}

.studio-header-right {
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.studio-body {
  background: #07090d;
}

.studio-sidebar-left,
.studio-sidebar-right {
  background: color-mix(in srgb, var(--bg-surface) 94%, #050607);
}

.studio-sidebar-left {
  width: 268px;
}

.studio-sidebar-right {
  width: 320px;
}

.studio-workspace {
  padding: 0;
  overflow: hidden;
  align-items: stretch;
  justify-content: stretch;
  background: #050607;
}

.studio-workspace canvas#studio-canvas {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  box-shadow: none;
  cursor: default;
}

.studio-tools-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.studio-tools-grid .btn.active {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-primary) 58%, transparent);
}

.studio-layer-item {
  min-height: 38px;
  gap: var(--space-1);
}

.studio-layer-item.is-locked {
  opacity: 0.72;
}

.studio-layer-item.is-dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.studio-layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
}

.studio-layer-item .btn {
  width: 28px;
  height: 28px;
  padding: 0;
}

.studio-empty,
.studio-measurement-readout {
  color: var(--text-muted);
  font-size: var(--text-xs);
  padding: var(--space-2);
}

.studio-properties-form .form-input,
.studio-properties-form .form-select,
.studio-channel-item input[type="range"],
.studio-channel-item input[type="color"] {
  width: 100%;
}

.studio-channel-item .channel-color-picker {
  width: 24px;
  height: 24px;
  min-width: 24px;
}

.studio-property-row,
.studio-radio-row,
.studio-channel-top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.studio-property-row .btn {
  flex: 1;
  min-width: 72px;
}

.studio-radio-row label {
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.studio-channel-top {
  justify-content: space-between;
}

.studio-channel-top label {
  flex: 1;
  min-width: 0;
  flex-direction: row;
  align-items: center;
}

.studio-channel-top input[type="color"] {
  width: 34px;
  height: 28px;
}

.studio-channel-item .histogram-editor {
  margin-top: var(--space-2);
}

.studio-channel-item.is-disabled {
  opacity: 0.62;
}

.studio-channel-item .studio-channel-readout {
  margin-top: 6px;
}

.studio-histogram-strip {
  height: 32px;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(90deg, #020203, #1c2430);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.studio-histogram-strip svg {
  width: 100%;
  height: 100%;
  display: block;
}

#studio-minimap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  width: 180px;
  height: 120px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #050607;
  box-shadow: var(--shadow-lg);
}

.studio-command-palette {
  position: fixed;
  inset: 0;
  z-index: var(--z-viewer-modal-top);
  display: grid;
  place-items: start center;
  padding-top: 14vh;
  background: rgba(0,0,0,0.46);
  backdrop-filter: blur(10px);
}

.studio-command-palette.hidden {
  display: none !important;
}

.studio-command-dialog {
  width: min(560px, calc(100vw - 32px));
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-2);
}

.studio-command-list {
  display: grid;
  gap: 2px;
  max-height: 340px;
  overflow: auto;
}

.studio-command-list button {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.studio-command-list button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

@media (max-width: 980px) {
  .studio-body {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto auto;
  }

  .studio-sidebar-left,
  .studio-sidebar-right {
    width: 100%;
    max-height: 30vh;
    border: 0;
    border-top: 1px solid var(--border-subtle);
  }

  .studio-workspace {
    grid-row: 1;
    min-height: 42vh;
  }
}

/* ── Slice Inspector Panel ───────────────────────────────── */
.slice-inspector {
  width: 300px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: width 0.25s ease, opacity 0.2s ease;
  order: 3; /* appears after the canvas container */
}

.slice-inspector.hidden {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border-left: none;
  padding: 0;
  pointer-events: none;
}

/* ── Z-Stack Browser Panel ──────────────────────────────── */
.zstack-browser {
  width: 300px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: width 0.25s ease, opacity 0.2s ease;
  order: 4;
}

.zstack-browser.zstack-hidden {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border-left: none;
  padding: 0;
  pointer-events: none;
}

.zstack-diagram {
  width: 100%;
  aspect-ratio: 1.3;
  background: linear-gradient(180deg, rgba(0,0,0,0.3) 0%, rgba(0,20,40,0.4) 100%);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zstack-diagram canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.zstack-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zstack-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-xs);
}

.zstack-info-label {
  color: var(--text-muted);
  font-weight: var(--weight-medium);
}

.zstack-info-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-semibold);
}

.zstack-diagram-row {
  display: flex;
  gap: 4px;
  align-items: stretch;
  height: 280px;
}

.zstack-diagram-row .zstack-diagram {
  flex: 1;
  min-width: 0;
  aspect-ratio: auto;
  height: 100%;
}

.zstack-vslider-wrap {
  width: 36px;
  flex-shrink: 0;
  position: relative;
}

.zstack-vslider {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  width: 280px !important;
  max-width: none !important;
  height: 24px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.zstack-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.zstack-slice-readout {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  min-width: 60px;
  text-align: center;
}

.slicer-preview-mount {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.slicer-preview-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
}

.slicer-presets {
  display: flex;
  gap: var(--space-2);
}

.slicer-presets .btn {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
}

.slicer-presets .btn.active {
  background: var(--color-primary);
  color: var(--bg-base);
  border-color: var(--color-primary);
}
