/*
 * Les 2MB – styles. Conçus d'abord pour le mobile (390 px), puis étendus à la
 * tablette (rail latéral à partir de 768 px) et à l'ordinateur (menu latéral
 * permanent au-delà de 1 024 px). Interface provisoire, à reprendre d'après
 * les maquettes Figma : les couleurs et tailles sont réunies ci-dessous.
 */

:root {
  --vert: #2f5d3a;
  --vert-fonce: #1f4029;
  --vert-clair: #e7efe4;
  --fond: #f6f4ee;
  --surface: #ffffff;
  --texte: #1c1f1a;
  --texte-discret: #55594f;
  --bordure: #c9cdbf;
  --attention: #8a4b00;
  --attention-fond: #fbefd9;
  --danger: #a12626;
  --ok: #1f5f33;
  --rayon: 12px;
  --hauteur-barre: 64px;
  --largeur-rail: 88px;
  --largeur-menu: 232px;
  --police: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Un élément masqué le reste, même s'il porte une classe qui fixe son affichage. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--police);
  font-size: 17px;
  line-height: 1.45;
  color: var(--texte);
  background: var(--fond);
}

h1, h2 { line-height: 1.2; margin: 0; }
p { margin: 0 0 0.75rem; }
a { color: var(--vert-fonce); }

/* ---------- Structure ---------- */

.entete {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0.5rem 1rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  background: var(--vert);
  color: #fff;
}

.entete h1 { font-size: 1.25rem; font-weight: 650; flex: 1; }

.etat-sauvegarde { font-size: 0.85rem; opacity: 0; transition: opacity 0.2s; }
.etat-sauvegarde.visible { opacity: 1; }

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: #fff;
  color: var(--vert-fonce);
}

.contenu {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: calc(var(--hauteur-barre) + 1.5rem + env(safe-area-inset-bottom));
  outline: none;
}

/* ---------- Navigation : barre basse sur mobile ---------- */

.navigation {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--bordure);
  padding-bottom: env(safe-area-inset-bottom);
}

.lien-nav {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--hauteur-barre);
  padding: 0.35rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--texte-discret);
}

