:root {
  --fond: #f4f6f9;
  --surface: #ffffff;
  --texte: #17212b;
  --discret: #5f6b7a;
  --bord: #dfe4ea;
  --accent: #123a56;
  --accent-texte: #ffffff;
  --accent-doux: #e7eef5;
  --ok: #1f7a4d;
  --attention-fond: #fff6e0;
  --attention-bord: #e9c46a;
  --info-fond: #e9f1fb;
  --info-bord: #9bbce3;
  --danger: #b3261e;
  --rayon: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f141a;
    --surface: #18202a;
    --texte: #e6ebf1;
    --discret: #9aa7b6;
    --bord: #2a3440;
    --accent: #6fa8d6;
    --accent-texte: #0b1620;
    --accent-doux: #1d2b39;
    --ok: #57c08a;
    --attention-fond: #2b2414;
    --attention-bord: #7a6224;
    --info-fond: #142233;
    --info-bord: #2f5175;
    --danger: #ef8b84;
    color-scheme: dark;
  }
}

* { 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(90px + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 1.2rem; text-transform: capitalize; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }
code { font-size: 0.9em; background: var(--accent-doux); padding: 1px 5px; border-radius: 5px; }
.discret { color: var(--discret); font-size: 0.88rem; }
.chargement, .vide { color: var(--discret); text-align: center; padding: 32px 16px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: 0.6; cursor: progress; }
.primaire, .secondaire, .danger {
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  min-height: 44px;
}
.primaire { background: var(--accent); color: var(--accent-texte); }
.secondaire { background: var(--surface); border: 1px solid var(--bord); }
.danger { color: var(--danger); border: 1px solid currentColor; }
.large { width: 100%; }
.lien { color: var(--discret); text-decoration: underline; padding: 4px; font-size: 0.88rem; }
.icone { width: 44px; height: 44px; border-radius: 50%; font-size: 1.5rem; line-height: 1; color: inherit; }
.icone:hover { background: var(--accent-doux); }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--surface);
}
input[type="file"] { padding: 8px 4px; border-style: dashed; font-size: 0.9rem; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--discret); }
label.case { flex-direction: row; align-items: center; gap: 10px; color: var(--texte); font-size: 1rem; }
label.case input { width: 22px; min-height: 22px; }

/* Connexion */
.connexion { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; text-align: center; }
.connexion h1 { margin: 12px 0 20px; font-size: 1.4rem; text-transform: none; }
.connexion form { display: grid; gap: 14px; text-align: left; }
.erreur { color: var(--danger); margin: 0; }

/* En-tête */
.entete {
  background: var(--accent);
  color: var(--accent-texte);
  padding: calc(8px + env(safe-area-inset-top)) 16px 12px;
}
.entete .mois { display: flex; align-items: center; justify-content: space-between; max-width: 760px; margin: 0 auto; }
.entete .resume { display: flex; gap: 16px; align-items: center; max-width: 760px; margin: 2px auto 0; font-size: 0.92rem; }
.entete .resume .lien { margin-left: auto; color: inherit; opacity: 0.8; }
.entete .icone:hover { background: rgba(255, 255, 255, 0.15); }

.onglets {
  position: sticky; top: 0; z-index: 5;
  display: flex; background: var(--surface); border-bottom: 1px solid var(--bord);
  overflow-x: auto;
}
.onglets button {
  flex: 1; padding: 12px 8px; min-height: 46px; white-space: nowrap;
  color: var(--discret); font-weight: 600; border-bottom: 3px solid transparent;
}
.onglets button[aria-selected="true"] { color: var(--texte); border-bottom-color: var(--accent); }

.contenu { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 16px; }
.titre-ligne { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.titre-ligne h2 { margin: 0; }

.alerte { border-radius: var(--rayon); padding: 12px 14px; border: 1px solid; font-size: 0.93rem; margin: 0; }
.alerte ul { margin: 6px 0 0; padding-left: 20px; }
.alerte.attention { background: var(--attention-fond); border-color: var(--attention-bord); }
.alerte.info { background: var(--info-fond); border-color: var(--info-bord); }

/* Listes */
.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.liste .ligne {
  width: 100%; text-align: left; display: grid; gap: 4px;
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 12px 14px;
}
.liste.compacte .ligne { border-radius: 10px; }
.ligne:hover { border-color: var(--accent); }
.ligne.inactif { opacity: 0.55; }
.ligne .l1, .ligne .l2 { display: flex; justify-content: space-between; gap: 12px; }
.ligne .fournisseur { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .montant { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ligne .l2 { color: var(--discret); font-size: 0.86rem; align-items: center; }
.ligne .l2 > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Les enfants de grille et de flex ne rétrécissent pas sous leur contenu sans min-width: 0. */
.contenu > *, .liste > li, .ligne > span, .ligne .l1 > span:first-child, .ligne .l2 > span:first-child { min-width: 0; }
.ligne .l1 > span:first-child, .ligne .l2 > span:first-child { flex: 1; }
.pastilles { display: flex; gap: 4px; flex-shrink: 0; }
.pastille { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-doux); color: var(--texte); }
.pastille.a_traiter { background: var(--attention-fond); border: 1px solid var(--attention-bord); }
.pastille.valide { color: var(--ok); }
.pastille.exporte { color: var(--discret); }

.export { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--bord); }
.export:last-child { border-bottom: 0; }
.export .boutons { display: flex; gap: 6px; }

/* Récap */
table.recap { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.recap th, .recap td { padding: 7px 4px; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: top; }
.recap th { color: var(--discret); font-weight: 600; font-size: 0.8rem; }
.recap .n { text-align: right; white-space: nowrap; }
.recap tfoot td { font-weight: 700; border-bottom: 0; }
@media (max-width: 480px) {
  .recap th:nth-child(4), .recap td:nth-child(4) { display: none; }
}

/* Actions flottantes */
.actions-flottantes {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--fond) 35%);
}
.actions-flottantes .primaire { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }

/* Fiche (dialog) */
dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px); background: var(--surface); color: var(--texte);
}
dialog::backdrop { background: rgba(8, 14, 20, 0.5); }
.fiche { padding: 0 16px 16px; }
.fiche header {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  display: flex; justify-content: space-between; align-items: center; padding: 10px 0;
}
.fiche h2 { margin: 0; }
.fiche .grille { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fiche .plein { grid-column: 1 / -1; }
.fiche footer { display: flex; justify-content: space-between; margin-top: 16px; gap: 12px; }
.apercu { display: block; margin-bottom: 12px; text-align: center; padding: 10px; border: 1px solid var(--bord); border-radius: 10px; color: var(--accent); }
.apercu img { max-width: 100%; max-height: 260px; border-radius: 6px; display: block; margin: 0 auto; }
@media (max-width: 380px) { .fiche .grille { grid-template-columns: 1fr; } }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--texte); color: var(--fond); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: 0.2s; max-width: calc(100vw - 32px); z-index: 20; font-size: 0.93rem;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }
#toast.erreur { background: var(--danger); color: #fff; }
#toast.ok { background: var(--ok); color: #fff; }
