@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-dark: #090d16;
  --bg-panel: #111827;
  --bg-panel-secondary: #1f2937;
  --bg-card: #182232;
  --bg-input: #0f172a;
  --border-color: #1e293b;
  --border-light: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-cyan: #06b6d4;
  --accent-cyan-hover: #0891b2;
  --accent-emerald: #10b981;
  --accent-indigo: #6366f1;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --focus-ring: rgba(6, 182, 212, 0.4);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-panel: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --header-height: 54px;
  --footer-height: 28px;
  --toolbar-width: 56px;
  --sidebar-width: 320px;
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.4;
}

/* App Container */
#app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.4);
}

.brand-icon svg {
  width: 16px;
  height: 16px;
  stroke: white;
}

.project-name-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.project-name-input:hover, .project-name-input:focus {
  background: var(--bg-input);
  border-color: var(--border-light);
  outline: none;
}

.header-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  padding: 3px 6px;
  border-radius: var(--radius-md);
}

.unit-selector {
  display: flex;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.unit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.unit-btn.active {
  background-color: var(--accent-cyan);
  color: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-panel-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background-color: var(--border-color);
  border-color: var(--border-light);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-cyan-hover));
  border: none;
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.4);
}

.btn-emerald {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  border: none;
  color: white;
  font-weight: 600;
}

.btn-icon-only {
  padding: 6px;
}

.btn svg {
  width: 14px;
  height: 14px;
}

/* Main Workspace Layout */
.app-workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height) - var(--footer-height));
  position: relative;
}

/* Left Toolbar */
.toolbar {
  width: var(--toolbar-width);
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
  z-index: 60;
}

.tool-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.tool-section-label {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.tool-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background-color: var(--bg-panel-secondary);
  color: var(--text-main);
  border-color: var(--border-light);
}

.tool-btn.active {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(59, 130, 246, 0.15));
  color: var(--accent-cyan);
  border-color: rgba(6, 182, 212, 0.4);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

.toolbar-divider {
  width: 30px;
  height: 1px;
  background-color: var(--border-color);
  margin: 4px 0;
}

/* Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background-color: #020617;
  color: #f8fafc;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10000;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-panel);
}

.floating-controls [data-tooltip]::after,
.sidebar [data-tooltip]::after {
  left: 50%;
  top: auto;
  bottom: 100%;
  transform: translateX(-50%);
  margin-left: 0;
  margin-bottom: 8px;
}

.simulation-bar [data-tooltip]::after,
.header [data-tooltip]::after {
  left: 50%;
  top: 100%;
  bottom: auto;
  transform: translateX(-50%);
  margin-left: 0;
  margin-top: 8px;
}

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

/* Canvas Area */
.canvas-container {
  flex: 1;
  position: relative;
  background-color: var(--bg-dark);
  overflow: hidden;
}

#viewport-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Simulation Controls Bar Overlay */
.simulation-bar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(10, 15, 29, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: 10px;
  padding: 6px 16px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  z-index: 100;
  width: 880px;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  user-select: none;
  touch-action: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.simulation-bar.is-dragging {
  border-color: #38bdf8;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85), 0 0 20px rgba(56, 189, 248, 0.45);
}

.sim-bookmarks { display: flex; gap: 3px; max-width: 150px; overflow-x: auto; }
.sim-bookmark, .sim-bookmark-add { font-size: 10px; padding: 3px 5px; white-space: nowrap; }

.history-popup { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 300; width: 210px; padding: 8px; background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: var(--radius-md); box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.history-popup-header { display: flex; justify-content: space-between; color: var(--text-main); font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.history-popup-header button { background: none; border: 0; color: var(--text-muted); cursor: pointer; }
.history-entry { display: block; width: 100%; text-align: left; padding: 5px 7px; margin: 2px 0; color: var(--text-main); background: transparent; border: 0; border-radius: 4px; cursor: pointer; font-size: 11px; }
.history-entry:hover { background: var(--bg-input); color: var(--accent-cyan); }
.history-empty { display: block; color: var(--text-muted); font-size: 11px; padding: 5px; }

.sim-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
  opacity: 0.65;
  cursor: grab;
  padding: 4px 2px;
  transition: opacity 0.15s ease, transform 0.15s ease;
  flex: 0 0 auto;
}

.sim-drag-handle:hover {
  opacity: 1;
  transform: scale(1.15);
}

.sim-drag-handle:active {
  cursor: grabbing;
}

.sim-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

#btn-sim-play {
  width: 95px;
  min-width: 95px;
  max-width: 95px;
  justify-content: center;
  text-align: center;
  flex: 0 0 95px;
  box-sizing: border-box;
}

#btn-sim-reset {
  width: 74px;
  min-width: 74px;
  max-width: 74px;
  justify-content: center;
  text-align: center;
  flex: 0 0 74px;
  box-sizing: border-box;
}