.lien-nav[aria-current="page"] { color: var(--vert-fonce); background: var(--vert-clair); }
.lien-nav.bientot { color: #7b7f74; }
.lien-nav:focus-visible { outline: 3px solid var(--vert-fonce); outline-offset: -3px; }

.icone { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icone-points { stroke-width: 3.2; }

.etiquette-bientot {
  font-size: 0.6rem;
  font-weight: 600;
  line-height: 1.3;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #ecebe4;
  color: var(--texte-discret);
}

/* ---------- Cartes ---------- */

.carte {
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  padding: 1rem;
  margin-bottom: 1rem;
}

.carte h2 { font-size: 1.15rem; margin-bottom: 0.6rem; }
.carte > :last-child { margin-bottom: 0; }

.carte-info { background: var(--vert-clair); border-color: #b9cbb3; }
.carte-alerte { background: var(--attention-fond); border-color: #e2c48d; }
.carte-bientot { background: transparent; border-style: dashed; }

.discret { color: var(--texte-discret); font-size: 0.92rem; }

.etat { font-weight: 600; }
.etat-ok { color: var(--ok); }
.etat-attention { color: var(--attention); }

/* ---------- Formulaires ---------- */

.formulaire { display: grid; gap: 1rem; margin: 0.5rem 0 1rem; }

.champ { display: grid; gap: 0.3rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.champ label, .champ legend { font-weight: 600; padding: 0; }

.saisie { display: flex; align-items: center; gap: 0.5rem; }

input[type="text"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1.5px solid #8d9285;
  border-radius: 8px;
}

textarea { min-height: 110px; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible, .bouton:focus-visible {
  outline: 3px solid var(--vert);
  outline-offset: 2px;
}

.unite { flex: none; min-width: 2rem; color: var(--texte-discret); font-weight: 600; }

.case { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; font-weight: 400; }
.case input { width: 22px; height: 22px; accent-color: var(--vert); }

.erreur { margin: 0; min-height: 0; color: var(--danger); font-size: 0.9rem; font-weight: 600; }
.en-erreur input, .en-erreur select, .en-erreur textarea { border-color: var(--danger); }

/* ---------- Boutons ---------- */

.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  color: var(--vert-fonce);
  background: #fff;
  border: 1.5px solid var(--vert);
  border-radius: 10px;
  cursor: pointer;
}

.bouton-principal { color: #fff; background: var(--vert); }
.bouton-danger { color: var(--danger); border-color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.actions p { flex-basis: 100%; }

/* ---------- Résumés, compteurs, modules ---------- */

.resume { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; margin: 0 0 0.75rem; }
.resume dt { color: var(--texte-discret); }
.resume dd { margin: 0; font-weight: 600; }
.resume dd.discret { font-weight: 400; }

.grille-compteurs { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.compteur {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}
.compteur .nombre { font-size: 1.8rem; font-weight: 700; color: var(--vert-fonce); }

.liste-modules { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.ligne-module { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.liste-modules p { margin: 0.15rem 0 0; }

.pastille { flex: none; font-size: 0.78rem; font-weight: 600; padding: 0.1rem 0.6rem; border-radius: 999px; border: 1px solid var(--bordure); }
.pastille-stable { background: var(--vert-clair); color: var(--ok); border-color: #b9cbb3; }
.pastille-beta { background: var(--attention-fond); color: var(--attention); }
.pastille-developpement { background: #ecebe4; color: var(--texte-discret); }

/* ---------- Zones et tests de sol ---------- */

.ecran > :last-child { margin-bottom: 0; }

.lien-retour { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 0.5rem; font-weight: 600; }

.avertissement {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--attention-fond);
  border: 1px solid #e2c48d;
  color: #5c3200;
  font-weight: 600;
}

.liste-zones, .liste-tests, .historique { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.6rem; }

.carte-zone {
  display: grid;
  gap: 0.15rem;
  min-height: 56px;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--bordure);
  border-radius: 10px;
  background: #fff;
  color: inherit;
  text-decoration: none;
}
.carte-zone strong { color: var(--vert-fonce); font-size: 1.05rem; }
.carte-zone:focus-visible { outline: 3px solid var(--vert); outline-offset: 2px; }

.formulaire-ligne .saisie { align-items: stretch; }
.formulaire-ligne .bouton { flex: none; }

.etapes { margin: 0.5rem 0 0; padding-left: 1.4rem; display: grid; gap: 0.5rem; }

.lecture { padding: 0.8rem; margin-bottom: 0.75rem; border-radius: 10px; background: var(--vert-clair); border: 1px solid #b9cbb3; }
.lecture h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.lecture > :last-child { margin-bottom: 0; }

.synthese { margin: 0 0 0.75rem; display: grid; gap: 0.15rem; }
.synthese dt { color: var(--texte-discret); margin-top: 0.5rem; }
.synthese dd { margin: 0; display: grid; }
.synthese .valeur { font-weight: 650; }

.historique > li { padding: 0.7rem 0.9rem; border: 1px solid var(--bordure); border-radius: 10px; }
.historique p { margin: 0.2rem 0 0.4rem; }
.historique summary { min-height: 40px; display: flex; align-items: center; cursor: pointer; color: var(--vert-fonce); font-weight: 600; }
.historique details[open] summary { margin-bottom: 0.4rem; }

.bouton-discret { min-height: 40px; border-color: var(--bordure); color: var(--texte-discret); font-weight: 600; }

a.compteur { color: inherit; text-decoration: none; }

/* ---------- Aménagements ---------- */

.filtres { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 0.9rem; }

.formulaire-ligne { display: grid; gap: 0.75rem; }

.calculs h3 { margin: 1rem 0 0.5rem; font-size: 1rem; }
.calculs > :last-child { margin-bottom: 0; }

.resultats dd { font-size: 1.1rem; }

.couches { list-style: none; margin: 0 0 0.75rem; padding: 0; border: 1px solid var(--bordure); border-radius: 10px; overflow: hidden; }
.couches li { display: grid; gap: 0.15rem; padding: 0.55rem 0.8rem; border-top: 1px solid var(--bordure); }
.couches li:first-child { border-top: 0; }
.mesures-couche { display: flex; justify-content: space-between; gap: 1rem; color: var(--texte-discret); }
.mesures-couche strong { color: var(--texte); text-align: right; }
.mesures-couche span { flex: none; white-space: nowrap; }

/* Coupe : la première couche est en bas, les hauteurs sont proportionnelles aux épaisseurs. */
.coupe { display: flex; flex-direction: column-reverse; height: 260px; margin-bottom: 0.75rem; border: 1.5px solid #6b6f63; border-radius: 6px; overflow: hidden; }
.couche-coupe {
  flex-basis: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-top: 1px solid #6b6f63;
  overflow: hidden;
}
.couche-coupe:last-child { border-top: 0; }
.couche-coupe span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.couche-coupe span:last-child { flex: none; }
.ton-0 { background: #cdbfa6; }
.ton-1 { background: #dfe6c8; }
.ton-2 { background: #b9a88a; }
.ton-3 { background: #8a7a62; color: #fff; }

/* ---------- Module Eau ---------- */

.carte h3 { margin: 1rem 0 0.5rem; font-size: 1rem; }
.encart-eau { border-color: #a9c4d6; background: #f3f8fb; }
.cumuls dd { font-weight: 600; }
.cumuls dd .discret { font-weight: 400; }
.resultats dd { display: grid; }
.precision { font-size: 0.85rem; font-weight: 400; }
.ligne-depart { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 40px; }
.ligne-depart p { margin: 0; }
.carte-detail-eau .liste-zones { margin-bottom: 0.5rem; }

/* ---------- Sauvegarde, Savoir, Avis ---------- */

.fichier-masque { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.fichier-masque:focus-visible + *, label.bouton:focus-within { outline: 3px solid var(--vert); outline-offset: 2px; }
.confirmation { margin: 0.75rem 0; padding: 0.8rem; border: 1.5px solid #e2c48d; border-radius: 10px; background: var(--attention-fond); }

.lien-tutoriel { margin: 0.75rem 0 0; font-weight: 600; }
.sources { margin: 0 0 0.75rem; padding-left: 1.2rem; display: grid; gap: 0.5rem; overflow-wrap: anywhere; }
.fiche-savoir .etapes { margin-bottom: 0.9rem; }

.tableau-savoir { width: 100%; border-collapse: collapse; margin: 0 0 1rem; font-size: 0.95rem; }
.tableau-savoir th { text-align: left; padding: 0.5rem 0.6rem; background: #555555; color: #fff; }
.tableau-savoir td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--bordure); vertical-align: top; }

/* Sur mobile, chaque ligne de tableau devient une carte. */
@media (max-width: 767px) {
  .tableau-savoir thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tableau-savoir, .tableau-savoir tbody, .tableau-savoir tr, .tableau-savoir td { display: block; }
  .tableau-savoir tr { margin-bottom: 0.6rem; padding: 0.5rem 0.8rem; border: 1px solid var(--bordure); border-radius: 10px; }
  .tableau-savoir td { padding: 0.25rem 0; border-bottom: 0; }
  .tableau-savoir td:empty { display: none; }
  .tableau-savoir td::before { content: attr(data-colonne); display: block; font-size: 0.8rem; color: var(--texte-discret); }
  .tableau-savoir td:first-child { font-weight: 650; }
}

.apercu-avis { margin: 0 0 0.75rem; padding: 0.8rem; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 0.9rem; background: #f3f2ec; border: 1px solid var(--bordure); border-radius: 8px; }

#impression { display: none; }

/* ---------- Tablette : rail latéral compact ---------- */

@media (min-width: 768px) {
  .navigation {
    top: 0;
    right: auto;
    width: var(--largeur-rail);
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.25rem;
    padding: calc(64px + env(safe-area-inset-top)) 0.4rem 1rem;
    border-top: 0;
    border-right: 1px solid var(--bordure);
  }
  .lien-nav { flex: none; border-radius: 10px; min-height: 68px; }
  .entete { padding-left: calc(var(--largeur-rail) + 1.25rem); }
  .contenu { padding: 1.5rem; padding-left: calc(var(--largeur-rail) + 1.5rem); max-width: calc(820px + var(--largeur-rail)); margin: 0; }
  .formulaire { grid-template-columns: 1fr 1fr; column-gap: 1.25rem; }
  .formulaire > fieldset, .formulaire > .champ:has(textarea), .formulaire > button { grid-column: 1 / -1; }
  .formulaire > button { justify-self: start; }
}

/* ---------- Ordinateur : menu latéral permanent ---------- */

@media (min-width: 1025px) {
  .navigation { width: var(--largeur-menu); padding-left: 0.75rem; padding-right: 0.75rem; }
  .lien-nav { flex-direction: row; justify-content: flex-start; gap: 0.8rem; min-height: 52px; padding: 0.4rem 0.9rem; font-size: 1rem; }
  .etiquette-bientot { margin-left: auto; font-size: 0.7rem; }
  .entete { padding-left: calc(var(--largeur-menu) + 2rem); }
  .contenu { padding: 2rem; padding-left: calc(var(--largeur-menu) + 2rem); max-width: calc(900px + var(--largeur-menu)); }
}

/* ---------- Impression : A4 portrait, noir et blanc ---------- */

@page { size: A4 portrait; margin: 15mm; }

@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  #app { display: none; }
  #impression { display: block; }
  #impression h1 { font-size: 16pt; margin-bottom: 2mm; }
  .date-impression { font-size: 9pt; color: #333; margin-bottom: 6mm; }
  .bloc-impression { margin-bottom: 6mm; }
  /* Titre de section sur fond gris clair, jamais séparé de son tableau */
  #impression h2 {
    font-size: 12pt;
    padding: 2mm 3mm;
    background: #e6e6e6;
    break-after: avoid;
    page-break-after: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #impression table { width: 100%; border-collapse: collapse; }
  #impression thead { display: table-header-group; }
  #impression th {
    text-align: left;
    padding: 1.5mm 3mm;
    background: #555555;
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #impression td { padding: 1.5mm 3mm; border-bottom: 0.3pt solid #999; vertical-align: top; }
  #impression td:first-child { width: 38%; font-weight: 600; }
  #impression tr { break-inside: avoid; page-break-inside: avoid; }
}
