/*
 * Thème unique bleu nuit : toute la page dans la même tonalité, avec trois niveaux de fond
 * (plan, surface, surface-2) et des couleurs réservées aux données (dépenses, recettes, états).
 * L'impression repasse en clair (voir @media print).
 */
:root {
  color-scheme: dark;
  --plan: #0e2440;
  --surface: #14304f;
  --surface-2: #1b3b60;
  --piste: #0a1b30;
  --encre: #f2f6fb;
  --encre-2: #b4c3d7;
  --encre-3: #94a6bf;
  --filet: rgba(255, 255, 255, 0.08);
  --bordure: rgba(255, 255, 255, 0.11);
  --accent: #2a78d6;
  --accent-encre: #ffffff;
  --survol: rgba(255, 255, 255, 0.05);

  /* Séries : dépenses (bleu) et recettes (vert d'eau) ; « en cours » dans un ton plus sourd. */
  --dep: #5aa0f2;
  --dep-encours: #2f6cb8;
  --rec: #3ccf96;
  --rec-encours: #1d8a62;

  /* Marqueurs d'état, toujours accompagnés d'un symbole et d'un libellé. */
  --bon: #34c759;
  --attention: #fbbf24;
  --critique: #f06262;
  --critique-encre: #ff9d9d;

  --infobulle-fond: #f2f6fb;
  --infobulle-encre: #0e2440;
}

* { box-sizing: border-box; }
/* Un élément masqué le reste, quel que soit son affichage par défaut (boutons, segments…). */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 0 48px;
  background: var(--plan);
  color: var(--encre);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; }

.masque { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.discret { color: var(--encre-2); font-size: 13px; }
.dec { font-size: 0.66em; font-weight: 500; color: var(--encre-2); }
.negatif, .negatif .dec { color: var(--critique-encre); }

.bandeau, main, .message, .pied { max-width: 1560px; margin-inline: auto; padding-inline: 28px; }

/* ---------- Bandeau : identité, section, indicateurs clés ---------- */
.bandeau { padding-top: 20px; padding-bottom: 20px; }
.bandeau-haut { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.marque { display: flex; align-items: center; gap: 14px; }
.logo {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent); color: var(--accent-encre);
  font-weight: 700; letter-spacing: 0.02em;
}
.titre-ligne { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.auteur { color: var(--encre-3); font-size: 12px; }
.sous-titre { color: var(--encre-2); font-size: 13px; margin-top: 1px; }
.entete-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.bouton {
  display: inline-flex; align-items: center;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--bordure); border-radius: 8px;
  background: var(--surface); color: var(--encre);
  font: inherit; font-weight: 550; white-space: nowrap; cursor: pointer;
}
.bouton:hover { background: var(--surface-2); }
.bouton-principal { background: var(--accent); border-color: var(--accent); color: var(--accent-encre); }
.bouton-principal:hover { background: var(--accent); filter: brightness(1.12); }
.bouton-principal:focus-within, :focus-visible { outline: 2px solid var(--dep); outline-offset: 2px; }

.segments { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface); border: 1px solid var(--filet); }
.segments[hidden] { display: none; }
.segments button {
  height: 30px; padding: 0 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--encre-2);
  font: inherit; font-weight: 550; white-space: nowrap; cursor: pointer;
}
.segments button:hover { color: var(--encre); }
.segments button[aria-pressed="true"] { background: var(--encre); color: var(--plan); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.kpis[hidden] { display: none; }
.kpi {
  display: flex; align-items: center; gap: 16px; min-width: 0;
  padding: 16px 18px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--filet);
}
.kpi-corps { flex: 1; min-width: 0; }
.kpi h2 { color: var(--encre-2); font-size: 13px; font-weight: 600; }
.kpi-valeur { font-size: 26px; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi-sous { color: var(--encre-2); font-size: 12.5px; }
.kpi .jauge-legende { margin-top: 6px; }

.anneau { flex: none; }
.anneau circle { fill: none; transition: stroke-dasharray 0.9s cubic-bezier(0.2, 0.7, 0.2, 1); }
.anneau .anneau-piste { stroke: var(--piste); }
.anneau text { fill: var(--encre); font-size: 17px; font-weight: 650; font-family: inherit; }
.kpi-dep .anneau .realise { stroke: var(--dep); }
.kpi-dep .anneau .encours { stroke: var(--dep-encours); }
.kpi-rec .anneau .realise { stroke: var(--rec); }
.kpi-rec .anneau .encours { stroke: var(--rec-encours); }

.comparaison { display: grid; gap: 6px; margin: 8px 0 6px; }
.comparaison > div { display: grid; gap: 3px; }
.comparaison .ligne { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--encre-2); }
.comparaison .ligne b { color: var(--encre); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.comparaison .piste { height: 6px; }

/* ---------- Corps de page ---------- */
.message {
  margin-bottom: 16px; padding: 10px 14px;
  border: 1px solid var(--critique); border-radius: 8px;
  background: var(--surface); color: var(--critique-encre);
}
.message[hidden] { display: none; }

.accueil { padding: 72px 24px; border: 2px dashed var(--bordure); border-radius: 14px; text-align: center; }
.accueil h2 { font-size: 18px; margin-bottom: 8px; }
.accueil p { max-width: 520px; margin: 0 auto 6px; color: var(--encre-2); }
body.depot .accueil, body.depot #contenu { outline: 3px dashed var(--dep); outline-offset: 6px; border-radius: 14px; }

.cartes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.carte, .panneau {
  background: var(--surface);
  border: 1px solid var(--filet);
  border-radius: 12px;
  padding: 18px 20px;
  min-width: 0;
}
/* Liseré de couleur en tête des cartes Dépenses et Recettes. */
.carte { box-shadow: inset 0 3px 0 var(--serie); }
.carte-dep { --serie: var(--dep); }
.carte-rec { --serie: var(--rec); }
.carte-titre { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.carte-titre h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.carte-titre h2 i { width: 10px; height: 10px; border-radius: 3px; background: var(--serie); }
.etiquette {
  padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--serie) 16%, transparent);
  color: var(--encre); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}