.sim-center {
  flex: 1 1 auto;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.sim-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-left: 4px;
}

.sim-speed-selector {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  flex: 0 0 auto;
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  box-sizing: border-box;
}

.form-select-sm {
  background-color: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 5px;
  color: var(--text-main);
  padding: 3px 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.form-select-sm:hover, .form-select-sm:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.25);
}

.sim-range {
  flex: 1 1 auto;
  width: 100%;
  min-width: 60px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.sim-time-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: #94a3b8;
  white-space: nowrap;
  flex: 0 0 120px;
  width: 120px;
  min-width: 120px;
  letter-spacing: 0.3px;
  box-sizing: border-box;
  overflow: hidden;
}

.sim-time-label .sim-time-cur {
  color: #38bdf8;
  font-weight: 800;
}

.sim-time-label .sim-time-sep {
  color: #64748b;
  font-weight: 400;
  padding: 0 1px;
}

.sim-time-label .sim-time-tot {
  color: #94a3b8;
}

.sim-tool-badge {
  font-size: 10.5px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  flex: 0 0 145px;
  width: 145px;
  min-width: 145px;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sim-tool-badge:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: #fbbf24;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
  transform: translateY(-1px);
}

.sim-hud {
  background-color: rgba(3, 7, 18, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 5px;
  padding: 3px 8px;
  flex: 0 0 165px;
  width: 165px;
  min-width: 165px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6);
}

.sim-hud-line {
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: #38bdf8;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* Floating Controls Overlay (Zoom & Viewport) */
.floating-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 15, 29, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: 10px;
  padding: 5px 8px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  z-index: 35;
  user-select: none;
  touch-action: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.floating-controls.is-dragging {
  border-color: #38bdf8;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85), 0 0 20px rgba(56, 189, 248, 0.45);
}

.floating-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
  opacity: 0.65;
  cursor: grab;
  padding: 4px 2px;
  margin-left: 2px;
  transition: opacity 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.floating-drag-handle:hover {
  opacity: 1;
  transform: scale(1.15);
}

.floating-drag-handle:active {
  cursor: grabbing;
}

.floating-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  min-width: 28px;
  width: auto;
  height: 28px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.floating-btn.active {
  background-color: var(--accent-cyan);
  color: white;
}

/* Grid button's third state: grid visible through a translucent board layer */
.floating-btn.grid-overlay {
  background-color: var(--accent-amber);
  color: white;
}

.grid-intensity-popup {
  position: absolute;
  right: 76px;
  top: 38px;
  z-index: 20;
  width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.grid-intensity-popup[hidden] { display: none; }
.grid-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -2px -2px 8px;
  color: var(--text-main);
  font-size: 11px;
  font-weight: 600;
}
.grid-popup-header button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
}
.grid-popup-header button:hover { color: var(--text-main); }
.grid-intensity-popup label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 10px;
}
.grid-intensity-popup output { color: var(--text-main); }
.grid-intensity-popup input { width: 100%; accent-color: var(--accent-cyan); }
.grid-preset-row { display: flex; gap: 4px; margin: 7px 0; }
.grid-preset-row button {
  flex: 1; border: 1px solid var(--border-color); border-radius: 3px;
  background: transparent; color: var(--text-muted); font: inherit; font-size: 9px; padding: 3px 2px; cursor: pointer;
}
.grid-preset-row button:hover { color: var(--text-main); border-color: var(--accent-cyan); }
.entity-visibility, .entity-lock {
  border: 0; background: transparent; color: var(--text-dim); cursor: pointer; padding: 1px 2px; font-size: 11px;
}
.entity-visibility:hover, .entity-lock:hover { color: var(--accent-cyan); }
.entity-item[aria-hidden="true"] { opacity: 0.55; }

