/* ============================================================
   OpticLab — feuille de style unifiée
   DA claire d'atelier : canvas os, panneaux blancs, hairlines,
   un seul accent (bleu acier désaturé), numérique en mono.
   ============================================================ */

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

:root {
  --canvas:        #F6F4F0;
  --surface:       #FFFFFF;
  --surface-2:     #FAF8F4;
  --border:        #E7E3DC;
  --border-strong: #D8D3CA;
  --ink:           #1A1916;
  --ink-2:         #46423B;
  --muted:         #7D776C;
  --accent:        #3F5E85;
  --accent-soft:   #E9EFF6;
  --accent2:       #3F5E85; /* compat : référencé inline par selection.js */
  --danger:        #A33D3D;
  --danger-soft:   #F6E8E8;
  --warn:          #956400;
  --shadow-1:      0 1px 2px rgba(56, 50, 38, 0.05);
  --shadow-2:      0 6px 24px rgba(56, 50, 38, 0.08);
  --r-lg: 14px;
  --r-md: 8px;
  --r-sm: 6px;
  --font-ui:      'Outfit', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --ease:  cubic-bezier(0.22, 1, 0.36, 1);
  --ease-2: cubic-bezier(0.32, 0.72, 0, 1);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--canvas);
  color: var(--ink);
  overflow: hidden;
  line-height: 1.5;
}

button { font-family: inherit; }

::selection { background: var(--accent-soft); }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  user-select: none;
}
.logo-icon {
  font-size: 15px;
  color: var(--accent);
  transform: translateY(-1px);
}
.logo-text {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.logo-text em {
  font-style: italic;
  color: var(--accent);
}

/* Tabs — segmented control discret */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 220ms var(--ease), background 220ms var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Boutons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 200ms var(--ease), color 200ms var(--ease),
              border-color 200ms var(--ease), transform 150ms var(--ease-2),
              opacity 200ms var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
.btn svg { width: 14px; height: 14px; flex: none; }

.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover { background: #33302A; }

.btn-outline {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--muted); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ── Dropdown export ────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: 5px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 250ms var(--ease);
  z-index: 150;
}
.dropdown-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.dropdown-item {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.dropdown-item:hover { background: var(--surface-2); color: var(--ink); }

/* ── Structure principale ───────────────────────────────────── */
main {
  position: fixed;
  inset: 56px 0 0 0;
}
.tab-content {
  display: none;
  height: 100%;
}
.tab-content.active { display: flex; }

/* ── Panneau latéral flottant ───────────────────────────────── */
#tab-viewport { padding: 14px; gap: 14px; }

.sidebar {
  width: 316px;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 16px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: 0; }

.sidebar-title {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.info-block {
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
}
.info-block p { margin: 2px 0; }
.info-block span { font-family: var(--font-mono); font-size: 11px; color: var(--ink); }

.sel-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

/* ── Réglettes (sliders monture) ────────────────────────────── */
.prop-stack { display: flex; flex-direction: column; gap: 6px; }
.prop-stack label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.params-slider label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.params-slider .slider-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--ink);
  transition: color 200ms var(--ease);
}
.params-slider:has(input:active) .slider-val { color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--ink) var(--fill), var(--border-strong) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--ink);
  box-shadow: var(--shadow-1);
  transition: transform 250ms var(--ease-2), border-color 200ms var(--ease);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.2); }
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.35);
  border-color: var(--accent);
}
input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: var(--border-strong);
}
input[type="range"]::-moz-range-progress {
  height: 2px;
  border-radius: 1px;
  background: var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--ink);
  transition: transform 250ms var(--ease-2), border-color 200ms var(--ease);
}
input[type="range"]:active::-moz-range-thumb {
  transform: scale(1.35);
  border-color: var(--accent);
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

.range-readout {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
}

/* ── Sélecteur de partie + swatches couleur ─────────────────── */
.part-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.part-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 4px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 200ms var(--ease), color 200ms var(--ease),
              background 200ms var(--ease), transform 150ms var(--ease-2);
}
.part-chip svg { width: 34px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.4; }
.part-chip:hover { border-color: var(--border-strong); color: var(--ink-2); }
.part-chip:active { transform: scale(0.97); }
.part-chip.active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface-2);
}
.part-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatch-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.swatch {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: transform 200ms var(--ease-2), box-shadow 200ms var(--ease);
  /* léger vernis façon chip d'acétate */
  background-image: linear-gradient(145deg, rgba(255,255,255,0.28), rgba(255,255,255,0) 45%);
}
.swatch:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.swatch:active { transform: translateY(0) scale(0.95); }
.swatch.active {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatch-name {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
}

/* ── Panneau sauvegardes repliable ──────────────────────────── */
details.saves-panel summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}
details.saves-panel summary::-webkit-details-marker { display: none; }
details.saves-panel summary::before {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 250ms var(--ease);
}
details.saves-panel[open] summary::before { transform: rotate(45deg); }

