/* =========================================================================
   Milbatiment Gestion — feuille de style unique.
   Pensée d'abord pour l'iPhone (règles Apple : cibles de 44 px, encoche,
   barre d'onglets, listes groupées), puis élargie pour le PC.
   Guide des composants : docs/03-interface.md
   Point de bascule : < 900 px = téléphone/tablette (onglets en bas),
                      ≥ 900 px = PC (barre latérale).
   ========================================================================= */

/* ---------- 1. Couleurs (clair / sombre automatique) ---------- */
:root {
  color-scheme: light dark;
  --fond: #f2f2f7;                    /* fond groupé iOS */
  --cellule: #ffffff;
  --cellule-presse: #e5e5ea;
  --cellule-survol: #f7f7fa;
  --texte: #1c1c1e;
  --texte-2: #636366;                 /* texte secondaire (contraste ≥ 4,5:1) */
  --texte-3: #8e8e93;                 /* chevrons, éléments décoratifs */
  --separateur: rgba(60, 60, 67, .22);
  --champ-gris: rgba(118, 118, 128, .12);
  --accent: #b5501f;                  /* brique Milbatiment */
  --accent-fond: #b5501f;             /* fond des boutons principaux (texte blanc) */
  --accent-presse: #8f3d15;
  --accent-doux: rgba(181, 80, 31, .11);
  --vert: #1d7d36;
  --vert-doux: rgba(36, 138, 61, .13);
  --rouge: #d70015;
  --rouge-doux: rgba(215, 0, 21, .09);
  --bleu: #0a60c2;
  --bleu-doux: rgba(0, 113, 227, .11);
  --orange: #a35200;
  --orange-doux: rgba(255, 149, 0, .16);
  --barre-fond: rgba(249, 249, 251, .86);
  --lateral-fond: #2b2f36;            /* gris foncé de la marque */
  --lateral-texte: #e9eaec;
  --ombre: 0 6px 20px rgba(0, 0, 0, .14), 0 1px 3px rgba(0, 0, 0, .08);
  --rayon: 12px;
  --rayon-petit: 9px;
  --hauteur-onglets: 50px;
  --hauteur-nav: 44px;
  --haut-sur: env(safe-area-inset-top, 0px);
  --bas-sur: env(safe-area-inset-bottom, 0px);
  --gauche-sur: env(safe-area-inset-left, 0px);
  --droite-sur: env(safe-area-inset-right, 0px);
  --marge: max(16px, var(--gauche-sur));
  --marge-d: max(16px, var(--droite-sur));
}

/* Thème sombre choisi */
html[data-theme="sombre"] {
    --fond: #000000;
    --cellule: #1c1c1e;
    --cellule-presse: #3a3a3c;
    --cellule-survol: #242426;
    --texte: #ffffff;
    --texte-2: #a1a1a8;
    --texte-3: #6e6e74;
    --separateur: rgba(84, 84, 88, .65);
    --champ-gris: rgba(118, 118, 128, .24);
    --accent: #f08a57;
    --accent-fond: #c0562a;
    --accent-presse: #9c4520;
    --accent-doux: rgba(240, 138, 87, .16);
    --vert: #32d74b;
    --vert-doux: rgba(50, 215, 75, .16);
    --rouge: #ff6961;
    --rouge-doux: rgba(255, 69, 58, .16);
    --bleu: #64aaff;
    --bleu-doux: rgba(10, 132, 255, .2);
    --orange: #ffb340;
    --orange-doux: rgba(255, 159, 10, .2);
    --barre-fond: rgba(22, 22, 24, .86);
    --lateral-fond: #1c1c1e;
    --ombre: 0 6px 20px rgba(0, 0, 0, .5);
  }
/* Thème automatique : suit le réglage de l'appareil */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --fond: #000000;
    --cellule: #1c1c1e;
    --cellule-presse: #3a3a3c;
    --cellule-survol: #242426;
    --texte: #ffffff;
    --texte-2: #a1a1a8;
    --texte-3: #6e6e74;
    --separateur: rgba(84, 84, 88, .65);
    --champ-gris: rgba(118, 118, 128, .24);
    --accent: #f08a57;
    --accent-fond: #c0562a;
    --accent-presse: #9c4520;
    --accent-doux: rgba(240, 138, 87, .16);
    --vert: #32d74b;
    --vert-doux: rgba(50, 215, 75, .16);
    --rouge: #ff6961;
    --rouge-doux: rgba(255, 69, 58, .16);
    --bleu: #64aaff;
    --bleu-doux: rgba(10, 132, 255, .2);
    --orange: #ffb340;
    --orange-doux: rgba(255, 159, 10, .2);
    --barre-fond: rgba(22, 22, 24, .86);
    --lateral-fond: #1c1c1e;
    --ombre: 0 6px 20px rgba(0, 0, 0, .5);
  }
}

