:root {
  --fond: #f4f6f5;
  --carte: #ffffff;
  --texte: #17211d;
  --doux: #66736d;
  --bord: #e2e7e4;
  --accent: #1f7a5a;
  --accent-clair: #e3f3ec;
  --rouge: #c0392b;
  --rouge-clair: #fbe9e7;
  --orange: #c77a06;
  --orange-clair: #fdf1dc;
  --vert: #1f7a5a;
  --barre: #e7ecea;
  --ombre: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --rayon: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f1412; --carte: #18201c; --texte: #e8eeeb; --doux: #93a19a; --bord: #26302b;
    --accent: #3fb68b; --accent-clair: #17352a; --rouge: #ef6f61; --rouge-clair: #3a1c19;
    --orange: #e9a23b; --orange-clair: #3a2a12; --vert: #3fb68b; --barre: #26302b;
    --ombre: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--doux); font-weight: 600; margin: 22px 4px 8px; }
.conteneur { max-width: 560px; margin: 0 auto; padding: 0 14px; }

/* En-tête */
.entete { position: sticky; top: 0; z-index: 5; background: var(--fond); padding-top: env(safe-area-inset-top); }
.entete .conteneur { display: flex; align-items: center; gap: 8px; height: 54px; }
.entete .titre { font-weight: 700; font-size: 19px; flex: 1; display: flex; align-items: center; gap: 8px; color: var(--texte); }
.icone-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: var(--texte); cursor: pointer; padding: 0; }
.icone-btn:active { background: var(--barre); }
.icone-btn svg { width: 22px; height: 22px; }

/* Barre d'onglets */
.onglets { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--carte); border-top: 1px solid var(--bord);
  padding-bottom: env(safe-area-inset-bottom); }
.onglets .conteneur { display: flex; justify-content: space-around; align-items: center; height: 64px; padding: 0 4px; }
.onglets a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--doux); position: relative; }
.onglets a svg { width: 24px; height: 24px; }
.onglets a.actif { color: var(--accent); font-weight: 600; }
.onglets a.plus { flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff; justify-content: center;
  margin: 0 8px; box-shadow: 0 4px 12px rgba(31, 122, 90, .35); }
.onglets a.plus svg { width: 28px; height: 28px; }
.pastille { position: absolute; top: -4px; left: calc(50% + 6px); background: var(--rouge); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; padding: 0 5px; text-align: center; }

