:root {
  --fond: #f6f4ef;
  --carte: #ffffff;
  --encre: #1f2933;
  --discret: #66707a;
  --ligne: #e3dfd6;
  --accent: #1f5c63;
  --accent-fonce: #164349;
  --ok: #2f7d4f;
  --ok-fond: #e4f2ea;
  --danger: #b3382c;
  --danger-fond: #fbe9e6;
  --attention: #9a6a00;
  --attention-fond: #fbf0d4;
  --rayon: 12px;
  --haut-nav: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--haut-nav) + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 0.6rem; }
p { margin: 0.4rem 0; }
.discret { color: var(--discret); font-size: 0.9rem; }
.sr { position: absolute; left: -9999px; }
.chf { white-space: nowrap; font-variant-numeric: tabular-nums; }
main { max-width: 980px; margin: 0 auto; padding: 0.5rem 1rem 2rem; }

/* En-tête et navigation : barre fixe en bas sur mobile */
.haut { display: flex; align-items: center; gap: 1rem; padding: 0.6rem 1rem; background: var(--accent); color: #fff; }
.marque { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.marque span { font-weight: 400; opacity: 0.8; font-size: 0.85rem; margin-left: 0.3rem; }
.deco { margin-left: auto; }
.lien { background: none; border: 0; color: #fff; font: inherit; min-height: 44px; padding: 0 0.5rem; text-decoration: underline; cursor: pointer; }
.nav { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--ligne); padding-bottom: env(safe-area-inset-bottom); }
.nav a { position: relative; display: flex; align-items: center; justify-content: center; min-height: var(--haut-nav);
  color: var(--encre); text-decoration: none; font-size: 0.8rem; font-weight: 600; text-align: center; padding: 0 2px; }
.nav a.actif { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); background: #f1f6f6; }
.pastille { display: inline-block; min-width: 1.4rem; margin-left: 0.25rem; padding: 0 0.35rem; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: 0.75rem; line-height: 1.4rem; text-align: center; }
@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .nav { position: static; display: flex; gap: 0.25rem; background: none; border: 0; padding: 0; margin-left: 1rem; }
  .nav a { color: #fff; font-size: 0.95rem; padding: 0 0.9rem; min-height: 44px; border-radius: 8px; }
  .nav a.actif { background: rgba(255, 255, 255, 0.18); color: #fff; box-shadow: none; }
  .nav a:hover { background: rgba(255, 255, 255, 0.12); }
}

/* Messages */
.flash { padding: 0.8rem 1rem; border-radius: var(--rayon); margin: 0.5rem 0; font-weight: 600; }
.flash-ok { background: var(--ok-fond); color: var(--ok); }
.flash-err { background: var(--danger-fond); color: var(--danger); }

/* Cartes */
.carte { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 1rem; margin: 0.8rem 0; }
.carte-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.numero { font-weight: 700; }
.etiquette { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--discret); font-weight: 700; }
.resume { white-space: pre-wrap; overflow-wrap: anywhere; }
.contexte { font-weight: 600; }
.sujet { font-weight: 600; margin: 0.3rem 0; }
.extrait, .texte-long { white-space: pre-wrap; overflow-wrap: anywhere; color: #3b454e; }
details summary { cursor: pointer; padding: 0.3rem 0; min-height: 44px; }
.apercu { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--ligne); margin: 0.4rem 0; }
.vide { color: var(--discret); text-align: center; padding: 2rem 0; }
.compte { font-size: 0.85rem; background: #ebe7dd; border-radius: 99px; padding: 0.05rem 0.55rem; font-weight: 600; vertical-align: middle; }
.retour { margin: 0.2rem 0; }
.retour a { display: inline-block; padding: 0.6rem 0; text-decoration: none; }
.chip { display: inline-block; background: #ebe7dd; border-radius: 99px; padding: 0.3rem 0.4rem 0.3rem 0.9rem; }
.chip a { padding: 0.5rem; text-decoration: none; }

/* Boutons et champs : zones tactiles >= 48 px */
.bouton { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 1.1rem; border-radius: 10px;
  border: 2px solid transparent; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; background: #eee; color: var(--encre); }
.bouton:disabled { opacity: 0.55; cursor: wait; }
.bouton.principal { background: var(--accent); color: #fff; }
.bouton.principal:hover { background: var(--accent-fonce); }
.bouton.secondaire { background: #fff; border-color: var(--accent); color: var(--accent); }
.bouton.ok { background: var(--ok); color: #fff; }
.bouton.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.bouton.attention { background: var(--attention-fond); border-color: var(--attention); color: var(--attention); }
.bouton.lien-danger { background: none; color: var(--danger); text-decoration: underline; }
.bouton.choix { width: 100%; justify-content: flex-start; text-align: left; background: #f1f6f6; border-color: var(--ligne); font-weight: 400; gap: 0.4rem; flex-wrap: wrap; padding: 0.6rem 1rem; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; min-height: 48px; padding: 0.6rem 0.8rem; font: inherit; color: inherit; background: #fff;
  border: 2px solid var(--ligne); border-radius: 10px; }
input:focus, select:focus, textarea:focus, .bouton:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid #7fb4ba; outline-offset: 2px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 0.6rem 0 0.2rem; }
.decision .actions, .actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.7rem; }
.decision .actions .bouton { flex: 1 1 28%; }
.recherche, .ligne-form, .nouveau, .filtres { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.recherche input, .ligne-form input, .ligne-form select, .nouveau input, .filtres input, .filtres select { flex: 1; min-width: 0; }
.filtres { flex-wrap: wrap; }
.filtres input { flex: 2 1 200px; }
.filtres select { flex: 1 1 140px; }
@media (max-width: 540px) { .recherche, .ligne-form, .nouveau { flex-direction: column; } .actions-demande .bouton { width: 100%; } }
.resultats, .liste, .cartes, .liste-factures, .chronologie { list-style: none; padding: 0; margin: 0.4rem 0; }
.resultats li { margin: 0.4rem 0; }
.liste li { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 0.8rem 1rem; margin: 0.5rem 0; }
.liste a { text-decoration: none; }
.ignorer { margin-top: 0.3rem; }

/* Pastilles de statut */
.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 99px; font-size: 0.8rem; font-weight: 700; background: #ebe7dd; color: #4a4f55; }
.s-acceptee, .s-regle-confirmee, .s-doc-accepte, .s-doc-envoye, .s-dossier-paye { background: var(--ok-fond); color: var(--ok); }
.s-refusee, .s-regle-rejetee, .s-doc-refuse, .s-doc-annule, .s-dossier-annule { background: var(--danger-fond); color: var(--danger); }
.s-a_corriger, .s-en_attente, .s-regle-proposee, .s-doc-a_valider { background: var(--attention-fond); color: var(--attention); }
.canal-whatsapp { background: #dcf3e3; color: #1b6a3a; }
.canal-mail { background: #e0ebf7; color: #234e7d; }
.pay { background: var(--ok-fond); color: var(--ok); }

/* Tableau de dossiers : colonnes sur grand écran, sections sur mobile */
.tableau { display: block; }
.colonne.vide { display: none; }
.cartes { display: grid; gap: 0.5rem; }
.mini { display: flex; flex-direction: column; gap: 0.1rem; background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon);
  padding: 0.7rem 0.9rem; text-decoration: none; color: inherit; min-height: 48px; }
.mini:hover { border-color: var(--accent); }
@media (min-width: 900px) {
  main:has(.tableau) { max-width: none; }
  .tableau { display: flex; gap: 0.8rem; overflow-x: auto; align-items: flex-start; padding-bottom: 1rem; }
  .colonne, .colonne.vide { display: block; flex: 0 0 240px; background: #efece4; border-radius: var(--rayon); padding: 0.2rem 0.7rem 0.7rem; }
}
.annules { margin-top: 1rem; }

/* Fiche dossier */
.titre-dossier { font-size: 1.2rem; font-weight: 600; margin: 0.2rem 0 0.6rem; }
.infos { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0.5rem 0; }
.infos dt { color: var(--discret); font-size: 0.9rem; }
.infos dd { margin: 0; overflow-wrap: anywhere; }
.chronologie { border-left: 3px solid var(--ligne); margin-left: 0.4rem; padding-left: 0.9rem; }
.ev { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 0.7rem 0.9rem; margin: 0.6rem 0; position: relative; }
.ev::before { content: ""; position: absolute; left: -1.3rem; top: 1rem; width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--accent); border: 2px solid var(--fond); }
.ev-message.sortant { background: #f1f6f6; }
.ev-paiement::before { background: var(--ok); }
.ev-validation::before { background: var(--attention); }
.ev-tete { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.montants { margin: 0.3rem 0; }
.lignes { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.lignes td { padding: 0.3rem 0.2rem; border-top: 1px solid var(--ligne); }
.num { text-align: right; white-space: nowrap; }
.pieces { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.piece { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.8rem; background: #f1f6f6; border: 1px solid var(--ligne); border-radius: 8px; text-decoration: none; overflow-wrap: anywhere; }

/* Factures */
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem; margin: 0.6rem 0; }
.tuile { display: flex; flex-direction: column; background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 0.8rem 1rem; text-decoration: none; color: inherit; }
.tuile strong { font-size: 1.3rem; }
.tuile.retard { background: var(--danger-fond); border-color: #e6b8b2; }
.tuile.retard strong { color: var(--danger); }
.tuile.paye strong { color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip-lien { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem; border-radius: 99px; background: #ebe7dd; text-decoration: none; color: var(--encre); font-weight: 600; }
.chip-lien.actif { background: var(--accent); color: #fff; }
.somme { float: right; font-size: 1rem; }
.facture { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); margin: 0.5rem 0; }
.fac-lien { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.8rem; padding: 0.7rem 1rem; text-decoration: none; color: inherit; min-height: 48px; }
.fac-num { font-weight: 700; }
.fac-montant { text-align: right; font-weight: 700; }
.fac-echeance { grid-column: 1 / -1; font-size: 0.9rem; }
.fac-echeance.retard { color: var(--danger); font-weight: 700; }

/* Connexion */
.page-connexion { padding-bottom: 0; }
.connexion { max-width: 420px; padding-top: 12vh; }
.connexion h1 span { display: block; font-size: 0.95rem; font-weight: 400; color: var(--discret); }
.connexion .bouton { width: 100%; margin-top: 1rem; }