.jauge { display: flex; height: 14px; border-radius: 7px; background: var(--piste); overflow: hidden; }
.jauge i, .piste i, .mini i { display: block; height: 100%; transition: width 0.8s cubic-bezier(0.2, 0.7, 0.2, 1); }
.jauge i + i, .piste i + i { box-shadow: inset 2px 0 0 var(--surface); }
.carte-dep .jauge .realise, .kpi-dep .jauge-legende .realise, .carte-dep .jauge-legende .realise { background: var(--dep); }
.carte-dep .jauge .encours, .kpi-dep .jauge-legende .encours, .carte-dep .jauge-legende .encours { background: var(--dep-encours); }
.carte-rec .jauge .realise, .kpi-rec .jauge-legende .realise, .carte-rec .jauge-legende .realise { background: var(--rec); }
.carte-rec .jauge .encours, .kpi-rec .jauge-legende .encours, .carte-rec .jauge-legende .encours { background: var(--rec-encours); }
.jauge-legende { display: flex; gap: 6px 16px; flex-wrap: wrap; margin-top: 8px; color: var(--encre-2); font-size: 12.5px; }
.jauge-legende span { display: inline-flex; align-items: center; gap: 6px; }
.jauge-legende i { width: 10px; height: 10px; border-radius: 3px; }
/* Le disponible correspond à la partie vide de la jauge. */
.jauge-legende .disponible { background: var(--piste); box-shadow: inset 0 0 0 1px var(--bordure); }

.chiffres { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px 16px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--filet); }
.chiffres div { min-width: 0; }
.chiffres dt { color: var(--encre-2); font-size: 12.5px; }
.chiffres dd { margin: 2px 0 0; font-weight: 650; font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Répartition par origine des fonds */
.origines { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--filet); }
.origines h3 { margin: 0 0 6px; color: var(--encre-2); font-size: 12.5px; font-weight: 600; }
.origines table { width: 100%; border-collapse: collapse; font-size: 13px; }
.origines th, .origines td { padding: 6px 0 6px 12px; text-align: right; white-space: nowrap; }
.origines thead th { color: var(--encre-3); font-size: 12px; font-weight: 500; }
.origines tbody th { padding-left: 0; text-align: left; font-weight: 550; white-space: normal; }
.origines tbody td { font-variant-numeric: tabular-nums; }
.origines tbody tr > * { border-top: 1px solid var(--filet); }
.origines .mini { width: 56px; }
.carte-dep .origines .mini .realise { background: var(--dep); }
.carte-dep .origines .mini .encours { background: var(--dep-encours); opacity: 1; }
.carte-rec .origines .mini .realise { background: var(--rec); }
.carte-rec .origines .mini .encours { background: var(--rec-encours); opacity: 1; }
.origines .valeur { min-width: 44px; }