/* Cartes, listes */
.carte { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 16px; margin-bottom: 12px; }
.carte.lien { display: block; color: inherit; }
.liste { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); overflow: hidden; margin-bottom: 12px; }
.liste > * { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; border-top: 1px solid var(--bord); }
.liste > *:first-child { border-top: 0; }
.liste .emoji { font-size: 22px; width: 32px; text-align: center; flex: none; }
.liste .milieu { flex: 1; min-width: 0; }
.liste .nom { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.liste .sous { font-size: 13px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.liste .droite { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.doux { color: var(--doux); }
.petit { font-size: 13px; }
.positif { color: var(--vert); }
.negatif { color: var(--rouge); }
.chiffre { font-variant-numeric: tabular-nums; }

/* Accueil */
.mois-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.mois-nav .nom { font-weight: 700; font-size: 17px; text-align: center; }
.mois-nav .nom small { display: block; font-weight: 400; font-size: 12px; color: var(--doux); }
.hero { text-align: center; padding: 22px 16px; }
.hero .etiquette { color: var(--doux); font-size: 14px; }
.hero .grand { font-size: 42px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 2px 0; }
.hero .detail { font-size: 14px; color: var(--doux); }
.hero .stats { display: flex; justify-content: center; gap: 22px; margin-top: 14px; font-size: 13px; color: var(--doux); }
.hero .stats b { display: block; color: var(--texte); font-size: 15px; }
.alerte-tri { display: flex; align-items: center; gap: 12px; background: var(--orange-clair); color: var(--texte); border-radius: var(--rayon); padding: 14px 16px; margin-bottom: 12px; }
.alerte-tri .gros { font-size: 26px; }
.alerte-tri .milieu { flex: 1; }
.alerte-tri b { display: block; }
.jauge { height: 8px; background: var(--barre); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.jauge > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.jauge.attention > span { background: var(--orange); }
.jauge.depasse > span { background: var(--rouge); }

/* Boutons, formulaires */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 18px;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--barre); color: var(--texte); text-align: center; }
.btn.principal { background: var(--accent); color: #fff; }
.btn.danger { background: var(--rouge-clair); color: var(--rouge); }
.btn.large { width: 100%; }
.btn.petit { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(.98); }
.champ { margin-bottom: 14px; }
.champ label, .etiq { display: block; font-size: 14px; color: var(--doux); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--bord);
  background: var(--carte); color: var(--texte); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.montant-saisie { font-size: 40px !important; font-weight: 800; text-align: center; border: 0 !important; background: none !important; padding: 8px !important; }
.case { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 15px; }
.case input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.ligne { display: flex; gap: 10px; align-items: center; }
.ligne > .f { flex: 1; min-width: 0; }

/* Grille de choix d'enveloppe (tri, saisie) */
.choix { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.choix button, .choix label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 78px;
  padding: 10px 6px; border-radius: 14px; border: 1px solid var(--bord); background: var(--carte); color: var(--texte); font: inherit;
  font-size: 13px; font-weight: 600; text-align: center; cursor: pointer; line-height: 1.2; }
.choix .e { font-size: 26px; }
.choix button:active, .choix label:active { background: var(--accent-clair); }
.choix input { position: absolute; opacity: 0; pointer-events: none; }
.choix label:has(input:checked) { border-color: var(--accent); background: var(--accent-clair); outline: 2px solid var(--accent); }
.choix .secondaire { font-weight: 500; color: var(--doux); }
.segment { display: flex; background: var(--barre); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.segment label { flex: 1; text-align: center; padding: 9px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 15px; color: var(--doux); }
.segment input { display: none; }
.segment label:has(input:checked) { background: var(--carte); color: var(--texte); box-shadow: var(--ombre); }

/* Tri */
.tx-carte { text-align: center; padding: 22px 16px; }
.tx-carte .tiers { font-size: 22px; font-weight: 700; }
.tx-carte .montant { font-size: 36px; font-weight: 800; margin: 6px 0; font-variant-numeric: tabular-nums; }
.tx-carte .brut { font-size: 12px; color: var(--doux); word-break: break-word; margin-top: 8px; }

/* Filtres */
.puces { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.puces::-webkit-scrollbar { display: none; }
.puces a { flex: none; padding: 7px 12px; border-radius: 20px; background: var(--carte); border: 1px solid var(--bord); color: var(--texte); font-size: 14px; white-space: nowrap; }
.puces a.actif { background: var(--accent); border-color: var(--accent); color: #fff; }
.jour { font-size: 13px; color: var(--doux); font-weight: 600; margin: 14px 4px 6px; display: flex; justify-content: space-between; }

/* Plan */
.repartir { position: sticky; top: 54px; z-index: 4; display: flex; justify-content: space-between; align-items: center; }
.repartir.ok { background: var(--accent-clair); }
.repartir.trop { background: var(--rouge-clair); }
.env-plan { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.env-plan > .emoji-in { flex: 0 0 52px; text-align: center; font-size: 22px; padding: 8px 4px; }
.env-plan > input[type=text]:not(.emoji-in) { flex: 1 1 calc(100% - 60px); min-width: 0; }
.env-plan > select { flex: 1 1 0; min-width: 0; }
.env-plan > .ligne { flex: 0 0 150px; gap: 6px; }
.env-plan input.montant-in { text-align: right; font-weight: 700; }
.env-outils { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.env-outils select { width: auto; padding: 6px 10px; font-size: 14px; }

/* Messages */
.bandeau { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 15px; }
.bandeau.ok { background: var(--accent-clair); }
.bandeau.erreur { background: var(--rouge-clair); color: var(--rouge); }
.bandeau.alerte { background: var(--orange-clair); }
.code { font-family: ui-monospace, monospace; font-size: 13px; background: var(--barre); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
ol.etapes { padding-left: 20px; margin: 8px 0; }
ol.etapes li { margin-bottom: 8px; }
.vide { text-align: center; padding: 40px 20px; color: var(--doux); }
.vide .gros { font-size: 48px; }
.connexion { min-height: 100vh; display: flex; align-items: center; }
.connexion .carte { width: 100%; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--texte); color: var(--fond); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 92vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); animation: disparaitre 4s forwards; }
.toast.erreur { background: var(--rouge); color: #fff; animation-duration: 8s; }
@keyframes disparaitre { 0%, 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
