/* ─────────────────────────────  Jetons  ───────────────────────────── */
:root {
  /* Accent repris du logo AHD76 (ahd76.svg). Jamais de valeur codée en dur
     ailleurs : tout passe par ces jetons. */
  --accent: #3366ff;
  --accent-clair: #a3baff;
  --accent-survol: #2850c7;
  /* Couleur du texte posé SUR un aplat de couleur. En thème sombre les aplats
     s'éclaircissent, donc le lettrage doit s'assombrir — sinon le contraste
     tombe à 2,5:1. Chaque aplat porteur de texte a son jeton « sur- ».
     L'ambre n'en a pas : il ne sert jamais de fond à du texte. */
  --sur-accent: #ffffff;
  --sur-rouge: #ffffff;

  --fond: #f6f7fa;
  --surface: #ffffff;
  --surface-2: #eff1f7;
  --bordure: #d9dde8;
  --texte: #171b24;
  --texte-doux: #5c6675;

  --rouge: #b3261e;
  --rouge-fond: #fdecea;
  --ambre: #8a6100;
  --ambre-fond: #fdf4e0;

  --rayon: 10px;
  --ombre: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
  --police: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) {
    --fond: #0f1117;
    --surface: #171b24;
    --surface-2: #1f2531;
    --bordure: #2f3746;
    --texte: #e7eaf2;
    --texte-doux: #99a1b3;
    --accent: #7fa0ff;
    --accent-survol: #9db6ff;
    --sur-accent: #0f1117;
    --sur-rouge: #0f1117;
    --rouge: #ff8a80;
    --rouge-fond: #3a1a17;
    --ambre: #f0c264;
    --ambre-fond: #362a10;
    --ombre: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
  }
}

:root[data-theme="sombre"] {
  --fond: #0f1117;
  --surface: #171b24;
  --surface-2: #1f2531;
  --bordure: #2f3746;
  --texte: #e7eaf2;
  --texte-doux: #99a1b3;
  --accent: #7fa0ff;
  --accent-survol: #9db6ff;
  --sur-accent: #0f1117;
  --sur-rouge: #0f1117;
  --rouge: #ff8a80;
  --rouge-fond: #3a1a17;
  --ambre: #f0c264;
  --ambre-fond: #362a10;
  --ombre: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--police);
  font-size: 15px;
  color: var(--texte);
  background: var(--fond);
  -webkit-text-size-adjust: 100%;
}

