/* Courrier : registre apps de la charte 450ppm (§8). Toutes les valeurs viennent de tokens.css. */

:root { --font-corps: var(--font-app); }
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-weight: var(--fw-app-texte); }
h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.icone { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.monogramme { fill: currentColor; height: 22px; width: auto; flex: none; }
.montant { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Coquille ── */
.coquille { display: grid; grid-template-columns: var(--app-rail) minmax(0, 1fr); min-height: 100vh; }
:root[data-menu="ouvert"] .coquille { grid-template-columns: var(--app-menu) minmax(0, 1fr); }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--e-2); padding: 0 10px var(--e-3); background: var(--c-fond-2); border-right: 1px solid var(--c-filet); }
.rail-tete { height: var(--app-barre); display: flex; align-items: center; justify-content: center; gap: 2px; font-family: var(--font); font-weight: var(--fw-medium); color: var(--c-encre); }
.rail-tete .marque-suffixe, .rail-libelle { display: none; }
.marque-suffixe { font-family: var(--font); font-size: var(--app-fs-md); font-weight: var(--fw-medium); color: var(--c-encre-2); }
.rail-liste, .rail-pied { display: flex; flex-direction: column; gap: var(--e-1); align-items: center; }
.rail-pied { margin-top: auto; }
.rail-entree { position: relative; display: flex; align-items: center; justify-content: center; gap: var(--e-3); width: 40px; height: 40px; border: 0; border-radius: var(--r-pilule); background: transparent; color: var(--c-encre-2); font-size: var(--app-fs-sm); font-weight: var(--fw-app-libelle); cursor: pointer; transition: background var(--duree), color var(--duree); }
.rail-entree:hover { background: var(--c-actif); color: var(--c-encre); }
.rail-entree.actif { background: var(--c-encre); color: var(--c-fond); }
.rail-compteur { position: absolute; top: 2px; right: 2px; width: 8px; height: 8px; border-radius: var(--r-pilule); background: var(--c-attention); box-shadow: 0 0 0 2px var(--c-fond-2); font-size: 0; }
:root[data-menu="ouvert"] .rail { padding: 0 var(--e-3) var(--e-3); }
:root[data-menu="ouvert"] .rail-tete { justify-content: flex-start; padding-left: var(--e-2); }
:root[data-menu="ouvert"] .rail-tete .marque-suffixe, :root[data-menu="ouvert"] .rail-libelle { display: inline; }
:root[data-menu="ouvert"] .rail-liste, :root[data-menu="ouvert"] .rail-pied { align-items: stretch; }
:root[data-menu="ouvert"] .rail-entree { width: auto; justify-content: flex-start; padding: 0 var(--e-3); }
:root[data-menu="ouvert"] .rail-compteur { position: static; margin-left: auto; width: auto; height: auto; padding: 1px 8px; background: var(--c-attention-fond); color: var(--c-attention); box-shadow: none; font-size: 11px; font-weight: var(--fw-app-fort); }
:root[data-menu="ouvert"] .rail-repli .icone { transform: none; }
.rail-repli .icone { transform: rotate(180deg); }

.colonne { min-width: 0; }
.barre { height: var(--app-barre); display: flex; align-items: center; justify-content: center; padding: 0 var(--app-gouttiere); }
.barre-recherche { position: relative; width: min(360px, 100%); color: var(--c-encre-2); }
.barre-recherche .icone { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); }
.barre-recherche .champ-recherche { padding-left: 36px; }
.page { max-width: var(--app-page); margin: 0 auto; padding: 28px var(--app-gouttiere) var(--e-8); }

/* ── En-tête de page ── */
.entete { margin-bottom: var(--e-5); }
.fil { font-size: var(--app-fs-xs); font-weight: var(--fw-app-libelle); color: var(--c-encre-2); margin-bottom: var(--e-1); }
.fil a { color: var(--c-ocre-texte); text-decoration: underline; text-decoration-color: var(--c-ocre); text-underline-offset: 3px; }
.entete-ligne { display: flex; align-items: center; justify-content: space-between; gap: var(--e-4); flex-wrap: wrap; }
.entete h1 { font-size: var(--app-fs-xl); font-weight: var(--fw-app-titre); line-height: 1.2; }
.entete-outils { display: flex; align-items: center; gap: var(--e-3); flex-wrap: wrap; }
.entete-meta { font-size: var(--app-fs-sm); color: var(--c-encre-2); margin-top: var(--e-1); }

