:root {
  /* Industrial CAD Color Palette */
  --cad-red-primary: #d32f2f;
  --cad-red-dark: #9a0007;
  --cad-red-hover: #b71c1c;
  --cad-red-light: rgba(211, 47, 47, 0.12);
  --cad-red-border: rgba(211, 47, 47, 0.4);

  /* CAD Slate & Metallic Workspace Grays */
  --bg-dark: #0f1217;
  --bg-header: #151921;
  --bg-panel: #181d27;
  --bg-panel-hover: #212735;
  --bg-input: #1e2430;

  /* Accent & Status Colors */
  --accent-cyan: #38bdf8;
  --accent-blue: #29b6f6;
  --accent-emerald: #34d399;
  --accent-purple: #c084fc;
  --accent-amber: #fbbf24;

  /* Text & Typography */
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Borders & Spacing */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: #2a3243;
  --border-active: var(--cad-red-primary);
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

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

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

/* App Header */
.app-header {
  height: 48px;
  background: var(--bg-header);
  border-bottom: 2px solid var(--cad-red-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 10;
}

.home-link {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  color: var(--accent-cyan);
  font: 700 11px var(--font-mono);
  text-decoration: none;
}

.home-logo {
  display: block;
  width: 28px;
  height: 28px;
  padding: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cad-icon {
  font-size: 18px;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  border-left: 1px solid var(--border-medium);
  padding-left: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.cad-status-tag {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
}

.header-info-button {
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  transition: all 0.15s ease;
}

.header-info-button:hover {
  background: var(--bg-panel-hover);
  border-color: var(--accent-cyan);
}

.info-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 10px;
  font-family: var(--font-mono);
}

/* Info Dialog */
.info-dialog:not([open]) {
  display: none;
}

.info-dialog {
  margin: auto;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 0;
  width: min(90vw, 540px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

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

.info-dialog-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-dialog-version {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--cad-red-light);
  color: var(--cad-red-primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.dialog-close-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.dialog-close-button:hover {
  color: var(--text-main);
}

.info-dialog-body {
  padding: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

.info-dialog-body p {
  margin-bottom: 12px;
}

.info-dialog-list {
  padding-left: 20px;
  margin-bottom: 14px;
}

.info-dialog-list li {
  margin-bottom: 6px;
}

.info-dialog-footer {
  padding: 12px 20px;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
}

.info-dialog-commit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* Workspace Layout */
.workspace {
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 240px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-medium);
  display: flex;
  flex-direction: column;
}

.sidebar-scroll-content {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.compact-drop-zone {
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-md);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-dark);
  transition: all 0.2s ease;
}

.compact-drop-zone:hover, .compact-drop-zone.dragover {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.05);
}

.drop-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-main);
  margin-bottom: 4px;
}

.drop-sublabel {
  font-size: 11px;
  color: var(--text-dim);
}

.sidebar-box {
  background: var(--bg-dark);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
}

.sidebar-box.flex-1 {
  flex: 1;
  display: flex;
  flex-direction: column;
}

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

.kv-table {
  width: 100%;
  font-size: 11px;
}

.kv-table td {
  padding: 3px 0;
}

.kv-key {
  color: var(--text-dim);
  width: 70px;
}

.kv-val {
  color: var(--text-main);
  font-family: var(--font-mono);
  word-break: break-all;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  text-align: left;
  transition: all 0.15s ease;
}

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

.nav-btn.active {
  background: var(--cad-red-light);
  border-color: var(--cad-red-border);
  color: #ff8a80;
  font-weight: 600;
}

.nav-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 10px;
  color: var(--text-muted);
}

.nav-btn.active .nav-badge {
  background: var(--cad-red-primary);
  color: #fff;
}

/* Main Panel */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  overflow: hidden;
}

.main-top-bar {
  height: 44px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.main-top-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.btn-grid {
  display: flex;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 11px;
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-panel-hover);
  border-color: var(--accent-cyan);
}

.btn-success {
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--accent-emerald);
}

.btn-success:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.25);
}

.main-scroll-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  position: relative;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Inspector Sections */
.inspector-section {
  margin-bottom: 28px;
  scroll-margin-top: 14px;
}

.inspector-section:last-child {
  margin-bottom: 60px;
}

.section-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dense-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.dense-table-wrapper {
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow-x: auto;
  max-height: 600px;
}

.dense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.dense-table th {
  background: var(--bg-header);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-medium);
  position: sticky;
  top: 0;
  z-index: 1;
}

.dense-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.dense-table tr:hover td {
  background: var(--bg-panel-hover);
}

/* 3D Viewer Container */
.viewer-3d-wrapper {
  position: relative;
  width: 100%;
  height: 580px;
  background: #0d1017;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.viewer-3d-wrapper.maximized {
  position: fixed;
  top: 48px;
  left: 0;
  width: 100vw;
  height: calc(100vh - 48px);
  z-index: 999;
  border-radius: 0;
  border: none;
}

#canvas-3d {
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-controls-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 10;
}

.viewer-info-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15, 18, 23, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.viewer-flyout-panel {
  position: absolute;
  top: 50px;
  right: 12px;
  width: 320px;
  max-height: 480px;
  background: rgba(24, 29, 39, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 14px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  display: none;
}

.viewer-flyout-panel.active {
  display: block;
}

.flyout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.flyout-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent-cyan);
}

/* Spatial Tree */
.tree-node {
  margin-left: 18px;
  border-left: 1px dashed var(--border-medium);
  padding-left: 10px;
  margin-top: 4px;
}

.tree-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-main);
  font-size: 12px;
}

.tree-header:hover {
  background: var(--bg-panel-hover);
}

.tree-icon {
  font-size: 13px;
}

.tree-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}

.drag-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 23, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.drag-overlay-content {
  text-align: center;
  color: var(--accent-cyan);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.drag-overlay-icon {
  font-size: 48px;
}

.drag-overlay-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.drag-overlay-subtext {
  font-size: 12px;
  color: var(--text-muted);
}
