/* ── Catppuccin Mocha palette ─────────────────────────────────────────────── */
:root {
  --base:    #1e1e2e;
  --mantle:  #181825;
  --crust:   #11111b;
  --surface0:#313244;
  --surface1:#45475a;
  --surface2:#585b70;
  --overlay0:#6c7086;
  --overlay1:#7f849c;
  --text:    #cdd6f4;
  --subtext: #a6adc8;
  --blue:    #89b4fa;
  --sky:     #89dceb;
  --teal:    #94e2d5;
  --green:   #a6e3a1;
  --yellow:  #f9e2af;
  --peach:   #fab387;
  --red:     #f38ba8;
  --mauve:   #cba6f7;
  --accent:  #89b4fa;
  --accent2: #a6e3a1;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  background: var(--base);
  color: var(--text);
  overflow: hidden;
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  flex-shrink: 0;
  height: 40px;
}
.file-label  { color: var(--green); font-weight: 600; }
.dep-warn    { color: var(--peach); font-size: 11px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: calc(100vh - 40px - 30px);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 240px;
  max-width: 340px;
  background: var(--mantle);
  border-right: 1px solid var(--surface0);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  padding-bottom: 12px;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface1); border-radius: 3px; }

/* ── Collapsible panels ──────────────────────────────────────────────────── */
.panel {
  border-bottom: 1px solid var(--surface0);
}
.panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface0);
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.03em;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▶"; font-size: 9px; color: var(--overlay1); transition: transform 0.15s; }
.panel[open] > summary::before { transform: rotate(90deg); }
.panel > summary:hover { background: var(--surface1); }

.panel-body {
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Form elements ───────────────────────────────────────────────────────── */
label  { color: var(--subtext); }
.row   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

input[type="number"],
input[type="text"],
select {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
}
input[type="number"]:focus,
select:focus { outline: 1px solid var(--blue); }

input[type="range"] {
  flex: 1;
  accent-color: var(--blue);
  height: 4px;
  cursor: pointer;
}

.tilt-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tilt-val { color: var(--sky); min-width: 38px; text-align: right; font-size: 11px; }

.ax-label  { min-width: 44px; font-weight: 700; font-size: 11px; }

.dim-grid {
  display: grid;
  grid-template-columns: 24px 70px 80px;
  align-items: center;
  gap: 4px 6px;
}
.dim-val { color: var(--sky); font-size: 12px; }
.dim-entry { width: 80px; }

.hint { color: var(--overlay1); font-size: 11px; line-height: 1.4; }
.checkbox-row { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* Range track canvas */
.range-track-wrap { margin: 6px 0 2px; }
#range-canvas { width: 100%; height: 36px; cursor: pointer; background: transparent; }
.range-row { display: flex; align-items: center; gap: 4px; }
.range-lbl { color: var(--blue); min-width: 28px; font-weight: 700; }

.export-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button, .btn-primary, .btn-secondary, .btn-ghost {
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 10px;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--blue);
  color: var(--mantle);
  font-weight: 700;
}
.btn-primary:hover  { background: var(--sky); }
.btn-secondary {
  background: var(--surface1);
  color: var(--text);
}
.btn-secondary:hover { background: var(--surface2); }
.btn-ghost {
  background: transparent;
  color: var(--subtext);
  border: 1px solid var(--surface1);
}
.btn-ghost:hover { background: var(--surface0); color: var(--text); }
.btn-tiny {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  color: var(--text);
  border-radius: 3px;
  padding: 1px 7px;
  font-size: 13px;
  cursor: pointer;
}
.full-width { width: 100%; }

/* ── Viewport ────────────────────────────────────────────────────────────── */
.viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--base);
  padding: 6px 8px 6px;
}
.viewport-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--surface0);
  flex-shrink: 0;
}
.vp-title { font-weight: 700; color: var(--blue); font-size: 14px; }
.view-toggle { display: flex; gap: 12px; }
.view-toggle label { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--subtext); }
.view-toggle label:has(input:checked) { color: var(--text); }