.floating-select {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  height: 28px;
  border-radius: var(--radius-sm);
  padding: 0 6px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s;
}

.floating-select:hover,
.floating-select:focus {
  border-color: var(--accent-cyan);
  color: var(--text-main);
}

.floating-select option {
  background-color: var(--bg-panel-secondary);
  color: var(--text-main);
}

.floating-divider {
  width: 1px;
  height: 18px;
  background-color: var(--border-color);
}

.zoom-label {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

/* Right Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

/* Sidebar Tabs Navigation */
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background-color: var(--bg-dark);
  border-bottom: 1px solid var(--border-color);
  padding: 4px;
  gap: 2px;
}

.sidebar-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 9.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-tab svg {
  width: 15px;
  height: 15px;
}

.sidebar-tab:hover {
  background-color: var(--bg-panel-secondary);
  color: var(--text-main);
}

.sidebar-tab.active {
  background-color: var(--bg-panel);
  color: var(--accent-cyan);
  border-color: var(--border-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Tool Library Card Component */
.tool-library-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-library-card:hover {
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(56, 189, 248, 0.4);
}

.tool-library-card.active {
  background: rgba(14, 116, 144, 0.25);
  border-color: var(--accent-cyan);
  box-shadow: inset 0 0 8px rgba(6, 182, 212, 0.2);
}

.tool-card-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.tool-card-body {
  flex: 1;
  min-width: 0;
}

.tool-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-card-meta {
  font-size: 9.5px;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
  margin-top: 1px;
}

.tool-card-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.empty-state-card {
  margin: 20px 16px;
  padding: 24px 16px;
  background-color: rgba(15, 23, 42, 0.5);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.empty-state-card svg {
  width: 32px;
  height: 32px;
  color: var(--text-dim);
}

.empty-state-card span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.empty-state-card p {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
}

.sidebar-section {
  border-bottom: 1px solid var(--border-color);
  padding: 14px 16px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-cyan);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width {
  grid-column: span 2;
}

label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-unit input, .form-input, .form-select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 6px 8px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  transition: all 0.15s;
}

.input-with-unit input {
  padding-right: 28px;
}

.input-unit-tag {
  position: absolute;
  right: 6px;
  font-size: 10px;
  color: var(--text-dim);
  pointer-events: none;
  font-weight: 600;
}

.form-input:focus, .input-with-unit input:focus, .form-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--focus-ring);
  outline: none;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* Layer & Shape List */
.entity-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
  margin-top: 8px;
}

.entity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.15s;
}

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

.entity-item.selected {
  background-color: rgba(6, 182, 212, 0.12);
  border-color: var(--accent-cyan);
}

.entity-name {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.entity-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background-color: var(--bg-panel-secondary);
  color: var(--accent-cyan);
  font-family: 'JetBrains Mono', monospace;
}

.entity-group-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background-color: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-weight: 600;
  margin-left: 2px;
}

.entity-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  min-width: 18px;
  text-align: center;
}