.saves-list {
  margin-top: 10px;
  max-height: 170px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
}
.save-item {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-2);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-align: left;
  cursor: pointer;
  transition: background 150ms var(--ease), border-color 150ms var(--ease);
}
.save-item:hover { background: var(--surface-2); border-color: var(--border-strong); }
.saves-empty { color: var(--muted); font-size: 11px; padding: 4px 0; }

/* ── Toggles affichage ──────────────────────────────────────── */
.display-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.display-toggles label {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}
.display-toggles input[type="checkbox"] {
  appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: background 180ms var(--ease), border-color 180ms var(--ease);
}
.display-toggles input[type="checkbox"]::before {
  content: '';
  width: 8px;
  height: 8px;
  transform: scale(0);
  background: #fff;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  transition: transform 180ms var(--ease-2);
}
.display-toggles input[type="checkbox"]:checked {
  background: var(--ink);
  border-color: var(--ink);
}
.display-toggles input[type="checkbox"]:checked::before { transform: scale(1); }
.display-toggles input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Sculpture ──────────────────────────────────────────────── */
.sculpt-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.sculpt-mode-button {
  padding: 7px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 200ms var(--ease), color 200ms var(--ease), background 200ms var(--ease);
}
.sculpt-mode-button:hover { color: var(--ink-2); border-color: var(--border-strong); }
.sculpt-mode-button.active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface-2);
}

.sculpt-enabled .viewport-wrap canvas { cursor: crosshair; }

/* ── Viewport ───────────────────────────────────────────────── */
.viewport-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #f4f2ee; /* raccord avec G3D.scene.background */
}
.viewport-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.viewport-overlay {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 13px;
  pointer-events: none;
}

.welcome-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 5;
  pointer-events: none;
  text-align: center;
  animation: welcome-in 900ms var(--ease) both;
}
@keyframes welcome-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.welcome-overlay h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 40px;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin-bottom: 12px;
}
.welcome-overlay p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  max-width: 44ch;
  text-wrap: balance;
}

/* Zone de drop */
.drop-zone {
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: var(--r-md);
  background: rgba(63, 94, 133, 0.06);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease);
}
.drop-zone.drag-over { opacity: 1; }

/* ── Onglet Géométrie ───────────────────────────────────────── */
#tab-geometry { padding: 14px; }
.geo-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  min-height: 0;
}
.geo-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.geo-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
}
.geo-actions { display: flex; gap: 8px; }
.geo-stats {
  margin-left: auto;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
}

.tri-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
}
.tri-form h3 { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.tri-inputs { display: flex; gap: 18px; flex-wrap: wrap; }
.vertex-group { display: flex; align-items: center; gap: 6px; }
.vertex-group label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.vertex-group input {
  width: 74px;
  padding: 5px 7px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
}
.vertex-group input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tri-form-actions { margin-top: 12px; display: flex; gap: 8px; }

.tri-list-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.tri-list-header {
  display: grid;
  grid-template-columns: 60px 1fr 1fr 1fr 90px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.tri-list { flex: 1; overflow-y: auto; scrollbar-width: thin; }
.tri-row {
  display: grid;
  grid-template-columns: 60px 1fr 1fr 1fr 90px;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  cursor: pointer;
  transition: background 120ms var(--ease);
}
.tri-row:hover { background: var(--surface-2); }
.tri-row.selected { background: var(--accent-soft); }
.tri-idx {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.tri-verts, .coord {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 10.5px;
  color: var(--ink-2);
}
.tri-actions { display: flex; justify-content: flex-end; }
.tri-actions .btn { padding: 3px 9px; font-size: 10.5px; }
.tri-empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms var(--ease), transform 350ms var(--ease-2);
  z-index: 300;
  max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warn); }

/* ── Modale presets sculpture ───────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 22, 0.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms var(--ease);
  z-index: 250;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: 18px 20px 20px;
  width: min(420px, calc(100vw - 40px));
  transform: translateY(10px) scale(0.98);
  transition: transform 350ms var(--ease-2);
}
.modal-backdrop.open .modal-panel { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
}
.modal-close {
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: color 150ms var(--ease), background 150ms var(--ease);
}
.modal-close:hover { color: var(--ink); background: var(--surface-2); }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.preset-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 14px 6px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: 11.5px;
  cursor: pointer;
  transition: border-color 200ms var(--ease), background 200ms var(--ease),
              transform 150ms var(--ease-2);
}
.preset-button:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.preset-button:active { transform: scale(0.97); }
.preset-button.active { border-color: var(--ink); background: var(--surface-2); }
.preset-button svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

/* ── Divers ─────────────────────────────────────────────────── */
.oma-row .label { color: var(--muted); }
.oma-row .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--ink);
}

.sculpt-info p:first-child { font-weight: 500; }

/* Accessibilité : mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
