/* MaliFacture — feuille de style unique, mobile d'abord.
   Palette : vert profond (confiance, bambara « ji » = eau/source), or/sable
   (le Sahel), et un rouge terre pour les retards. Trois couleurs, pas plus. */

:root {
  --vert: #0f5132;
  --vert-clair: #157347;
  --vert-pale: #e7f2ec;
  --sable: #c99700;
  --sable-pale: #fff6dc;
  --terre: #a3352a;
  --terre-pale: #fdecea;
  --encre: #14201a;
  --gris: #5c6b63;
  --bord: #dbe3de;
  --fond: #f6f8f7;
  --carte: #ffffff;
  --rayon: 14px;
  --ombre: 0 1px 2px rgba(20, 32, 26, 0.06), 0 8px 24px rgba(20, 32, 26, 0.05);
}

* { box-sizing: border-box; }

/* `display: grid` sur .nav et .entete écraserait le style natif de [hidden]. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fond);
  color: var(--encre);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--vert-clair); }

h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; }

.muet { color: var(--gris); }
.petit { font-size: 0.82rem; }
.centre { text-align: center; }
.droite { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cache { display: none !important; }

/* Structure ------------------------------------------------------------- */
.entete {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--carte);
  border-bottom: 1px solid var(--bord);
}
.marque { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; letter-spacing: -0.02em; }
.marque .pastille {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--vert); color: #fff;
  display: grid; place-items: center; font-size: 0.95rem; font-weight: 800;
}
.entete .espace { flex: 1; }
/* Mode installé (écran d'accueil) : l'en-tête respecte l'encoche. */
.installee .entete { padding-top: max(0.7rem, env(safe-area-inset-top)); }

.contenu { max-width: 980px; margin: 0 auto; padding: 1rem 1rem 6rem; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--carte); border-top: 1px solid var(--bord);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 0.55rem 0.2rem 0.5rem;
  font-size: 0.68rem; color: var(--gris); text-decoration: none;
  border-top: 2px solid transparent;
}
.nav a[aria-current="page"] { color: var(--vert); border-top-color: var(--vert); font-weight: 600; }
.nav a .ico { font-size: 1.15rem; line-height: 1; }

@media (min-width: 760px) {
  .nav {
    position: static; max-width: 980px; margin: 0.5rem auto 0;
    border: 1px solid var(--bord); border-radius: var(--rayon);
    grid-template-columns: repeat(5, max-content); justify-content: start; gap: 0.3rem;
    padding: 0.3rem;
  }
  .nav a { flex-direction: row; gap: 0.4rem; font-size: 0.9rem; padding: 0.5rem 0.9rem; border-radius: 10px; border-top: 0; }
  .nav a[aria-current="page"] { background: var(--vert-pale); }
  .contenu { padding-bottom: 2rem; }
}

