/* Suivi budgétaire — feuille de style unique, sans dépendance ni CDN.
   Outil de saisie intensive : tableaux denses, en-têtes figés, contrastes
   francs, rien de décoratif qui coûte de la place.

   PALETTE « Le Phare » : bleu, or, beige (demande du 4 novembre 2026).
   Le bleu porte la structure (barre, liens, onglet actif), l'or signale ce qui
   est à lire en premier (totaux, repères, onglet survolé), le beige fait les
   fonds et les filets.

   Contrastes mesurés sur le fond réel #faf7f1, et non sur du blanc :
     texte            #1c2c3a   13,35:1   AAA
     mention discrète #5a6675    5,47:1   AA
     bleu / liens     #1b4a6b    8,77:1   AAA
     or (texte)       #8a6a14    4,73:1   AA
     vert             #2f6b3f    5,96:1   AA
     rouge            #b3261e    6,11:1   AA
     blanc sur bleu   #1b4a6b    9,38:1   AAA
     texte sur or vif #c9a227    5,90:1   AA

   L'or vif #c9a227 ne porte JAMAIS de texte blanc (2,42:1) : il sert aux
   aplats, aux filets et aux jauges, avec du texte foncé par-dessus.
   La couleur n'est jamais le seul signal : un écart porte aussi son signe, une
   jauge son repère, un poste hors exploitation son étiquette. */