.entity-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.entity-move {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 4px;
  width: 18px;
  height: 18px;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.entity-move:hover {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

/* Footer Status Bar */
.app-footer {
  height: var(--footer-height);
  background-color: var(--bg-dark);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  z-index: 20;
}

.status-left, .status-center, .status-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.status-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 0.5px;
}

.status-val {
  color: var(--text-main);
  font-size: 11px;
}

.shortcut-hints {
  display: flex;
  align-items: center;
  gap: 5px;
}

.shortcut-pill {
  font-size: 10px;
  color: var(--text-dim);
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  padding: 1px 6px;
  border-radius: 4px;
}

.shortcut-pill b {
  color: var(--text-muted);
}

/* Transient status toast (e.g. stock thickness clamp warnings) */
.status-toast {
  position: fixed;
  bottom: calc(var(--footer-height, 32px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(120, 53, 15, 0.28);
  border: 1px solid rgba(245, 158, 11, 0.65);
  color: #fcd34d;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-toast.visible {
  opacity: 1;
}

/* Right-click context menu (node/segment actions) */
.context-menu {
  position: fixed;
  z-index: 2000;
  min-width: 160px;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
}

.context-menu .ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.context-menu .ctx-item:hover {
  background-color: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
}

.context-menu .ctx-item.danger:hover {
  background-color: rgba(244, 63, 94, 0.15);
  color: #f43f5e;
}

.context-menu .ctx-sep {
  height: 1px;
  margin: 4px 6px;
  background-color: var(--border-light);
}

/* Entity header + overlap/nesting inspection section in the context menu */
.context-menu .ctx-entity-header {
  padding: 6px 12px 5px;
  font-size: 11px;
  font-weight: 600;
  color: #38bdf8;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
  white-space: nowrap;
}

.context-menu .ctx-overlap-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 12px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim);
}

.context-menu .ctx-overlap-item .ov-icon {
  color: #38bdf8;
  flex-shrink: 0;
}

.context-menu .ctx-overlap-item.muted {
  opacity: 0.75;
}

.context-menu .ctx-overlap-item.selectable {
  cursor: pointer;
  border-radius: 6px;
}

.context-menu .ctx-overlap-item.selectable:hover {
  background-color: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
}

.context-menu .ctx-overlap-item.selectable:hover .ov-icon {
  color: #38bdf8;
}

/* Tool Switcher Quick Menu */
.tool-switch-menu {
  z-index: 9999;
  min-width: 250px;
  max-width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.7), 0 0 15px rgba(56, 189, 248, 0.15);
  border-radius: 8px;
  padding: 6px;
}

.tool-switch-menu .tool-menu-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px 3px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 4px;
}

.tool-switch-menu .tool-menu-group-title {
  font-size: 9.5px;
  font-weight: 700;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px 2px 8px;
}

.tool-switch-menu .tool-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  font-size: 11px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
}

.tool-switch-menu .tool-menu-item:hover {
  background: rgba(56, 189, 248, 0.15);
  color: #f8fafc;
}

.tool-switch-menu .tool-menu-item.active {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
  font-weight: 600;
}

.tool-switch-menu .tool-menu-item .tool-menu-num {
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
}

.tool-switch-menu .tool-menu-footer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 8px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  border: 1px dashed rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
  color: #38bdf8;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-switch-menu .tool-menu-footer-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  color: #fff;
  border-color: #38bdf8;
}

/* --- Live Depth Gauge HUD Overlay --- */
.depth-gauge-hud {
  position: absolute;
  top: 58px;
  right: 18px;
  width: 250px;
  max-width: 280px;
  background: rgba(10, 15, 29, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: 10px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 0 20px rgba(6, 182, 212, 0.06);
  padding: 11px 13px;
  z-index: 25;
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  overflow: hidden;
  transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.depth-gauge-hud.is-dragging {
  border-color: #38bdf8;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85), 0 0 20px rgba(56, 189, 248, 0.45);
  opacity: 0.96;
}

.depth-gauge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  padding-bottom: 7px;
  cursor: grab;
  touch-action: none;
  min-width: 0;
}

.depth-gauge-header:active {
  cursor: grabbing;
}

.hud-title-group {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-cyan);
  min-width: 0;
}

.hud-drag-handle {
  opacity: 0.65;
  flex-shrink: 0;
}

.depth-gauge-title {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #38bdf8;
  text-shadow: 0 0 8px rgba(56, 189, 248, 0.35);
  white-space: nowrap;
}

.hud-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hud-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud-badge.rapid {
  background: rgba(239, 68, 68, 0.22);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.45);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.2);
}

.hud-badge.cutting {
  background: rgba(16, 185, 129, 0.22);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.45);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.2);
}

.hud-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.15s ease;
}

.hud-close-btn:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.18);
}