/* Choix du thème (Clair par défaut ; Sombre ; Automatique = comme l'appareil). */
html[data-theme="clair"] { color-scheme: light; }
html[data-theme="sombre"] { color-scheme: dark; }
html[data-theme="auto"] { color-scheme: light dark; }

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;  /* on dessine nous-mêmes le retour au toucher */
  background: var(--fond);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;                      /* taille « corps » iOS */
  line-height: 1.35;
  color: var(--texte);
  background: var(--fond);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;           /* pas de délai ni de zoom au double toucher */
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { flex: none; }
.icone { display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.visuellement-cache {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.seulement-bureau, .seulement-moyen { display: none !important; }

/* Titres : grand titre iOS en haut de chaque page. */
h1 {
  font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: .01em;
  margin: 4px 0 14px; overflow-wrap: break-word;
}
h2 { font-size: 22px; font-weight: 700; margin: 28px 0 10px; letter-spacing: .01em; }
h2 { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 .lien-section {
  display: inline-flex; align-items: center; min-height: 44px; margin: -10px -8px -10px 0; padding: 0 8px;
  font-size: 17px; font-weight: 400; white-space: nowrap;
}
.section-titre {
  font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: .03em;
  color: var(--texte-2); margin: 26px 16px 7px;
}
.section-note { font-size: 13px; color: var(--texte-2); margin: 7px 16px 0; }
.discret { color: var(--texte-2); font-size: 15px; }
.sous-titre-page { color: var(--texte-2); font-size: 15px; margin: -8px 0 16px; }
p { margin: 0 0 12px; }

/* ---------- 3. Structure de page ---------- */
.cadre { min-width: 0; }
.page {
  max-width: 1180px; margin: 0 auto;
  padding: 4px var(--marge-d) 28px var(--marge);
}
body.connecte .page {
  /* place pour la barre d'onglets + le bouton flottant */
  padding-bottom: calc(var(--hauteur-onglets) + var(--bas-sur) + 96px);
}
.etroite { max-width: 460px; margin: 0 auto; }

/* Barre du haut (barre de navigation iOS) */
.barre-nav {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: calc(var(--hauteur-nav) + var(--haut-sur));
  padding: var(--haut-sur) var(--marge-d) 0 max(8px, var(--gauche-sur));
  background: var(--fond);
  border-bottom: .5px solid transparent;
  transition: background-color .2s, border-color .2s;
}
body.defile .barre-nav {
  background: var(--barre-fond);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom-color: var(--separateur);
}
.nav-gauche, .nav-droite { display: flex; align-items: center; min-width: 0; }
.nav-droite { justify-content: flex-end; gap: 4px; }
.nav-titre {
  font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
  opacity: 0; transition: opacity .2s;
}
body.defile .nav-titre { opacity: 1; }
.nav-retour, .bouton-nav {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; min-width: 44px; padding: 0 6px;
  color: var(--accent); font-size: 17px; background: none; border: 0; font-family: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap; border-radius: 8px;
}
.nav-retour span { overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.bouton-nav { font-weight: 600; justify-content: center; }
.nav-retour:active, .bouton-nav:active { opacity: .4; }
.nav-retour:hover, .bouton-nav:hover { text-decoration: none; background: var(--accent-doux); }
.barre-nav form { margin: 0; }

/* Barre d'onglets en bas (téléphone et tablette) */
.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 0 var(--droite-sur) var(--bas-sur) var(--gauche-sur);
  background: var(--barre-fond);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--separateur);
}
.onglets a {
  flex: 1 1 0; min-width: 0; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: var(--hauteur-onglets); padding: 4px 2px 3px;
  color: var(--texte-3); font-size: 10.5px; font-weight: 500; letter-spacing: .01em;
  text-decoration: none;
}
.onglets a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.onglets a.actif { color: var(--accent); }
.onglets a:active { opacity: .5; }
/* Thème clair choisi */
html[data-theme="clair"] .onglets a:not(.actif) { color: #6e6e73; }
/* Thème automatique : suit le réglage de l'appareil */
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] .onglets a:not(.actif) { color: #6e6e73; }
}

/* Barre latérale (PC) : cachée sur téléphone */
.barre-laterale { display: none; }

/* Feuille « Plus » (fenêtre qui monte du bas) */
.feuille {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 560px;
  max-height: calc(100dvh - 40px);
  padding: 0; border: 0; border-radius: 14px 14px 0 0;
  background: var(--fond); color: var(--texte);
  box-shadow: var(--ombre);
}
.feuille[open] { display: block; animation: monter .28s cubic-bezier(.2, .8, .2, 1); }
.feuille::backdrop { background: rgba(0, 0, 0, .35); }
.feuille-contenu {
  padding: 6px var(--marge-d) calc(20px + var(--bas-sur)) var(--marge);
  overflow-y: auto; max-height: calc(100dvh - 40px);
}
.feuille-poignee { width: 36px; height: 5px; border-radius: 3px; background: var(--texte-3); opacity: .5; margin: 0 auto 6px; }
.feuille-entete { display: flex; align-items: center; justify-content: space-between; margin: 0 0 14px; }
.feuille-entete strong { font-size: 20px; }
/* Thème sombre choisi */
html[data-theme="sombre"] .feuille { background: #1c1c1e; }
html[data-theme="sombre"] .feuille .liste { background: #2c2c2e; }
/* Thème automatique : suit le réglage de l'appareil */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .feuille { background: #1c1c1e; }
  html[data-theme="auto"] .feuille .liste { background: #2c2c2e; }
}
.feuille .liste { margin-bottom: 18px; }
@keyframes monter { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .feuille[open] { animation: none; } * { transition: none !important; } }
.bouton-rond {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%; padding: 0;
  background: var(--champ-gris); color: var(--texte-2); cursor: pointer;
  background-clip: content-box; padding: 7px;  /* rond visible de 30 px, cible de 44 px */
}

/* ---------- 4. Messages ---------- */
.message {
  padding: 12px 16px; border-radius: var(--rayon); margin: 0 0 16px;
  background: var(--bleu-doux); color: var(--texte); font-size: 15px; border: 0;
}
.message ul { margin: 4px 0 0; padding-left: 20px; }
.message.succes { background: var(--vert-doux); }
.message.info { background: var(--bleu-doux); }
.message.erreur { background: var(--rouge-doux); }
.message.attention { background: var(--orange-doux); }
.message p { margin: 0 0 6px; }

/* ---------- 5. Boutons ---------- */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 0; border-radius: var(--rayon);
  background: var(--accent-fond); color: #fff;
  font: inherit; font-size: 17px; font-weight: 600; line-height: 1.2; text-align: center;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, transform .1s;
}
.bouton:hover { background: var(--accent-presse); text-decoration: none; }
.bouton:active { transform: scale(.97); background: var(--accent-presse); }
.bouton.secondaire { background: var(--accent-doux); color: var(--accent); }
.bouton.secondaire:hover, .bouton.secondaire:active { background: rgba(181, 80, 31, .2); }
.bouton.destructif { background: var(--rouge-doux); color: var(--rouge); }
.bouton.destructif:hover, .bouton.destructif:active { background: rgba(215, 0, 21, .16); }
.bouton.grand { display: flex; width: 100%; min-height: 50px; }
button.lien {
  background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit;
  padding: 0; min-height: 44px; text-decoration: underline;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0; }
.en-ligne { display: inline; margin: 0; }
.titre-actions {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 12px;
}
.titre-actions h1 { margin-right: auto; }

/* Bouton d'action principale : pastille flottante au-dessus des onglets sur téléphone. */
.action-principale {
  position: fixed; z-index: 25;
  right: calc(var(--marge-d) + 0px);
  bottom: calc(var(--hauteur-onglets) + var(--bas-sur) + 14px);
  min-height: 50px; padding: 0 20px 0 16px; border-radius: 25px;
  box-shadow: var(--ombre);
}

/* ---------- 6. Listes iOS (cellules groupées) ---------- */
.liste, .groupe-liste {
  list-style: none; margin: 0 0 20px; padding: 0;
  background: var(--cellule); border-radius: var(--rayon); overflow: hidden;
}
.groupe-liste .liste { margin: 0; border-radius: 0; }
.liste > li { position: relative; }
.liste > li + li::before {                /* séparateur décalé, comme sur iOS */
  content: ""; position: absolute; top: 0; right: 0; left: 16px; z-index: 1;
  border-top: .5px solid var(--separateur);
}
.liste > li.avec-icone + li::before, .liste > li:has(.cellule-icone) + li::before { left: 58px; }
.cellule {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 11px 14px 11px 16px;
  color: var(--texte); text-decoration: none;
  width: 100%; background: none; border: 0; font: inherit; text-align: left;
}
a.cellule, button.cellule { cursor: pointer; transition: background-color .15s; }
a.cellule:hover, button.cellule:hover { text-decoration: none; background: var(--cellule-survol); }
a.cellule:active, button.cellule:active { background: var(--cellule-presse); transition: none; }
.cellule.actif .cellule-titre { color: var(--accent); font-weight: 600; }
.cellule-texte { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cellule-titre { font-size: 17px; overflow-wrap: break-word; }
.cellule-sous-titre { font-size: 15px; color: var(--texte-2); overflow-wrap: break-word; }
.cellule-sous-titre .etiquette { margin: 2px 4px 0 0; }
.cellule-valeur {
  flex: 0 0 auto; margin-left: auto; text-align: right; color: var(--texte-2);
  font-size: 17px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.cellule-valeur .montant { color: var(--texte); }
.cellule-valeur small { display: block; font-size: 13px; color: var(--texte-2); }
.cellule .chevron { color: var(--texte-3); opacity: .8; margin-right: -4px; }
.cellule-icone {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px; background: var(--accent-fond); color: #fff;
}
.cellule-icone.gris { background: #8e8e93; }
.cellule-icone.rouge { background: var(--rouge); }
.cellule-icone.vert { background: #34a853; }
.cellule-icone.bleu { background: #0a84ff; }
.cellule-bouton.destructif .cellule-titre { color: var(--rouge); }
.liste > li.archive .cellule-titre { color: var(--texte-2); }
.liste > li.vide, .liste-vide {
  padding: 26px 16px; text-align: center; color: var(--texte-2); font-size: 15px;
}
.liste .col { display: none; }            /* colonnes : visibles seulement sur PC */
.liste-entete { display: none; }
.compteur { font-size: 13px; color: var(--texte-2); margin: -12px 16px 20px; }

/* ---------- 7. Montants, étiquettes, barres ---------- */
.montant { white-space: nowrap; font-variant-numeric: tabular-nums; }
.montant.negatif, .negatif { color: var(--rouge); }
.montant.entree { color: var(--vert); }
.nombre { text-align: right; font-variant-numeric: tabular-nums; }
.etiquette {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 13px; font-weight: 500; line-height: 1.35; white-space: nowrap; vertical-align: middle;
  background: var(--champ-gris); color: var(--texte-2); border: 0;
}
.etiquette.verte, .statut-en_cours { background: var(--vert-doux); color: var(--vert); }
.etiquette.bleue, .statut-livre { background: var(--bleu-doux); color: var(--bleu); }
.etiquette.orange { background: var(--orange-doux); color: var(--orange); }
.etiquette.rouge { background: var(--rouge-doux); color: var(--rouge); }
.etiquette.grise, .statut-archive { background: var(--champ-gris); color: var(--texte-2); }
h1 .etiquette { font-size: 15px; vertical-align: 6px; letter-spacing: 0; }
.barre {
  display: inline-block; width: 120px; max-width: 100%; height: 6px;
  background: var(--champ-gris); border-radius: 99px; vertical-align: middle; overflow: hidden;
}
.barre span { display: block; height: 100%; background: var(--vert); border-radius: 99px; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: rgba(255, 255, 255, .16); color: #fff;
}
.badge.saisie { background: #2e7d43; }
.badge.consultation { background: #3d6fb6; }

/* ---------- 8. Tableau de bord (accueil) ---------- */
.date-du-jour { color: var(--texte-2); font-size: 15px; margin: -10px 0 18px; }
.date-du-jour::first-letter { text-transform: uppercase; }
.carte-solde {
  background: var(--cellule); border-radius: var(--rayon); padding: 16px 16px 14px; margin: 0 0 20px;
}
.carte-solde .libelle { font-size: 15px; color: var(--texte-2); }
.carte-solde .grand-montant {
  display: block; font-size: 34px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; margin: 2px 0 2px;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--texte);
}
.carte-solde .grand-montant.negatif { color: var(--rouge); }
.chiffres, .tuiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 0 0 20px;
}
.chiffres { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chiffre, .tuile {
  display: flex; flex-direction: column; gap: 2px; min-height: 44px;
  background: var(--cellule); border-radius: var(--rayon); padding: 12px 14px;
  color: var(--texte); text-decoration: none; border: 0; min-width: 0;
}
a.chiffre:hover, a.tuile:hover { text-decoration: none; background: var(--cellule-survol); }
a.chiffre:active, a.tuile:active { background: var(--cellule-presse); }
.chiffre strong, .tuile strong {
  font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}
.tuile strong.montant { font-size: 19px; }
.groupe-details.totaux dd .montant.entree { color: var(--vert); }
@media (min-width: 900px) { .groupe-details.totaux { max-width: 460px; } }
.chiffre span, .tuile span { color: var(--texte-2); font-size: 14px; }
.chiffre .icone { color: var(--accent); margin-bottom: 4px; }

/* ---------- 9. Recherche, filtres, contrôle segmenté ---------- */
.filtres-formulaire { margin: 0 0 16px; }
.barre-recherche { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.recherche {
  position: relative; flex: 1 1 auto; display: flex; align-items: center; margin: 0; min-width: 0;
  color: var(--texte-2); font-weight: 400;
}
.recherche .icone { position: absolute; left: 10px; pointer-events: none; }
.recherche input {
  width: 100%; min-height: 44px; margin: 0; padding: 0 12px 0 36px;
  border: 0; border-radius: 11px; background: var(--champ-gris); color: var(--texte);
}
.recherche input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.bouton-filtres {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 11px; cursor: pointer;
  background: var(--champ-gris); color: var(--texte-2);
}
.bouton-filtres.actifs, .bouton-filtres[aria-expanded="true"] { background: var(--accent-doux); color: var(--accent); }
.pastille-nombre {
  position: absolute; top: -4px; right: -4px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; background: var(--accent-fond); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.panneau-filtres { margin: 0 0 12px; }
.panneau-filtres .groupe { margin-bottom: 10px; }
.panneau-boutons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmente {
  display: flex; padding: 2px; margin: 0 0 12px; border-radius: 11px; background: var(--champ-gris);
}
.segmente label {
  flex: 1 1 0; margin: -2px 0; padding: 2px 0; position: relative; display: flex; font-weight: 500; min-width: 0;
}
.segmente input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmente span {
  flex: 1; display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 40px; padding: 0 6px; border-radius: 9px; font-size: 15px; cursor: pointer;
  color: var(--texte); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.segmente input:checked + span {
  background: var(--cellule); font-weight: 600; box-shadow: 0 2px 6px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04);
}
/* Thème sombre choisi */
html[data-theme="sombre"] .segmente input:checked + span { background: #636366; }
/* Thème automatique : suit le réglage de l'appareil */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .segmente input:checked + span { background: #636366; }
}
.segmente input:focus-visible + span { outline: 2px solid var(--accent); }
/* Anciens filtres en ligne (compatibilité) */
.filtres { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin: 8px 0 16px; }
.filtres input, .filtres select { width: auto; margin: 0; flex: 1 1 160px; }
.filtres label { margin: 0; font-weight: 400; font-size: 14px; flex: 1 1 140px; }
.filtres label input { width: 100%; margin-top: 3px; }

/* ---------- 10. Formulaires ---------- */
input, select, textarea {
  font: inherit; font-size: 17px;                /* ≥ 16 px : Safari ne zoome pas */
  color: var(--texte);
}
/* Champs « nus » (hors groupe iOS) */
label { display: block; margin: 0 0 14px; font-weight: 600; }
label small { font-weight: 400; color: var(--texte-2); }
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; min-height: 44px;
  border: .5px solid var(--separateur); border-radius: var(--rayon-petit); background: var(--cellule);
}
select {
  -webkit-appearance: none; appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 88px; resize: vertical; line-height: 1.4; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
legend { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--texte-2); padding: 0 16px 7px; font-weight: 400; }
.formulaire { max-width: 680px; }
.ligne { display: grid; grid-template-columns: 1fr; gap: 0; }

/* Groupe de formulaire iOS : un bloc blanc arrondi, une ligne par champ. */
.groupe {
  background: var(--cellule); border-radius: var(--rayon); overflow: hidden; margin: 0 0 8px;
}
.groupe > *, .groupe .ligne > * { position: relative; }
.groupe > * + *::before, .groupe .ligne > * + *::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--separateur);
}
.champ { display: block; margin: 0; padding: 8px 16px 4px; font-weight: 400; }
.champ:focus-within { box-shadow: inset 3px 0 0 var(--accent); }
.champ-libelle { display: block; font-size: 13px; font-weight: 500; color: var(--texte-2); }
.champ:focus-within .champ-libelle { color: var(--accent); }
.champ-libelle abbr { text-decoration: none; color: var(--rouge); }
.champ-libelle small { font-size: 13px; }
.champ-aide { display: block; font-size: 13px; color: var(--texte-2); padding-bottom: 6px; }
.champ input:where(:not([type="checkbox"]):not([type="radio"])), .champ select, .champ textarea {
  display: block; width: 100%; margin: 0; padding: 4px 0 8px; min-height: 36px;
  border: 0; border-radius: 0; background-color: transparent; outline: none;
}
.champ select { padding-right: 26px; background-position: right 2px center; }
.champ textarea { min-height: 72px; }
.champ input::placeholder, .champ textarea::placeholder { color: var(--texte-3); }

/* Case à cocher en interrupteur iOS */
.bascule, label.case {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; margin: 0; padding: 6px 16px; font-weight: 400; cursor: pointer;
}
.bascule input, label.case input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; flex: none; order: 2;
  position: relative; width: 51px; height: 31px; margin: 0; border-radius: 16px;
  background: var(--champ-gris); border: 0; cursor: pointer; transition: background-color .2s;
}
/* Thème clair choisi */
html[data-theme="clair"] .bascule input:not(:checked), html[data-theme="clair"] label.case input[type="checkbox"]:not(:checked) { background: #e3e3e8; }
/* Thème automatique : suit le réglage de l'appareil */
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] .bascule input:not(:checked), html[data-theme="auto"] label.case input[type="checkbox"]:not(:checked) { background: #e3e3e8; }
}
.bascule input::after, label.case input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .2s;
}
.bascule input:checked, label.case input[type="checkbox"]:checked { background: #34c759; }
.bascule input:checked::after, label.case input[type="checkbox"]:checked::after { transform: translateX(20px); }
.bascule input:focus-visible, label.case input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.boutons-formulaire { display: grid; gap: 10px; margin: 24px 0 8px; }
.zone-danger { margin-top: 28px; }

/* ---------- 11. Fiches (détails) ---------- */
.groupe-details { background: var(--cellule); border-radius: var(--rayon); margin: 0 0 20px; overflow: hidden; }
.groupe-details .detail {
  position: relative; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 2px 16px; min-height: 44px; padding: 11px 16px;
}
.groupe-details .detail + .detail::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--separateur);
}
.groupe-details dt { color: var(--texte); flex: none; }
.groupe-details dd { margin: 0; color: var(--texte-2); text-align: right; min-width: 0; overflow-wrap: break-word; flex: 1 1 50%; }
.groupe-details dd .montant { color: var(--texte); font-weight: 600; }
.groupe-details dd a { display: inline-flex; align-items: center; min-height: 44px; margin: -11px 0; }
.groupe-details dd .montant.negatif { color: var(--rouge); }
.groupe-details .detail.empile { display: block; }
.groupe-details .detail.empile dt { font-size: 13px; color: var(--texte-2); margin-bottom: 2px; }
.groupe-details .detail.empile dd { text-align: left; color: var(--texte); }
.texte-libre { white-space: pre-wrap; }
/* Ancienne présentation dt/dd (compatibilité) */
.details { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 0; }
.details dt { color: var(--texte-2); font-size: 14px; }
.details dd { margin: 0 0 10px; }

/* Cartes (compatibilité et blocs libres) */
.carte { background: var(--cellule); border-radius: var(--rayon); padding: 16px; margin: 0 0 16px; border: 0; }

/* ---------- 12. Connexion et pages publiques ---------- */
body.public .barre-nav { background: transparent; }
.ecran-accueil { text-align: center; padding-top: 4vh; }
.ecran-accueil .logo { width: 84px; height: 84px; border-radius: 19px; box-shadow: var(--ombre); margin: 0 auto 14px; display: block; }
.ecran-accueil h1 { font-size: 28px; margin-bottom: 4px; }
.ecran-accueil .discret { margin-bottom: 26px; }
.ecran-accueil form, .ecran-accueil .message, .ecran-accueil .groupe { text-align: left; }
.ecran-accueil .boutons-formulaire .bouton.grand { width: 100%; min-height: 50px; }

/* ---------- 13. Tableau large (PC) et grille de saisie défilante ---------- */
.defilant, .tableau-large {
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  background: var(--cellule); border-radius: var(--rayon); margin: 0 0 20px;
}
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: .5px solid var(--separateur); vertical-align: top; }
th {
  font-size: 13px; font-weight: 600; color: var(--texte-2); white-space: nowrap;
  background: var(--cellule); position: sticky; top: 0; z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--cellule-survol); }
tr.archive td { color: var(--texte-2); }
td.vide { text-align: center; color: var(--texte-2); padding: 24px; }
tfoot td { font-weight: 700; border-top: 1px solid var(--separateur); border-bottom: 0; }

/* Grille de saisie : 1re colonne (noms) et en-tête figés, défilement horizontal. */
.grille-saisie {
  overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  max-height: calc(100dvh - 220px);
  background: var(--cellule); border-radius: var(--rayon); margin: 0 0 20px;
}
.grille-saisie table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.grille-saisie th, .grille-saisie td {
  padding: 0; text-align: center; vertical-align: middle; min-width: 46px; height: 46px;
  border-bottom: .5px solid var(--separateur); border-right: .5px solid var(--separateur);
}
.grille-saisie thead th { position: sticky; top: 0; z-index: 2; padding: 6px 4px; line-height: 1.15; }
.grille-saisie thead th small { display: block; font-weight: 400; }
.grille-saisie th.weekend, .grille-saisie td.weekend { background: var(--champ-gris); }
.grille-saisie .col-nom {
  position: sticky; left: 0; z-index: 1; background: var(--cellule);
  text-align: left; padding: 6px 12px; min-width: 150px; max-width: 190px; white-space: normal;
  font-size: 15px; font-weight: 500; box-shadow: 1px 0 0 var(--separateur);
}
.grille-saisie thead .col-nom { z-index: 3; }
.grille-saisie .col-total { font-weight: 600; padding: 0 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grille-saisie select, .grille-saisie input {
  width: 100%; height: 46px; min-height: 46px; margin: 0; padding: 0 2px; border: 0; border-radius: 0;
  background: transparent; text-align: center; text-align-last: center; font-size: 17px;
  font-variant-numeric: tabular-nums; background-image: none;
}
.grille-saisie select:focus, .grille-saisie input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.grille-saisie .rempli { background: var(--vert-doux); }
.grille-saisie .demi { background: var(--orange-doux); }

/* Vue par personne (téléphone) : une ligne par jour, contrôle segmenté + compteur. */
.jours { list-style: none; margin: 0 0 20px; padding: 0; background: var(--cellule); border-radius: var(--rayon); overflow: hidden; }
.jour {
  position: relative; display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 10px;
  min-height: 56px; padding: 6px 12px 6px 16px;
}
.jour + .jour::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--separateur); }
.jour-date { font-size: 15px; line-height: 1.15; }
.jour-date small { display: block; font-size: 13px; color: var(--texte-2); text-transform: capitalize; }
.jour.weekend .jour-date { color: var(--texte-2); }
.jour .segmente { margin: 0; }
.jour .segmente span { min-height: 40px; }
.pas-a-pas { display: inline-flex; align-items: center; border-radius: 10px; background: var(--champ-gris); }
.pas-a-pas button {
  width: 44px; height: 44px; border: 0; background: none; color: var(--accent); font-size: 22px; font-weight: 500;
  cursor: pointer; padding: 0; border-radius: 10px;
}
.pas-a-pas button:active { background: var(--cellule-presse); }
.pas-a-pas input {
  width: 30px; min-height: 44px; margin: 0; padding: 0; border: 0; background: transparent;
  text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield;
}
.pas-a-pas input::-webkit-outer-spin-button, .pas-a-pas input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pas-a-pas small { display: none; }
.resume-personne {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  background: var(--cellule); border-radius: var(--rayon); padding: 12px 16px; margin: 0 0 12px;
}

/* ---------- 14. Téléphone étroit ---------- */
@media (max-width: 380px) {
  h1 { font-size: 30px; }
  .carte-solde .grand-montant { font-size: 30px; }
  .chiffre strong { font-size: 22px; }
  .jour { grid-template-columns: 50px 1fr auto; gap: 6px; padding-left: 12px; }
}

/* ---------- 15. PC (≥ 900 px) : barre latérale, colonnes, tableaux ---------- */
@media (min-width: 900px) {
  body { font-size: 16px; }
  input, select, textarea { font-size: 16px; }
  .seulement-bureau { display: revert !important; }
  .seulement-mobile { display: none !important; }
  body.connecte { display: grid; grid-template-columns: 248px minmax(0, 1fr); }
  body.connecte .page { padding: 4px 32px 48px; }
  .onglets, .feuille { display: none !important; }
  .barre-nav { padding: 8px 32px 0 24px; }
  h1 { font-size: 30px; margin-bottom: 18px; }

  .barre-laterale {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 4px;
    padding: 18px 12px 16px; background: var(--lateral-fond); color: var(--lateral-texte);
  }
  .marque {
    display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px;
    color: #fff; font-weight: 700; font-size: 17px; text-decoration: none;
  }
  .marque:hover { text-decoration: none; }
  .marque img { border-radius: 8px; }
  .marque small { display: block; font-weight: 400; font-size: 13px; color: #f0a477; }
  .menu-lateral { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .menu-lateral a {
    display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
    color: var(--lateral-texte); border-radius: 10px; font-size: 15px; font-weight: 500; text-decoration: none;
  }
  .menu-lateral a .icone { opacity: .85; }
  .menu-lateral a:hover { background: rgba(255, 255, 255, .08); }
  .menu-lateral a.actif { background: #b5501f; color: #fff; }
  .menu-lateral a.actif .icone { opacity: 1; }
  .session { border-top: 1px solid rgba(255, 255, 255, .12); padding: 12px 6px 0; font-size: 14px; }
  .session-nom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 6px 6px; }
  .session form { margin: 0; }
  .lien-sortie {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 6px;
    background: none; border: 0; border-radius: 10px; color: #f0a477; font: inherit; font-size: 14px; cursor: pointer;
  }
  .lien-sortie:hover { background: rgba(255, 255, 255, .08); }

  .action-principale {
    position: static; box-shadow: none; min-height: 44px; border-radius: var(--rayon); padding: 0 18px 0 14px;
  }
  .boutons-formulaire { display: flex; flex-direction: row-reverse; justify-content: flex-start; }
  .boutons-formulaire .bouton.grand { width: auto; min-width: 150px; min-height: 44px; }
  .ligne { grid-template-columns: 1fr 1fr; }
  .groupe .ligne > * + *::before { left: 0; top: 0; bottom: 0; right: auto; border-top: 0; border-left: .5px solid var(--separateur); }
  .filtres-formulaire { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
  .barre-recherche { flex: 1 1 260px; margin: 0; }
  .panneau-filtres, .panneau-filtres[hidden] { display: flex !important; flex: 3 1 420px; gap: 10px; align-items: center; margin: 0; }
  .bouton-filtres { display: none !important; }
  .panneau-filtres .groupe { flex: 1 1 auto; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .panneau-filtres .groupe .ligne { grid-column: span 2; }
  .panneau-filtres .champ { padding-top: 4px; padding-bottom: 2px; }
  .panneau-filtres .champ input:where(:not([type="checkbox"])), .panneau-filtres .champ select { min-height: 30px; padding-bottom: 4px; }
  .filtres-formulaire .segmente { flex: 0 1 380px; margin: 0; }
  .panneau-filtres .groupe > * + *::before { left: 0; top: 0; bottom: 0; right: auto; border-top: 0; border-left: .5px solid var(--separateur); }
  .panneau-boutons { display: flex; gap: 10px; flex: none; }
  .details { grid-template-columns: 200px 1fr; gap: 8px 16px; }
  .details dd { margin: 0; }

  /* Listes en colonnes : mêmes cellules, alignées comme un tableau. */
  .groupe-liste.colonnes .liste-entete, .groupe-liste.colonnes .cellule {
    display: grid; grid-template-columns: var(--colonnes); align-items: center; gap: 12px;
  }
  .groupe-liste.colonnes .liste-entete {
    padding: 10px 14px 8px 16px; font-size: 13px; font-weight: 600; color: var(--texte-2);
    border-bottom: .5px solid var(--separateur);
  }
  .groupe-liste.colonnes .cellule { min-height: 48px; padding-top: 9px; padding-bottom: 9px; }
  .groupe-liste.colonnes .col { display: block; min-width: 0; font-size: 15px; color: var(--texte-2); overflow-wrap: break-word; }
  .groupe-liste.colonnes .col.nombre, .groupe-liste.colonnes .liste-entete .nombre { text-align: right; }
  .groupe-liste.colonnes .cellule-valeur { margin-left: 0; }
  .groupe-liste.colonnes .cellule-sous-titre.seulement-mobile { display: none; }
  .groupe-liste.colonnes .cellule-titre { font-size: 16px; font-weight: 500; }
  .grille-saisie { max-height: calc(100vh - 220px); }
}
/* PC moyen (900–1279 px) : on cache les colonnes « large » ; leur contenu passe en sous-titre. */
@media (min-width: 900px) and (max-width: 1279px) {
  .seulement-moyen { display: revert !important; }
  .groupe-liste.colonnes .large { display: none !important; }
}
/* Grand PC (≥ 1280 px) : toutes les colonnes. */
@media (min-width: 1280px) {
  body.connecte { grid-template-columns: 264px minmax(0, 1fr); }
  .groupe-liste.colonnes .liste-entete, .groupe-liste.colonnes .cellule { grid-template-columns: var(--colonnes-large, var(--colonnes)); }
}

/* ---------- 16. Impression ---------- */
@media print {
  .onglets, .barre-laterale, .barre-nav, .action-principale, .filtres-formulaire, .feuille, .bouton { display: none !important; }
  body.connecte { display: block; }
  body, .page { background: #fff; color: #000; padding: 0; }
  .liste, .groupe-liste, .groupe-details, .carte, .defilant { border: 1px solid #ccc; }
}

/* Sections repliables (<details class="section-repliable">) : titre touchable au doigt. */
.section-repliable > summary { display: flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; color: var(--accent); }

/* Choix du thème dans le menu */
.choix-theme { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 3px; border-radius: 10px; background: var(--champ-gris); }
.choix-theme button { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--texte); font: inherit; font-size: 14px; cursor: pointer; }
.choix-theme button[aria-pressed="true"] { background: var(--cellule); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.barre-laterale .choix-theme { margin: 8px 0; background: rgba(255, 255, 255, .08); }
.barre-laterale .choix-theme button { color: #e6e6eb; min-height: 32px; font-size: 13px; }
.barre-laterale .choix-theme button[aria-pressed="true"] { background: rgba(255, 255, 255, .18); color: #fff; }

/* Accueil : boutons d'ajout directs (grille de tuiles, au pouce sur téléphone). */
.ajouts-rapides { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin: 0 0 24px; }
.ajouts-rapides a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 78px;
  padding: 10px 6px; border-radius: var(--rayon); background: var(--cellule); color: var(--texte);
  text-decoration: none; font-size: 14px; font-weight: 500; text-align: center;
}
.ajouts-rapides a .icone { color: var(--accent); }
.ajouts-rapides a:hover { text-decoration: none; background: var(--cellule-survol); }
.ajouts-rapides a:active { background: var(--cellule-presse); }
