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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --rack-bg: #1f2937;
  --rack-label: #e5e7eb;
  --canvas-dot: #d1d5db;
}

[data-theme="dark"] {
  --bg: #111827;
  --surface: #1f2937;
  --border: #374151;
  --text: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --rack-bg: #374151;
  --rack-label: #e5e7eb;
  --canvas-dot: #374151;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top Bar ── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-left h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.tools {
  display: flex;
  gap: 2px;
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius);
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.tool-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.tool-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-controls button:hover {
  background: var(--bg);
  color: var(--text);
}

#zoom-level {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

#zoom-level:hover {
  color: var(--primary);
}

#btn-export, #btn-import {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

#btn-export:hover, #btn-import:hover {
  background: var(--bg);
  color: var(--text);
}

/* ── Main Layout ── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
}

#btn-add-item {
  padding: 5px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

#btn-add-item:hover {
  background: var(--primary-hover);
}

.search-box {
  padding: 8px 16px;
}

.search-box input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.filter-box {
  padding: 0 16px 8px;
}

.filter-box select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
  outline: none;
  background: var(--surface);
}

#item-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* ── Item Cards ── */
.item-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: grab;
  transition: all 0.15s;
  position: relative;
}

.item-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.item-card:active {
  cursor: grabbing;
}

.item-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.item-card-title {
  font-size: 13px;
  font-weight: 500;
}

.item-card-qty {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.item-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.item-sku {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

.item-category {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 8px;
}

.item-location {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.item-location::before {
  content: '📍 ';
}

.item-location.unassigned {
  color: var(--text-muted);
  font-style: italic;
}

.item-location.unassigned::before {
  content: '';
}

.item-card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 2px;
}

.item-card:hover .item-card-actions {
  display: flex;
}

.item-card-actions button {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-card-actions button:hover {
  background: var(--border);
}

.item-card-actions button.danger:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin-top: 12px;
  font-size: 13px;
}

.empty-state .hint, .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.empty-message {
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}

/* ── Canvas ── */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  background-image: radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

#canvas-container.panning, #canvas-container.space-held {
  cursor: grab;
}

#canvas-container.panning {
  cursor: grabbing;
}

#canvas-container.tool-sector {
  cursor: crosshair;
}

#canvas-container.tool-rack {
  cursor: crosshair;
}

#canvas-container.drop-active {
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

/* ── Sectors ── */
.sector {
  position: absolute;
  border: 2px dashed;
  border-radius: var(--radius);
  min-width: 80px;
  min-height: 60px;
  transition: box-shadow 0.15s;
}

.sector.selected {
  box-shadow: 0 0 0 2px var(--primary);
}

.sector.drop-highlight {
  box-shadow: 0 0 0 3px var(--primary);
}

.sector-label {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px dashed;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sector-badge {
  font-size: 10px;
  font-weight: 500;
  color: white;
  padding: 1px 6px;
  border-radius: 8px;
}

.sector-preview {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(37, 99, 235, 0.08);
  border-radius: var(--radius);
  pointer-events: none;
}

/* Resize handles */
.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 5;
}

.sector:hover .resize-handle,
.sector.selected .resize-handle {
  opacity: 1;
}

.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* ── Level Filter ── */
#level-filter {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  box-shadow: var(--shadow);
}

.level-filter-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 2px;
  user-select: none;
}