.depth-gauge-body {
  display: flex;
  gap: 14px;
  align-items: stretch;
  min-width: 0;
}

.depth-scale-container {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.depth-scale-track {
  display: flex;
  gap: 7px;
  align-items: stretch;
  height: 110px;
}

.depth-scale-ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  color: #94a3b8;
  text-align: right;
  min-width: 24px;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
}

.depth-scale-ticks .zero {
  color: #38bdf8;
  font-weight: 800;
}

.depth-scale-bar {
  position: relative;
  width: 9px;
  border-radius: 5px;
  background: linear-gradient(to bottom,
    #38bdf8 0%,
    #34d399 26%,
    #fbbf24 65%,
    #f43f5e 100%
  );
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.depth-scale-fill {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px 4px 0 0;
}

.depth-pointer {
  position: absolute;
  left: -4px;
  right: -4px;
  height: 2px;
  background: #ffffff;
  box-shadow: 0 0 8px #ffffff, 0 0 14px rgba(56, 189, 248, 0.95);
  transition: top 0.04s linear;
  z-index: 2;
}

.depth-readouts {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.depth-readout-tool {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  box-sizing: border-box;
}

.depth-readout-tool:hover {
  background: rgba(245, 158, 11, 0.22);
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.28);
  transform: translateY(-1px);
}

.readout-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.readout-tool-icon {
  color: #fbbf24;
  opacity: 0.75;
  flex-shrink: 0;
}

.readout-tool-name {
  font-size: 10.5px;
  font-weight: 700;
  color: #fbbf24;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  min-width: 0;
  max-width: 100%;
}

.depth-readout-main {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-sizing: border-box;
}

.readout-label {
  font-size: 8.5px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.readout-val {
  font-size: 14.5px;
  font-weight: 800;
  color: #38bdf8;
  letter-spacing: 0.3px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.depth-readout-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 0;
}

.readout-mini {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  box-sizing: border-box;
}

.readout-mini-label {
  font-size: 8.5px;
  color: #94a3b8;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.readout-mini-val {
  font-size: 11px;
  font-weight: 700;
  color: #f8fafc;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-card.wide {
  max-width: 760px;
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  color: var(--text-main);
  background-color: var(--bg-panel-secondary);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* G-Code Viewer */
.gcode-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gcode-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background-color: var(--bg-dark);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.gcode-preflight { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); font-size: 11px; }
.gcode-preflight.is-ready { color: #86efac; border-color: rgba(34,197,94,.45); background: rgba(34,197,94,.08); }
.gcode-preflight.has-warning { color: #fcd34d; border-color: rgba(245,158,11,.45); background: rgba(245,158,11,.08); }
.gcode-preflight.is-blocked { color: #fda4af; border-color: rgba(244,63,94,.55); background: rgba(244,63,94,.1); }

.metric-box {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-val {
  font-size: 13px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-cyan);
}

.gcode-textarea {
  width: 100%;
  height: 320px;
  background-color: #030712;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
  white-space: pre;
}

.gcode-textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ==========================================================================
   Tool Change Notice inside Depth Gauge HUD
   ========================================================================== */

.depth-readout-tool.flashing-tool-change {
  animation: hudToolCardFlash 0.45s ease-in-out 4 !important;
  border-color: #f59e0b !important;
}

@keyframes hudToolCardFlash {
  0%, 100% {
    background-color: rgba(245, 158, 11, 0.22);
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.7), inset 0 0 10px rgba(245, 158, 11, 0.35);
    border-color: #fbbf24;
  }
  50% {
    background-color: rgba(15, 23, 42, 0.6);
    box-shadow: none;
    border-color: rgba(245, 158, 11, 0.2);
  }
}

.hud-tool-change-tag {
  font-size: 8px;
  font-weight: 800;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid #f59e0b;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-left: auto;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
  animation: hudTagPulse 0.45s infinite alternate ease-in-out;
}

@keyframes hudTagPulse {
  0% {
    transform: scale(0.92);
    opacity: 0.75;
  }
  100% {
    transform: scale(1.08);
    opacity: 1;
  }
}
