/* Balance Âgée Clients — styles (mobile d'abord) */
:root {
  --bleu: #1f3a5f;
  --bleu-clair: #2c5282;
  --fond: #f4f6fa;
  --carte: #ffffff;
  --bordure: #e3e8ef;
  --texte-doux: #6b7785;
  --vert: #2fb36d;
  --orange: #f2a33a;
  --rouge: #e5484d;
  --hauteur-nav: 62px;
  --bs-primary: #1f3a5f;
  --bs-primary-rgb: 31, 58, 95;
  --bs-link-color: #2c5282;
  --bs-link-color-rgb: 44, 82, 130;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--fond);
  color: #1b2430;
  font-size: 15px;
  padding-bottom: calc(var(--hauteur-nav) + env(safe-area-inset-bottom) + 12px);
}
a { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--bleu); --bs-btn-border-color: var(--bleu); --bs-btn-hover-bg: var(--bleu-clair); --bs-btn-hover-border-color: var(--bleu-clair); --bs-btn-active-bg: #172c48; }
.btn-outline-primary { --bs-btn-color: var(--bleu); --bs-btn-border-color: var(--bleu); --bs-btn-hover-bg: var(--bleu); --bs-btn-hover-border-color: var(--bleu); }

/* ---- En-tête ---- */
.entete {
  position: sticky; top: 0; z-index: 1030;
  background: var(--bleu); color: #fff;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.entete-contenu { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: .5rem .9rem; }
.marque { display: flex; align-items: center; gap: .55rem; color: #fff; }
.marque span { display: flex; flex-direction: column; line-height: 1.1; }
.marque small { opacity: .7; font-size: .72rem; }
.maj { font-size: .75rem; background: rgba(255,255,255,.14); padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; }
.maj.ancienne { background: var(--orange); color: #1b2430; }
.btn-entete { color: #fff; font-size: 1.5rem; padding: 0 .25rem; border: 0; }
.btn-entete:hover, .btn-entete:focus { color: #dbe6f5; }

.contenu { max-width: 1100px; margin: 0 auto; padding: .9rem .9rem 1rem; }
.titre-page { font-size: 1.25rem; font-weight: 700; color: var(--bleu); margin-bottom: .8rem; }
.titre-bloc { font-size: .95rem; font-weight: 700; color: var(--bleu); margin: 0 0 .6rem; }
.lien-retour { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }

/* ---- Barre de navigation basse ---- */
.barre-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--bordure);
  height: calc(var(--hauteur-nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.barre-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--texte-doux); font-size: .7rem; gap: 2px; }
.barre-nav a i { font-size: 1.3rem; }
.barre-nav a.actif { color: var(--bleu); font-weight: 700; }
.barre-nav a.actif i { transform: translateY(-1px); }

/* ---- Blocs ---- */
.carte-bloc { background: var(--carte); border: 1px solid var(--bordure); border-radius: 14px; padding: .9rem; margin-bottom: .9rem; }
.total-general { background: #e8eef6; }

.recherche { position: relative; }
.recherche i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--texte-doux); }
.recherche input { padding-left: 2.3rem; border-radius: 12px; height: 44px; font-size: 16px; /* évite le zoom iOS */ }

/* ---- Indicateurs ---- */
.grille-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: .9rem; }
@media (min-width: 900px) { .grille-kpi { grid-template-columns: repeat(4, 1fr); } }
/* Accueil : 5 indicateurs ; sur téléphone le dernier (impayés) occupe toute la largeur */
.grille-kpi-5 .kpi-large { grid-column: span 2; }
@media (min-width: 900px) { .grille-kpi-5 { grid-template-columns: repeat(5, 1fr); } .grille-kpi-5 .kpi-large { grid-column: auto; } }
.kpi { background: var(--carte); border: 1px solid var(--bordure); border-radius: 14px; padding: .75rem .8rem; display: flex; flex-direction: column; min-width: 0; }
.kpi-libelle { font-size: .74rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .02em; }
.kpi-valeur { font-size: 1.35rem; font-weight: 800; color: var(--bleu); line-height: 1.25; margin: .15rem 0; overflow-wrap: anywhere; }
.kpi-detail { font-size: .72rem; color: var(--texte-doux); }
.kpi.principal { background: linear-gradient(135deg, var(--bleu), var(--bleu-clair)); border: 0; }
.kpi.principal .kpi-libelle, .kpi.principal .kpi-detail { color: rgba(255,255,255,.8); }
.kpi.principal .kpi-valeur { color: #fff; }
.kpi.danger { border-left: 4px solid var(--rouge); }
.kpi.danger .kpi-valeur { color: var(--rouge); }
.kpi.attention { border-left: 4px solid var(--orange); }

.mini-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem .8rem; margin: .7rem 0 .5rem; }
@media (min-width: 700px) { .mini-kpi { grid-template-columns: repeat(4, 1fr); } }
.mini-kpi span { display: block; font-size: .72rem; color: var(--texte-doux); }
.mini-kpi strong { font-size: 1.05rem; }

.totaux-filtre { display: flex; gap: .4rem; overflow-x: auto; margin: .2rem 0 .7rem; padding-bottom: 2px; scrollbar-width: none; }
.totaux-filtre > div { flex: 0 0 auto; background: #fff; border: 1px solid var(--bordure); border-radius: 10px; padding: .35rem .65rem; }
.totaux-filtre span { display: block; font-size: .68rem; color: var(--texte-doux); }
.totaux-filtre strong { font-size: .95rem; }

/* ---- Alertes ---- */
.alertes-resume { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.alerte-case { border-radius: 12px; padding: .6rem .5rem; text-align: center; color: #1b2430; display: flex; flex-direction: column; }
.alerte-case strong { font-size: 1.5rem; line-height: 1.1; }
.alerte-case span { font-size: .72rem; }
.alerte-case.rouge { background: #fde4e4; }
.alerte-case.orange { background: #feefd9; }
.alerte-case.vert { background: #dcf5e7; }

.point-alerte { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; background: #c3cad3; vertical-align: middle; }
.point-alerte.vert, .badge-alerte.vert .point { background: var(--vert); }
.point-alerte.orange, .badge-alerte.orange .point { background: var(--orange); }
.point-alerte.rouge, .badge-alerte.rouge .point { background: var(--rouge); box-shadow: 0 0 0 3px rgba(229,72,77,.18); }
.badge-alerte { display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 600; padding: .25rem .6rem; border-radius: 99px; white-space: nowrap; }
.badge-alerte .point { width: 9px; height: 9px; border-radius: 50%; }
.badge-alerte.vert { background: #dcf5e7; color: #17663e; }
.badge-alerte.orange { background: #feefd9; color: #8a5300; }
.badge-alerte.rouge { background: #fde4e4; color: #a3171c; }

/* ---- Listes ---- */
.liste-clients { display: flex; flex-direction: column; gap: .45rem; }
.ligne-client {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  background: #fff; border: 1px solid var(--bordure); border-left: 4px solid var(--bordure);
  border-radius: 12px; padding: .6rem .7rem; color: inherit;
}
.ligne-client:active { background: #f0f4fa; }
.ligne-client.alerte-vert { border-left-color: var(--vert); }
.ligne-client.alerte-orange { border-left-color: var(--orange); }
.ligne-client.alerte-rouge { border-left-color: var(--rouge); }
.ligne-client.inactif { opacity: .55; }
.ligne-gauche { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.ligne-nom { display: flex; flex-direction: column; min-width: 0; }
.ligne-nom strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-nom small, .ligne-droite small { color: var(--texte-doux); font-size: .72rem; }
.ligne-droite { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex: 0 0 auto; }
.ligne-droite strong { font-size: .95rem; }

.liste-repartition { list-style: none; padding: 0; margin: .5rem 0 0; }
.liste-repartition li a { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; border-top: 1px solid var(--bordure); color: inherit; font-size: .88rem; }
.puce { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: 0 0 10px; }

.graphique { position: relative; height: 210px; }

/* Parts de chiffre d'affaires (accueil) */
.liste-parts { list-style: none; padding: 0; margin: 0; }
.liste-parts li a { display: block; padding: .45rem 0; border-top: 1px solid var(--bordure); color: inherit; font-size: .86rem; }
.liste-parts li:first-child a { border-top: 0; }
.liste-parts .nom-part { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.liste-parts .part, .liste-repartition .part { display: inline-block; min-width: 3.6em; text-align: right; color: var(--bleu-clair); font-weight: 600; }
.barre-part { height: 6px; background: #eef2f8; border-radius: 99px; margin-top: .3rem; overflow: hidden; }
.barre-part > div { height: 100%; background: linear-gradient(90deg, var(--bleu-clair), #5b8def); border-radius: 99px; }
.ligne-droite .ca-part { color: var(--bleu-clair); }

/* ---- Filtres ---- */
.filtres { margin-bottom: .6rem; }
.filtres-ligne { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
@media (min-width: 800px) { .filtres-ligne { grid-template-columns: repeat(4, 1fr); } }
.filtres select { font-size: 15px; border-radius: 10px; }

/* ---- Fiche client ---- */
.fiche-entete { background: #fff; border: 1px solid var(--bordure); border-top: 5px solid var(--bordure); border-radius: 14px; padding: .9rem; margin-bottom: .9rem; }
.fiche-entete.alerte-vert { border-top-color: var(--vert); }
.fiche-entete.alerte-orange { border-top-color: var(--orange); }
.fiche-entete.alerte-rouge { border-top-color: var(--rouge); }
.etiquettes { display: flex; flex-wrap: wrap; gap: .35rem; }
.etiquette { background: #eef2f8; color: var(--bleu); border-radius: 99px; padding: .2rem .6rem; font-size: .75rem; }
.barre-composition { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: #eef2f8; }
.barre-composition .echu { background: var(--rouge); }
.barre-composition .non-echu { background: var(--vert); }
.liste-detail { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .88rem; }
.liste-detail dt { font-weight: 400; color: var(--texte-doux); }
.liste-detail dd { margin: 0; text-align: right; font-weight: 600; }

/* ---- Tableaux compacts ---- */
.tableau-compact { font-size: .82rem; }
.tableau-compact th { font-weight: 600; color: var(--texte-doux); font-size: .72rem; }
details summary { cursor: pointer; color: var(--bleu-clair); font-size: .88rem; }

/* ---- Carte ---- */
.carte-clients { height: calc(100vh - 230px); min-height: 380px; border-radius: 14px; border: 1px solid var(--bordure); z-index: 1; }
.page-carte .contenu { padding-bottom: .3rem; }
.legende-carte { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .5rem; align-items: center; }
.bulle-client { min-width: 220px; font-size: .82rem; }
.bulle-client h3 { font-size: .95rem; margin: 0 0 .15rem; color: var(--bleu); }
.bulle-client .sous-titre { color: var(--texte-doux); font-size: .74rem; margin-bottom: .45rem; }
.bulle-client table { width: 100%; }
.bulle-client td { padding: 2px 0; }
.bulle-client td:last-child { text-align: right; font-weight: 600; }
.bulle-client .lien-fiche { display: block; margin-top: .5rem; text-align: center; background: var(--bleu); color: #fff !important; border-radius: 8px; padding: .35rem; }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.bulle-client .montant-echu { color: #c53030; }
.marqueur-client { border-radius: 50%; border: 1.5px solid #fff; opacity: .88; box-shadow: 0 1px 3px rgba(0,0,0,.35); cursor: pointer; transform: translateY(50%); }

/* ---- Divers ---- */
.vide { text-align: center; padding: 3rem 1rem; color: var(--texte-doux); }
.vide i { font-size: 3rem; color: #b6c1cf; }
.ligne-historique { display: flex; justify-content: space-between; gap: .8rem; padding: .6rem 0; border-top: 1px solid var(--bordure); }
.ligne-historique:first-of-type { border-top: 0; }
.remarques { white-space: pre-wrap; font-size: .75rem; margin: .3rem 0 0; color: var(--texte-doux); }
.cases-multiples { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .8rem; }
.form-control, .form-select { font-size: 16px; }

/* ---- Connexion ---- */
.page-connexion { padding-bottom: 0; background: linear-gradient(160deg, #1f3a5f 0%, #2c5282 55%, #f4f6fa 55%); min-height: 100vh; }
.boite-connexion { max-width: 400px; margin: 8vh auto 0; background: #fff; border-radius: 18px; padding: 2rem 1.5rem; box-shadow: 0 10px 40px rgba(0,0,0,.15); }

@media (min-width: 992px) {
  body { font-size: 15.5px; }
}
