/* ==========================================================================
   3D Studio - Comprehensive Design System & Stylesheet
   Theme: Modern Dark Glassmorphism (v3.0 CAD & Raytracing Suite)
   ========================================================================== */

:root {
  --bg-dark: #090d16;
  --bg-panel: rgba(18, 24, 38, 0.8);
  --bg-panel-solid: #121826;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-hover: rgba(255, 255, 255, 0.08);
  --bg-active: rgba(59, 130, 246, 0.2);

  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #3b82f6;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-secondary: #8b5cf6;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.45);

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

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

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

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

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

.app-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: #fff;
}

.app-title small {
  font-size: 11px;
  font-weight: 500;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
}

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

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

.tool-group {
  display: flex;
  gap: 4px;
}

/* Buttons System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

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

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

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.45);
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: 1px solid var(--border-color);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.btn-xs:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg-hover);
  color: #fff;
}

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

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

/* Dropdown Menu */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 210px;
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glass);
  padding: 6px;
  display: none;
  z-index: 200;
}

.dropdown:hover .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-main);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: var(--bg-hover);
  color: #fff;
}

/* --------------------------------------------------------------------------
   Workspace Main Layout
   -------------------------------------------------------------------------- */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Sidebar Toolbar */
.left-palette {
  width: 80px;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 8px;
  overflow-y: auto;
  z-index: 10;
}

.palette-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.palette-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 0 4px 1px 4px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 50px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-btn i {
  font-size: 15px;
}

.tool-btn span {
  font-size: 9.5px;
  font-weight: 500;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.tool-btn.active {
  background: var(--bg-active);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: inset 0 0 12px rgba(59, 130, 246, 0.2);
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
}

.mode-btn:hover {
  background: var(--bg-hover);
  color: #fff;
}

.mode-btn.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

/* Center Viewport */
.viewport-area {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #1a2336 0%, #080c14 100%);
  overflow: hidden;
}

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

/* Viewport Overlays */
.viewport-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 20;
}

.viewport-overlay * {
  pointer-events: auto;
}

.viewport-overlay.top-left {
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewport-overlay.top-right {
  top: 14px;
  right: 14px;
}

.viewport-overlay.bottom-right {
  bottom: 14px;
  right: 14px;
}

.badge {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(8px);
}

.badge-accent {
  background: rgba(245, 158, 11, 0.25);
  border-color: var(--accent-warning);
  color: #fbbf24;
}

.info-tag {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-muted);
  backdrop-filter: blur(8px);
}

#view-cube-container {
  width: 100px;
  height: 100px;
}

/* --------------------------------------------------------------------------
   Quad-Viewport Dividers & Badges
   -------------------------------------------------------------------------- */
.quad-view-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

.quad-divider-h {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: rgba(59, 130, 246, 0.35);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.quad-divider-v {
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(59, 130, 246, 0.35);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.quad-label {
  position: absolute;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #93c5fd;
  background: rgba(15, 23, 42, 0.7);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid rgba(59, 130, 246, 0.3);
  backdrop-filter: blur(4px);
}

.top-left-label { top: 8px; left: 8px; }
.top-right-label { top: 8px; left: calc(50% + 8px); }
.bottom-left-label { top: calc(50% + 8px); left: 8px; }
.bottom-right-label { top: calc(50% + 8px); left: calc(50% + 8px); }

/* --------------------------------------------------------------------------
   Push / Pull Tool In-Scene HUD
   -------------------------------------------------------------------------- */
.pushpull-hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--accent-warning);
  backdrop-filter: blur(16px);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 50;
}

.pushpull-hud p {
  font-size: 11px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Floating Context Booleans HUD
   -------------------------------------------------------------------------- */
.context-booleans-hud {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(59, 130, 246, 0.4);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(59, 130, 246, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 50;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.hud-header {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.hud-title {
  font-weight: 700;
  color: #60a5fa;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-subtitle {
  color: var(--text-muted);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 10px;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

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

.sidebar-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 10px 2px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tab-btn i {
  font-size: 12px;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

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

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-primary);
  margin-top: 4px;
}

.help-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.csg-node-banner {
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-md);
  padding: 10px;
}

.csg-badge {
  font-size: 11px;
  font-weight: 700;
  color: #c4b5fd;
  display: flex;
  align-items: center;
  gap: 6px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 10px;
  color: var(--text-dim);
  gap: 12px;
}

.empty-state i {
  font-size: 36px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 13px;
  line-height: 1.5;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.input-text, .input-select, .input-num {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
  transition: border 0.2s;
}

.input-text:focus, .input-select:focus, .input-num:focus {
  border-color: var(--border-focus);
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

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

.vector-input-group label {
  font-size: 11px;
  color: var(--text-dim);
}

input[type="range"] {
  accent-color: var(--accent-primary);
  width: 100%;
  cursor: pointer;
}

.input-color {
  width: 100%;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: none;
  cursor: pointer;
}

/* Material Presets Grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.material-preset-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
}

.material-preset-btn:hover {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Outliner Tree */
.outliner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.outliner-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.outliner-item {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  overflow: hidden;
}

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

.outliner-item.selected {
  background: var(--bg-active);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.outliner-item-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
}

.outliner-item .item-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.outliner-item .item-actions {
  display: flex;
  gap: 6px;
  opacity: 0.6;
}

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

/* Nested Outliner Children for CSG Node */
.outliner-children {
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
  padding: 4px 8px 6px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.outliner-child-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
}

.outliner-child-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.outliner-child-item.child-selected {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-secondary);
  color: #c4b5fd;
}

/* --------------------------------------------------------------------------
   2D Sketch Modal
   -------------------------------------------------------------------------- */
.sketch-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.sketch-modal.hidden {
  display: none;
}

.sketch-modal-content {
  width: 680px;
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sketch-modal-header h3 {
  font-family: var(--font-heading);
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-primary);
}

.sketch-body {
  display: flex;
  padding: 20px;
  gap: 20px;
}

.sketch-canvas-container {
  background: #0d131f;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
}

#sketch-2d-canvas {
  background: radial-gradient(circle at center, #1b263b 0%, #0d131f 100%);
  cursor: crosshair;
  border-radius: var(--radius-sm);
}

.sketch-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   Bottom Status Bar
   -------------------------------------------------------------------------- */
.app-footer {
  height: 28px;
  background: rgba(5, 8, 14, 0.95);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  font-size: 11px;
  color: var(--text-dim);
  z-index: 100;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-item span {
  color: var(--text-main);
  font-weight: 500;
}

/* Utility Helpers */
.hidden { display: none !important; }
.w-full { width: 100%; }
.margin-top { margin-top: 12px; }
.margin-top-lg { margin-top: 20px; }
.margin-bottom { margin-bottom: 8px; }
.text-xs { font-size: 10px; }
.btn-group { display: flex; gap: 4px; }