/* ── Contrôles ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--app-controle); padding: 0 16px; border: 1px solid var(--c-filet-fort); border-radius: var(--r-pilule); background: var(--c-surface); color: var(--c-encre); font-size: 13.5px; font-weight: var(--fw-app-fort); white-space: nowrap; cursor: pointer; transition: background var(--duree), border-color var(--duree), color var(--duree); }
.btn:hover { border-color: var(--c-encre); }
.btn:disabled { color: var(--c-encre-3); border-color: var(--c-filet); cursor: default; }
.btn-principal { background: var(--c-encre); border-color: var(--c-encre); color: var(--c-fond); }
.btn-principal:hover { background: var(--c-ombre); }
:root[data-theme="dark"] .btn-principal:hover { background: var(--c-sur-ombre); }
.btn-discret { background: transparent; border-color: transparent; color: var(--c-encre-2); }
.btn-discret:hover { background: var(--c-survol); border-color: transparent; color: var(--c-encre); }
.btn-petit { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn-icone { width: var(--app-controle); padding: 0; }
.btn-sur-ombre { background: transparent; color: var(--c-sur-ombre); border-color: var(--c-sur-ombre-2); height: 30px; }
.lien { border: 0; background: none; padding: 0; color: var(--c-ocre-texte); text-decoration: underline; text-decoration-color: var(--c-ocre); text-underline-offset: 3px; cursor: pointer; }

.champ { height: var(--app-controle); width: 100%; padding: 0 14px; border: 1px solid var(--c-filet-fort); border-radius: var(--r-pilule); background: var(--c-surface); color: var(--c-encre); }
.champ:focus-visible, .btn:focus-visible, .ligne:focus-visible, .rail-entree:focus-visible, .segmente button:focus-visible, .famille:focus-visible, .mini-ligne:focus-visible { outline: none; box-shadow: var(--focus); }
.zone { height: auto; padding: 10px 14px; border-radius: var(--r-lg); resize: vertical; }
.libelle { display: block; font-size: var(--app-fs-xs); font-weight: var(--fw-app-libelle); color: var(--c-encre-2); margin-bottom: var(--e-1); }
.message-erreur { min-height: 20px; font-size: var(--app-fs-sm); color: var(--c-erreur); }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: var(--e-3); }

.segmente { display: inline-flex; padding: 3px; border: 1px solid var(--c-filet); border-radius: var(--r-pilule); background: var(--c-surface); }
.segmente button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; border: 0; border-radius: var(--r-pilule); background: transparent; color: var(--c-encre-2); font-size: var(--app-fs-sm); font-weight: var(--fw-app-libelle); cursor: pointer; }
.segmente button.actif { background: var(--c-encre); color: var(--c-fond); }
.segmente-n { font-size: 11px; font-weight: var(--fw-app-fort); }

.puce { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: var(--r-pilule); font-size: 11.5px; font-weight: var(--fw-app-fort); white-space: nowrap; background: var(--c-surface-2); color: var(--c-encre-2); }
.puce::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-pilule); background: currentColor; }
.puce-ok { background: var(--c-ok-fond); color: var(--c-ok); }
.puce-attention { background: var(--c-attention-fond); color: var(--c-attention); }
.puce-erreur { background: var(--c-erreur-fond); color: var(--c-erreur); }
.puce-info { background: var(--c-info-fond); color: var(--c-info); }

/* ── Cartes, chiffres, listes ── */
.carte { background: var(--c-surface); border: 1px solid var(--c-filet); border-radius: var(--r-lg); box-shadow: var(--ombre-carte); }
.chiffres { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: var(--e-4); margin-bottom: var(--e-6); }
.chiffre { display: flex; flex-direction: column; gap: var(--e-1); padding: var(--e-4) 20px; min-width: 0; }
.chiffre-libelle { font-size: var(--app-fs-xs); font-weight: var(--fw-app-libelle); color: var(--c-encre-2); }
.chiffre-valeur { font-size: var(--app-fs-kpi); font-weight: var(--fw-app-titre); line-height: 1.15; letter-spacing: -0.02em; }
.chiffre-maitre .chiffre-valeur { font-size: var(--app-fs-maitre); font-weight: var(--fw-app-maitre); letter-spacing: -0.03em; }
.chiffre-note { font-size: var(--app-fs-xs); color: var(--c-encre-2); }