.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #ffffff;
  border-radius: 6px;
  margin-top: 6px;
  cursor: crosshair;
  user-select: none;
}
#preview-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.preview-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--overlay1);
  font-size: 16px;
  line-height: 1.8;
  pointer-events: none;
}
.preview-hint.hidden { display: none; }

.spinner {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 22px;
  color: var(--blue);
  animation: spin 1s linear infinite;
}
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Rotation sliders below preview */
.rot-sliders {
  padding: 8px 0 4px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rot-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

/* ── Status bar ──────────────────────────────────────────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 30px;
  padding: 0 12px;
  background: var(--mantle);
  border-top: 1px solid var(--surface0);
  flex-shrink: 0;
  font-size: 11px;
  color: var(--overlay1);
}
#status-lbl { flex: 1; }
#progress-bar {
  width: 160px;
  height: 6px;
  accent-color: var(--green);
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: 10px;
  width: min(92vw, 940px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface0);
  border-bottom: 1px solid var(--surface1);
  flex-shrink: 0;
}
.modal-title { flex: 1; text-align: center; font-weight: 700; color: var(--text); font-size: 14px; }
.modal-legend {
  display: flex;
  gap: 16px;
  padding: 6px 14px;
  background: var(--base);
  flex-shrink: 0;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--subtext);
}
.pair-canvas-wrap {
  flex: 1;
  overflow: hidden;
  background: white;
  cursor: crosshair;
  min-height: 300px;
  position: relative;
}
.pair-canvas-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  /* transparent overlay for click capture */
}
.pair-click-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface0);
  border-top: 1px solid var(--surface1);
  flex-shrink: 0;
}

/* ── Project list ────────────────────────────────────────────────────────── */
.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--surface1);
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface0);
  transition: background 0.1s;
}
.project-item:hover { background: var(--surface1); }

/* ── File tree ───────────────────────────────────────────────────────────── */
.file-tree-node {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  border-radius: 3px;
}
.file-tree-icon { flex-shrink: 0; font-size: 13px; }
.file-tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.file-tree-size { color: var(--overlay1); font-size: 11px; flex-shrink: 0; }
.file-tree-dxf  { cursor: pointer; color: var(--blue); }
.file-tree-dxf:hover { background: var(--surface0); }

/* ── Sheet size list rows ────────────────────────────────────────────────── */
.sheet-size-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

/* ── Drag-and-drop highlight ─────────────────────────────────────────────── */
.canvas-wrap.dragover {
  outline: 3px dashed var(--blue);
  outline-offset: -3px;
}

/* ── Modal drag + resize ─────────────────────────────────────────────────── */
.modal-box { position: relative; }
.modal-header { user-select: none; }

.modal-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: se-resize;
  z-index: 20;
  background:
    linear-gradient(135deg, transparent 50%, var(--surface2) 50%),
    linear-gradient(135deg, transparent 60%, var(--overlay0) 60%);
  border-radius: 0 0 10px 0;
  opacity: 0.7;
}
.modal-resize-handle:hover { opacity: 1; }

/* ── Render preview modal ───────────────────────────────────────────────── */
#render-canvas { cursor: grab; }
#render-canvas:active { cursor: grabbing; }

/* ── Axis gizmo overlay ─────────────────────────────────────────────────── */
#axis-gizmo { display: block; }

/* ── Render sidebar sections ────────────────────────────────────────────── */
.render-section {
  border: 1px solid var(--surface0);
  border-radius: 5px;
  padding: 6px 8px 4px;
}
.render-section-title {
  color: var(--blue);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.03em;
  margin-bottom: 5px;
}
.render-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
}
.render-row label {
  min-width: 56px;
  font-size: 11px;
  color: var(--subtext);
  flex-shrink: 0;
}