.level-btn {
  width: 32px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.level-btn:first-of-type {
  width: auto;
  padding: 0 8px;
}

.level-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.level-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Racks ── */
.rack {
  position: absolute;
  background: var(--rack-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: box-shadow 0.15s, opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
}

.rack:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.rack.selected {
  box-shadow: 0 0 0 2px var(--primary), 0 2px 8px rgba(0,0,0,0.2);
}

.rack.drop-highlight {
  box-shadow: 0 0 0 3px var(--primary), 0 2px 8px rgba(0,0,0,0.2);
}

.rack.rack-hidden {
  display: none;
}

.rack-level-1 { z-index: 1; }
.rack-level-2 { z-index: 2; }
.rack-level-3 { z-index: 3; }
.rack-level-4 { z-index: 4; }

.rack-level-1 { border-left: 3px solid #22c55e; }
.rack-level-2 { border-left: 3px solid #3b82f6; }
.rack-level-3 { border-left: 3px solid #f97316; }
.rack-level-4 { border-left: 3px solid #ef4444; }

.rack-label {
  color: var(--rack-label);
  font-size: 11px;
  font-weight: 500;
  user-select: none;
  text-align: center;
  padding: 2px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80%;
}

.rack-label-rotated {
  transform: rotate(-90deg);
  white-space: nowrap;
  overflow: visible;
  max-width: none;
  font-size: 10px;
}

.rack-level-badge {
  position: absolute;
  bottom: -8px;
  left: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.rack-level-1 .rack-level-badge { background: #22c55e; }
.rack-level-2 .rack-level-badge { background: #3b82f6; }
.rack-level-3 .rack-level-badge { background: #f97316; }
.rack-level-4 .rack-level-badge { background: #ef4444; }

.rack-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ── Action Bar ── */
#action-bar {
  position: fixed;
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

#action-bar.visible {
  opacity: 1;
  pointer-events: auto;
}

#action-bar button {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

#action-bar button:hover {
  background: var(--bg);
  color: var(--text);
}

#action-bar button.danger:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

#modal-overlay.hidden {
  display: none;
}

#modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  min-width: 380px;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}

#modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

#modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

#modal-body {
  padding: 20px;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  background: var(--surface);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.btn-primary {
  padding: 8px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  padding: 8px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-text {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}

.btn-text:hover {
  text-decoration: underline;
}

/* ── Color Picker ── */
.color-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.color-btn {
  width: 32px;
  height: 32px;
  border: 2px solid;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}

.color-btn:hover {
  transform: scale(1.15);
}

.color-btn.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--primary);
}

/* ── Image Upload ── */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-upload-area:hover, .image-upload-area.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

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

.image-preview {
  max-width: 100%;
  max-height: 120px;
  border-radius: var(--radius-sm);
}

/* ── Rack Items List ── */
.rack-items-list {
  max-height: 300px;
  overflow-y: auto;
}

.rack-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.rack-item-row:last-child {
  border-bottom: none;
}

.rack-item-info strong {
  font-size: 13px;
}

.rack-item-info .sku {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  font-family: monospace;
}

.rack-item-qty {
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
}

/* ── Shortcuts hint ── */
.shortcuts-hint {
  position: fixed;
  bottom: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  box-shadow: var(--shadow);
  z-index: 50;
}

.shortcuts-hint kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: inherit;
}

/* ── Form hint ── */
.form-hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Level Legend ── */
#level-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 20;
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  box-shadow: var(--shadow);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Dashboard Panel ── */
#dashboard-panel {
  position: fixed;
  top: 52px;
  right: 0;
  width: 280px;
  height: calc(100vh - 52px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0,0,0,0.06);
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#dashboard-panel.hidden {
  display: none;
}

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

.dashboard-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.dashboard-header button {
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dashboard-header button:hover {
  background: var(--bg);
  color: var(--text);
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 16px;
}

.dash-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.dash-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.dash-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dash-section {
  padding: 0 16px 12px;
}

.dash-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.dash-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.dash-row:last-child {
  border-bottom: none;
}

.dash-row.warn span:last-child {
  font-weight: 600;
  color: var(--danger);
}

/* ── Move select in rack items ── */
.rack-item-actions-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.move-select {
  width: 110px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface);
  cursor: pointer;
}

.move-select:focus {
  border-color: var(--primary);
  outline: none;
}

/* ── Sector items summary ── */
.sector-items-summary {
  padding: 8px 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ── CSV / Dashboard buttons ── */
#btn-dashboard, #btn-csv {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

#btn-dashboard:hover, #btn-csv:hover {
  background: var(--bg);
  color: var(--text);
}

/* ── Touch / Mobile ── */
@media (max-width: 768px) {
  #sidebar {
    width: 220px;
  }

  .shortcuts-hint {
    display: none;
  }

  #topbar {
    padding: 0 8px;
    height: 46px;
  }

  .topbar-left h1 {
    font-size: 14px;
  }

  #btn-export, #btn-import, #btn-dashboard, #btn-csv {
    padding: 5px 8px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  #sidebar {
    display: none;
  }

  #level-legend {
    bottom: 4px;
    left: 4px;
    padding: 4px 8px;
    gap: 6px;
  }

  .legend-item {
    font-size: 10px;
  }
}

/* ── Topbar Icon Buttons ── */
.topbar-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.topbar-icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.topbar-icon-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Multi-selection ── */
.rack.multi-selected,
.sector.multi-selected {
  box-shadow: 0 0 0 2px #8b5cf6, 0 2px 8px rgba(139, 92, 246, 0.3);
}

.rack.multi-selected::after,
.sector.multi-selected::after {
  content: '✓';
  position: absolute;
  top: -10px;
  left: -10px;
  width: 18px;
  height: 18px;
  background: #8b5cf6;
  color: white;
  border-radius: 50%;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Canvas Search ── */
#canvas-search {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 260px;
}

#canvas-search.hidden {
  display: none;
}

