/* Couleurs, police et tailles : variables du thème du site (site/site.css, chargé avant). */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* --- Mise en page : desktop ------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 12px;
  height: calc(100dvh - var(--menu-height)); /* le menu du site occupe le haut (site.css) */
  padding: 12px;
}

.results {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.dimensions { margin: 0; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.stage {
  flex: 1;
  min-height: 0;
  padding: 16px;
  background: var(--stage);
  /* Le glissement de la ligne 2 est horizontal : le défilement vertical de la page reste possible. */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.stage svg { display: block; width: 100%; height: 100%; overflow: visible; }
.stage #line2, .stage #line3 { cursor: grab; }
.stage.dragging, .stage.dragging #line2, .stage.dragging #line3 { cursor: grabbing; }
.stage #case, .stage #gap, .stage #support { transition: opacity 0.1s; }
.stage.moving #case, .stage.moving #gap, .stage.moving #support { opacity: 0.35; }
.stage.stale svg { opacity: 0.35; }
.stage #dims { color: var(--muted); }
.stage #drag-hint { color: var(--accent); }

/* --- Vue 2D : dessin et feu tricolore côte à côte ---------------------------------- */

.stage-row { flex: 1; min-height: 0; display: flex; }
.stage-row .stage { flex: 1; min-width: 0; }

.status-panel, .side-panel {
  flex: none; width: 200px; overflow-y: auto; padding: 14px 12px;
  border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* --- Vue 3D : nom du projet et boutons ------------------------------------------- */

.project-panel { align-items: stretch; width: 220px; }
.project-panel .field { margin-bottom: 4px; }
.project-panel .hint, .project-message { margin: 0; font-size: 0.8rem; line-height: 1.35; }
.project-message { padding: 6px 8px; border-radius: 4px; background: var(--info-bg); color: var(--info-ink); }

/* Modification d'une création d'un autre par un administrateur (D-052) */
.edit-box {
  margin: 0; padding: 8px 10px; border-radius: 4px; border-left: 3px solid var(--warn);
  background: var(--warn-bg); color: var(--warn-ink); font-size: 0.8rem; line-height: 1.4;
  overflow-wrap: anywhere;
}
.edit-box strong { display: block; font-size: 0.85rem; }
.edit-box .hint { display: block; margin: 4px 0 0; color: inherit; font-size: 0.75rem; }
.designer-page.is-editing .pane-3d { box-shadow: inset 0 0 0 2px var(--warn); }
.project-panel > * { flex-shrink: 0; } /* le panneau défile plutôt que d'écraser un bouton */
.project-panel a.button { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.button {
  min-height: var(--touch); padding: 8px 12px; font: inherit; font-weight: 600; border-radius: 8px;
  cursor: pointer; transition: background 0.1s, opacity 0.1s;
}
.button:disabled { opacity: 0.45; cursor: default; }
.button-primary { color: var(--on-accent); background: var(--accent); border: 1px solid var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.button-secondary { color: var(--accent); background: var(--panel); border: 1px solid var(--accent); }
.button-secondary:hover:not(:disabled) { background: var(--hover); }
.traffic-light {
  display: flex; flex-direction: column; gap: 8px; padding: 9px;
  background: #2b2f36; border-radius: 14px;
}
.lamp { width: 26px; height: 26px; border-radius: 50%; opacity: 0.22; transition: opacity 0.15s, box-shadow 0.15s; }
.lamp-red { background: #e5332a; }
.lamp-orange { background: #f39c12; }
.lamp-green { background: #27ae60; }
.status-panel[data-light="red"] .lamp-red,
.status-panel[data-light="orange"] .lamp-orange,
.status-panel[data-light="green"] .lamp-green { opacity: 1; box-shadow: 0 0 12px currentColor; }
.status-panel[data-light="red"] .lamp-red { color: #e5332a; }
.status-panel[data-light="orange"] .lamp-orange { color: #f39c12; }
.status-panel[data-light="green"] .lamp-green { color: #27ae60; }
.status-label { margin: 0; font-weight: 600; font-size: 0.9rem; text-align: center; }
.status-panel[data-light="red"] .status-label { color: var(--danger); }
.status-panel[data-light="orange"] .status-label { color: var(--warn); }
.status-panel[data-light="green"] .status-label { color: var(--success); }
.issues { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 8px; font-size: 0.8rem; line-height: 1.35; }
.issue { padding: 6px 8px 6px 10px; border-left: 4px solid; border-radius: 4px; }
.issue-error { border-color: #e5332a; background: var(--danger-bg); color: var(--danger-ink); }
.issue-warning { border-color: #f39c12; background: var(--warn-bg); color: var(--warn-ink); }

.stage-3d { position: relative; padding: 0; touch-action: pan-y; }
.stage-3d canvas { display: block; width: 100%; height: 100%; }
.stage-status {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 16px;
  text-align: center; color: var(--muted); pointer-events: none;
}
.stage-status[hidden] { display: none; }

.stage-empty { display: grid; place-items: center; text-align: center; color: var(--muted); }
.stage-empty p { margin: 0; max-width: 28ch; }

.params {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* --- Formulaire --------------------------------------------------------------- */

fieldset { margin: 14px 0 0; padding: 14px 0 0; border: 0; border-top: 1px solid var(--line); min-width: 0; }
legend { padding: 0; font-weight: 600; font-size: 1rem; float: left; width: 100%; margin-bottom: 10px; }
legend + * { clear: both; }

.field { margin-bottom: 14px; }
.field > label, .field .label { display: block; margin-bottom: 6px; font-size: 0.9rem; color: var(--muted); }

select, input[type="text"] {
  width: 100%;
  min-height: var(--touch);
  padding: 8px 12px;
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 8px;
}

input[type="text"][aria-invalid="true"] { border-color: var(--danger); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.text-input { position: relative; }
.text-input input { padding-right: 58px; }
.counter {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none;
}

.messages { margin: 0 0 4px; font-size: 0.9rem; color: var(--danger); }

/* Réglage : bouton −, curseur, bouton +, valeur. */
.check { display: flex; align-items: center; gap: 10px; min-height: var(--touch); margin-bottom: 8px; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }

.stepper { display: grid; grid-template-columns: var(--touch) minmax(0, 1fr) var(--touch) 5.2em; align-items: center; gap: 8px; }

.stepper button {
  width: var(--touch); height: var(--touch);
  font: inherit; font-size: 1.35rem; line-height: 1;
  color: var(--ink); background: var(--control);
  border: 1px solid var(--field-line); border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.stepper button:active:not(:disabled) { background: var(--control-active); }
.stepper button:disabled, .stepper input:disabled { opacity: 0.45; cursor: default; }

.stepper input[type="range"] { width: 100%; height: var(--touch); margin: 0; accent-color: var(--accent); }
.stepper output { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.field-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: -6px 0 14px; }
.hint { margin: 0; font-size: 0.82rem; color: var(--muted); }

button.link {
  flex: none; min-height: var(--touch); margin-top: -10px; padding: 6px 2px; font: inherit; font-size: 0.9rem;
  color: var(--accent); background: none; border: 0; text-decoration: underline; cursor: pointer;
}
button.link:disabled { color: var(--muted); opacity: 0.6; text-decoration: none; cursor: default; }

/* Couleurs */
.color-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.color-head .label { margin-bottom: 6px; }
.chosen { font-size: 0.9rem; }

/* Les pastilles se répartissent sur une ligne tant qu'il y a la place, sinon elles passent à la ligne. */
.swatches { display: grid; grid-template-columns: repeat(auto-fit, minmax(26px, 1fr)); gap: 6px; }
.swatch { position: relative; display: grid; place-items: center start; min-height: 40px; cursor: pointer; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.swatch .chip {
  display: block; width: 100%; max-width: 34px; aspect-ratio: 1; border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 2px var(--panel);
}
/* Pastille presque noire (le noir) : contour du thème, gris clair en thème foncé (site.css). */
.swatch .chip.is-dark { border-color: var(--chip-dark-line); }
.swatch input:checked + .chip { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.swatch input:focus-visible + .chip { outline: 2px solid var(--accent); outline-offset: 5px; }

/* --- Fenêtre « Ajouter au panier » (D-043) ------------------------------------- */

.cart-dialog {
  width: min(440px, calc(100vw - 32px)); padding: 20px; border: 0; border-radius: var(--radius);
  background: var(--panel); color: var(--ink); box-shadow: 0 12px 40px var(--shadow);
}
.cart-dialog::backdrop { background: rgba(5, 6, 4, 0.6); }
.cart-dialog h2 { margin: 0 0 12px; font-size: 1.25rem; letter-spacing: 0; text-transform: none; color: var(--ink); }
.cart-dialog-item { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 16px; overflow-wrap: anywhere; }
.cart-dialog .price { flex: none; font-weight: 600; }
.cart-dialog .dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cart-dialog .dialog-actions .button { flex: 1 1 180px; }
.cart-dialog .project-message { margin: 12px 0 0; }
.cart-dialog .dialog-cancel { display: block; margin: 18px auto 0; }

/* --- Tableau des polices -------------------------------------------------------- */

.button-block { display: block; width: 100%; margin-top: 8px; }

.gallery {
  width: min(1600px, calc(100vw - 32px)); height: calc(100dvh - 32px); max-width: none; max-height: none;
  padding: 0; border: 0; border-radius: var(--radius); background: var(--panel); color: var(--ink);
  box-shadow: 0 12px 40px var(--shadow);
}
.gallery[open] { display: flex; flex-direction: column; }
.gallery::backdrop { background: rgba(5, 6, 4, 0.6); }
.gallery-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.gallery-head h2 { margin-bottom: 4px; }
.gallery-head .button { flex: none; }
.gallery-grid {
  flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 14px 16px 20px;
  display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); gap: 12px; align-content: start;
}
.gallery-item {
  display: flex; flex-direction: column; width: 100%; height: 100%; padding: 0; font: inherit; color: inherit;
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  overflow: hidden; transition: border-color 0.1s, box-shadow 0.1s;
}
.gallery-item:hover:not(:disabled) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gallery-item[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.gallery-item:disabled { cursor: default; }
/* Cadre d'image de proportions fixes : toutes les cases ont la même hauteur. */
.gallery-image {
  position: relative; display: grid; place-items: center; aspect-ratio: 3 / 2; min-height: 0; overflow: hidden;
  padding: 6px; background: var(--stage); color: var(--muted); font-size: 0.75rem; text-align: center;
}
.gallery-image img { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; }
.gallery-item[data-state="loading"] .gallery-image::after { content: "…"; font-size: 1.4rem; }
.gallery-group {
  grid-column: 1 / -1; margin: 10px 0 -2px; padding-bottom: 4px; border-bottom: 1px solid var(--line);
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.gallery-group:first-child { margin-top: 0; }
.gallery-name { padding: 6px 8px; font-size: 0.82rem; line-height: 1.25; overflow-wrap: anywhere; }
.gallery-item[aria-current="true"] .gallery-name { font-weight: 600; color: var(--accent); }

/* --- Mise en page : mobile ---------------------------------------------------- */

@media (max-width: 800px) {
  html, body { height: auto; }

  .layout { display: block; height: auto; padding: 0 0 env(safe-area-inset-bottom); }

  /* Les panneaux deviennent des enfants directs de la page : l'aperçu 2D peut rester collé en haut. */
  .results { display: contents; }

  .pane { border-radius: 0; border-width: 0 0 1px; }

  .pane-2d { position: sticky; top: 0; z-index: 2; height: 46dvh; min-height: 260px; box-shadow: 0 2px 8px var(--shadow); }
  .pane-2d .stage { padding: 10px; }

  /* Sur mobile, le feu passe sous le dessin, en ligne, avec la liste à côté. */
  .stage-row { flex-direction: column; }
  .project-panel { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  .status-panel {
    width: auto; max-height: 7.5em; flex-direction: row; align-items: flex-start;
    border-left: 0; border-top: 1px solid var(--line); padding: 8px 12px;
  }
  .traffic-light { flex-direction: row; gap: 5px; padding: 5px 7px; border-radius: 10px; }
  .lamp { width: 14px; height: 14px; }
  .status-label { white-space: nowrap; font-size: 0.8rem; }
  .issues { font-size: 0.75rem; gap: 4px; }
  .issue { padding: 3px 6px; }

  .pane-3d { height: auto; }
  .pane-3d .stage-3d { flex: none; height: 42dvh; min-height: 240px; }

  .params { border-radius: 0; border: 0; overflow: visible; padding: 14px 16px 28px; }

  /* Tableau des polices : plein écran, moins de colonnes. */
  .gallery { width: 100vw; height: 100dvh; border-radius: 0; }
  .gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px 12px 16px; }
}

@media (max-width: 520px) {
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