.groupe { margin-bottom: var(--e-5); }
.groupe-tete { display: flex; align-items: baseline; justify-content: space-between; gap: var(--e-4); padding: 0 var(--e-4) var(--e-2); }
.groupe-tete h2 { font-size: var(--app-fs-sm); font-weight: var(--fw-app-titre); }
.groupe-tete .montant { font-size: var(--app-fs-sm); font-weight: var(--fw-app-fort); }
.liste { overflow: hidden; }
.ligne { display: grid; align-items: center; gap: var(--e-4); width: 100%; min-height: var(--app-row); padding: 6px var(--e-4); border: 0; border-top: 1px solid var(--c-filet); background: transparent; text-align: left; font-weight: var(--fw-app-libelle); }
.ligne:first-child { border-top: 0; }
button.ligne, .ligne.cliquable { cursor: pointer; transition: background var(--duree); }
button.ligne:hover, .ligne.cliquable:hover { background: var(--c-survol); }
.ligne-dette { grid-template-columns: minmax(0, 1fr) 190px 236px 120px 110px; }
.ligne-courrier { grid-template-columns: 96px minmax(0, 1fr) 150px 190px 100px; }
.ligne-tache { grid-template-columns: minmax(0, 1fr) 190px 130px 96px 70px; }
.ligne-mouvement { grid-template-columns: 96px minmax(0, 1fr) 190px 130px 110px; }
div.ligne-mouvement { cursor: default; }
.comptes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--e-3); margin-bottom: var(--e-5); }
.compte { display: flex; flex-direction: column; gap: 2px; padding: var(--e-4); background: var(--c-surface); border: 1px solid var(--c-filet); border-radius: var(--r-lg); }
.compte-nombre { font-size: var(--app-fs-xl); font-weight: var(--fw-app-titre); }
.comptes-recherche .champ { width: 260px; }
.ligne-principal { display: flex; flex-direction: column; min-width: 0; }
.ligne-titre, .ligne-second { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-second { display: block; font-size: 12.5px; font-weight: var(--fw-app-texte); color: var(--c-encre-2); }
.ligne-meta { font-size: 12.5px; font-weight: var(--fw-app-texte); color: var(--c-encre-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-puces { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ligne-date { font-size: var(--app-fs-sm); font-variant-numeric: tabular-nums; }
.ligne-date.en-retard { color: var(--c-erreur); }
.ligne-montant { text-align: right; font-weight: var(--fw-app-fort); }
.ligne-action { font-size: var(--app-fs-sm); color: var(--c-encre-2); text-align: right; }
.ligne-faite .ligne-titre { color: var(--c-encre-2); }

.familles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--e-4); }
.famille { display: flex; flex-direction: column; gap: var(--e-2); padding: var(--e-4) 20px; align-items: flex-start; transition: border-color var(--duree); }
.famille:hover { border-color: var(--c-filet-fort); }
.famille-nom { font-size: var(--app-fs-md); font-weight: var(--fw-app-fort); }
.famille-organismes { font-size: 12.5px; color: var(--c-encre-2); min-height: 38px; }
.famille-pied { display: flex; justify-content: space-between; gap: var(--e-3); width: 100%; font-size: var(--app-fs-sm); color: var(--c-encre-2); }
.famille-du { color: var(--c-encre); font-weight: var(--fw-app-fort); }

.vide { padding: var(--e-7) var(--e-5); text-align: center; color: var(--c-encre-2); }

/* ── Connexion ── */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: var(--e-5); }
.connexion-carte { width: min(360px, 100%); display: flex; flex-direction: column; gap: var(--e-2); padding: var(--e-6); background: var(--c-surface); border: 1px solid var(--c-filet); border-radius: var(--r-lg); }
.marque { display: flex; align-items: center; gap: 2px; margin-bottom: var(--e-4); }

/* ── Dossier : PDF à gauche, fiche à droite ── */
.feuille { position: fixed; inset: 0; z-index: 20; display: flex; justify-content: flex-end; background: color-mix(in srgb, var(--c-ombre) 40%, transparent); }
.feuille-corps { display: grid; grid-template-columns: minmax(0, 1fr) 460px; width: min(1320px, 100%); height: 100%; background: var(--c-fond); box-shadow: var(--ombre-2); }
.pdf { width: 100%; height: 100%; border: 0; border-right: 1px solid var(--c-filet); background: var(--c-fond-2); }
.pdf-absent { display: grid; place-items: center; padding: var(--e-6); text-align: center; color: var(--c-encre-2); }
.feuille-fiche { overflow-y: auto; padding: var(--e-4) var(--e-5) var(--e-7); display: flex; flex-direction: column; gap: var(--e-4); }
.feuille-tete { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--e-3); }
.feuille-tete h2 { font-size: var(--app-fs-lg); font-weight: var(--fw-app-titre); line-height: 1.25; }
.bloc { display: flex; flex-direction: column; gap: var(--e-3); padding: var(--e-4); background: var(--c-surface); border: 1px solid var(--c-filet); border-radius: var(--r-lg); }
.bloc h3 { font-size: var(--app-fs-base); font-weight: var(--fw-app-fort); }
.bloc-attention { border-color: var(--c-attention); }
.bloc-actions { display: flex; gap: var(--e-2); flex-wrap: wrap; align-items: center; }
.bloc-actions .champ { width: 150px; }
.banque { display: flex; flex-direction: column; gap: var(--e-2); padding: var(--e-3) 0; border-top: 1px solid var(--c-filet); border-bottom: 1px solid var(--c-filet); }
.banque-mouvement { display: flex; flex-direction: column; gap: var(--e-2); padding: var(--e-2) 0; }
.banque-texte { display: flex; flex-direction: column; gap: 2px; font-size: var(--app-fs-sm); }
.banque-texte .ligne-second { white-space: normal; overflow: visible; }
.questions { display: flex; flex-direction: column; gap: 6px; padding-left: var(--e-4); list-style: disc; font-size: var(--app-fs-sm); }
.note { font-size: var(--app-fs-sm); color: var(--c-encre-2); }
.cite { font-size: var(--app-fs-base); }
.paires { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 6px var(--e-3); font-size: var(--app-fs-sm); }
.paires dt { color: var(--c-encre-2); }
.paires dd { overflow-wrap: anywhere; }
.repli summary { cursor: pointer; font-size: var(--app-fs-sm); font-weight: var(--fw-app-libelle); color: var(--c-encre-2); }
.repli[open] summary { margin-bottom: var(--e-2); }
.texte-ocr { margin: 0; max-height: 360px; overflow: auto; padding: var(--e-3); border-radius: var(--r-lg); background: var(--c-surface-2); font-family: var(--font-app); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.dette-tete { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--e-3); }
.dette-montant { display: block; font-size: var(--app-fs-kpi); font-weight: var(--fw-app-titre); letter-spacing: -0.02em; line-height: 1.15; }
.dette-courriers { display: flex; flex-direction: column; }
.mini-ligne { display: grid; grid-template-columns: 96px 1fr auto; gap: var(--e-3); align-items: center; min-height: var(--app-row-compact); padding: 0 var(--e-2); border: 0; border-top: 1px solid var(--c-filet); background: transparent; text-align: left; font-size: var(--app-fs-sm); cursor: pointer; }
.mini-ligne:hover { background: var(--c-survol); }
.mini-ligne.actif { background: var(--c-actif); box-shadow: inset 2px 0 0 var(--c-ocre); }
.historique { display: flex; flex-direction: column; gap: var(--e-2); font-size: 12.5px; }
.historique li { display: flex; flex-direction: column; overflow-wrap: anywhere; }
.historique-date { color: var(--c-encre-2); }