#canvas-search input {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  background: transparent;
  color: var(--text);
}

#canvas-search-results {
  max-height: 200px;
  overflow-y: auto;
}

.search-result-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border);
  color: var(--text);
}

.search-result-item:hover {
  background: var(--bg);
}

.search-result-type {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

/* ── Heatmap ── */
.rack.heatmap-empty {
  background: #22c55e !important;
  border-left-color: #16a34a !important;
}

.rack.heatmap-low {
  background: #84cc16 !important;
  border-left-color: #65a30d !important;
}

.rack.heatmap-medium {
  background: #eab308 !important;
  border-left-color: #ca8a04 !important;
}

.rack.heatmap-high {
  background: #f97316 !important;
  border-left-color: #ea580c !important;
}

.rack.heatmap-full {
  background: #ef4444 !important;
  border-left-color: #dc2626 !important;
}

#heatmap-legend {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  box-shadow: var(--shadow);
  font-size: 11px;
  color: var(--text-secondary);
}

#heatmap-legend .hl-title {
  font-weight: 600;
  margin-right: 4px;
  color: var(--text);
}

#heatmap-legend .hl-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: 4px;
}

/* ── List View ── */
#list-view {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 16px;
}

#list-view.hidden {
  display: none;
}

.list-view-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.list-view-table th {
  background: var(--bg);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.list-view-table td {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.list-view-table tr:hover td {
  background: var(--bg);
}

.list-view-table .rack-name-cell {
  font-weight: 600;
}

.list-view-table .level-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.list-view-table .items-cell {
  font-size: 12px;
  color: var(--text-secondary);
}

.list-view-table .empty-cell {
  color: var(--text-muted);
  font-style: italic;
}

.list-view-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-view-actions h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ── Inventory Mode ── */
.inventory-rack-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.inventory-rack-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.inventory-rack-header.checked {
  background: rgba(34, 197, 94, 0.1);
}

.inventory-rack-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.inventory-check {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.15s;
}

.inventory-check.done {
  background: #22c55e;
  border-color: #22c55e;
  color: white;
}

.inventory-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.inventory-item-row:last-child {
  border-bottom: none;
}

.inventory-count-input {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  background: var(--surface);
  color: var(--text);
}

.inventory-count-input.mismatch {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
}

.inventory-count-input.match {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.05);
}

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

.inventory-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.inventory-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.inventory-progress-fill {
  height: 100%;
  background: #22c55e;
  border-radius: 4px;
  transition: width 0.3s;
}

.inventory-progress-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Category Icons in Racks ── */
.rack-category-icons {
  position: absolute;
  bottom: -6px;
  right: 4px;
  display: flex;
  gap: 1px;
  font-size: 10px;
  line-height: 1;
}

/* ── Dark theme misc overrides ── */
[data-theme="dark"] .image-upload-area:hover,
[data-theme="dark"] .image-upload-area.dragover {
  background: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] #action-bar button.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

[data-theme="dark"] .item-card-actions button:hover {
  background: var(--border);
}

[data-theme="dark"] .item-card-actions button.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}
