/* ------------------------------------------------------------------
   GEST-CO — Gestion Commerciale & Recouvrement
   ------------------------------------------------------------------

   Ce fichier réunit trois couches, dans cet ordre :

     1. LA COQUE      — sidebar, bandeau, cockpit, commandes. Écrite pour
                        GEST-CO : compacte, sobre, orientée pilotage.
     2. LES ÉCRANS    — cartes, tableaux, étiquettes, filtres, fenêtre client.
                        Repris tels quels du chantier « Balance âgée » : les
                        neuf écrans du recouvrement en dépendent au pixel près.
     3. LE TARIF      — la couche du domaine tarifaire, PORTÉE PAR « .pricing ».
                        Ses classes portent parfois les mêmes noms (.carte,
                        .kpi, .vide) ; les cantonner sous un préfixe évite
                        qu'elles ne déteignent sur les écrans du recouvrement.

   Charte : blanc dominant, vert AMCOVET, beaucoup d'air, aucune couleur
   gratuite. Le rouge et l'orange sont réservés à l'alerte. Jamais de thème
   sombre. Le caractère « futuriste » vient de la typographie, des espacements
   et de la retenue — pas d'effets.
   ------------------------------------------------------------------ */

:root {
  --vert: #009a3e;
  --vert-fonce: #0b5233;
  --vert-clair: #e8f5ed;
  --vert-filet: #cfe7d9;
  --bleu: #0b5fa5;
  --bleu-clair: #e7f0f9;
  --orange: #c25e00;
  --orange-clair: #fdf0e3;
  --rouge: #b3261e;
  --rouge-clair: #fbeae9;
  --encre: #17201b;
  --encre-doux: #5b6660;
  --encre-tres-doux: #8b948f;
  --papier: #ffffff;
  --fond: #f6f8f7;
  --filet: #e3e8e5;
  --ombre: 0 1px 2px rgba(23, 32, 27, .05), 0 4px 16px rgba(23, 32, 27, .04);
  --ombre-forte: 0 8px 40px rgba(23, 32, 27, .16);
  --rayon: 12px;
  --sidebar: 214px;
  --sidebar-reduite: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: var(--encre);
  background: var(--fond);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 600; margin: 0; letter-spacing: -.015em; }
button { font: inherit; cursor: pointer; }
a { color: var(--bleu); }

/* ----------------------------- Cartes ----------------------------- */

.grille-kpi {
  display: grid; gap: 14px; margin-bottom: 26px;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
}

.kpi {
  background: var(--papier); border: 1px solid var(--filet); border-radius: var(--rayon);
  padding: 16px 18px; box-shadow: var(--ombre); text-align: left;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s;
}
.kpi[data-cliquable] { cursor: pointer; }
.kpi[data-cliquable]:hover { border-color: var(--vert); }
.kpi .intitule { font-size: 12px; color: var(--encre-doux); }
.kpi .valeur { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .complement { font-size: 11px; color: var(--encre-doux); }
.kpi.attention .valeur { color: var(--orange); }
.kpi.critique .valeur { color: var(--rouge); }
.kpi.positif .valeur { color: var(--vert); }

.carte {
  background: var(--papier); border: 1px solid var(--filet); border-radius: var(--rayon);
  box-shadow: var(--ombre); padding: 20px; margin-bottom: 20px;
}
.carte h2 { font-size: 15px; margin-bottom: 14px; }
.carte h2 .discret { font-weight: 400; color: var(--encre-doux); font-size: 12px; }

.deux-colonnes { display: grid; gap: 20px; grid-template-columns: 1.15fr .85fr; }
@media (max-width: 1180px) { .deux-colonnes { grid-template-columns: 1fr; } }

/* ---------------------------- Tableaux ---------------------------- */

.enveloppe-tableau { overflow: auto; max-height: 68vh; border-radius: 10px; border: 1px solid var(--filet); }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--vert); border-bottom: 1px solid var(--vert-fonce);
  padding: 11px 12px; text-align: right; font-size: 11px; font-weight: 700;
  color: #fff; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