/* Bandeau réseau : hors connexion, ou factures préparées en attente d'envoi. */
.bandeau {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.5rem 1rem; font-size: 0.82rem;
  border-bottom: 1px solid var(--bord);
}
.bandeau.avert { background: var(--sable-pale); color: #6b5000; }
.bandeau.info { background: var(--vert-pale); color: var(--vert); }

/* Cartes ---------------------------------------------------------------- */
.carte {
  background: var(--carte); border: 1px solid var(--bord);
  border-radius: var(--rayon); box-shadow: var(--ombre);
  padding: 1rem; margin-bottom: 0.9rem;
}
.carte.serre { padding: 0.7rem 0.9rem; }
.grille { display: grid; gap: 0.75rem; }
.grille.deux { grid-template-columns: 1fr; }
@media (min-width: 620px) {
  .grille.deux { grid-template-columns: 1fr 1fr; }
  .grille.trois { grid-template-columns: repeat(3, 1fr); }
}

.grille, .kpi { min-width: 0; }
.grille > *, .kpi > * { min-width: 0; }

.kpi { display: grid; gap: 0.6rem; grid-template-columns: 1fr 1fr; margin-bottom: 0.9rem; }
@media (min-width: 720px) { .kpi { grid-template-columns: repeat(4, 1fr); } }
.kpi .carte { margin: 0; padding: 0.85rem; }
.kpi .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gris); }
.kpi .valeur { font-size: clamp(0.98rem, 4.2vw, 1.15rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .valeur.neg { color: var(--terre); }
.kpi .valeur.pos { color: var(--vert); }

/* Formulaires ----------------------------------------------------------- */
label { display: block; font-size: 0.84rem; font-weight: 600; margin-bottom: 0.25rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 0.65rem 0.7rem;
  border: 1px solid var(--bord); border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--vert-clair); outline-offset: 1px; border-color: var(--vert-clair);
}
textarea { min-height: 80px; resize: vertical; }
.champ { margin-bottom: 0.8rem; }
.aide { font-size: 0.78rem; color: var(--gris); margin-top: 0.2rem; }
.erreur-champ { font-size: 0.78rem; color: var(--terre); margin-top: 0.2rem; }

.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.7rem 1.1rem; border-radius: 10px; border: 1px solid var(--vert);
  background: var(--vert); color: #fff; font-weight: 600; cursor: pointer;
  text-decoration: none; min-height: 44px;
}
.bouton:hover { background: var(--vert-clair); }
.bouton:disabled { opacity: 0.55; cursor: not-allowed; }
.bouton.second { background: #fff; color: var(--vert); }
.bouton.second:hover { background: var(--vert-pale); }
.bouton.discret { background: none; border-color: transparent; color: var(--gris); }
.bouton.discret:hover { background: var(--fond); color: var(--encre); }
.bouton.danger { background: #fff; border-color: var(--terre); color: var(--terre); }
.bouton.danger:hover { background: var(--terre-pale); }
.bouton.bloc { width: 100%; }
.bouton.mini { padding: 0.35rem 0.65rem; min-height: 34px; font-size: 0.82rem; }
.rangee { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.rangee.fin { justify-content: flex-end; }

/* Tableaux -------------------------------------------------------------- */
.tableau { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tableau th, .tableau td { padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: top; }
.tableau th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gris); font-weight: 600; }
.tableau td.nombre, .tableau th.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tableau tbody tr:last-child td { border-bottom: 0; }
.tableau tbody tr.cliquable { cursor: pointer; }
.tableau tbody tr.cliquable:hover { background: var(--fond); }
.defile { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* Cartes de facture ----------------------------------------------------- */
.facture-carte {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: #fff; border: 1px solid var(--bord); border-radius: 12px;
  padding: 0.7rem 0.85rem; margin-bottom: 0.5rem; cursor: pointer;
}
.facture-carte:hover, .facture-carte:focus-visible { border-color: var(--vert-clair); background: var(--vert-pale); }
.facture-carte .mono { white-space: nowrap; }

/* Badges ---------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  background: var(--fond); color: var(--gris); border: 1px solid var(--bord);
}
.badge.paye { background: var(--vert-pale); color: var(--vert); border-color: #bfdfcd; }
.badge.attente { background: var(--sable-pale); color: #7a5c00; border-color: #f0dfa8; }
.badge.retard { background: var(--terre-pale); color: var(--terre); border-color: #f2c9c4; }
.badge.annule { background: #fff; color: var(--gris); text-decoration: line-through; }

/* Messages -------------------------------------------------------------- */
.message { padding: 0.7rem 0.85rem; border-radius: 10px; margin-bottom: 0.8rem; font-size: 0.9rem; }
.message.info { background: var(--vert-pale); color: var(--vert); }
.message.avert { background: var(--sable-pale); color: #6b5000; }
.message.erreur { background: var(--terre-pale); color: var(--terre); }

/* Auth ------------------------------------------------------------------ */
.auth-ecran { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; }
.auth-boite { width: 100%; max-width: 420px; }
.auth-boite .carte { padding: 1.4rem; }
.onglets { display: flex; gap: 0.3rem; background: var(--fond); padding: 0.25rem; border-radius: 10px; margin-bottom: 1rem; }
.onglets button {
  flex: 1; padding: 0.5rem; border: 0; background: none; border-radius: 8px;
  font-weight: 600; color: var(--gris); cursor: pointer;
}
.onglets button[aria-selected="true"] { background: #fff; color: var(--vert); box-shadow: var(--ombre); }

/* Lignes de facture ----------------------------------------------------- */
.ligne-facture {
  display: grid; grid-template-columns: 1fr 72px 110px 32px; gap: 0.4rem; margin-bottom: 0.4rem;
  align-items: start;
}
.ligne-facture input { padding: 0.5rem; }
.ligne-facture .sup {
  border: 0; background: none; color: var(--terre); font-size: 1.1rem; cursor: pointer; padding: 0.4rem 0;
}
@media (max-width: 560px) {
  .ligne-facture { grid-template-columns: 1fr 62px 92px 28px; }
  .ligne-facture input { font-size: 0.9rem; }
}
.total-bloc { border-top: 1px solid var(--bord); margin-top: 0.6rem; padding-top: 0.6rem; }
.total-bloc .ligne { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.total-bloc .ligne.fort { font-weight: 700; font-size: 1.1rem; }

/* Facture publique ------------------------------------------------------ */
.facture-doc { background: #fff; border: 1px solid var(--bord); border-radius: var(--rayon); overflow: hidden; }
.facture-tete { padding: 1.1rem; border-bottom: 1px solid var(--bord); display: flex; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.facture-corps { padding: 1.1rem; }
.facture-total { background: var(--vert-pale); padding: 1rem 1.1rem; }
.facture-total .ligne { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.facture-total .ligne.fort { font-weight: 800; font-size: 1.25rem; color: var(--vert); }
.pied-facture { padding: 0.9rem 1.1rem; font-size: 0.78rem; color: var(--gris); border-top: 1px solid var(--bord); }

.choix-paiement { display: grid; gap: 0.5rem; }
@media (min-width: 560px) { .choix-paiement { grid-template-columns: 1fr 1fr; } }
.choix {
  display: flex; align-items: center; gap: 0.6rem; width: 100%;
  padding: 0.75rem; border: 1px solid var(--bord); border-radius: 12px;
  background: #fff; cursor: pointer; text-align: left;
}
.choix:hover { border-color: var(--vert-clair); background: var(--vert-pale); }
.choix .op { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; }
.op.orange { background: #ff7900; }
.op.moov { background: #0a4a9f; }
.op.wave { background: #1dc4ea; color: #06313b; }
.op.virement { background: #4a5568; }
.op.cinetpay { background: var(--vert); }

.destinataire {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  background: var(--fond); border: 1px dashed var(--bord); border-radius: 10px;
  padding: 0.6rem 0.75rem; margin: 0.5rem 0;
}
.destinataire .num { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; font-size: 1.02rem; letter-spacing: 0.02em; }

/* Modale ---------------------------------------------------------------- */
.voile {
  position: fixed; inset: 0; background: rgba(20, 32, 26, 0.45);
  display: grid; place-items: end center; z-index: 50; padding: 0;
}
@media (min-width: 620px) { .voile { place-items: center; padding: 1rem; } }
.modale {
  background: #fff; width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 1.2rem;
}
@media (min-width: 620px) { .modale { border-radius: 18px; } }
.modale .fermer { float: right; border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--gris); }

/* Divers ---------------------------------------------------------------- */
.separateur { height: 1px; background: var(--bord); margin: 0.9rem 0; border: 0; }
.vide { text-align: center; padding: 1.6rem 1rem; color: var(--gris); }
.vide .ico { font-size: 2rem; display: block; margin-bottom: 0.4rem; }
.pastille-rail { display: inline-flex; align-items: center; gap: 0.35rem; }
.pastille-rail .op { width: 22px; height: 22px; border-radius: 6px; font-size: 0.6rem; }
.charge { text-align: center; padding: 2rem; color: var(--gris); }
.spinner {
  width: 22px; height: 22px; border: 2px solid var(--bord); border-top-color: var(--vert);
  border-radius: 50%; animation: tour 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes tour { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
@media print {
  .entete, .nav, .bouton, .voile { display: none !important; }
  .contenu { padding: 0; }
  .facture-doc { border: 0; box-shadow: none; }
}
