:root {
  --ciment: #e7e9e5;
  --papier: #ffffff;
  --encre: #16211c;
  --trait: #c9cec6;
  --gris: #6c7369;
  --orange: #e2571c;
  --plan: #2f5d7c;
  --alerte: #9a3b33;
  --statut: #8a8f87;
  --rayon: 4px;
  --touche: 52px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ciment);
  color: var(--encre);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--plan); outline-offset: 2px; }

/* Marque ----------------------------------------------------------------- */
.marque {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-weight: 800; letter-spacing: 0.02em;
}
.marque span { font-size: 0.95rem; }
.marque b {
  background: var(--orange); color: #fff;
  padding: 1px 7px; border-radius: 2px; font-size: 1rem;
}
.marque--grand span { font-size: 1.6rem; }
.marque--grand b { font-size: 1.7rem; padding: 2px 10px; }

/* En-tête ---------------------------------------------------------------- */
.barre-haut { position: sticky; top: 0; z-index: 20; }
.entete {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--encre); color: #fff;
}
.entete .marque span { color: #fff; }
.entete-droite { display: flex; align-items: center; gap: 14px; }
#sync-badge { font-size: 0.78rem; color: #b9c2ba; }
#sync-badge[data-etat='horsligne'] { color: #f0b070; }
#sync-badge[data-etat='erreur'], #sync-badge[data-etat='acces'] { color: #f39b8f; }
.lien {
  background: none; border: 0; padding: 8px 2px; cursor: pointer;
  color: inherit; text-decoration: underline; text-underline-offset: 3px; font-size: 0.9rem;
}
.entete--editeur { border-bottom: 3px solid var(--statut); }
.etat-enr { font-size: 0.78rem; color: #b9c2ba; }
.select-statut {
  background: #26332c; color: #fff; border: 1px solid #3b4a41;
  border-radius: var(--rayon); padding: 8px 10px; font-size: 0.85rem;
}

/* Recherche et filtres --------------------------------------------------- */
.barre-recherche { padding: 14px 16px 8px; }
.barre-recherche input {
  width: 100%; height: var(--touche); padding: 0 14px;
  border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--papier);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips--filtre { padding: 4px 16px 12px; overflow-x: auto; flex-wrap: nowrap; }
.chips--filtre::-webkit-scrollbar { display: none; }
.chip {
  min-height: 44px; padding: 8px 14px; white-space: nowrap; cursor: pointer;
  background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon);
  font-size: 0.92rem;
}
.chip--actif { background: var(--encre); color: #fff; border-color: var(--encre); }

/* Liste ------------------------------------------------------------------ */
.liste { padding: 0 16px 120px; display: grid; gap: 10px; }
.carte {
  background: var(--papier); border: 1px solid var(--trait); border-left: 5px solid var(--c, var(--trait));
  border-radius: var(--rayon); padding: 14px 14px 12px; cursor: pointer;
}
.carte-haut { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.carte h2 { font-size: 1.06rem; margin: 0 0 2px; }
.pastille {
  flex: none; font-size: 0.72rem; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, white); color: var(--c);
  border: 1px solid color-mix(in srgb, var(--c) 35%, white);
}
.carte-adresse { margin: 2px 0 6px; color: var(--gris); font-size: 0.92rem; }
.carte-meta { margin: 0; font-size: 0.84rem; color: var(--gris); }
.carte-lots { margin: 6px 0 0; font-size: 0.84rem; color: var(--plan); }
.carte-dirty { display: inline-block; margin-top: 8px; font-size: 0.75rem; color: var(--orange); }
.vide { padding: 48px 8px; text-align: center; color: var(--gris); }
.vide p { margin: 0 0 6px; }
.vide-sous { font-size: 0.9rem; }

.fab {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  height: 58px; border: 0; border-radius: var(--rayon); cursor: pointer;
  background: var(--orange); color: #fff; font-weight: 700; font-size: 1.02rem;
  box-shadow: 0 6px 18px rgba(22, 33, 28, 0.22);
}

/* Sommaire éditeur ------------------------------------------------------- */
.sommaire {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px;
  background: var(--ciment); border-bottom: 1px solid var(--trait);
}
.sommaire::-webkit-scrollbar { display: none; }
.sommaire-item {
  flex: none; background: none; border: 0; padding: 8px 6px; cursor: pointer;
  font-size: 0.85rem; color: var(--gris); white-space: nowrap;
}

/* Blocs de formulaire ---------------------------------------------------- */
.editeur { padding: 12px 16px 140px; display: grid; gap: 14px; }
.bloc {
  background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 16px;
  display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; align-content: start;
  scroll-margin-top: 118px;
}
.bloc > * { grid-column: 1 / -1; }
.champ--court { grid-column: span 1; display: flex; flex-direction: column; justify-content: flex-end; }
.champ--court .label { margin-top: auto; }
.bloc-titre { font-size: 0.98rem; margin: 0 0 4px; letter-spacing: 0.01em; }
.bloc-titre::after {
  content: ''; display: block; width: 34px; height: 3px; background: var(--orange); margin-top: 8px;
}
.bloc-note { margin: 10px 0 0; font-size: 0.86rem; color: var(--gris); }
.champ { margin-top: 16px; }
.label { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 7px; }
.requis { font-style: normal; font-weight: 400; color: var(--orange); font-size: 0.78rem; }
.champ input, .champ textarea, .piece input, .piece textarea, .lot--libre input, .lot--libre textarea {
  width: 100%; padding: 12px 12px; min-height: var(--touche);
  background: #fbfcfa; border: 1px solid var(--trait); border-radius: var(--rayon);
}
.champ textarea, .piece textarea { min-height: auto; resize: vertical; line-height: 1.4; }
.aide { margin: 8px 0 0; font-size: 0.8rem; color: var(--gris); }

.alertes:empty { display: none; }
.alerte {
  margin: 12px 0 0; padding: 10px 12px; font-size: 0.85rem;
  background: #fdf3ee; border-left: 4px solid var(--alerte); color: #5a2b25; border-radius: 0 var(--rayon) var(--rayon) 0;
}

/* Lots ------------------------------------------------------------------- */
.lots { display: grid; gap: 6px; margin-top: 14px; }
.lot { border: 1px solid var(--trait); border-radius: var(--rayon); overflow: hidden; }
.lot--actif { border-color: var(--encre); }
.lot-bouton {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--touche);
  padding: 10px 12px; background: #fbfcfa; border: 0; cursor: pointer; text-align: left;
}
.lot--actif .lot-bouton { background: var(--encre); color: #fff; }
.lot-coche {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border: 2px solid currentColor; border-radius: 3px; font-size: 0.9rem; font-weight: 700;
}
.lot-nom { font-size: 0.95rem; }
.lot-obs { border: 0; border-top: 1px solid var(--trait); width: 100%; padding: 12px; resize: vertical; }
.lot--libre { padding: 12px; display: grid; gap: 8px; border-style: dashed; }

/* Pièces ----------------------------------------------------------------- */
.pieces { display: grid; gap: 12px; margin-top: 14px; }
.piece { border: 1px solid var(--trait); border-radius: var(--rayon); padding: 12px; display: grid; gap: 8px; background: #fbfcfa; }
.piece-haut { display: flex; gap: 8px; align-items: center; }
.piece-nom { font-weight: 600; }
.piece-x, .vignette-x {
  flex: none; width: 44px; height: 44px; border: 1px solid var(--trait); background: #fff;
  border-radius: var(--rayon); font-size: 1.2rem; cursor: pointer; color: var(--alerte);
}
.galerie { display: flex; gap: 8px; flex-wrap: wrap; }
.galerie:empty { display: none; }
.vignette { position: relative; margin: 0; width: 96px; height: 96px; }
.vignette img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--rayon); border: 1px solid var(--trait); }
.vignette-x { position: absolute; top: -8px; right: -8px; width: 30px; height: 30px; line-height: 1; padding: 0; }

/* Signature -------------------------------------------------------------- */
.signature {
  width: 100%; height: 160px; background: #fbfcfa; touch-action: none;
  border: 1px dashed var(--trait); border-radius: var(--rayon);
}
.lien--effacer { color: var(--gris); }

/* Boutons ---------------------------------------------------------------- */
.btn {
  min-height: var(--touche); padding: 12px 16px; cursor: pointer;
  background: var(--papier); border: 1px solid var(--encre); border-radius: var(--rayon); font-weight: 600;
}
.btn--plein { background: var(--encre); color: #fff; }
.btn--danger { border-color: var(--alerte); color: var(--alerte); }
.btn--ajout { width: 100%; border-style: dashed; font-weight: 500; }
.btn--photo { width: 100%; background: var(--plan); border-color: var(--plan); color: #fff; }
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1.2fr auto; gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--ciment); border-top: 1px solid var(--trait);
}
.actions .btn--danger { padding: 12px; }

/* Écran d'accès ---------------------------------------------------------- */
.acces { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.acces-carte {
  width: min(420px, 100%); background: var(--papier); border: 1px solid var(--trait);
  border-radius: var(--rayon); padding: 28px; display: grid; gap: 14px;
}
.acces-txt { margin: 4px 0 6px; color: var(--gris); font-size: 0.94rem; }
.acces-carte input {
  width: 100%; min-height: var(--touche); padding: 12px;
  border: 1px solid var(--trait); border-radius: var(--rayon); background: #fbfcfa;
}
.erreur { color: var(--alerte); font-size: 0.88rem; margin: 0; }

/* Impression ------------------------------------------------------------- */
.impression { display: none; }
@media print {
  body { background: #fff; }
  .entete, .sommaire, .editeur, .actions, .fab, .liste, .barre-recherche, .chips--filtre { display: none !important; }
  .impression { display: block; padding: 0; color: #000; font-size: 11.5pt; }
  .p-entete { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #000; padding-bottom: 8px; }
  .p-entete h1 { font-size: 14pt; margin: 0; }
  .p-entete p { margin: 2px 0 0; font-size: 10pt; }
  .p-bloc { break-inside: avoid; margin-top: 14px; }
  .p-bloc h2 { font-size: 11pt; margin: 0 0 6px; border-bottom: 1px solid #999; padding-bottom: 3px; }
  .p-ligne, .p-piece { display: grid; grid-template-columns: 34% 1fr; gap: 10px; padding: 3px 0; border-bottom: 1px dotted #ccc; }
  .p-signature img { display: block; height: 70px; margin-top: 6px; }
  .p-vigilance { border-left: 3px solid #000; padding-left: 10px; }
  .p-alerte { margin: 4px 0; font-size: 10.5pt; }
  .p-pied { margin-top: 18px; font-size: 9pt; text-align: center; color: #444; }
  @page { size: A4; margin: 14mm; }
}

@media (min-width: 720px) {
  .liste { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .editeur { max-width: 780px; margin: 0 auto; }
  .fab { left: auto; width: 260px; }
  .actions { justify-content: center; grid-template-columns: repeat(3, minmax(0, 220px)); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