:root {
  --fond: #faf7f1;          /* beige clair */
  --fond-carte: #ffffff;
  --texte: #1c2c3a;         /* bleu anthracite */
  --texte-discret: #5a6675;
  --bord: #e8e0cf;          /* beige */
  --bord-fort: #d8ccb4;
  --bleu: #1b4a6b;
  --bleu-fort: #123549;
  --bleu-clair: #e8f0f5;
  --or: #8a6a14;            /* or lisible, pour le texte */
  --or-vif: #c9a227;        /* or des aplats et des filets */
  --or-clair: #faf2dd;
  --vert: #2f6b3f;
  --vert-clair: #eaf2ec;
  --rouge: #b3261e;
  --rouge-clair: #fbeceb;
  --section: #efe8d8;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: var(--bleu); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--bleu-fort); }

/* --- Barre du haut ----------------------------------------------------- */
.barre {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--bleu); color: #fff;
  padding: 8px 18px; border-bottom: 3px solid var(--or-vif);
}
.barre a { color: #fff; text-decoration: none; font-size: 14px; }
.barre a:hover { text-decoration: underline; color: #fff; }
.barre .logo { font-weight: 700; letter-spacing: .02em; font-size: 16px; }
.barre .espace { flex: 1; }
.barre .qui { font-size: 13px; opacity: .95; }
.barre .role {
  margin-left: 6px; padding: 1px 6px; border-radius: 10px;
  background: rgba(255, 255, 255, .18); font-size: 11px; text-transform: lowercase;
}
.barre button.lien { color: #fff; }

main { padding: 18px 18px 64px; max-width: 100%; }

h1 { font-size: 23px; margin: 10px 0 4px; font-weight: 700; }
h2 { font-size: 18px; margin: 28px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--bord-fort); }
h3 { font-size: 15px; margin: 18px 0 6px; }
.code-structure {
  font-size: 13px; background: var(--or-clair); color: var(--or);
  border: 1px solid var(--or-vif); border-radius: 4px; padding: 1px 7px; vertical-align: middle;
}

/* --- Onglets ----------------------------------------------------------- */
.onglets, .sous-onglets { display: flex; flex-wrap: wrap; gap: 2px; margin: 0 -18px 0; padding: 0 18px; }
.onglets { background: var(--fond-carte); border-bottom: 1px solid var(--bord-fort); }
.onglets a {
  padding: 9px 15px; text-decoration: none; color: var(--texte);
  border-bottom: 3px solid transparent; font-weight: 600; font-size: 14px;
}
.onglets a:hover { background: var(--or-clair); }
.onglets a.actif { border-bottom-color: var(--bleu); color: var(--bleu); background: var(--bleu-clair); }
.sous-onglets { background: var(--bleu-clair); border-bottom: 1px solid var(--bord-fort); padding: 4px 18px; }
.sous-onglets a {
  padding: 5px 11px; text-decoration: none; color: var(--bleu-fort);
  font-size: 13px; border-radius: 4px;
}
.sous-onglets a:hover { background: #fff; }
.sous-onglets a.actif { background: var(--bleu); color: #fff; font-weight: 600; }

.choix-annee { display: flex; align-items: center; gap: 4px; margin: 12px 0 6px; }
.choix-annee .etiquette { font-size: 13px; color: var(--texte-discret); margin-right: 4px; }
.choix-annee a, .choix-annee .actif {
  padding: 4px 12px; border: 1px solid var(--bord-fort); border-radius: 4px;
  text-decoration: none; font-size: 15px; font-weight: 600; background: var(--fond-carte);
}
.choix-annee .actif { background: var(--bleu); color: #fff; border-color: var(--bleu); }

/* --- Messages ---------------------------------------------------------- */
.message, .erreur {
  margin: 12px 0; padding: 10px 14px; border-radius: 5px; border-left: 4px solid;
}
.message { background: var(--or-clair); border-color: var(--or-vif); }
.erreur { background: var(--rouge-clair); border-color: var(--rouge); color: #7a1a14; }
.aide { color: var(--texte-discret); font-size: 13.5px; max-width: 76ch; margin: 8px 0; }
.aide code, code {
  background: var(--fond-carte); border: 1px solid var(--bord); border-radius: 3px;
  padding: 0 4px; font-size: 12.5px;
}
.liste-aide { color: var(--texte-discret); font-size: 13.5px; max-width: 76ch; }

/* --- Cartouches de tête ------------------------------------------------ */
.cartouches { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 8px; }
.cartouche {
  background: var(--fond-carte); border: 1px solid var(--bord-fort);
  border-top: 3px solid var(--or-vif); border-radius: 5px;
  padding: 10px 16px; min-width: 190px; flex: 1 1 190px;
}
.cartouche-titre { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-discret); }
.cartouche-valeur { font-size: 25px; font-weight: 700; line-height: 1.2; margin: 2px 0; }
.cartouche-valeur .sur { font-size: 15px; font-weight: 400; color: var(--texte-discret); }
.cartouche-sous { font-size: 12.5px; color: var(--texte-discret); }

/* --- Tableaux ---------------------------------------------------------- */
.debordement { overflow-x: auto; border: 1px solid var(--bord-fort); border-radius: 5px; background: var(--fond-carte); }

/* Tableau plus large que l'écran : le conteneur devient un PANNEAU défilant,
   comme un tableur. Trois conséquences voulues :
     - la barre de défilement horizontale est toujours visible, en bas du
       panneau, et non en bas d'une page de deux mètres de haut ;
     - les en-têtes de colonnes restent figés (thead est déjà sticky, et il
       suit le conteneur qui défile) ;
     - le panneau ne dépasse jamais les trois quarts de la hauteur de l'écran.
   La hauteur n'est PAS imposée : max-height ne s'applique qu'au-delà. */
.debordement.large {
  overflow: auto;
  overflow-x: scroll;          /* « scroll » et non « auto » : la barre se voit */
  max-height: 76vh;
  overscroll-behavior-x: contain;
}
.debordement.large::-webkit-scrollbar { height: 14px; width: 14px; }
.debordement.large::-webkit-scrollbar-track { background: var(--section); }
.debordement.large::-webkit-scrollbar-thumb {
  background: var(--bord-fort); border-radius: 7px; border: 3px solid var(--section);
}
.debordement.large::-webkit-scrollbar-thumb:hover { background: var(--or-vif); }
.debordement.large { scrollbar-color: var(--bord-fort) var(--section); }
table.grille {
  border-collapse: collapse; width: 100%; background: var(--fond-carte);
  font-size: 14px;
}
.debordement table.grille { border: 0; }
table.grille.serree { font-size: 13px; }
table.grille.etroite { width: auto; min-width: 520px; }
table.grille caption { text-align: left; padding: 8px 10px; font-weight: 600; color: var(--texte-discret); }
table.grille th, table.grille td { padding: 5px 8px; border-bottom: 1px solid var(--bord); text-align: left; }
table.grille.serree th, table.grille.serree td { padding: 3px 6px; }
/* Titres de colonnes : 10 px dans les tableaux denses (12 ailleurs). Ils sont
   courts et en majuscules, ils restent lisibles, et vingt colonnes y gagnent. */
table.grille.serree thead th { font-size: 10px; letter-spacing: .02em; line-height: 1.2; }
table.grille thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--section); border-bottom: 2px solid var(--bord-fort);
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
table.grille tbody tr:hover { background: var(--or-clair); }
table.grille td.num, table.grille th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grille td.centre, table.grille th.centre { text-align: center; }
table.grille td.total, table.grille th.total { font-weight: 700; background: var(--bleu-clair); }
table.grille .discret { color: var(--texte-discret); font-size: 12px; margin-left: 6px; }

tr.ligne-total th, tr.ligne-total td {
  background: var(--bleu-clair); font-weight: 700; border-top: 2px solid var(--bleu);
  border-bottom: 1px solid var(--bord-fort);
}
tr.ligne-cumul th, tr.ligne-cumul td { background: var(--section); font-weight: 700; }
tr.ligne-forte th, tr.ligne-forte td { font-weight: 700; background: var(--or-clair); }
tr.separateur-mois th, tr.separateur-poste th {
  background: var(--bleu); color: #fff; font-weight: 700; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 0;
}
tr.separateur-poste th .discret, tr.separateur-mois th .discret { color: #e8e0cf; }
tr.separateur-poste.hors-expl th { background: var(--texte-discret); }
tr.separateur-poste th select { font-size: 12px; }
tr.vide-poste td { color: var(--texte-discret); font-style: italic; font-size: 12.5px; }
tr.hors-expl td, tr.hors-expl th { color: var(--texte-discret); }
tr.inactif td, tr.inactif th { opacity: .55; }
td.non-saisi, th.non-saisi { background: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--fond) 4px, var(--fond) 8px); }
td.hors-periode { background: var(--section); }

.etiquette-hors {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
  background: var(--fond-carte); color: var(--texte-discret);
  border: 1px solid var(--bord-fort); border-radius: 3px; padding: 0 5px; margin-left: 6px;
  white-space: nowrap;
}

.neg { color: var(--rouge); }
.pos { color: var(--vert); }
.vide { color: var(--bord-fort); }

/* --- Jauge (SVG : la CSP interdit les styles en ligne) ----------------- */
svg.jauge { width: 88px; height: 12px; vertical-align: middle; }
.jauge-fond { fill: var(--bord); }
.jauge-repere { fill: var(--texte); }
.zone-ok .jauge-barre { fill: var(--vert); }
.zone-vigilance .jauge-barre { fill: var(--or-vif); }
.zone-alerte .jauge-barre { fill: var(--rouge); }
.jauge-texte { font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }
td.jauge-cellule { white-space: nowrap; }

/* --- Formulaires ------------------------------------------------------- */
input, select, button, textarea { font: inherit; color: inherit; }
input[type="text"], input:not([type]), input[type="password"], input[type="date"], select, textarea {
  background: var(--fond-carte); border: 1px solid var(--bord-fort); border-radius: 4px;
  padding: 4px 7px; max-width: 100%;
}
input:focus, select:focus, button:focus {
  outline: 2px solid var(--or-vif); outline-offset: 1px;
}
label { display: block; font-size: 13px; color: var(--texte-discret); }
label input, label select { display: block; margin-top: 2px; color: var(--texte); font-size: 14px; }
label.case { display: flex; align-items: center; gap: 6px; color: var(--texte); }
label.case input { display: inline; margin: 0; }

.formulaire-grille {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
  background: var(--fond-carte); border: 1px solid var(--bord-fort); border-radius: 5px;
  padding: 12px 14px; margin: 10px 0;
}
.formulaire-ligne {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 10px 0;
}
.inline { display: inline; }
.ligne-form { display: contents; }

button {
  background: var(--bleu); color: #fff; border: 1px solid var(--bleu-fort);
  border-radius: 4px; padding: 6px 14px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--bleu-fort); }
.bouton-mini {
  display: inline-block; background: var(--fond-carte); color: var(--bleu);
  border: 1px solid var(--bord-fort); border-radius: 4px;
  padding: 2px 8px; font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.bouton-mini:hover { background: var(--or-clair); }
button.lien {
  background: none; border: 0; color: var(--bleu); padding: 2px 4px;
  cursor: pointer; font-weight: 400; font-size: 12.5px; text-decoration: underline;
}
button.lien:hover { background: none; color: var(--bleu-fort); }
button.lien.danger { color: var(--rouge); }
td.actions { white-space: nowrap; }
td.actions form { display: inline; }

/* Champs de saisie dans les tableaux : sans bordure au repos, pour que la
   grille reste lisible ; la bordure apparaît au survol et à l'édition. */
td.cellule { padding: 0 !important; }
input.cel, input.cel-form {
  width: 100%; min-width: 68px; border: 1px solid transparent; border-radius: 0;
  background: transparent; text-align: right; padding: 4px 6px;
  font-variant-numeric: tabular-nums;
}
input.cel:hover, input.cel-form:hover { border-color: var(--bord-fort); background: var(--fond-carte); }
input.cel:focus, input.cel-form:focus { background: #fff; border-color: var(--bleu); text-align: left; }
input.cel.enregistre { background: var(--vert-clair); }
input.cel.refuse { background: var(--rouge-clair); border-color: var(--rouge); }
/* Sans largeur explicite, un <input> se dimensionne sur vingt caractères, soit
   environ 170 px : une case « étroite » qui ne l'était pas. Le contenu reste
   atteignable — le champ défile quand on écrit dedans. */
input.etroit { min-width: 62px; width: 84px; }
/* Les champs de date d'un tableau dense : le sélecteur du navigateur a une
   largeur minimale incompressible, mais la police et les marges, non. Quatre
   colonnes de dates y gagnent près de 150 px. */
table.grille.serree input[type="date"] {
  font-size: 11.5px; padding: 2px 3px; width: 104px; min-width: 104px;
}
table.grille.serree td.date { width: 1%; white-space: nowrap; padding-left: 3px; padding-right: 3px; }
/* Unité collée à un champ de saisie (« 12 m »). */
.unite { font-size: 11.5px; color: var(--texte-discret); margin-left: 2px; }
input.tres-etroit { min-width: 42px; width: 56px; }
/* Un abonnement mensuel ne dépasse pas quatre chiffres (« 9 999 »), une durée
   trois (« 120 »). Les cases sont dimensionnées pour cela, pas pour le cas
   général d'un montant à six chiffres. */
input.mini { min-width: 52px; width: 52px; }
/* La durée : trois chiffres, et rien de plus.
   La case ne faisait pas la largeur de la colonne — c'étaient ses marges
   intérieures (12 px) et l'espace réservé au « m » qui l'élargissaient. Ici,
   tout est ramené au strict nécessaire : 30 px pour « 120 » en corps 12,
   3 px de marge de part et d'autre, et la cellule elle-même perd ses 6 px de
   padding latéral. La colonne passe d'environ 59 px à 42 px. */
input.micro {
  min-width: 30px; width: 30px; padding: 2px 3px; font-size: 12px; text-align: right;
}
table.grille.serree td.duree, table.grille.serree th.duree { padding: 3px 2px; width: 1%; white-space: nowrap; }
table.grille.serree td.duree .unite { margin-left: 1px; font-size: 10px; }
/* Un champ de TEXTE dans un tableau a besoin d'une largeur utile : 90 px.
   Mais cette règle, plus spécifique que les classes de largeur, s'appliquait
   aussi aux cases étroites et écrasait leur largeur — une durée à trois
   chiffres occupait 90 px, un département aussi. Les classes explicites sont
   donc exclues : quand une largeur est demandée, c'est elle qui vaut. */
table.grille td input:not(.cel):not(.cel-form):not(.micro):not(.mini):not(.etroit):not(.tres-etroit):not([type="checkbox"]):not([type="date"]) {
  min-width: 90px;
}
tr.modifiee td { background: var(--or-clair); }

/* Cellule de texte long : fermée, elle ne montre que les premiers mots ;
   ouverte (au clic), elle déplie une zone de saisie. Le texte entier est dans
   l'infobulle du survol. */
td.texte-long { max-width: 136px; }
td.texte-long summary {
  cursor: pointer; font-size: 11.5px; max-width: 126px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
td.texte-long summary:hover { color: var(--bleu); }
td.texte-long details[open] { position: relative; }
td.texte-long details[open] summary { white-space: normal; overflow: visible; font-weight: 600; }
td.texte-long textarea {
  width: 260px; max-width: 42vw; margin-top: 3px; font-size: 12px;
  background: var(--fond-carte); border: 1px solid var(--bleu); border-radius: 4px; padding: 4px 6px;
}
td.texte-long .texte-deploye { margin: 3px 0 0; font-size: 12px; max-width: 260px; }

/* Boutons à icône. La hauteur de ligne commande la taille : 16 px de dessin,
   une bordure discrète, et la couleur du danger pour la corbeille. */
.bouton-icone {
  background: var(--fond-carte); color: var(--bleu); border: 1px solid var(--bord-fort);
  border-radius: 4px; padding: 2px 5px; line-height: 1; cursor: pointer;
}
.bouton-icone:hover { background: var(--or-clair); border-color: var(--or-vif); }
.bouton-icone.danger { color: var(--rouge); }
.bouton-icone.danger:hover { background: var(--rouge-clair); border-color: var(--rouge); }
svg.icone { width: 15px; height: 15px; display: block; }

.cellule-objectif { white-space: nowrap; }
.cellule-objectif .atteint { display: block; font-size: 11.5px; color: var(--texte-discret); }

/* --- Contrôles --------------------------------------------------------- */
ul.controles { list-style: none; padding: 0; margin: 8px 0; }
ul.controles li {
  background: var(--fond-carte); border: 1px solid var(--bord-fort);
  border-left: 4px solid var(--bord-fort); border-radius: 4px;
  padding: 8px 12px; margin-bottom: 6px;
}
ul.controles li strong { display: block; }
ul.controles li span { display: block; font-size: 13px; color: var(--texte-discret); margin: 2px 0 4px; }
li.niveau-alerte { border-left-color: var(--rouge); }
li.niveau-vigilance { border-left-color: var(--or-vif); }
li.niveau-information { border-left-color: var(--bleu); }
.pastille-nombre {
  display: inline-block; min-width: 22px; text-align: center; border-radius: 11px;
  padding: 0 7px; font-size: 13px; color: #fff; background: var(--texte-discret);
}
.pastille-nombre.alerte { background: var(--rouge); }
.pastille-nombre.vigilance { background: var(--or-vif); color: var(--texte); }
.pastille-nombre.information { background: var(--bleu); }
.pastille-nombre.zero { background: var(--bord-fort); color: var(--texte-discret); }

/* --- Connexion --------------------------------------------------------- */
.carte-connexion {
  max-width: 380px; margin: 8vh auto; background: var(--fond-carte);
  border: 1px solid var(--bord-fort); border-top: 4px solid var(--or-vif);
  border-radius: 6px; padding: 24px 26px;
}
.carte-connexion h1 { margin-top: 0; }
.carte-connexion label { margin: 12px 0; color: var(--texte); }
.carte-connexion input { width: 100%; }
.carte-connexion button { width: 100%; margin-top: 12px; padding: 9px; }

/* --- État d'enregistrement --------------------------------------------- */
.etat-enregistrement {
  position: fixed; right: 14px; bottom: 14px; z-index: 50;
  background: var(--bleu); color: #fff; border-radius: 4px;
  padding: 6px 12px; font-size: 13px; box-shadow: 0 2px 8px rgba(28, 44, 58, .25);
  opacity: 0; transform: translateY(6px); transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.etat-enregistrement.visible { opacity: 1; transform: none; }
.etat-enregistrement.ok { background: var(--vert); }
.etat-enregistrement.ko { background: var(--rouge); }

/* --- Impression -------------------------------------------------------- */
@media print {
  .barre, .onglets, .sous-onglets, .choix-annee, .etat-enregistrement,
  .formulaire-grille, .formulaire-ligne, td.actions, th.actions { display: none !important; }
  body { background: #fff; font-size: 10pt; }
  main { padding: 0; }
  .debordement, .debordement.large { overflow: visible; border: 0; max-height: none; }
  /* Rien ne doit rester caché sur le papier : les textes se déplient, et les
     cases de saisie sont remplacées par leur contenu. */
  td.texte-long { max-width: none; }
  td.texte-long summary { white-space: normal; overflow: visible; max-width: none; }
  td.texte-long textarea { display: none; }
  td.texte-long details > p.texte-deploye { display: block; }
  table.grille { font-size: 8.5pt; }
  table.grille thead th { position: static; }
  a { color: var(--texte); text-decoration: none; }
}

/* --- Petits écrans ----------------------------------------------------- */
@media (max-width: 760px) {
  main { padding: 12px 10px 48px; }
  .cartouche { min-width: 140px; }
  .barre { gap: 10px; padding: 8px 10px; }
  .onglets, .sous-onglets { margin: 0 -10px; padding: 0 10px; }
}
