:root {
  --papier: #F5F1E8;
  --carte: #FFFDF8;
  --encre: #1F2A30;
  --doux: #5E6A70;
  --trait: #E2DACB;
  --brique: #B4532A;
  --brique-fonce: #8E3F1E;
  --sapin: #2F5D50;
  --sapin-pale: #E3EDE7;
  --ambre: #A86B00;
  --ambre-pale: #FBF0D9;
  --rouge: #A83226;
  --rouge-pale: #F8E3DF;
  --rayon: 14px;
  --titre: "Fraunces", Georgia, serif;
  --texte: "Instrument Sans", -apple-system, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--papier); color: var(--encre);
  font: 16px/1.45 var(--texte);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 560px; margin: 0 auto; padding: 0 18px 110px; }
h1, h2, h3 { font-family: var(--titre); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 30px; line-height: 1.1; }
h2 { font-size: 21px; margin: 28px 0 10px; }
h3 { font-size: 17px; }
p { margin: 0 0 10px; }
a { color: var(--sapin); }
.doux { color: var(--doux); }
.petit { font-size: 14px; }
.cache { display: none !important; }

/* ---------- Barre du haut ---------- */
.haut { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 8px; }
.haut .titre { display: flex; align-items: center; gap: 10px; min-width: 0; }
.haut img { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.haut .nom-carnet { font-size: 13px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.haut .marque { font-family: var(--titre); font-weight: 700; font-size: 19px; line-height: 1.1; }
.icone-bouton {
  border: 1px solid var(--trait); background: var(--carte); color: var(--encre);
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icone-bouton svg { width: 20px; height: 20px; }
.retour { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--doux); font: 600 15px var(--texte); padding: 18px 0 6px; cursor: pointer; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 13px 18px; min-height: 48px;
  font: 600 16px var(--texte); cursor: pointer; text-decoration: none;
  background: var(--encre); color: #fff;
}
.btn.principal { background: var(--brique); }
.btn.principal:active { background: var(--brique-fonce); }
.btn.second { background: var(--carte); color: var(--encre); border: 1px solid var(--trait); }
.btn.lien { background: none; color: var(--sapin); padding: 8px 4px; min-height: 0; }
.btn.danger { background: none; color: var(--rouge); border: 1px solid var(--rouge-pale); }
.btn.plein { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.rangee { display: flex; gap: 10px; flex-wrap: wrap; }
.rangee > .btn { flex: 1; }

.grand-bouton {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  background: var(--brique); color: #fff; border: 0; border-radius: 18px; padding: 18px 20px; cursor: pointer; margin-top: 14px;
  box-shadow: 0 6px 18px rgba(180, 83, 42, .22);
}
.grand-bouton .rond { width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; flex: none; }
.grand-bouton svg { width: 26px; height: 26px; }
.grand-bouton b { display: block; font: 700 18px var(--texte); }
.grand-bouton span { font-size: 14px; opacity: .9; }

/* ---------- Cartes et listes ---------- */
.carte { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 16px; }
.carte + .carte { margin-top: 10px; }
.liste { list-style: none; margin: 0; padding: 0; background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); overflow: hidden; }
.liste li + li { border-top: 1px solid var(--trait); }
.liste button.ligne, .liste a.ligne, .liste div.ligne {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; background: none; border: 0;
  text-align: left; font: inherit; color: inherit; cursor: pointer; text-decoration: none;
}
.ligne .vignette { width: 46px; height: 46px; border-radius: 10px; background: var(--sapin-pale); color: var(--sapin); display: grid; place-items: center; flex: none; overflow: hidden; }
.ligne .vignette img { width: 100%; height: 100%; object-fit: cover; }
.ligne .vignette svg { width: 22px; height: 22px; }
.ligne .corps { flex: 1; min-width: 0; }
.ligne .corps b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ligne .corps span { display: block; font-size: 14px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ligne .fleche { color: var(--trait); flex: none; }
.vide { text-align: center; padding: 26px 18px; color: var(--doux); }

.pastille { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pastille.retard { background: var(--rouge-pale); color: var(--rouge); }
.pastille.bientot { background: var(--ambre-pale); color: var(--ambre); }
.pastille.ok { background: var(--sapin-pale); color: var(--sapin); }
.pastille.neutre { background: #EEE8DC; color: var(--doux); }

.compteur { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; font-size: 14px; color: var(--doux); }
.jauge { flex: 1; height: 6px; background: var(--trait); border-radius: 9px; overflow: hidden; max-width: 140px; }
.jauge i { display: block; height: 100%; background: var(--sapin); }

.recherche { width: 100%; margin-bottom: 10px; }

/* ---------- Formulaires ---------- */
label.champ { display: block; margin-bottom: 14px; }
label.champ > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; font: 16px var(--texte); color: var(--encre); background: #fff;
  border: 1px solid var(--trait); border-radius: 11px; padding: 12px 13px; min-height: 48px; -webkit-appearance: none; appearance: none;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sapin); outline-offset: 0; border-color: transparent; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detecte { font-size: 12px; font-weight: 600; color: var(--sapin); margin-left: 6px; }
.code { font-size: 26px !important; letter-spacing: 5px; text-align: center; font-variant-numeric: tabular-nums; }

.puces { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.puce { border: 1px solid var(--trait); background: #fff; color: var(--encre); border-radius: 99px; padding: 8px 14px; font: 500 15px var(--texte); cursor: pointer; }
.puce.choisie { background: var(--sapin); color: #fff; border-color: var(--sapin); }

.option-rappel { border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--carte); margin-bottom: 10px; overflow: hidden; }
.option-rappel > label.tete { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.option-rappel > label.tete input { width: 22px; height: 22px; accent-color: var(--sapin); flex: none; }
.option-rappel > label.tete b { display: block; }
.option-rappel > label.tete span { font-size: 14px; color: var(--doux); }
.option-rappel .detail { padding: 0 16px 14px 50px; }
.option-rappel:not(.active) .detail { display: none; }
.note-recu { background: var(--sapin-pale); color: var(--sapin); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px; }

/* ---------- Photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin: 12px 0; }
.photo { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: #EEE8DC; border: 1px solid var(--trait); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .type { position: absolute; left: 6px; bottom: 6px; right: 6px; font-size: 11px; font-weight: 700; background: rgba(31,42,48,.75); color: #fff; padding: 3px 7px; border-radius: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo .retirer { position: absolute; top: 5px; right: 5px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(31,42,48,.75); color: #fff; font-size: 16px; cursor: pointer; }
.photo.pdf { display: grid; place-items: center; color: var(--doux); font-weight: 700; }
.ajout-photo { aspect-ratio: 3 / 4; border-radius: 12px; border: 2px dashed var(--trait); background: none; color: var(--doux); display: grid; place-items: center; align-content: center; gap: 6px; font: 600 13px var(--texte); cursor: pointer; padding: 6px; text-align: center; }
.ajout-photo svg { width: 26px; height: 26px; }

.chargement { display: grid; place-items: center; gap: 14px; padding: 60px 10px; text-align: center; }
.roue { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--trait); border-top-color: var(--brique); animation: tourne .9s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

/* ---------- Fiche ---------- */
.entete-fiche { padding: 4px 0 6px; }
.entete-fiche .cat { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brique); }
.entete-fiche h1 { margin: 4px 0 6px; }
.grille-infos { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--trait); border: 1px solid var(--trait); border-radius: var(--rayon); overflow: hidden; }
.grille-infos > div { background: var(--carte); padding: 11px 14px; min-width: 0; }
.grille-infos dt { font-size: 12px; color: var(--doux); font-weight: 600; }
.grille-infos dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.grille-infos .large, .grille-infos > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
.bouton-bris {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; margin: 16px 0 4px;
  background: var(--encre); color: #fff; border: 0; border-radius: 16px; padding: 16px 18px; cursor: pointer;
}
.bouton-bris svg { width: 26px; height: 26px; flex: none; }
.bouton-bris b { display: block; font-size: 17px; }
.bouton-bris span { font-size: 14px; opacity: .8; }
.section-tete { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.section-tete h2 { margin-bottom: 10px; }

/* ---------- En cas de bris ---------- */
.bris-bloc { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 16px; margin-bottom: 10px; }
.bris-bloc h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bris-bloc h3 .num { width: 24px; height: 24px; border-radius: 50%; background: var(--brique); color: #fff; font: 700 13px var(--texte); display: grid; place-items: center; }
.copiable { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--trait); }
.copiable:first-of-type { border-top: 0; }
.copiable code { font: 600 16px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.loi { background: var(--ambre-pale); border: 1px solid #EBD6A8; border-radius: var(--rayon); padding: 16px; font-size: 15px; }
.loi h3 { margin-bottom: 6px; }

/* ---------- Feuille (fenêtre du bas) ---------- */
#feuille { position: fixed; inset: 0; z-index: 20; background: rgba(31,42,48,.42); display: flex; align-items: flex-end; justify-content: center; }
#feuille[hidden] { display: none; }
#feuille .panneau {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--papier);
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  animation: monte .2s ease-out;
}
#feuille .panneau h2 { margin-top: 0; }
#feuille .apercu { width: 100%; border-radius: 12px; display: block; }
@keyframes monte { from { transform: translateY(30px); opacity: 0; } }

#avis { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--encre); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 36px); box-shadow: 0 8px 24px rgba(0,0,0,.2); }

.bandeau-demo { margin-top: 12px; background: var(--ambre-pale); color: var(--ambre); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 600; }

/* ---------- Connexion ---------- */
.accueil-connexion { padding-top: 12vh; }
.accueil-connexion .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 18px; }
.accueil-connexion h1 { font-size: 34px; margin-bottom: 10px; }
.accueil-connexion .lead { font-size: 17px; color: var(--doux); margin-bottom: 26px; }
.etapes-mini { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 10px; }
.etapes-mini li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; color: var(--doux); }
.etapes-mini li b { color: var(--encre); }
.etapes-mini .n { width: 24px; height: 24px; border-radius: 50%; background: var(--sapin-pale); color: var(--sapin); font-weight: 700; font-size: 13px; display: grid; place-items: center; flex: none; }

@media (min-width: 600px) {
  #app { padding-top: 12px; }
}