/* ─────────────────────────────  Barre  ────────────────────────────── */
.barre {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--bordure);
  padding-top: max(10px, env(safe-area-inset-top));
}
.marque { display: flex; align-items: center; gap: 9px; font-weight: 650; color: inherit; text-decoration: none; }
.marque img { border-radius: 7px; }
.onglets { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.onglets button {
  border: 0; background: transparent; color: var(--texte-doux);
  padding: 7px 13px; border-radius: 999px; font: inherit; font-weight: 550; cursor: pointer;
}
.onglets button:hover { background: var(--surface-2); color: var(--texte); }
.onglets button.actif { background: var(--accent); color: var(--sur-accent); }
.icone {
  border: 1px solid var(--bordure); background: var(--surface); color: var(--texte-doux);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer; font-size: 15px;
}

/* ─────────────────────────────  Structure  ────────────────────────── */
main { max-width: 1120px; margin: 0 auto; padding: 22px 18px 80px; }
.vue { display: none; }
.vue.actif { display: block; }

.entete-vue {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
h1 { font-size: 21px; margin: 0; letter-spacing: -0.2px; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1px;
     color: var(--texte-doux); margin: 26px 0 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.indice { color: var(--texte-doux); font-size: 13px; align-self: center; }
.indice em, label em { display: block; font-style: normal; font-size: 12px;
                       color: var(--texte-doux); margin-top: 3px; font-weight: 400; }

/* ─────────────────────────────  Boutons  ──────────────────────────── */
button {
  font: inherit; font-weight: 550; cursor: pointer;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--bordure); background: var(--surface); color: var(--texte);
}
button:hover { background: var(--surface-2); }
button.primaire { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
button.primaire:hover { background: var(--accent-survol); border-color: var(--accent-survol); }
button.danger { background: var(--rouge); border-color: var(--rouge); color: var(--sur-rouge); }
button.danger:hover { filter: brightness(0.92); }
button.discret { background: transparent; border-style: dashed; color: var(--texte-doux); width: 100%; margin-top: 8px; }
button.lien { background: none; border: 0; color: inherit; text-decoration: underline; padding: 0 4px; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ─────────────────────────────  Cartes / listes  ──────────────────── */
.carte {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--rayon); padding: 18px; box-shadow: var(--ombre);
}
.liste { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: 8.5rem 1fr auto auto;
  gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--rayon); padding: 12px 14px; cursor: pointer;
}
.item:hover { border-color: var(--accent-clair); }
.item .principal { font-weight: 600; }
.item .secondaire { color: var(--texte-doux); font-size: 13px; }
.item .montant { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.vide { color: var(--texte-doux); text-align: center; padding: 44px 16px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .3px; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.brouillon { background: var(--surface-2); color: var(--texte-doux); border-color: var(--bordure); }
.badge.emise { background: var(--accent); color: var(--sur-accent); }
.badge.payee { background: transparent; color: var(--accent); border-color: var(--accent); }
/* Règlement incomplet : même famille que « payée », mais le trait discontinu
   dit qu'il manque quelque chose. Fond transparent et non --surface-2, qui
   ferait tomber le texte à 4,15:1 en thème clair. */
.badge.partielle { background: transparent; color: var(--accent);
                   border-color: var(--accent); border-style: dashed; }
.badge.annulee { background: var(--surface-2); color: var(--texte-doux);
                 border-color: var(--bordure); text-decoration: line-through; }
.badge.avoir { background: var(--ambre-fond); color: var(--ambre); border-color: var(--ambre); }

/* ─────────────────────────────  Formulaires  ──────────────────────── */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px;
        font-weight: 550; color: var(--texte-doux); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--texte);
  background: var(--fond); border: 1px solid var(--bordure);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { resize: vertical; }
.grille-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; }
.grille-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.large { grid-column: 1 / -1; }
.case { flex-direction: row; align-items: flex-start; gap: 9px; margin-top: 16px; font-weight: 500; color: var(--texte); }
.case input { width: auto; margin-top: 3px; }
.case-inline { flex-direction: row; align-items: center; gap: 8px; color: var(--texte); }
.case-inline input { width: auto; }

/* ─────────────────────────────  Lignes de facture  ────────────────── */
.tableau-lignes { border: 1px solid var(--bordure); border-radius: var(--rayon); overflow: hidden; }
.ligne {
  display: grid; grid-template-columns: 7.5rem 1fr 5rem 7.5rem 8rem 2.2rem;
  gap: 8px; align-items: center; padding: 8px 10px;
  border-bottom: 1px solid var(--bordure);
}
.ligne:last-child { border-bottom: 0; }
.ligne.entete { background: var(--surface-2); font-size: 12px; font-weight: 650;
                color: var(--texte-doux); text-transform: uppercase; letter-spacing: .6px; }
.ligne.debours { background: color-mix(in srgb, var(--ambre-fond) 55%, transparent); }
.ligne .num, .ligne input.num { text-align: right; font-variant-numeric: tabular-nums; }
.ligne .calcule { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.ligne .retirer { border: 0; background: transparent; color: var(--texte-doux); padding: 4px; }
.ligne .retirer:hover { color: var(--rouge); background: transparent; }

/* ─────────────────────────────  Totaux  ───────────────────────────── */
.totaux { margin-top: 20px; margin-left: auto; width: min(360px, 100%); display: grid; gap: 6px; }
.totaux div { display: flex; justify-content: space-between; gap: 16px; font-size: 14px; }
.totaux span { color: var(--texte-doux); }
.totaux b { font-variant-numeric: tabular-nums; }
.totaux .net { border-top: 2px solid var(--accent); padding-top: 9px; margin-top: 5px; font-size: 18px; }
.totaux .net b { color: var(--accent); }

/* ─────────────────────────────  Tuiles  ───────────────────────────── */
.annee { color: var(--texte-doux); font-weight: 400; }

.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tuile {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--rayon); padding: 15px 17px; box-shadow: var(--ombre);
  display: flex; flex-direction: column; gap: 4px;
}
.tuile .etiquette { font-size: 12px; text-transform: uppercase; letter-spacing: .9px;
                    color: var(--texte-doux); font-weight: 650; }
.tuile b { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.tuile em { font-style: normal; font-size: 12px; color: var(--texte-doux); line-height: 1.45; }
.tuile.majeure { border-color: var(--accent); }
.tuile.majeure b { color: var(--accent); }
.tuile.accent-rouge b { color: var(--rouge); }

/* ─────────────────────────────  Jauges  ───────────────────────────── */
.jauges { display: grid; gap: 12px; }
.jauge { background: var(--surface); border: 1px solid var(--bordure);
         border-radius: var(--rayon); padding: 14px 16px; }
.jauge .tete { display: flex; justify-content: space-between; gap: 12px;
               font-size: 13.5px; margin-bottom: 9px; flex-wrap: wrap; }
.jauge .tete b { font-variant-numeric: tabular-nums; }
.jauge .piste { height: 9px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.jauge .barre { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.jauge.important .barre { background: var(--ambre); }
.jauge.critique .barre { background: var(--rouge); }
.jauge .note { font-size: 12px; color: var(--texte-doux); margin-top: 8px; line-height: 1.5; }

/* ───────────────────────────  Déclarations  ───────────────────────── */
.declaration {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--rayon); padding: 14px 16px;
}
.declaration.due { border-left: 3px solid var(--ambre); }
.declaration.retard { border-left: 3px solid var(--rouge); }
.declaration.faite { border-left: 3px solid var(--accent); opacity: .72; }
.declaration .tete { display: flex; justify-content: space-between; align-items: center;
                     gap: 12px; flex-wrap: wrap; }
.declaration .periode { font-weight: 650; }
.declaration .limite { font-size: 12.5px; color: var(--texte-doux); }
.declaration .somme { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums;
                      color: var(--accent); margin: 8px 0 2px; }
.declaration .apres { font-size: 12.5px; color: var(--texte-doux); }
.declaration details { margin-top: 10px; }
.declaration summary { cursor: pointer; font-size: 12.5px; color: var(--texte-doux); }
.declaration .detail-ligne { display: flex; justify-content: space-between; gap: 10px;
                             font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--bordure); }

/* ─────────────────────────────  Tableaux  ─────────────────────────── */
.tableau { width: 100%; border-collapse: collapse; background: var(--surface);
           border: 1px solid var(--bordure); border-radius: var(--rayon); overflow: hidden; }
.tableau th { background: var(--surface-2); text-align: left; font-size: 12px;
              text-transform: uppercase; letter-spacing: .7px; color: var(--texte-doux);
              padding: 10px 12px; font-weight: 650; }
.tableau td { padding: 9px 12px; border-top: 1px solid var(--bordure); font-size: 14px; }
.tableau td.num, .tableau th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tableau tfoot td { font-weight: 700; background: var(--surface-2); }
.defilant { overflow-x: auto; }

.grille-encaissement {
  display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr auto;
  gap: 11px; align-items: end; margin-top: 14px;
  padding-top: 14px; border-top: 1px solid var(--bordure);
}
.encaissement-ligne {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--bordure); font-size: 14px;
}
.encaissement-ligne .montant { font-variant-numeric: tabular-nums; font-weight: 650; }

/* ─────────────────────────────  Alertes  ──────────────────────────── */
.alerte { border-radius: var(--rayon); padding: 12px 15px; margin-bottom: 14px;
          font-size: 14px; line-height: 1.55; border: 1px solid; }
.alerte ul { margin: 8px 0 0; padding-left: 20px; }
.alerte.bloquant { background: var(--rouge-fond); border-color: var(--rouge); color: var(--rouge); }
.alerte.prudence { background: var(--ambre-fond); border-color: var(--ambre); color: var(--ambre); }
.alerte.verrou { background: var(--surface-2); border-color: var(--bordure); color: var(--texte-doux); }
.alerte.info { background: var(--surface); border-color: var(--bordure); color: var(--texte-doux); }
.alerte.info b { color: var(--texte); }
.alerte.critique { background: var(--rouge-fond); border-color: var(--rouge); color: var(--rouge); }
.alerte.important { background: var(--ambre-fond); border-color: var(--ambre); color: var(--ambre); }
.alerte.information { background: var(--surface); border-color: var(--accent-clair); color: var(--texte-doux); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--texte); color: var(--fond);
  padding: 11px 20px; border-radius: 999px; box-shadow: var(--ombre);
  font-size: 14px; font-weight: 550; z-index: 50; max-width: 90vw;
}
.toast.erreur { background: var(--rouge); color: var(--sur-rouge); }

dialog {
  border: 1px solid var(--bordure); border-radius: var(--rayon);
  background: var(--surface); color: var(--texte);
  padding: 22px; max-width: 460px; box-shadow: var(--ombre);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin-top: 0; color: var(--texte); text-transform: none;
            letter-spacing: 0; font-size: 17px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 20px 0 0; }

/* ─────────────────────────────  Connexion  ────────────────────────── */
.page-connexion { display: flex; min-height: 100vh; min-height: 100dvh; }
.connexion {
  margin: auto; padding: 24px 18px;
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px;
}
.retour-site { color: var(--texte-doux); text-decoration: none; font-size: 13px; font-weight: 550; }
.retour-site:hover { color: var(--accent); }
.connexion-carte { padding: 26px 24px; }
.connexion-logo { border-radius: 12px; display: block; margin-bottom: 14px; }
.connexion h1 { font-size: 22px; margin-bottom: 4px; }
.connexion form { display: flex; flex-direction: column; gap: 13px; margin-top: 18px; }
.large-bouton { width: 100%; padding: 11px 14px; margin-top: 4px; }
.connexion-pied { display: block; margin: 16px 0 0; line-height: 1.5; }

/* ─────────────────────────────  Session  ──────────────────────────── */
.session { display: flex; align-items: center; gap: 8px; }
.session .qui {
  font-size: 12.5px; color: var(--texte-doux); font-weight: 600;
  max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.barre .lien-site { color: var(--texte-doux); text-decoration: none; font-size: 13px; font-weight: 550; }
.barre .lien-site:hover { color: var(--accent); }

/* ─────────────────────────────  Adaptatif  ────────────────────────── */
@media (max-width: 820px) {
  .grille-3 { grid-template-columns: repeat(2, 1fr); }
  .ligne { grid-template-columns: 1fr 1fr; grid-auto-rows: min-content; row-gap: 6px; }
  .ligne.entete { display: none; }
  .ligne > * { grid-column: span 1; }
  .ligne .designation { grid-column: 1 / -1; }
  .item { grid-template-columns: 1fr auto; }
}

@media (max-width: 820px) {
  .grille-encaissement { grid-template-columns: 1fr 1fr; }
  .grille-encaissement button { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  main { padding: 16px 12px 70px; }
  .grille-2, .grille-3, .grille-encaissement { grid-template-columns: 1fr; }
  .tuile b { font-size: 22px; }
  .barre { flex-wrap: wrap; }
  .onglets { width: 100%; order: 3; margin-left: 0; }
  .actions button { flex: 1 1 auto; }
}
