:root {
  --fond: #f5f6f8;
  --carte: #ffffff;
  --texte: #1f2933;
  --texte-doux: #52606d;
  --bordure: #d9dee5;
  --accent: #1f4e79;
  --accent-clair: #e8f0f8;
  --retard: #b42318;
  --retard-fond: #fdecea;
  --attente: #8a5a00;
  --attente-fond: #fdf3dc;
  --j7: #c05621;
  --j7-fond: #fdeee3;
  --j30: #2b6cb0;
  --j30-fond: #e7f0fa;
  --fait: #2f6f4e;
  --fait-fond: #e6f4ec;
  --rayon: 10px;
}

* { box-sizing: border-box; }

[x-cloak] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--texte);
  background: var(--fond);
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1rem; }
h2 small, h3 small { font-weight: 400; color: var(--texte-doux); font-size: .85rem; }

button, select, input { font: inherit; color: inherit; }

button, .bouton {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .5rem .9rem;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: var(--carte);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .bouton:hover { border-color: var(--accent); }
.bouton { color: var(--accent); font-weight: 600; }
button.principal { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.principal:hover { background: #173d61; }
button.discret { background: transparent; color: var(--texte-doux); }
button.lien {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-align: left;
  white-space: normal;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.puce { padding: .2rem .6rem; font-size: .85rem; border-radius: 999px; }

select, input[type="text"], input[type="search"], input[type="number"], input[type="date"] {
  padding: .45rem .55rem;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: #fff;
  max-width: 100%;
}

:focus-visible { outline: 3px solid #7aa7d6; outline-offset: 1px; }

.bandeau-exemple {
  padding: .55rem 1rem;
  background: #fff7d6;
  border-bottom: 1px solid #ecd889;
  color: #5c4a00;
  font-size: .9rem;
  text-align: center;
}

.page { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 3rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.page > *, .charge > *, .pilotage > * { min-width: 0; }
.carte { overflow-x: auto; }

.entete { display: flex; gap: 1.5rem; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.entete > div:first-child { flex: 1 1 520px; }
.surtitre { margin: 0 0 .25rem; color: var(--texte-doux); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.accroche { margin: .5rem 0 0; color: var(--texte-doux); max-width: 70ch; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.carte, .pilotage, .compteur {
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  padding: 1rem;
}

.pilotage { display: grid; grid-template-columns: minmax(280px, 1.1fr) 2fr; gap: 1.25rem; }
.date-simulee label { display: block; margin-bottom: .35rem; }
.date-simulee input[type="range"] { width: 100%; accent-color: var(--accent); }
.reperes { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .35rem; }
.aide { margin: .5rem 0 0; color: var(--texte-doux); font-size: .85rem; }
.filtres { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; align-content: start; }
.filtres label { display: grid; gap: .3rem; font-size: .85rem; color: var(--texte-doux); }
.filtres select { color: var(--texte); width: 100%; }

.compteurs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.compteur { border-left-width: 5px; }
.compteur h2 { font-size: .9rem; font-weight: 600; color: var(--texte-doux); }
.compteur .valeur { margin: .25rem 0 0; font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.compteur .detail { margin: .15rem 0 0; min-height: 1.2em; font-size: .8rem; color: var(--texte-doux); }
.compteur-retard { border-left-color: var(--retard); }
.compteur-retard .valeur { color: var(--retard); }
.compteur-j7 { border-left-color: var(--j7); }
.compteur-j7 .valeur { color: var(--j7); }
.compteur-j30 { border-left-color: var(--j30); }
.compteur-j30 .valeur { color: var(--j30); }
.compteur-attente { border-left-color: var(--attente); }
.compteur-attente .valeur { color: var(--attente); }

.charge { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; }
.zone-graphique { position: relative; height: 280px; margin-top: .75rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .55rem; text-align: left; vertical-align: top; border-bottom: 1px solid #eceff3; }
thead th { font-size: .8rem; color: var(--texte-doux); font-weight: 600; background: #fafbfc; }
td small, th small { display: block; color: var(--texte-doux); font-size: .78rem; font-weight: 400; }
.table-charge { margin-top: .75rem; }
.table-charge td { font-variant-numeric: tabular-nums; }
.table-charge tr.selectionne { background: var(--accent-clair); }

.onglets { display: flex; gap: .25rem; border-bottom: 1px solid var(--bordure); margin: -1rem -1rem 1rem; padding: .5rem .75rem 0; }
.onglets button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: .6rem .8rem; color: var(--texte-doux); }
.onglets button.actif { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pastille { display: inline-block; min-width: 1.6rem; padding: 0 .4rem; border-radius: 999px; background: #eef1f5; font-size: .78rem; text-align: center; }

.barre { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.barre p { margin: 0; color: var(--texte-doux); }
.barre input[type="search"] { flex: 1 1 260px; }

.date { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.regle { color: var(--texte-doux); font-size: .8rem; }
small.regle { margin-top: .15rem; }
.report { color: var(--j7); }
.badge-report { display: inline-block; margin-left: .3rem; padding: 0 .45rem; border-radius: 999px; background: var(--j7-fond); color: var(--j7); font-size: .75rem; font-weight: 600; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: #eef1f5; color: var(--texte-doux); }
.badge-retard { background: var(--retard-fond); color: var(--retard); }
.badge-attente { background: var(--attente-fond); color: var(--attente); }
.badge-j7 { background: var(--j7-fond); color: var(--j7); }
.badge-j30 { background: var(--j30-fond); color: var(--j30); }
.badge-fait { background: var(--fait-fond); color: var(--fait); }
.badge-nouveau { margin-left: .4rem; background: var(--accent-clair); color: var(--accent); }
tr.situation-retard td:first-child { box-shadow: inset 3px 0 0 var(--retard); }
tr.situation-attente td:first-child { box-shadow: inset 3px 0 0 var(--attente); }
tr.situation-fait { color: var(--texte-doux); }
.table-echeances select { width: 100%; min-width: 9.5rem; }
.suite { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; color: var(--texte-doux); font-size: .85rem; }
.vide { color: var(--texte-doux); text-align: center; padding: 1rem; }

.regles summary { cursor: pointer; font-weight: 600; }
.regles table { margin-top: .75rem; font-size: .88rem; }

.pied { color: var(--texte-doux); font-size: .82rem; text-align: center; }

.voile { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; justify-content: flex-end; z-index: 20; }
.panneau { width: min(860px, 100%); height: 100%; overflow-y: auto; background: var(--carte); padding: 1.25rem; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); }
.modale { margin: auto; width: min(680px, calc(100% - 1.5rem)); max-height: calc(100% - 2rem); overflow-y: auto; background: var(--carte); border-radius: var(--rayon); padding: 1.25rem; }
.panneau-entete { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; }
.panneau-entete h2 { font-size: 1.25rem; }
.fermer { font-size: 1.4rem; line-height: 1; padding: .2rem .65rem; }

.formulaire { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--bordure); }
.formulaire label, .formulaire fieldset { display: grid; gap: .3rem; font-size: .85rem; color: var(--texte-doux); }
.formulaire fieldset { border: 0; padding: 0; margin: 0; grid-template-columns: auto auto 1fr; align-items: center; column-gap: 1rem; }
.formulaire legend { padding: 0; margin-bottom: .3rem; }
.formulaire input, .formulaire select { color: var(--texte); width: 100%; }
.formulaire .radio { display: inline-flex; align-items: center; gap: .35rem; color: var(--texte); font-size: .95rem; }
.formulaire .radio input { width: auto; }
.formulaire .large { grid-column: 1 / -1; }
.puces { display: flex; gap: .35rem; flex-wrap: wrap; }
.erreur { color: var(--retard); font-size: .8rem; min-height: 0; }
.erreur:empty { display: none; }
.panneau-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.etat-enregistrement { color: var(--texte-doux); font-size: .85rem; }

.echeancier { padding-top: 1rem; }
.echeancier h3 { font-size: 1.05rem; }
.groupe { margin-top: 1rem; }
.groupe h4 { font-size: .9rem; padding: .5rem .6rem; background: var(--accent-clair); border-radius: 8px; color: var(--accent); }
.table-echeancier { font-size: .9rem; }
.table-echeancier td.regle { font-size: .82rem; }

.etapes { padding-left: 1.2rem; display: grid; gap: .5rem; }
.etapes a { color: var(--accent); font-weight: 600; }
.resultat-import { margin-top: 1rem; }
.erreur-import { color: var(--retard); font-weight: 600; }
.table-rejets { margin: .5rem 0 1rem; font-size: .9rem; }
.table-rejets td:first-child { font-weight: 700; color: var(--retard); white-space: nowrap; }
.ajoutes { columns: 2; padding-left: 1.1rem; font-size: .9rem; }
.chargement { color: var(--texte-doux); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  max-width: min(640px, calc(100% - 2rem));
  padding: .75rem 1rem;
  background: #1f2933;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  z-index: 30;
}

@media (max-width: 960px) {
  .pilotage, .charge { grid-template-columns: 1fr; }
  .compteurs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  h1 { font-size: 1.3rem; }
  .filtres { grid-template-columns: 1fr; }
  .formulaire { grid-template-columns: 1fr; }
  .compteur .valeur { font-size: 1.7rem; }
  .ajoutes { columns: 1; }
  .table-echeances thead, .table-dossiers thead, .table-echeancier thead { display: none; }
  .table-charge { font-size: .78rem; }
  .table-charge th, .table-charge td { padding: .35rem .2rem; }
  .table-charge th small { display: none; }
  .table-echeances, .table-dossiers, .table-echeancier, .table-echeances tbody, .table-dossiers tbody, .table-echeancier tbody { display: block; }
  .table-echeances select { min-width: 0; }
  .onglets { overflow-x: auto; }
  .onglets button { padding: .55rem .5rem; }
  .table-echeances tr, .table-dossiers tr, .table-echeancier tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: .3rem .75rem;
    padding: .65rem .2rem;
    border-bottom: 1px solid var(--bordure);
  }
  .table-echeances td, .table-dossiers td, .table-echeancier td { border: 0; padding: 0; }
  .table-echeances td::before, .table-dossiers td::before, .table-echeancier td::before {
    content: attr(data-label);
    display: block;
    font-size: .72rem;
    color: var(--texte-doux);
    text-transform: uppercase;
    letter-spacing: .03em;
  }
  .table-echeances td:nth-child(2), .table-echeances td:nth-child(3), .table-dossiers td:first-child, .table-echeancier td:nth-child(2), .table-echeancier td:nth-child(3) { grid-column: 1 / -1; }
  tr.situation-retard td:first-child, tr.situation-attente td:first-child { box-shadow: none; }
  tr.situation-retard { border-left: 3px solid var(--retard); }
  tr.situation-attente { border-left: 3px solid var(--attente); }
}
