/* Configurateur 3D — thème clair/sombre, mise en page bureau et mobile, impression. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e6;
  --text: #1c2127;
  --muted: #66707b;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warning: #b26a00;
  --selected: #ff6a00;
  --viewer-bg: #eef1f4;
  --grid-major: #b9c2cc;
  --grid-minor: #d8dde3;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417;
    --surface: #1a1d21;
    --surface-2: #22262b;
    --border: #2f343a;
    --text: #e6e9ec;
    --muted: #98a2ad;
    --accent: #4c9eff;
    --accent-text: #0b1420;
    --danger: #ff6b5e;
    --warning: #f0b14a;
    --viewer-bg: #1d2126;
    --grid-major: #3a4149;
    --grid-minor: #2a3036;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.05rem; }
h2 { font-size: 0.95rem; margin-bottom: 10px; }
h3 { font-size: 0.9rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.tiny { font-size: 0.75rem; }
[hidden] { display: none !important; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 0.85rem; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.block { width: 100%; }
.btn.danger, .icon-btn.danger { color: var(--danger); }
.btn:disabled, .icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn {
  width: 30px; height: 30px; border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--text); font-size: 1rem; cursor: pointer; line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--surface-2);
  color: var(--muted); font-size: 0.75rem; text-align: center; font-weight: 500;
}

/* Barre du haut */
.app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.back { text-decoration: none; font-size: 1.2rem; color: var(--text); }
.tools { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle.small { font-size: 0.85rem; padding: 0 6px; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 220px; margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu-list button {
  width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.menu-list button:hover { background: var(--surface-2); }

/* Mise en page */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.stage { position: relative; min-height: 0; }
.viewer { position: absolute; inset: 0; overflow: hidden; background: var(--viewer-bg); }
.viewer canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.panel { overflow-y: auto; padding: 12px; border-left: 1px solid var(--border); background: var(--bg); }

.overlay {
  position: absolute; z-index: 5; background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.details { top: 12px; left: 12px; width: 280px; max-width: calc(100% - 24px); padding: 12px; }
.hint { bottom: 12px; left: 50%; transform: translateX(-50%); margin: 0; padding: 6px 12px; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.summary { margin: 0; display: grid; gap: 4px; }
.summary .row { display: flex; justify-content: space-between; gap: 12px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.summary.small { font-size: 0.85rem; }
.summary .total { font-weight: 700; border-top: 1px solid var(--border); padding-top: 4px; }

/* Étiquettes 3D */
.dim-label {
  padding: 2px 6px; border-radius: 4px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.dim-label.accent { background: var(--selected); border-color: var(--selected); color: #fff; }

/* Cartes du panneau */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; color: var(--muted); font-size: 0.85rem; }
.help {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-2); font-size: 0.7rem; cursor: help;
}
.number-row { display: flex; align-items: center; gap: 8px; }
.number-row input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
input[type="number"], select {
  min-height: 32px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.number-row input[type="number"] { width: 96px; flex: none; }
.unit { color: var(--muted); font-size: 0.8rem; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border: 1px solid var(--border);
  border-radius: 20px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dot { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 20%); }

/* Listes (usinages) */
.list + .list { margin-top: 16px; }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.list-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list-empty { margin: 0 0 4px; font-size: 0.85rem; }
.item { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; background: var(--surface-2); }
.item.selected { border-color: var(--selected); box-shadow: 0 0 0 1px var(--selected); }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.item-title { font-weight: 600; font-size: 0.85rem; }
.item-actions { display: flex; gap: 2px; }
.item-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-fields .field { margin: 0; }
.item-fields .number-row input[type="number"] { flex: 1; width: auto; min-width: 0; }

/* Champ mis en évidence depuis la vue 3D */
.field.selected { outline: 2px solid var(--selected); outline-offset: 4px; border-radius: 4px; }

/* Actions du produit (préréglages, aléatoire…) */
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* Éditeur de courbe */
.curve-editor { width: 100%; max-width: 300px; margin: 0 auto; height: auto; display: block; background: var(--surface-2); border-radius: 6px; touch-action: none; }
.curve-grid line { stroke: var(--border); stroke-width: 1; }
.curve-axis { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.curve-hull { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.curve-path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.curve-markers line { stroke: var(--selected); stroke-width: 1; stroke-dasharray: 5 3; }
.curve-markers text { fill: var(--selected); font-size: 10px; }
.curve-handle { fill: var(--surface); stroke: var(--accent); stroke-width: 2; cursor: grab; }
.curve-handle:hover, .curve-handle:focus-visible { fill: var(--accent); outline: none; }

/* Commande */
.price-total { margin: 10px 0; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.issues { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.issue { padding: 6px 10px; border-radius: 6px; font-size: 0.85rem; border-left: 3px solid; background: var(--surface-2); }
.issue.error { border-color: var(--danger); }
.issue.warning { border-color: var(--warning); }
.issue.clickable { cursor: pointer; }
.issue.clickable:hover { background: var(--border); }
.cart { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cart-item { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; font-size: 0.85rem; }
.cart-item .price { font-variant-numeric: tabular-nums; }
.cart-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.cart-actions strong { margin-right: auto; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 10px 16px;
  border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

/* Catalogue */
.catalog { min-height: 100dvh; }
.catalog-head { padding: 32px 16px 16px; max-width: 1100px; margin: 0 auto; }
.catalog-head h1 { font-size: 1.6rem; margin-bottom: 6px; }
.catalog main { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.tile h2 { font-size: 1.05rem; margin: 6px 0; }
.tile h2 a { text-decoration: none; }
.tile h2 a::after { content: " →"; }
.tile p { margin: 0; color: var(--muted); }
.tile.disabled { opacity: 0.6; box-shadow: none; }
.family { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.print-sheet { display: none; }

/* Mobile : vue 3D en haut, panneau dessous */
@media (max-width: 860px) {
  .app { height: auto; overflow: visible; }
  .layout { grid-template-columns: 1fr; }
  .stage { height: 55dvh; }
  .panel { border-left: 0; overflow: visible; padding: 12px 16px; }
  .details { display: none; }
  .hint { white-space: normal; width: calc(100% - 32px); text-align: center; }
  .tools .btn.ghost[data-view] { display: none; }
  .topbar { padding: 8px 16px; }
}

/* Impression : seule la fiche est imprimée */
@media print {
  body > *:not(.print-sheet) { display: none !important; }
  body { background: #fff; color: #000; height: auto; overflow: visible; }
  .print-sheet { display: block; padding: 0; font-size: 11pt; }
  .print-sheet h1 { font-size: 16pt; margin-bottom: 4px; }
  .print-sheet h2 { font-size: 12pt; margin: 16px 0 6px; }
  .print-sheet img { width: 100%; max-height: 90mm; object-fit: contain; border: 1px solid #ccc; }
  .print-sheet table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  .print-sheet th, .print-sheet td { border: 1px solid #bbb; padding: 3px 6px; text-align: left; }
  .print-sheet .summary dt { color: #444; }
}
