/* Module Retards clients — compléments à design.css (charte commune des modules) */

.page { padding: 24px 28px; max-width: 1500px; }
.entete-page { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.retour { font-size: 12.5px; text-decoration: none; color: var(--text3); display: inline-block; margin-bottom: 4px; }
.aide { font-size: 12px; color: var(--text3); font-weight: 400; margin-left: 8px; }

.perimetre { display: flex; align-items: center; }
.perimetre select { min-width: 260px; }

.carte { padding: 16px 18px; margin-bottom: 16px; }
.carte-titre { font-family: 'Raleway', sans-serif; font-weight: 800; color: var(--navy); margin-bottom: 10px; }
.barre-outils { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.barre-outils input[type=search] { max-width: 320px; }
.filtres-detail { display: flex; gap: 6px; flex-wrap: wrap; }

/* Tableaux de montants */
.tableau-montants th, .tableau-montants td { white-space: nowrap; vertical-align: middle; }
.tableau-montants .num { text-align: right; font-variant-numeric: tabular-nums; }
.tableau-montants td a { text-decoration: none; color: inherit; }
.tableau-montants td a:hover { text-decoration: underline; color: var(--navy); }
.ligne-total th, .ligne-total td { font-weight: 700; background: rgba(26, 34, 104, 0.05); }
.ligne-retard th, .ligne-retard td { font-weight: 700; color: #8b1a1a; }
.ligne-dont th { font-weight: 400; padding-left: 24px; color: var(--text2); }
/* Règlements non affectés : montant négatif, déduit du total */
.ligne-deduction th { font-weight: 400; font-style: italic; color: var(--text2); }
.ligne-deduction td { color: #1f6f8b; font-style: italic; }
.date-choisie { font-weight: 800; text-decoration: underline !important; }
.incomplet { font-size: 11px; font-weight: 400; color: #a15c00; }
.code { font-family: Consolas, 'Courier New', monospace; font-size: 12.5px; }

th[data-tri] { cursor: pointer; user-select: none; }
th.tri-croissant::after { content: ' ▲'; font-size: 10px; }
th.tri-decroissant::after { content: ' ▼'; font-size: 10px; }

/* Liste des clients et détail déplié */
.ligne-client { cursor: pointer; }
.ligne-client .col-ouvrir i { transition: transform .15s; display: inline-block; }
.ligne-client.ouvert .col-ouvrir i { transform: rotate(90deg); }
.col-ouvrir { width: 24px; }
.ligne-detail > td { background: #f7f8fc; padding: 8px 12px 14px 32px; }
.lignes-tiers table { font-size: 12.5px; background: white; }
.lignes-tiers td, .lignes-tiers th { white-space: nowrap; }
.lignes-tiers .statut-lettre, .lignes-tiers .statut-crediteur, .lignes-tiers .statut-ecarte { color: var(--text3); }
.col-commentaire { min-width: 220px; white-space: normal !important; }
textarea.commentaire { font-size: 12px; min-height: 30px; resize: vertical; transition: border-color .3s, background .3s; }
.enregistre, textarea.commentaire.enregistre { background: #eaf7ee !important; border-color: #3c9a5f !important; }
.en-erreur { border-color: #c0392b !important; background: #fdf0f0 !important; }

.tranche { padding: 1px 6px; border-radius: 8px; font-size: 11.5px; }
.tranche-non_echu { background: #eef3f8; color: #2c4a6b; }
.tranche-r1_10 { background: #fff7e0; color: #7a5a00; }
.tranche-r11_30 { background: #ffe9cc; color: #8a4b00; }
.tranche-r31_60 { background: #ffd9d0; color: #8b2a10; }
.tranche-r60 { background: #f5c6c6; color: #7a0f0f; font-weight: 700; }
.tranche-non_affecte { background: #e3f1f6; color: #1f6f8b; font-style: italic; }
.statut-non_affecte td { color: #1f6f8b; }

/* Suivi Allianz : couleurs demandées (vert 61-70 j, orange 71-90, rouge 91-120, noir au-delà) */
.legende-allianz { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin-bottom: 10px; }
.pastille { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-left: 8px; }
.pastille-jours { display: inline-block; min-width: 54px; text-align: center; padding: 2px 8px; border-radius: 10px; color: white; font-weight: 700; font-size: 12px; }
.couleur-vert { background: #2e8b57; }
.couleur-orange { background: #e67e22; }
.couleur-rouge { background: #c0392b; }
.couleur-noir { background: #1b1b1b; }
/* État de manquement (facture de plus de 105 jours) : client et factures non assurées */
.pastille-manquement { display: inline-block; padding: 1px 7px; border-radius: 10px; background: #7b1fa2; color: white; font-size: 11.5px; font-weight: 600; white-space: nowrap; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ligne-partie { opacity: .3; transition: opacity .5s; }
tr.sortie td { color: var(--text3); }
.cases-societes { display: flex; flex-wrap: wrap; gap: 4px 0; }

/* Connexion */
.page-login { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-cadre { width: 420px; max-width: 100%; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { height: 44px; }
.login-carte { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px; box-shadow: 0 16px 50px rgba(26, 34, 104, 0.12); }
.login-carte h1 { font-family: 'Raleway', sans-serif; font-size: 20px; font-weight: 800; color: var(--navy); text-align: center; margin: 0 0 4px; }
.login-carte .sub { font-size: 13px; color: var(--text3); text-align: center; margin-bottom: 24px; }
.login-carte label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.login-carte input { display: block; width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; box-sizing: border-box; }
.btn-login { display: block; text-align: center; text-decoration: none; background: var(--navy); color: white; border: none; width: 100%; padding: 13px; border-radius: var(--radius); font-family: 'Raleway', sans-serif; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; box-sizing: border-box; }
.btn-login:hover { background: var(--navy2); color: white; }
.ou { text-align: center; font-size: 12px; color: var(--text3); margin: 16px 0; }
.err { background: #fdf0f0; border: 1.5px solid #f5c0c0; color: #8b1a1a; border-radius: var(--radius); padding: 10px 14px; font-size: 12.5px; margin-bottom: 18px; }

@media (max-width: 767px) {
  .page { padding: 16px; }
  .perimetre select { min-width: 0; width: 100%; }
}

/* v0.2 — reporting au mois */
.dates-import { font-size: 10.5px; font-weight: 400; color: var(--text3); }
.ligne-evol th { font-weight: 400; color: var(--text2); font-size: 12.5px; }
.ligne-evol td { font-size: 12.5px; }
.evol-hausse { color: #b03a2e; }
.evol-baisse { color: #2e7d4f; }

/* v0.2 — indicateurs, graphique, fiche client */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface, #fff); border: 1px solid var(--border, #e3e6ef); border-radius: 10px; padding: 12px 14px; }
.kpi-libelle { font-size: 12px; color: var(--text3); }
.kpi-valeur { font-family: 'Raleway', sans-serif; font-size: 22px; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi-detail { font-size: 12px; color: var(--text2); }
.kpi-alerte .kpi-valeur { color: #8b1a1a; }
.kpi a { text-decoration: none; color: inherit; }
.graphique { margin: 0; }
.graphique svg { width: 100%; height: auto; display: block; }
.graphique .grille { stroke: #e6e8ef; stroke-width: 1; }
.graphique .axe { font-size: 11px; fill: #6b7280; font-family: 'Open Sans', sans-serif; }
.graphique a rect:hover { opacity: .8; }
.legende-graphique { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text2); margin-top: 6px; }
.legende-graphique i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.deux-colonnes { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }
@media (max-width: 1100px) { .deux-colonnes { grid-template-columns: 1fr; } }
.filtres-min { display: flex; gap: 8px; align-items: center; font-size: 12.5px; }
.filtres-min input { width: 110px; }
a.lien-client { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text3); }
a.lien-client:hover { color: var(--navy); }
.tableau-montants thead a { color: #fff !important; text-decoration: underline; text-underline-offset: 3px; }
.tableau-montants thead .dates-import { color: rgba(255, 255, 255, .7); }
.tableau-montants thead .incomplet { color: #ffd58a; }
.deux-colonnes { align-items: start; }
.lignes-tiers { overflow-x: auto; max-width: 100%; }

/* v0.2 — exports et impression */
.outils-etat { display: flex; gap: 6px; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  .app-header, .app-sidebar, .app-footer, .no-print, .perimetre, .barre-outils, .filtres-detail, .flash-bar, .retour, .aide { display: none !important; }
  .app-layout, .main-content, .page { display: block !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  body { background: #fff !important; font-size: 10px; }
  .carte, .kpi { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
  .table-responsive { overflow: visible !important; }
  .tableau-montants th, .tableau-montants td { padding: 2px 4px !important; }
  .tableau-montants thead th { background: #1a2268 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pastille-jours, .tranche, .graphique, .kpi { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  textarea.commentaire { border: none !important; resize: none; padding: 0; overflow: visible; }
  a { text-decoration: none !important; color: inherit !important; }
  .deux-colonnes { grid-template-columns: 3fr 2fr !important; }
}

/* v0.2 — contentieux et historique des commentaires */
.statut-dossier { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.statut-declaree { background: #fdecd2; color: #8a4b00; }
.statut-en_cours { background: #dfe8fb; color: #1a2268; }
.statut-indemnisee { background: #e3f4e8; color: #22663b; }
.statut-recouvree { background: #e3f4e8; color: #22663b; }
.statut-classee { background: #ececec; color: #555; }
.kpi-texte { font-size: 17px; }
.historique-commentaire { font-size: 12px; max-height: 320px; overflow-y: auto; }
.historique-ligne { padding: 4px 0; border-bottom: 1px dashed #e3e6ef; white-space: normal; }
.historique-quand { display: block; color: var(--text3); font-size: 11px; }
.historique-texte { white-space: pre-wrap; }
.bouton-historique { font-size: 11px; padding: 0; border: 0; background: none; color: var(--text3); }
.bouton-historique:hover { color: var(--navy); text-decoration: underline; }
td .historique-commentaire { background: #fafbfe; border: 1px solid #e3e6ef; border-radius: 6px; padding: 4px 8px; margin-top: 4px; max-height: 180px; }

/* v0.3 — compte en lecture seule : aucune action de saisie affichée */
.lecture-seule main form[method="POST"], .lecture-seule .outils-ecriture { display: none !important; }
.lecture-seule textarea.commentaire { background: transparent; border-color: transparent; resize: none; }
.badge-lecture { font-size: 11px; background: #eef0f7; color: var(--navy); border-radius: 8px; padding: 2px 8px; }

/* v0.3 — courriers de relance (page A4 imprimable) */
.barre-courrier { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; background: #fff; border-bottom: 1px solid #e3e6ef; position: sticky; top: 0; z-index: 10; }
.courrier { background: #fff; width: 210mm; max-width: 100%; min-height: 297mm; margin: 20px auto; padding: 18mm 18mm 14mm; box-shadow: 0 6px 30px rgba(0,0,0,.1); font-size: 12.5px; color: #111; }
.courrier-entete { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18mm; }
.courrier-societe { font-family: 'Raleway', sans-serif; font-weight: 800; font-size: 16px; color: var(--navy); }
.courrier-destinataire { width: 85mm; margin-top: 20mm; }
.courrier-adresse { min-height: 18mm; }
.courrier-date { text-align: right; margin-bottom: 6mm; }
.courrier-envoi { font-weight: 700; margin-bottom: 3mm; }
.courrier-objet { margin-bottom: 6mm; }
.courrier p { margin-bottom: 4mm; text-align: justify; }
.courrier-factures { width: 100%; border-collapse: collapse; margin: 4mm 0 6mm; font-size: 11.5px; }
.courrier-factures th, .courrier-factures td { border-bottom: 1px solid #ccc; padding: 3px 6px; text-align: left; }
.courrier-factures .num { text-align: right; font-variant-numeric: tabular-nums; }
.courrier-factures tfoot th { border-top: 2px solid #333; border-bottom: none; }
.courrier-signature { margin-top: 12mm; margin-left: 100mm; }
.courrier-pied { margin-top: 18mm; font-size: 10px; color: #777; }
@media print {
  @page :first { margin: 0; }
  .courrier { margin: 0; box-shadow: none; width: auto; min-height: 0; }
}
.relances-historique td { font-size: 12.5px; }
.logo-societe-mini { height: 24px; max-width: 70px; object-fit: contain; }
.courrier-logo { max-height: 22mm; max-width: 60mm; object-fit: contain; display: block; margin-bottom: 3mm; }

/* v0.4 — rapport mensuel (A4 portrait) */
.rapport { font-size: 11px; }
.rapport h1 { font-family: 'Raleway', sans-serif; font-weight: 800; font-size: 20px; color: var(--navy); margin: 2mm 0 1mm; }
.rapport h2 { font-family: 'Raleway', sans-serif; font-weight: 800; font-size: 13px; color: var(--navy); margin: 6mm 0 2mm; }
.rapport-sous-titre { color: #666; }
.rapport-entete { border-bottom: 2px solid var(--navy); padding-bottom: 3mm; margin-bottom: 4mm; }
.rapport-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm; }
.rapport-kpis div { border: 1px solid #ddd; border-radius: 6px; padding: 2mm 3mm; }
.rapport-kpis span { display: block; color: #666; font-size: 10px; }
.rapport-kpis strong { display: block; font-size: 16px; color: var(--navy); font-variant-numeric: tabular-nums; }
.rapport-kpis em { font-style: normal; font-size: 10px; color: #555; }
.rapport .rouge { color: #8b1a1a !important; }
.rapport-table { width: 100%; border-collapse: collapse; font-size: 10.5px; }
.rapport-table th, .rapport-table td { border-bottom: 1px solid #e3e3e3; padding: 1.5mm 2mm; text-align: left; font-weight: 400; }
.rapport-table thead th { background: #1a2268; color: #fff; font-weight: 600; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.rapport-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rapport-table .fort th, .rapport-table .fort td { font-weight: 700; }
.rapport-deux { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
.rapport .graphique { max-width: 150mm; }
@media print { .rapport { padding: 10mm 12mm; } }
/* Courriers et rapport : A4 portrait (les autres états restent en paysage) */
@media print {
  @page portrait { size: A4 portrait; margin: 0; }
  .courrier { page: portrait; }
}

/* Mise en service (page Imports) : bloc dépliable */
details.carte > summary.carte-titre { cursor: pointer; list-style: revert; }
details.carte:not([open]) > summary.carte-titre { margin-bottom: 0; }