/* Marqueurs d'état */
.pastille {
  display: inline-grid; place-items: center; flex: none;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 10px; font-weight: 800; line-height: 1; color: #fff;
}
.pastille.bon { background: var(--bon); color: #0b0b0b; }
.pastille.attention { background: var(--attention); color: #0b0b0b; }
.pastille.critique { background: var(--critique); }

/* Panneaux */
.panneaux { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.panneau-titre { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.legende { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; color: var(--encre-2); font-size: 12.5px; }
.legende li { display: inline-flex; align-items: center; gap: 6px; }
.pastille-serie { width: 10px; height: 10px; border-radius: 3px; }
.serie-dep { background: var(--dep); }
.serie-rec { background: var(--rec); }
.serie-dep-encours { background: var(--dep-encours); }
.serie-rec-encours { background: var(--rec-encours); }

.services { display: grid; gap: 4px; }
.service {
  display: grid; grid-template-columns: minmax(120px, 220px) minmax(0, 1fr);
  align-items: center; gap: 16px;
  width: 100%; padding: 8px 10px; margin: 0 -10px;
  border: 0; border-radius: 8px; background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.service:hover { background: var(--survol); }
.service-nom { min-width: 0; }
.service-nom b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-nom small { color: var(--encre-3); font-size: 12px; }
.barres { display: grid; gap: 4px; }
.barre { display: grid; grid-template-columns: minmax(0, 1fr) 52px; align-items: center; gap: 10px; }
.piste { display: flex; height: 10px; background: var(--piste); border-radius: 0 5px 5px 0; overflow: hidden; }
.barre.dep .piste .realise, .comparaison .piste.dep i { background: var(--dep); }
.barre.dep .piste .encours { background: var(--dep-encours); }
.barre.rec .piste .realise, .comparaison .piste.rec i { background: var(--rec); }
.barre.rec .piste .encours { background: var(--rec-encours); }
.barre span { font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; color: var(--encre-2); }

.alertes { overflow-x: auto; }
.alerte-titre { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13.5px; font-weight: 600; }
.alerte-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.alerte-table th, .alerte-table td { padding: 7px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--filet); }
.alerte-table th { color: var(--encre-2); font-size: 12px; font-weight: 600; }
.alerte-table td { font-variant-numeric: tabular-nums; }
.alerte-table th:first-child, .alerte-table td:first-child { text-align: left; padding-left: 0; }
.alerte-table th:last-child, .alerte-table td:last-child { padding-right: 0; }
.alerte-table td:last-child { font-weight: 650; }
.alerte-table tbody tr { cursor: pointer; }
.alerte-table tbody tr:hover td { background: var(--survol); }
.alerte-table button { padding: 0; border: 0; background: transparent; color: var(--encre); font: inherit; text-align: left; cursor: pointer; }
.alerte-suite { margin-top: 8px; color: var(--encre-3); font-size: 12.5px; }

/* ---------- Tableau d'exécution ---------- */
/* Le tableau détaillé est en clair : on y redéfinit les couleurs, tout le reste en découle. */
.panneau-tableau {
  color-scheme: light;
  --plan: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --piste: #e9e8e3;
  --encre: #0b0b0b;
  --encre-2: #52514e;
  --encre-3: #6b6a66;
  --filet: #e1e0d9;
  --bordure: rgba(11, 11, 11, 0.12);
  --survol: rgba(11, 11, 11, 0.045);
  --dep: #2a78d6;
  --dep-encours: #9ec5f4;
  --rec: #1baf7a;
  --rec-encours: #a3dfc8;
  --bon: #0ca30c;
  --attention: #fab219;
  --critique: #d03b3b;
  --critique-encre: #b02a2a;
  color: var(--encre);
  border-color: transparent;
  padding-bottom: 12px;
}
.outils { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.case { display: inline-flex; align-items: center; gap: 6px; color: var(--encre-2); white-space: nowrap; cursor: pointer; }
.case input { margin: 0; accent-color: var(--critique); }

.filtres { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.filtres label { display: inline-flex; align-items: center; gap: 8px; color: var(--encre-2); font-size: 13px; }
.filtres select, .filtres input[type="search"] {
  height: 34px; max-width: 100%; padding: 0 10px;
  border: 1px solid var(--bordure); border-radius: 8px;
  background: var(--plan); color: var(--encre); font: inherit;
}
.filtres select { max-width: 230px; }
.filtres select.actif, .filtres input.actif { border-color: var(--dep); box-shadow: 0 0 0 1px var(--dep); }
.filtres input[type="search"] { width: 190px; }
.filtres input::placeholder { color: var(--encre-3); }
.groupe-contenu { display: inline-flex; align-items: center; gap: 16px; }
.groupe .case { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 550; color: var(--encre); }

/*
 * Pas de défilement interne : le tableau se déplie dans la page et ses en-têtes restent
 * collés en haut de l'écran pendant le défilement. Sur un écran trop étroit pour ses
 * colonnes, il défile seulement en largeur (voir les media queries).
 */
.tableau-cadre { position: relative; margin: 0 -20px; border-top: 1px solid var(--filet); }
.tableau { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tableau th, .tableau td { padding: 7px 5px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--filet); background: var(--surface); }
.tableau td { font-variant-numeric: tabular-nums; }
.tableau thead { position: sticky; top: 0; z-index: 3; }
.tableau thead tr.colonnes th { white-space: normal; line-height: 1.25; vertical-align: bottom; }
.tableau td.libelle { white-space: normal; min-width: 190px; }
.tableau .col-libelle, .tableau td.libelle { position: sticky; left: 0; z-index: 1; }
.tableau thead th { background: var(--surface-2); color: var(--encre-2); font-weight: 600; font-size: 12px; }
.tableau .groupe { text-align: center; font-size: 12.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--encre); }
.tableau .groupe-dep { box-shadow: inset 0 -3px 0 var(--dep); }
.tableau .groupe-rec { box-shadow: inset 0 -3px 0 var(--rec); }
.tableau .col-libelle, .tableau td.libelle { text-align: left; padding-left: 20px; }
.tableau .groupe-rec, .tableau .debut-rec { border-left: 2px solid var(--bordure); }
.tableau .debut-rec, .tableau .debut-dep { padding-left: 12px; }
.tableau td:last-child, .tableau th:last-child { padding-right: 20px; }
.tableau tbody tr:hover td { background: color-mix(in srgb, var(--encre) 6%, var(--surface)); }
.tableau .vide { color: var(--encre-3); }
.tableau td.encadre { box-shadow: inset 0 0 0 1.5px var(--critique); border-radius: 5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
/* Cadre unique autour de deux cellules voisines. */
.tableau td.encadre-debut {
  box-shadow: inset 1.5px 0 0 var(--critique), inset 0 1.5px 0 var(--critique), inset 0 -1.5px 0 var(--critique);
  border-radius: 5px 0 0 5px;
}
.tableau td.encadre-fin {
  box-shadow: inset -1.5px 0 0 var(--critique), inset 0 1.5px 0 var(--critique), inset 0 -1.5px 0 var(--critique);
  border-radius: 0 5px 5px 0;
}

.libelle-contenu { display: flex; align-items: center; gap: 6px; }
.chevron {
  display: inline-grid; place-items: center; flex: none;
  width: 20px; height: 20px; padding: 0;
  border: 0; border-radius: 5px; background: transparent;
  color: var(--encre-2); cursor: pointer;
}
.chevron:hover { background: var(--surface-2); }
.chevron svg { transition: transform 0.12s; }
.chevron[aria-expanded="true"] svg { transform: rotate(90deg); }
.chevron-vide { width: 20px; flex: none; }
.code { color: var(--encre-3); font-size: 12px; }

tr.niveau-section td { background: var(--surface-2); font-weight: 650; }
tr.niveau-section td.libelle { text-transform: uppercase; letter-spacing: 0.04em; font-size: 12.5px; }
tr.niveau-service td { font-weight: 600; }
tr.niveau-service .libelle-contenu { padding-left: 18px; }
tr.niveau-domaine .libelle-contenu { padding-left: 36px; }
tr.niveau-activite .libelle-contenu { padding-left: 54px; }
tr.niveau-activite td { color: var(--encre-2); }
tr.niveau-activite td.negatif, td.negatif { color: var(--critique-encre); }
tr.repere td { animation: repere 1.6s ease-out; }
@keyframes repere { from { background: color-mix(in srgb, var(--attention) 35%, var(--surface)); } }

.tableau tfoot td { background: var(--surface-2); font-weight: 650; border-top: 1px solid var(--bordure); border-bottom: 0; }

.exec { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
.exec .mini { display: flex; gap: 1px; width: 44px; height: 6px; border-radius: 3px; background: var(--piste); overflow: hidden; }
.exec .mini i.encours { opacity: 0.5; }
.exec .mini i.bon { background: var(--bon); }
.exec .mini i.attention { background: var(--attention); }
.exec .mini i.critique { background: var(--critique); }
.exec .valeur { min-width: 34px; }

.note { padding-top: 12px; }
.source { margin-top: 12px; text-align: right; }

/* Pied de page : mention de confidentialité, toujours visible (accueil compris). */
.pied { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--filet); color: var(--encre-3); font-size: 12px; text-align: center; }
.pied p { max-width: 760px; margin-inline: auto; }
.pied b { color: var(--encre-2); font-weight: 600; }

.infobulle {
  position: fixed; z-index: 10; max-width: 300px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--infobulle-fond); color: var(--infobulle-encre);
  font-size: 12.5px; line-height: 1.5; white-space: pre-line;
  pointer-events: none; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .jauge i, .piste i, .mini i, .anneau circle, .chevron svg { transition: none; }
  tr.repere td { animation: none; }
}

@media screen and (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Tableau resserré pour tenir dans la largeur sans défilement. */
  .tableau { font-size: 12px; }
  .tableau th, .tableau td { padding: 6px 4px; }
  .tableau td.libelle { min-width: 140px; }
  tr.niveau-service .libelle-contenu { padding-left: 12px; }
  tr.niveau-domaine .libelle-contenu { padding-left: 24px; }
  tr.niveau-activite .libelle-contenu { padding-left: 36px; }
  tr.niveau-section td.libelle { letter-spacing: 0.01em; font-size: 12px; }
  .tableau .col-libelle, .tableau td.libelle { padding-left: 16px; }
  .tableau td:last-child, .tableau th:last-child { padding-right: 16px; }
  .exec .mini { width: 28px; }
}
@media screen and (max-width: 1133px) {
  /* En dessous, le tableau défile en largeur dans son cadre (jamais en hauteur). */
  .tableau-cadre { overflow-x: auto; }
}
@media screen and (max-width: 1180px) {
  .cartes, .panneaux { grid-template-columns: minmax(0, 1fr); }
  /* Écran étroit : la mini-barre du tableau devient une pastille de la couleur de l'état. */
  .tableau .exec .mini { width: 8px; height: 8px; border-radius: 50%; }
  .tableau .exec .mini i { display: none; }
  .tableau .exec .mini.bon { background: var(--bon); }
  .tableau .exec .mini.attention { background: var(--attention); }
  .tableau .exec .mini.critique { background: var(--critique); }
}
@media screen and (max-width: 760px) {
  .bandeau, main, .message, .pied { padding-inline: 16px; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .chiffres { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-valeur { font-size: 22px; }
  .service { grid-template-columns: minmax(0, 1fr); gap: 6px; }
}

/*
 * ---------- Impression : rapport de gestion, tout en A4 paysage ----------
 * Page 1 : le rapport (#rapport), version imprimée du tableau de bord, construit à part dans
 * app.js. Pages suivantes : le tableau détaillé tel qu'affiché à l'écran. Le pied de page
 * (identité, pagination) est injecté par app.js (#style-impression).
 * Une seule orientation : Firefox ne sait pas mêler portrait et paysage (page blanche
 * ajoutée à la fin, pages d'un long tableau revenant au format par défaut).
 */
.rapport, .perimetre, .credit { display: none; }

@page {
  size: A4 landscape;
  margin: 11mm 12mm 14mm;
  /* Marges du haut déclarées vides : le navigateur n'y imprime pas son propre en-tête. */
  @top-left { content: ""; }
  @top-center { content: ""; }
  @top-right { content: ""; }
  @bottom-left { font: 7.5pt "Segoe UI", system-ui, sans-serif; color: #706e68; vertical-align: top; padding-top: 4mm; }
  @bottom-right { font: 7.5pt "Segoe UI", system-ui, sans-serif; color: #706e68; vertical-align: top; padding-top: 4mm; }
}

@media print {
  :root, .panneau-tableau {
    color-scheme: light;
    --plan: #ffffff; --surface: #ffffff; --surface-2: #f5f4ef; --piste: #ecebe6;
    --encre: #141413; --encre-2: #4d4c48; --encre-3: #706e68;
    --filet: #e4e2db; --bordure: rgba(20, 20, 19, 0.16);
    --dep: #1f5fae; --dep-encours: #a9c8ee; --rec: #13865e; --rec-encours: #a8dcc6;
    --bon: #0ca30c; --attention: #fab219; --critique: #d03b3b; --critique-encre: #a8261f;
  }
  /* Segoe UI classique : Firefox dessine la variante « Variable » en formes, sans texte dans le PDF. */
  body { padding: 0; background: #fff; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 10px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  main { max-width: none; padding: 0; }
  .bandeau, .message, .accueil, .cartes, .panneaux, .infobulle, .outils, .filtres, .groupe .case, .pied { display: none !important; }

  /* Page 1 : rapport. En-tête et chiffres clés sur toute la largeur, puis deux colonnes. */
  .rapport {
    display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); column-gap: 28px; align-items: start;
    grid-template-areas: "entete entete" "chiffres chiffres" "synthese alertes" "services alertes";
    color: var(--encre);
  }
  .rapport-entete { grid-area: entete; }
  .rapport-chiffres { grid-area: chiffres; }
  .bloc-synthese { grid-area: synthese; }
  .bloc-services { grid-area: services; }
  .bloc-alertes { grid-area: alertes; }
  .rapport h3 { font-size: 8.5px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--encre-2); }
  .sens-dep { --serie: var(--dep); --serie-encours: var(--dep-encours); }
  .sens-rec { --serie: var(--rec); --serie-encours: var(--rec-encours); }
  .rapport .realise { background: var(--serie); }
  .rapport .encours { background: var(--serie-encours); }

  .rapport-entete { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding-bottom: 10px; border-bottom: 2px solid var(--encre); }
  .rapport-surtitre { font-size: 9px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--encre-2); }
  .rapport h1 { margin-top: 3px; font-size: 24px; font-weight: 650; letter-spacing: -0.015em; line-height: 1.15; }
  .rapport-perimetre { text-align: right; font-size: 9px; color: var(--encre-2); }
  .rapport-perimetre b { display: block; margin-top: 1px; font-size: 12px; font-weight: 650; color: var(--encre); }

  .rapport-chiffres { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 14px; }
  .rapport-chiffre { min-width: 0; padding: 0 20px; border-left: 1px solid var(--filet); }
  .rapport-chiffre:first-child { padding-left: 0; border-left: 0; }
  .rapport-chiffre:last-child { padding-right: 0; }
  .rapport-valeur { margin-top: 4px; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .rapport-texte { margin-top: 6px; font-size: 9.5px; line-height: 1.45; color: var(--encre-2); }
  .rapport-barre { display: flex; height: 6px; margin-top: 7px; background: var(--piste); overflow: hidden; }
  .rapport-barre i { display: block; height: 100%; }
  .rapport-barre i + i { border-left: 1px solid #fff; }

  .rapport-bloc { margin-top: 20px; break-inside: avoid; }
  .rapport-bloc > h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 5px; border-bottom: 1px solid var(--filet); font-size: 13px; font-weight: 650; }
  .rapport-bloc > h2 small { font-size: 8.5px; font-weight: 500; color: var(--encre-2); }

  .rapport table { width: 100%; border-collapse: collapse; font-size: 10px; }
  .rapport th, .rapport td { padding: 4px 0 4px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--filet); font-variant-numeric: tabular-nums; }
  .rapport th:first-child, .rapport td:first-child { padding-left: 0; text-align: left; white-space: normal; }
  .rapport thead th { padding-top: 6px; font-size: 8.5px; font-weight: 650; color: var(--encre-2); border-bottom: 1px solid var(--encre); vertical-align: bottom; }
  .rapport tbody th { font-weight: 500; }
  .rapport .vide { color: var(--encre-3); }
  .rapport .exec .mini { width: 46px; height: 6px; border-radius: 0; }
  .rapport .exec .mini i.encours { opacity: 1; }
  .rapport .exec .valeur { min-width: 38px; }

  .rapport-synthese thead th:nth-child(6) { white-space: normal; width: 74px; }
  .rapport-synthese .ligne-total > * { padding-top: 7px; font-weight: 650; }
  .rapport-synthese .ligne-total .puce { display: inline-block; width: 8px; height: 8px; margin-right: 6px; background: var(--serie); }
  .rapport-synthese .ligne-detail > * { color: var(--encre-2); }
  .rapport-synthese .ligne-detail > th { padding-left: 14px; }

  .rapport-services th:first-child { width: 28%; }
  .rapport-services tbody th, .rapport-services tbody td { padding-top: 5px; padding-bottom: 5px; }
  .rapport-services tbody th b { display: block; font-weight: 650; }
  .rapport-services tbody th small { color: var(--encre-3); font-size: 8.5px; }
  .rapport-services td { padding-left: 18px; }
  .rapport-mesure .haut { display: flex; justify-content: space-between; gap: 8px; }
  .rapport-mesure .haut span { color: var(--encre-2); }
  .rapport-mesure .rapport-barre { margin-top: 3px; height: 7px; }

  .rapport-alertes { display: grid; gap: 16px; margin-top: 9px; }
  .rapport-alertes h3 { display: flex; align-items: center; gap: 6px; }
  .rapport-alertes .compte { padding: 0 6px; border-radius: 999px; background: var(--critique); color: #fff; font-size: 8px; letter-spacing: 0; }
  .rapport-alertes table { font-size: 9.5px; }
  .rapport-alertes thead th { white-space: normal; }
  .rapport-alertes tbody td:first-child { white-space: nowrap; }
  .rapport-alertes .ecart { font-weight: 650; }

  /* Pages suivantes : tableau détaillé, en paysage, en-têtes répétés à chaque page */
  .panneau-tableau { break-before: page; padding: 0; border: 0; border-radius: 0; background: none; }
  .panneau-tableau .panneau-titre { align-items: baseline; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid var(--encre); }
  .panneau-tableau h2 { font-size: 16px; }
  .perimetre { display: block; font-size: 9px; color: var(--encre-2); }
  .tableau-cadre { margin: 0; border-top: 0; overflow: visible; }
  .tableau { font-size: 10px; line-height: 1.3; }
  .tableau th, .tableau td { padding: 3px 4px; background: none; }
  .tableau thead { position: static; display: table-header-group; }
  /* Le total n'apparaît qu'une fois, à la fin (et non en bas de chaque page). */
  .tableau tfoot { display: table-row-group; }
  .tableau tr { break-inside: avoid; }
  /* Un intitulé de section, de service ou de domaine ne reste pas seul en bas de page. */
  tr.niveau-section, tr.niveau-service, tr.niveau-domaine { break-after: avoid; }
  .tableau .col-libelle, .tableau td.libelle { position: static; padding-left: 0; min-width: 0; }
  .tableau td:last-child, .tableau th:last-child { padding-right: 0; }
  .tableau thead th { background: none; font-size: 9px; }
  .tableau thead tr.colonnes th { border-bottom: 1px solid var(--encre); }
  .tableau .groupe { font-size: 9.5px; }
  .tableau .groupe-rec, .tableau .debut-rec { border-left-width: 1px; }
  /* Firefox trace mal les ombres internes dans le PDF (filets parasites) : bordures à la place. */
  .tableau .groupe-dep { box-shadow: none; border-bottom: 3px solid var(--dep); }
  .tableau .groupe-rec { box-shadow: none; border-bottom: 3px solid var(--rec); }
  .tableau td.encadre { box-shadow: none; border: 1.5px solid var(--critique); padding: 1.5px 2.5px; }
  .tableau td.encadre-debut { border-right: 0; padding-right: 4px; }
  .tableau td.encadre-fin { border-left: 0; padding-left: 4px; }
  .chevron, .chevron-vide { display: none; }
  tr.niveau-section td { background: var(--surface-2); }
  tr.niveau-section td.libelle { font-size: 10px; }
  tr.niveau-service .libelle-contenu { padding-left: 10px; }
  tr.niveau-domaine .libelle-contenu { padding-left: 22px; }
  tr.niveau-activite .libelle-contenu { padding-left: 34px; }
  .code { font-size: 8.5px; }
  .tableau tfoot td { background: none; border-top: 2px solid var(--encre); }
  .exec .mini { width: 26px; height: 5px; }
  .exec .valeur { min-width: 26px; }
  tr.repere td { animation: none; }
  .note { padding-top: 8px; font-size: 8.5px; }
  .source { margin-top: 4px; font-size: 8.5px; }
  .credit { display: block; margin-top: 1px; text-align: right; font-size: 8.5px; color: var(--encre-3); }
}
