/* =========================================================================
   Sketch3D — styles.css
   CAD-style layout matching the bspline palette aesthetic.
   ========================================================================= */

/* ── 1. Reset & Tokens ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
*:not(svg *) { font-family: inherit; }

:root {
  --bg:           #f4f5f7;
  --bg-panel:     #ffffff;
  --bg-header:    #f0f1f3;
  --bg-input:     #eceef1;
  --bg-viewport:  #2a2d32;

  --text:         #1a1c20;
  --text-dim:     #6b7280;
  --text-inverse: #f0f1f3;

  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow:  rgba(59, 130, 246, 0.15);

  --success:      #22c55e;
  --warning:      #f59e0b;
  --danger:       #ef4444;

  --border:       #d1d5db;
  --border-light: #e5e7eb;

  --radius-sm:    4px;
  --radius-md:    6px;
  --radius-lg:    8px;

  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w:    300px;
  --header-h:     0px;

  --shadow-sm:    0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.08);
  --transition:   150ms ease;
}

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

#preview-canvas,
#resizer {
  touch-action: none;
}

/* ── 2. App Shell ───────────────────────────────────────────────────────── */
.cad-app-shell {
  display: flex;
  width: 100%; height: 100%;
  overflow: hidden;
}

/* ── 3. Sidebar ─────────────────────────────────────────────────────────── */
.cad-sidebar {
  width: var(--sidebar-w);
  min-width: 240px;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.logo-icon {
  font-size: 20px;
  line-height: 1;
}

.app-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  flex: 1;
}

.version-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── 4. Panels (collapsible) ────────────────────────────────────────────── */
.panel {
  border-bottom: 1px solid var(--border-light);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--bg-header);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.panel-header:hover { background: #e8eaed; }

.panel-icon { font-size: 13px; }
.panel-chevron {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
  transition: transform var(--transition);
}
.panel.collapsed .panel-chevron { transform: rotate(-90deg); }
.panel.collapsed .panel-body { display: none; }

.panel-body {
  padding: 10px 14px 14px;
}

/* ── 5. Drop Zone ───────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.drop-zone-inner p {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

.drop-icon {
  width: 32px; height: 32px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.btn-link {
  background: none; border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.btn-link:hover { color: var(--accent-hover); }

.drop-hint {
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.7;
}

/* ── 6. Thumbnail Preview ───────────────────────────────────────────────── */
.thumb-preview {
  position: relative;
  margin-top: 8px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-light);
}
.thumb-preview.hidden { display: none; }

.thumb-preview img {
  width: 100%;
  display: block;
  max-height: 160px;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.thumb-remove:hover { background: var(--danger); }

.thumb-info {
  padding: 4px 8px;
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-header);
}

/* ── 7. Mode Buttons ────────────────────────────────────────────────────── */
.mode-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text);
  transition: all var(--transition);
}
.mode-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.mode-btn.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: inset 3px 0 0 var(--accent);
}
.mode-btn strong { font-size: 12px; font-weight: 600; }
.mode-btn small { font-size: 10px; color: var(--text-dim); }
.mode-emoji { font-size: 20px; flex-shrink: 0; }

/* ── 8. Parameter Controls ──────────────────────────────────────────────── */
.param-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}
.param-row:first-child { margin-top: 0; }

.param-val {
  font-weight: 700;
  color: var(--accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.checkbox-row {
  gap: 6px;
  justify-content: flex-start;
}
.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px; height: 14px;
}

/* Slider */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-input);
  outline: none;
  margin: 2px 0 0;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
}

.mode-params { margin-top: 6px; }

/* ── 9. Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-fusion {
  background: #f97316;
  border-color: #f97316;
  color: #fff;
  margin-top: 6px;
}
.btn-fusion:hover:not(:disabled) {
  background: #ea580c;
  border-color: #ea580c;
  color: #fff;
}

.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.btn-export { font-size: 11px; padding: 7px 8px; }

.status-line {
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-dim);
  min-height: 14px;
  text-align: center;
}
.status-line[data-kind="ok"]   { color: var(--success); }
.status-line[data-kind="warn"] { color: var(--warning); }
.status-line[data-kind="error"]{ color: var(--danger); }
.status-line[data-kind="busy"] { color: var(--accent); }

/* ── 10. Resizer ────────────────────────────────────────────────────────── */
.cad-resizer {
  width: 5px;
  cursor: col-resize;
  background: var(--border-light);
  flex-shrink: 0;
  transition: background var(--transition);
}
.cad-resizer:hover,
.cad-resizer.active {
  background: var(--accent);
}

/* ── 11. Viewport ───────────────────────────────────────────────────────── */
.cad-viewport {
  flex: 1;
  position: relative;
  background: var(--bg-viewport);
  overflow: hidden;
  min-width: 200px;
}

#preview-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.viewport-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  pointer-events: none;
  user-select: none;
}
.viewport-empty.hidden { display: none; }
.empty-icon { font-size: 64px; margin-bottom: 12px; opacity: 0.6; }
.viewport-empty h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #6b7280;
}
.viewport-empty p {
  margin: 6px 0 0;
  font-size: 13px;
  color: #6b7280;
  opacity: 0.7;
}

/* Toolbar */
.viewport-toolbar {
  position: absolute;
  bottom: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(30, 32, 38, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

.tb-btn {
  width: 30px; height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #d1d5db;
  cursor: pointer;
  transition: all var(--transition);
}
.tb-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.tb-btn.active { background: var(--accent); color: #fff; }

.tb-sep {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,0.12);
  margin: 0 4px;
}

.tb-info {
  font-size: 10px;
  color: #9ca3af;
  padding: 0 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── 12. Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .cad-app-shell {
    flex-direction: column;
  }
  .cad-sidebar {
    width: 100% !important;
    max-width: 100%;
    height: auto;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .cad-resizer {
    width: 100%;
    height: 5px;
    cursor: row-resize;
  }
  .cad-viewport {
    min-height: 200px;
  }
}
