:root {
  --jaune: #FADC0A;
  --noir: #111111;
  --gris: #5E5E5E;
  --gris-clair: #E6E6E6;
  --fond: #F5F4F0;
  --blanc: #FFFFFF;
  --alerte: #B3261E;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Jost', system-ui, sans-serif;
  color: var(--noir);
  background: var(--fond);
  font-size: 16px;
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
button {
  min-height: 40px;
  padding: 0 14px;
  border: 2px solid var(--noir);
  background: var(--blanc);
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
}
button:hover { background: var(--gris-clair); }
button.jaune { background: var(--jaune); }
button.jaune:hover { background: #F0CF00; }
button.noir { background: var(--noir); color: var(--blanc); }
button.lien { border: 0; background: none; padding: 0 4px; min-height: 32px; text-decoration: underline; font-weight: 500; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--jaune); outline-offset: 1px; }
input, select {
  min-height: 40px;
  border: 1px solid #9A9A9A;
  background: var(--blanc);
  padding: 0 8px;
  border-radius: 0;
  width: 100%;
}
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--noir); }

/* Barre du haut */
.barre {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--blanc); border-bottom: 6px solid var(--jaune);
}
.marque { display: flex; align-items: center; gap: 12px; }
.marque img { height: 44px; width: auto; }
.marque div { display: flex; flex-direction: column; line-height: 1.1; }
.marque strong { font-size: 22px; font-weight: 800; letter-spacing: 0.01em; }
.marque span { font-size: 14px; color: var(--gris); font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Mise en page */
.appli { flex: 1; display: flex; min-height: 0; }
#panneau {
  width: 400px; flex: none; overflow-y: auto; background: var(--blanc);
  border-right: 1px solid #D0D0D0; padding: 0 0 40px;
}
.scene { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
.vues { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap; background: var(--fond); }
.vues button { min-height: 38px; }
.vues button.actif { background: var(--noir); color: var(--blanc); }
#vue3d { flex: 1; position: relative; min-height: 300px; touch-action: none; }
#vue3d canvas { display: block; position: absolute; inset: 0; }
.aide-vue {
  position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,.9);
  padding: 6px 10px; font-size: 13px; pointer-events: none;
}
#alertes { position: absolute; right: 12px; top: 62px; max-width: 360px; display: flex; flex-direction: column; gap: 6px; }
#alertes div { background: var(--blanc); border-left: 6px solid var(--alerte); padding: 8px 10px; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }

/* Panneau de réglages */
details.sec { border-bottom: 1px solid var(--gris-clair); }
details.sec > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; gap: 10px;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: '+'; width: 22px; height: 22px; background: var(--jaune); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
details.sec[open] > summary::before { content: '–'; }
.sec-corps { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.champ { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 500; }
.champ .unite { display: flex; align-items: center; gap: 6px; }
.champ .unite span { color: var(--gris); white-space: nowrap; }
.ligne { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
.case { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; min-height: 40px; }
.bloc { border: 1px solid #D6D6D6; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #FBFBF9; }
.bloc-tete { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; }
.indice { font-size: 13px; color: var(--gris); margin: 0; }
.ajouts { display: flex; flex-wrap: wrap; gap: 6px; }
.choix-carreau {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; padding: 6px; min-height: 64px;
  border: 1px solid #9A9A9A; font-weight: 500;
}
.choix-carreau img { width: 52px; height: 52px; object-fit: cover; flex: none; border: 1px solid #ccc; }
.choix-carreau b { display: block; font-weight: 700; }
.choix-carreau small { color: var(--gris); font-size: 13px; }
.choix-carreau .changer { margin-left: auto; font-size: 13px; text-decoration: underline; }
.lettre { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; background: var(--noir); color: var(--jaune); font-weight: 800; }

/* Modales */
.modale { position: fixed; inset: 0; background: rgba(17,17,17,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modale[hidden] { display: none; }
.boite { background: var(--blanc); width: min(520px, 100%); max-height: 100%; overflow-y: auto; padding: 0 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.boite.large { width: min(1100px, 100%); }
.boite-tete { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--blanc); padding-top: 16px; z-index: 1; }
.boite-tete h2 { margin: 0; font-size: 24px; font-weight: 800; }
.fermer { font-size: 26px; width: 44px; padding: 0; }
.boite label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 15px; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.boutons { display: flex; justify-content: flex-end; }
.note { font-size: 13px; color: var(--gris); margin: 0; }
#ajout-apercu { max-width: 160px; max-height: 160px; object-fit: cover; }
.galerie-outils, .galerie-pied { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.galerie-outils input { flex: 1 1 220px; width: auto; }
.galerie-outils select { width: auto; }
.galerie-pied { border-top: 1px solid var(--gris-clair); padding-top: 12px; font-size: 14px; }
.galerie-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.carte {
  display: flex; flex-direction: column; text-align: left; padding: 0; min-height: 0; border: 2px solid #D6D6D6; background: var(--blanc);
}
.carte:hover { border-color: var(--noir); background: var(--blanc); }
.carte.choisi { border-color: var(--noir); box-shadow: inset 0 0 0 3px var(--jaune); }
.carte img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.carte span { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.carte b { font-size: 15px; line-height: 1.2; }
.carte small { font-size: 13px; color: var(--gris); font-weight: 500; }
.badge { align-self: flex-start; background: var(--noir); color: var(--blanc); font-size: 11px; padding: 2px 6px; font-weight: 600; margin-top: 4px; }
.badge.mur { background: #5B3E8C; }
.badge.ext { background: #2E6B4F; }
.badge.perso { background: var(--jaune); color: var(--noir); }
.badge.divers { background: #fff; color: var(--noir); outline: 2px dashed var(--noir); outline-offset: -2px; }
.carte .suppr { margin: 0 10px 10px; min-height: 30px; font-size: 13px; }

/* Fiche à l'écran */
#fiche-ecran { position: fixed; inset: 0; background: #DADADA; z-index: 30; overflow-y: auto; }
#fiche-ecran[hidden] { display: none; }
.fiche-barre { position: sticky; top: 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--noir); color: var(--blanc); padding: 10px 16px; z-index: 2; }
.fiche-barre span { font-size: 14px; color: #CFCFCF; flex: 1; }
.fiche-barre button:not(.jaune) { background: var(--noir); color: var(--blanc); border-color: var(--blanc); }
#fiche { padding: 16px 0 40px; }
.page {
  background: var(--blanc); width: 210mm; min-height: 297mm; margin: 0 auto 16px; padding: 12mm;
  display: flex; flex-direction: column; gap: 5mm; font-size: 11pt;
}
.page-tete { display: flex; justify-content: space-between; align-items: center; border-bottom: 4px solid var(--jaune); padding-bottom: 3mm; }
.page-tete .marque img { height: 36px; }
.page-tete .marque strong { font-size: 18px; }
.page-tete .infos { text-align: right; font-size: 10pt; color: var(--gris); }
.page h1 { font-size: 20pt; margin: 0; font-weight: 800; }
.page h2 { font-size: 15pt; margin: 0; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.page h3 { font-size: 12pt; margin: 0; }
.page img.vue { width: 100%; height: auto; border: 1px solid #ccc; display: block; }
.page .vue-boite { flex: 1; display: flex; flex-direction: column; justify-content: flex-start; }
.page img.vue.limite { max-height: 150mm; object-fit: contain; }
.page table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.page th, .page td { border: 1px solid #BDBDBD; padding: 2mm; text-align: left; vertical-align: middle; }
.page th { background: var(--noir); color: var(--blanc); font-weight: 600; }
.page td img { width: 18mm; height: 18mm; object-fit: cover; display: block; }
.page .chiffre { text-align: right; white-space: nowrap; }
.page .consignes { margin: 0; padding-left: 5mm; }
.page .consignes li { margin: 1mm 0; }
.page .alerte { border-left: 5px solid var(--alerte); padding: 2mm 3mm; background: #FBEDEC; }
.page .info { border-left: 5px solid var(--jaune); padding: 2mm 3mm; background: #FFFBE0; font-size: 10pt; }
.page .pied { margin-top: auto; font-size: 9pt; color: var(--gris); border-top: 1px solid var(--gris-clair); padding-top: 2mm; }
.carreaux-mur { display: flex; flex-wrap: wrap; gap: 3mm; }
.carreaux-mur > div { display: flex; gap: 3mm; align-items: center; border: 1px solid #D6D6D6; padding: 2mm; flex: 1 1 70mm; }
.carreaux-mur img { width: 16mm; height: 16mm; object-fit: cover; }

/* Synthèse sur une page */
.page.synthese { height: 297mm; padding: 9mm; gap: 3mm; font-size: 9pt; overflow: hidden; }
.synthese .page-tete { padding-bottom: 2mm; }
.synthese figure { margin: 0; border: 1px solid #CFCFCF; display: flex; flex-direction: column; min-height: 0; }
.synthese figcaption { background: var(--noir); color: var(--blanc); font-weight: 600; font-size: 9pt; padding: 1mm 2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.synthese figure img { flex: 1; min-height: 0; width: 100%; object-fit: contain; display: block; }
.syn-ligne { display: flex; flex-wrap: wrap; gap: 1mm 5mm; background: #FFFBE0; border-left: 5px solid var(--jaune); padding: 2mm 3mm; }
.syn-haut { display: grid; grid-template-columns: 1.15fr 1fr; gap: 3mm; height: 88mm; }
.syn-carreaux { display: flex; flex-direction: column; gap: 2mm; overflow: hidden; }
.syn-carreaux > div { display: flex; gap: 2.5mm; align-items: center; border: 1px solid #CFCFCF; padding: 1.5mm; }
.syn-carreaux img { width: 15mm; height: 15mm; object-fit: cover; flex: none; }
.syn-murs { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 3mm; flex: 1; min-height: 0; }
.synthese .pied { margin-top: 0; font-size: 8pt; }

/* Tablette et petits écrans */
@media (max-width: 960px) {
  .appli { flex-direction: column-reverse; }
  #panneau { width: auto; border-right: 0; border-top: 1px solid #D0D0D0; overflow: visible; }
  .scene { flex: none; height: 62vh; }
  body { height: auto; }
  .appli { min-height: auto; }
  html, body { height: auto; }
}

/* Impression : uniquement la fiche */
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: var(--blanc); display: block; }
  body > *:not(#fiche-ecran) { display: none !important; }
  #fiche-ecran { position: static; overflow: visible; background: none; display: block !important; }
  .fiche-barre { display: none; }
  #fiche { padding: 0; }
  .page { margin: 0; box-shadow: none; page-break-after: always; break-after: page; min-height: 0; height: 297mm; overflow: hidden; }
  .page:last-child { page-break-after: auto; break-after: auto; }
  .page.synthese { height: 296mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
