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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-panel: #0f3460;
  --bg-input: #1a1a3e;
  --accent: #00d4ff;
  --accent-dim: #0097b2;
  --accent-glow: rgba(0, 212, 255, 0.3);
  --text-primary: #e0e0e0;
  --text-secondary: #8899aa;
  --text-muted: #556677;
  --border: #2a2a4e;
  --danger: #ff4466;
  --success: #44ff88;
  --warning: #ffaa44;
  --font-mono: 'SF Mono', 'Consolas', 'Monaco', 'Menlo', 'Courier New', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', 'Arial', sans-serif;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

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

/* Toolbar */
#toolbar {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  min-height: 36px;
}

.toolbar-row + .toolbar-row {
  border-top: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
}

.toolbar-group + .toolbar-group {
  border-left: 1px solid var(--border);
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  position: relative;
}

.toolbar-btn:hover {
  background: var(--bg-panel);
  border-color: var(--border);
}

.toolbar-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.toolbar-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.toolbar-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  background: #000;
  color: var(--text-primary);
  font-size: 11px;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}

.toolbar-btn:hover[data-tooltip]::after {
  opacity: 1;
}

.toolbar-label {
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 6px;
  user-select: none;
}

.toolbar-shortcut {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #ffffff;
  padding: 2px 5px;
  background: #000000;
  border: 1px solid #444;
  border-radius: 4px;
  user-select: none;
  white-space: nowrap;
  line-height: 1.2;
}

/* Main Content */
#main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Side Panels */
#left-panel, #right-panel {
  width: 220px;
  min-width: 180px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

#right-panel {
  border-right: none;
  border-left: 1px solid var(--border);
  width: 240px;
}

.panel-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Firefox scrollbar */
.panel-body {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Webkit scrollbar */
.panel-body::-webkit-scrollbar {
  width: 6px;
}

.panel-body::-webkit-scrollbar-track {
  background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Viewport */
#viewport-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
}


/* Big length overlay while drawing */
#length-overlay {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 48px;
  font-weight: 700;
  color: #ff2244;
  text-shadow: 0 0 20px rgba(255, 34, 68, 0.5), 0 2px 4px rgba(0,0,0,0.8);
  pointer-events: none;
  user-select: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.15s;
  letter-spacing: 2px;
}

#length-overlay.visible {
  opacity: 1;
}

/* Status Bar */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-height: 24px;
  flex-shrink: 0;
}

/* Property Controls */
.prop-group {
  margin-bottom: 12px;
}

.prop-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-dim);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.prop-row {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  gap: 6px;
}

.prop-label {
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 60px;
  flex-shrink: 0;
}

.prop-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.15s;
}

.prop-input:focus {
  border-color: var(--accent);
}

.prop-input::-webkit-inner-spin-button {
  opacity: 0.5;
}

select.prop-input {
  cursor: pointer;
  appearance: auto;
}

/* Tube List Items */
.tube-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
  user-select: none;
}

.tube-item:hover {
  background: var(--bg-panel);
}

.tube-item.selected {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
}

.tube-item .tube-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tube-item .tube-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tube-item .tube-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.tube-item:hover .tube-actions {
  opacity: 1;
}

.tube-action-btn {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tube-action-btn:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.tube-action-btn.delete:hover {
  color: var(--danger);
}

/* Buttons */
.btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: var(--bg-panel);
  border-color: var(--accent-dim);
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
}

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

.btn-danger {
  border-color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 68, 102, 0.2);
  color: var(--danger);
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
}

/* Checkbox toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.toggle-switch {
  position: relative;
  width: 32px;
  height: 18px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  left: 2px;
  top: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(14px);
  background: white;
}

/* No tubes message */
.empty-message {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* Color picker input */
input[type="color"].prop-input {
  padding: 1px;
  height: 26px;
  cursor: pointer;
}

/* Section divider in properties */
.prop-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* Help Overlay */
#help-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#help-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.help-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  width: 620px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 40px var(--accent-glow);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.help-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.help-close:hover {
  color: var(--text-primary);
}

.help-body {
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.help-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent-dim);
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}

.help-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.help-row kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  white-space: nowrap;
  min-width: 20px;
  text-align: center;
}

.help-row span {
  flex: 1;
}

/* List Section Headers */
.list-section-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-dim);
  padding: 8px 8px 4px 8px;
  user-select: none;
}

.list-section-header.ref-section-header {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  color: var(--warning);
}

/* Reference Model List Items */
.ref-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
  user-select: none;
}

.ref-item:hover {
  background: var(--bg-panel);
}

.ref-item.selected {
  background: rgba(255, 170, 68, 0.15);
  border: 1px solid var(--warning);
}

.ref-item.multi-selected {
  background: rgba(255, 170, 68, 0.1);
  border: 1px solid rgba(255, 170, 68, 0.4);
}

.ref-item .ref-icon {
  flex-shrink: 0;
  color: var(--warning);
  display: flex;
  align-items: center;
}

.ref-item .ref-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-item .tube-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.ref-item:hover .tube-actions {
  opacity: 1;
}

/* Ghost (unreimported) ref model entries */
.ref-item.ghost {
  opacity: 0.5;
}

.ref-item.ghost .ref-name {
  font-style: italic;
}

.ref-ghost-hint {
  font-size: 9px;
  color: var(--warning);
  background: rgba(255, 170, 68, 0.15);
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
}

.ref-ghost-hint:hover {
  background: rgba(255, 170, 68, 0.3);
}

/* Range slider for opacity etc. */
.prop-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.prop-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.prop-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

/* Length warning styles for fixture presets */
.length-warning { color: #ffaa44; }
.length-exceeded { color: #ff4444; }

/* Tube grouping styles */
.tube-item.grouped {
  border-left: 3px solid transparent;
}

.tube-item.multi-selected {
  background: rgba(0, 212, 255, 0.12);
}

.tube-item.multi-selected.selected {
  background: var(--accent-glow);
}

.tube-group-badge {
  flex-shrink: 0;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  margin-right: -2px;
}

/* View select dropdown */
.toolbar-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  padding: 3px 6px;
  font-size: 11px;
  font-family: var(--font-ui);
  cursor: pointer;
  outline: none;
  height: 26px;
}

.toolbar-select:focus {
  border-color: var(--accent);
}

/* Isolation mode indicator */
.isolation-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--warning);
  font-size: 11px;
  font-weight: 600;
  animation: isolation-pulse 1.5s ease-in-out infinite;
}

@keyframes isolation-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Marquee selection overlay */
.marquee-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

.marquee-overlay.active {
  pointer-events: auto;
  cursor: crosshair;
}

.marquee-rect {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(0, 212, 255, 0.1);
  pointer-events: none;
}

/* Custom Fixture Dialog */
.custom-fixture-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.custom-fixture-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.custom-fixture-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 40px var(--accent-glow);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.custom-fixture-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.custom-fixture-body {
  padding: 16px 20px;
}
.custom-fixture-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.cfd-quick-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  padding-left: 66px;
}
.cfd-quick-btn {
  padding: 2px 6px !important;
  font-size: 10px !important;
}

/* Splash Screen */
#splash-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 1s;
}
#splash-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.splash-logo {
  width: 200px;
  margin-bottom: 20px;
  filter: invert(1);
}
.splash-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--accent);
}
.splash-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
  letter-spacing: 2px;
}