/* ── Fenêtre, toasts ── */
.fenetre { width: min(480px, calc(100% - 32px)); padding: var(--e-5); border: 1px solid var(--c-filet); border-radius: var(--r-lg); background: var(--c-surface); color: var(--c-encre); box-shadow: var(--ombre-2); }
.fenetre::backdrop { background: color-mix(in srgb, var(--c-ombre) 40%, transparent); }
.fenetre form { display: flex; flex-direction: column; gap: var(--e-2); }
.fenetre h2 { font-size: var(--app-fs-lg); font-weight: var(--fw-app-titre); margin-bottom: var(--e-2); }
.fenetre-actions { display: flex; justify-content: flex-end; gap: var(--e-2); margin-top: var(--e-2); }
.toasts { position: fixed; left: var(--e-5); bottom: var(--e-5); z-index: 40; display: flex; flex-direction: column; gap: var(--e-2); }
.toast { display: flex; align-items: center; gap: var(--e-4); padding: var(--e-3) var(--e-4); border-radius: var(--r-lg); background: var(--c-ombre); color: var(--c-sur-ombre); box-shadow: var(--ombre-2); font-size: var(--app-fs-sm); max-width: min(480px, calc(100vw - 48px)); }
.toast-erreur { box-shadow: var(--ombre-2), inset 4px 0 0 var(--c-erreur); }