thead th[data-tri]:hover { background: var(--vert-fonce); }
thead th:first-child, thead th.gauche { text-align: left; }
tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--filet);
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
tbody td:first-child, tbody td.gauche { text-align: left; }
tbody tr:hover { background: var(--fond); }
tbody tr.total td { font-weight: 600; background: var(--vert-clair); border-top: 2px solid var(--vert-filet); }

/* ------------------- Colonnes figées et double barre ---------------- */

/* Une cellule figée doit être opaque, sinon le contenu défile au travers. */
td.fige { position: sticky; z-index: 1; background: var(--papier); }
th.fige { position: sticky; z-index: 3; }
tbody tr:hover td.fige { background: var(--fond); }
tbody tr.total td.fige { background: var(--vert-clair); }
.fige-bord { box-shadow: 6px 0 8px -6px rgba(23, 32, 27, .22); }

/* Barre de défilement clonée au-dessus de l'en-tête. */
.defilement-haut {
  overflow-x: auto; overflow-y: hidden;
  border: 1px solid var(--filet); border-bottom: 0;
  border-radius: 10px 10px 0 0; background: var(--fond);
}
.defilement-haut > div { height: 1px; }
.defilement-haut + .enveloppe-tableau { border-radius: 0 0 10px 10px; }
td.zero { color: #c3ccc7; }

.nom-client {
  background: none; border: 0; padding: 0; color: var(--encre);
  font: inherit; text-align: left; cursor: pointer;
}
.nom-client:hover { color: var(--vert-fonce); text-decoration: underline; }

.montant-cliquable { cursor: pointer; }
.montant-cliquable:hover { color: var(--vert-fonce); text-decoration: underline; }

/* ---------------------------- Étiquettes -------------------------- */

.puce {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.puce.normal { background: var(--vert-clair); color: var(--vert-fonce); }
.puce.attention { background: #fdf0e2; color: var(--orange); }
.puce.critique { background: #fdeceb; color: var(--rouge); }
.puce.information { background: #e8f0f9; color: var(--bleu); }
.puce.neutre { background: var(--fond); color: var(--encre-doux); }

.badge-commentaire {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 6px; border-radius: 50%;
  background: var(--bleu); color: #fff; font-size: 10px; font-weight: 700;
  vertical-align: middle;
}

/* ----------------------------- Filtres ---------------------------- */

.filtres {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--papier); border: 1px solid var(--filet); border-radius: var(--rayon);
  padding: 14px 16px; margin-bottom: 18px; box-shadow: var(--ombre);
}
.filtre { display: flex; flex-direction: column; gap: 5px; }
.filtre label { font-size: 11px; font-weight: 600; color: var(--encre-doux); }
.filtre select, .filtre input {
  font: inherit; font-size: 13px; padding: 7px 10px;
  border: 1px solid var(--filet); border-radius: 8px; background: var(--papier); min-width: 160px;
}
.filtre input { min-width: 230px; }
.filtre select:focus, .filtre input:focus {
  outline: none; border-color: var(--vert); box-shadow: 0 0 0 3px var(--vert-clair);
}
.filtres .actions { margin-left: auto; display: flex; gap: 8px; }
.resume-filtre { font-size: 12px; color: var(--encre-doux); margin: 0 0 12px; }

/* ------------------------- Fenêtre client ------------------------- */

.voile {
  position: fixed; inset: 0; background: rgba(23, 32, 27, .32);
  display: grid; place-items: center; padding: 24px; z-index: 50;
}
.fenetre {
  background: var(--papier); border-radius: 16px; width: min(1180px, 100%);
  max-height: 92vh; overflow: auto; box-shadow: 0 24px 64px rgba(23, 32, 27, .22);
}

.entete-client {
  padding: 22px 26px 18px; border-bottom: 1px solid var(--filet);
  display: flex; justify-content: space-between; gap: 20px; align-items: flex-start;
  position: sticky; top: 0; background: var(--papier); z-index: 2;
}
.entete-client h2 { font-size: 18px; }
.entete-client .code { color: var(--encre-doux); font-size: 12px; margin-top: 3px; }
.chiffres-client { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 14px; }
.chiffres-client div span { display: block; font-size: 11px; color: var(--encre-doux); }
.chiffres-client div strong { font-size: 16px; font-variant-numeric: tabular-nums; }

.onglets { display: flex; gap: 4px; padding: 0 26px; border-bottom: 1px solid var(--filet); }
.onglets button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 12px 14px; color: var(--encre-doux); font-size: 13px;
}
.onglets button.actif { color: var(--vert-fonce); border-bottom-color: var(--vert); font-weight: 600; }
.corps-onglet { padding: 20px 26px 26px; }

.fermer {
  background: none; border: 1px solid var(--filet); border-radius: 8px;
  width: 32px; height: 32px; color: var(--encre-doux); font-size: 16px; line-height: 1;
}
.fermer:hover { border-color: var(--vert); color: var(--vert-fonce); }

/* ------------------------- Commentaires --------------------------- */

.zone-commentaire { background: var(--fond); border-radius: var(--rayon); padding: 16px; }
.zone-commentaire textarea {
  width: 100%; font: inherit; font-size: 13px; padding: 10px 12px; min-height: 84px;
  border: 1px solid var(--filet); border-radius: 8px; background: var(--papier); resize: vertical;
}
.zone-commentaire textarea:focus {
  outline: none; border-color: var(--vert); box-shadow: 0 0 0 3px var(--vert-clair);
}
.ligne-champs { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-top: 10px; }
.ligne-champs .filtre input { min-width: 150px; }

.historique-commentaires { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 10px; }
.historique-commentaires li {
  background: var(--papier); border: 1px solid var(--filet); border-left: 3px solid var(--bleu);
  border-radius: 8px; padding: 12px 14px;
}
.historique-commentaires .meta { font-size: 11px; color: var(--encre-doux); margin-bottom: 5px; }
.historique-commentaires .texte { white-space: pre-wrap; }
.historique-commentaires .echeance { font-size: 12px; color: var(--orange); font-weight: 600; margin-top: 6px; }

/* ---------------------------- Divers ------------------------------ */

.vide { color: var(--encre-doux); font-size: 13px; padding: 18px 0; }

.barre-repartition { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--fond); }
.barre-repartition span { display: block; height: 100%; }
.legende { display: grid; gap: 8px; margin-top: 14px; }
.legende div { display: flex; align-items: center; gap: 9px; font-size: 12px; }
.legende i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legende .montant { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }

.a-venir {
  background: var(--papier); border: 1px dashed var(--vert-filet); border-radius: var(--rayon);
  padding: 40px; text-align: center; color: var(--encre-doux);
}
.a-venir h2 { color: var(--encre); margin-bottom: 8px; font-size: 16px; }

@media print {
  .tiroir, .voile-menu, .bouton-menu,
  .filtres .actions, #boutonImprimer, .fermer { display: none !important; }
  .enveloppe-tableau { max-height: none; overflow: visible; }
  body { background: #fff; }
}

/* Le point bleu ne dit rien à lui seul : le survol révèle le commentaire. */
.badge-commentaire { cursor: help; }

/* Le bordereau de versement est désormais généré en PDF téléchargeable
   (js/pdf-bordereau.js) : plus besoin de gabarit imprimable à l'écran. */

/* ------------------- Titres retenus pour un bordereau --------------- */

.liste-selection {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 220px; overflow-y: auto;
}
.liste-selection li {
  display: flex; align-items: center; gap: 8px;
  background: var(--papier); border: 1px solid var(--filet); border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px;
}
.liste-selection-titre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste-selection-montant { font-variant-numeric: tabular-nums; white-space: nowrap; }
.liste-selection li .lien { white-space: nowrap; }

/* --------------------------- Import de fichiers ---------------------- */

.zone-depot {
  border: 2px dashed var(--vert-filet); border-radius: var(--rayon);
  padding: 26px 20px; text-align: center; background: var(--vert-clair);
  transition: border-color .15s, background .15s;
}
.zone-depot p { margin: 0; font-size: 13px; color: var(--encre-doux); }
.zone-depot-survolee { border-color: var(--vert); background: #ddf0e5; }