/* ── Écrans moyens et mobiles ── */
@media (max-width: 1100px) {
  .chiffres { grid-template-columns: 1fr 1fr; }
  .ligne-dette { grid-template-columns: minmax(0, 1fr) 236px 120px 110px; }
  .ligne-dette .ligne-meta, .ligne-courrier .ligne-meta, .ligne-tache .ligne-meta { display: none; }
  .ligne-courrier { grid-template-columns: 96px minmax(0, 1fr) 190px 100px; }
  .ligne-mouvement { grid-template-columns: 96px minmax(0, 1fr) 130px 110px; }
  .ligne-mouvement .ligne-meta { display: none; }
  .ligne-tache { grid-template-columns: minmax(0, 1fr) 130px 96px 70px; }
  .feuille-corps { grid-template-columns: minmax(0, 1fr) 400px; }
}
@media (max-width: 900px) {
  :root { --app-gouttiere: 24px; }
  .feuille-corps { grid-template-columns: 1fr; grid-template-rows: 45vh minmax(0, 1fr); }
  .pdf { border-right: 0; border-bottom: 1px solid var(--c-filet); }
}
@media (max-width: 640px) {
  :root { --app-gouttiere: 16px; }
  .coquille, :root[data-menu="ouvert"] .coquille { grid-template-columns: minmax(0, 1fr); }
  .rail, :root[data-menu="ouvert"] .rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 10; height: auto; flex-direction: row; justify-content: space-around; padding: 6px var(--e-2) calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--c-filet); }
  .rail-tete, .rail-repli { display: none; }
  .rail-liste, .rail-pied, :root[data-menu="ouvert"] .rail-liste, :root[data-menu="ouvert"] .rail-pied { flex-direction: row; margin: 0; gap: var(--e-1); align-items: center; }
  .rail-entree, :root[data-menu="ouvert"] .rail-entree { width: 44px; height: 44px; padding: 0; justify-content: center; }
  :root[data-menu="ouvert"] .rail-libelle { display: none; }
  .page { padding-bottom: 96px; }
  .chiffres { grid-template-columns: 1fr 1fr; gap: var(--e-3); }
  .chiffre-maitre { grid-column: 1 / -1; }
  .chiffre:not(.chiffre-maitre) .chiffre-valeur { font-size: var(--app-fs-lg); }
  .chiffre:last-child { display: none; }
  .ligne-dette, .ligne-courrier, .ligne-tache { grid-template-columns: minmax(0, 1fr) auto; row-gap: 2px; padding: 10px var(--e-4); }
  .ligne-mouvement { grid-template-columns: minmax(0, 1fr) auto; row-gap: 2px; padding: 10px var(--e-4); }
  .ligne-mouvement .ligne-principal { grid-column: 1 / -1; order: -1; }
  .ligne-mouvement .ligne-meta { display: none; }
  .ligne-mouvement .ligne-puces:empty { display: none; }
  .comptes-recherche .champ { width: 100%; }
  .ligne-dette .ligne-principal, .ligne-courrier .ligne-principal, .ligne-tache .ligne-principal { grid-column: 1 / -1; }
  .ligne-courrier .ligne-date { order: 3; }
  .ligne-puces:empty { display: none; }
  .ligne-dette .ligne-puces { grid-column: 1 / -1; }
  .btn, .champ { min-height: 44px; }
  .btn-petit { min-height: 36px; }
  .deux { grid-template-columns: 1fr; }
  .toasts { left: var(--e-4); right: var(--e-4); bottom: 80px; }
}
