/* ---------------------------------------------------------------------------
   Les graphiques (public/js/graphes.js) — 28/09/2026

   « Je veux voir des graphiques, je veux que ce soit joli à voir et bien
   animé, un peu comme sur Notion ou d'autres applications modernes. »

   Aucune teinte nouvelle : tout vient des variables de css/app.css, ou de
   leurs formes translucides déjà employées ailleurs. Les tailles suivent
   l'échelle typographique de css/ui-2026.css. Les animations sont courtes,
   n'ont lieu qu'à l'entrée, et s'effacent sous prefers-reduced-motion.
--------------------------------------------------------------------------- */

.gr { --gr-couleur: var(--navy); --gr-hauteur: 160px; position: relative; }
.gr.coral { --gr-couleur: var(--coral); }
.gr-vide {
  font-size: var(--txt-sm);
  color: var(--text-soft);
  font-style: italic;
  padding: 12px 0;
}

/* --- La figure et son tableau jumeau -------------------------------------- */
.gr-figure { margin: 0; }
.gr-bascule {
  margin-top: 10px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-soft);
  font-family: inherit;
  font-size: var(--txt-xs);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: color .15s ease;
}
.gr-bascule:hover { color: var(--text); }
.gr-tableau { width: 100%; border-collapse: collapse; font-size: var(--txt-sm); }
.gr-tableau th, .gr-tableau td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.gr-tableau th { font-size: var(--txt-xs); color: var(--text-soft); font-weight: 600; }
.gr-td-chiffre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Les repères : des filets pleins, d'une teinte à peine posée ---------- */
.gr-grille {
  position: absolute;
  left: 0; right: 0;
  top: 22px;
  height: var(--gr-hauteur);
  pointer-events: none;
}
.gr-tick {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: var(--border);
}
.gr-tick span {
  position: absolute;
  left: 0;
  bottom: 2px;
  font-size: var(--txt-xs);
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* --- Les colonnes ---------------------------------------------------------- */
.gr-colonnes { padding-top: 22px; }
.gr-cols {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-left: 44px;
}
.gr-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  outline: none;
}
.gr-col[data-action] { cursor: pointer; }
.gr-col-piste {
  width: 100%;
  height: var(--gr-hauteur);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.gr-col-barre {
  width: 100%;
  max-width: 24px;
  min-height: 2px;
  background: var(--gr-couleur);
  border-radius: 4px 4px 0 0;
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform .55s cubic-bezier(.22, .61, .36, 1), filter .15s ease;
  transition-delay: calc(var(--i, 0) * 35ms), 0s;
}
.gr.pret .gr-col-barre { transform: scaleY(1); }
.gr-col:hover .gr-col-barre, .gr-col:focus-visible .gr-col-barre { filter: brightness(1.12); }
.gr-col.estompe .gr-col-barre { opacity: .32; }
.gr-col-val,
.gr-col-nom {
  font-size: var(--txt-xs);
  color: var(--text-soft);
  line-height: 1.3;
  white-space: nowrap;
}
.gr-col-nom { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
/* L'étiquette se mesure sur toute la largeur nécessaire : une colonne étroite
   ne la coupe pas, elle déborde sur ses voisines vides. */
.gr-col-val {
  position: relative;
  z-index: 1;
  font-weight: 650;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity .2s ease;
}
.gr-col-val.visible, .gr-col:hover .gr-col-val, .gr-col:focus-visible .gr-col-val { opacity: 1; }
.gr-col.courant .gr-col-nom { color: var(--coral); font-weight: 700; }
/* Une colonne d'un mois hors période reste lisible, son nom aussi. */
.gr-col.estompe .gr-col-nom { opacity: .55; }

/* --- La courbe ------------------------------------------------------------- */
.gr-courbe { padding-top: 22px; }
.gr-trace {
  position: relative;
  height: var(--gr-hauteur);
  margin-left: 44px;
}
.gr-trace svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.gr-ligne {
  fill: none;
  stroke: var(--gr-couleur);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.1s cubic-bezier(.22, .61, .36, 1);
}
.gr.pret .gr-ligne { stroke-dashoffset: 0; }
.gr-aire {
  fill: var(--gr-couleur);
  opacity: 0;
  transition: opacity .8s ease .5s;
}
.gr.pret .gr-aire { opacity: .1; }
.gr-point {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: 0 0 -12px -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  outline: none;
  opacity: 0;
  transition: opacity .3s ease;
  transition-delay: calc(.5s + var(--i, 0) * 40ms);
}
.gr.pret .gr-point { opacity: 1; }
.gr-point::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gr-couleur);
  box-shadow: 0 0 0 2px var(--card);
  transition: transform .15s ease;
}
.gr-point:hover::before, .gr-point:focus-visible::before, .gr-point.courant::before { transform: scale(1.35); }
.gr-point-val {
  position: absolute;
  bottom: 16px;
  font-size: var(--txt-xs);
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity .2s ease;
}
.gr-point-val.visible, .gr-point:hover .gr-point-val, .gr-point:focus-visible .gr-point-val { opacity: 1; }
.gr-curseur {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--text-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.gr-curseur.visible { opacity: .5; }
.gr-axe-x {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0 44px;
  font-size: var(--txt-xs);
  color: var(--text-soft);
}
.gr-axe-x span { flex: 1 1 0; text-align: center; white-space: nowrap; }
.gr-axe-x span:first-child { text-align: left; }
.gr-axe-x span:last-child { text-align: right; }
.gr-axe-x span.courant { color: var(--coral); font-weight: 700; }
.gr-axe-x span.cache { visibility: hidden; }

/* --- Les barres horizontales ---------------------------------------------- */
.gr-barres { display: flex; flex-direction: column; gap: 11px; }
.gr-barre { border-radius: 6px; outline: none; }
.gr-barre[data-action] { cursor: pointer; }
.gr-barre-entete {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: var(--txt-sm);
}
.gr-barre-etiquette {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gr-barre-chiffre {
  flex-shrink: 0;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.gr-barre-detail { margin-left: 6px; }
.gr-barre-detail::before { content: '· '; }
.gr-barre-piste {
  display: block;
  height: 10px;
  background: rgba(11, 65, 122, .08);
  border-radius: 5px;
  overflow: hidden;
}
.gr-barre-remplissage {
  display: block;
  height: 100%;
  background: var(--gr-couleur);
  border-radius: 5px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .6s cubic-bezier(.22, .61, .36, 1);
  transition-delay: calc(var(--i, 0) * 45ms);
}
.gr.pret .gr-barre-remplissage { transform: scaleX(1); }
.gr-barre.accent { --gr-couleur: var(--coral); }
.gr-barre:hover .gr-barre-remplissage, .gr-barre:focus-visible .gr-barre-remplissage { filter: brightness(1.12); }

/* --- La barre empilée ------------------------------------------------------ */
.gr-empilee-barre {
  display: flex;
  height: 22px;
  gap: 2px;                       /* le blanc sépare, jamais un trait */
  border-radius: 6px;
  overflow: hidden;
}
.gr-segment {
  flex: 0 0 auto;
  min-width: 3px;
  background: var(--gr-couleur);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFF;
  font-size: var(--txt-xs);
  font-weight: 700;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .5s cubic-bezier(.22, .61, .36, 1), filter .15s ease;
  transition-delay: calc(var(--i, 0) * 90ms), 0s;
  outline: none;
}
.gr.pret .gr-segment { transform: scaleX(1); }
.gr-segment:hover, .gr-segment:focus-visible { filter: brightness(1.12); }
.gr-segment span { opacity: 0; transition: opacity .3s ease .5s; }
.gr.pret .gr-segment span { opacity: 1; }
.gr-legende {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 12px;
  font-size: var(--txt-sm);
}
.gr-legende-item { display: inline-flex; align-items: center; gap: 7px; }
.gr-legende-item.vide { opacity: .5; }
.gr-pastille {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--gr-couleur);
  flex-shrink: 0;
}
.gr-legende-nom { color: var(--text); }
.gr-legende-valeur { color: var(--text-soft); font-variant-numeric: tabular-nums; }

/* --- Le camembert ---------------------------------------------------------- */
.gr-camembert {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.gr-camembert-anneau { position: relative; width: 156px; height: 156px; flex-shrink: 0; }
.gr-camembert-anneau svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.gr-arc {
  fill: none;
  stroke: var(--gr-couleur);
  stroke-width: 17;
  stroke-dasharray: 0 999;
  stroke-dashoffset: var(--decalage);
  transition: stroke-dasharray .8s cubic-bezier(.22, .61, .36, 1), stroke-width .15s ease;
  transition-delay: calc(var(--i, 0) * 60ms), 0s;
  outline: none;
  cursor: default;
}
.gr.pret .gr-arc { stroke-dasharray: var(--longueur) var(--reste); }
.gr-arc:hover, .gr-arc:focus-visible { stroke-width: 20; }
.gr-arc-etiquette {
  fill: #FFF;
  transform: rotate(90deg);
  transform-box: fill-box;
  transform-origin: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
  transition-delay: calc(.6s + var(--i, 0) * 60ms);
}
.gr.pret .gr-arc-etiquette { opacity: 1; }
.gr-camembert-centre {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.gr-camembert-total { font-size: 24px; font-weight: 700; font-family: 'Poppins', sans-serif; line-height: 1.1; color: var(--text); }
.gr-camembert-libelle { font-size: var(--txt-xs); color: var(--text-soft); }
.gr-legende-colonne { flex-direction: column; gap: 5px; margin-top: 0; min-width: 0; flex: 1 1 160px; }
.gr-legende-colonne .gr-legende-item { justify-content: space-between; }
.gr-legende-colonne .gr-legende-nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- La jauge -------------------------------------------------------------- */
.gr-jauge { --gr-couleur: var(--coral); }
.gr-jauge.atteint { --gr-couleur: #2E9E5B; }
.gr-jauge-entete {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.gr-jauge-valeur { font-size: var(--txt-md); font-weight: 700; }
.gr-jauge-pct { font-size: var(--txt-sm); color: var(--text-soft); font-variant-numeric: tabular-nums; }
.gr-jauge-piste {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: rgba(245, 96, 88, .14);
  overflow: hidden;
}
.gr-jauge.atteint .gr-jauge-piste { background: rgba(11, 65, 122, .08); }
.gr-jauge-remplissage {
  height: 100%;
  border-radius: 7px;
  background: var(--gr-couleur);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .7s cubic-bezier(.22, .61, .36, 1);
}
.gr.pret .gr-jauge-remplissage { transform: scaleX(1); }
.gr-jauge-repere {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  opacity: .55;
}
.gr-jauge-sous { margin-top: 8px; font-size: var(--txt-sm); color: var(--text-soft); }

/* --- Les tuiles de chiffres ----------------------------------------------- */
.tuile-stat { display: flex; flex-direction: column; min-width: 0; }
.tuile-stat .label { margin-bottom: 6px; }
.tuile-ligne {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}
.tuile-stat .value { white-space: nowrap; font-variant-numeric: normal; }
.gr-etincelle {
  width: 84px;
  height: 32px;
  flex: 0 1 84px;       /* cède la place au chiffre plutôt que de déborder */
  min-width: 36px;
  --gr-couleur: var(--navy);
  overflow: visible;
}
.gr-etincelle.coral { --gr-couleur: var(--coral); }
.gr-etincelle.magenta { --gr-couleur: var(--magenta); }
.gr-etincelle-trace {
  fill: none;
  stroke: var(--gr-couleur);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset .9s cubic-bezier(.22, .61, .36, 1) .1s;
}
.gr-etincelle.pret .gr-etincelle-trace { stroke-dashoffset: 0; }
.gr-etincelle-aire { fill: var(--gr-couleur); opacity: 0; transition: opacity .6s ease .6s; }
.gr-etincelle.pret .gr-etincelle-aire { opacity: .12; }
.gr-etincelle-point { fill: var(--gr-couleur); opacity: 0; transition: opacity .3s ease .9s; }
.gr-etincelle.pret .gr-etincelle-point { opacity: 1; }
.tuile-delta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 8px;
  font-size: var(--txt-xs);
  color: var(--text-soft);
  line-height: 1.3;
}
.tuile-delta-valeur {
  white-space: nowrap;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.tuile-delta.bon .tuile-delta-valeur { color: #2E9E5B; background: rgba(46, 158, 91, .12); }
.tuile-delta.mauvais .tuile-delta-valeur { color: var(--magenta); background: rgba(240, 64, 93, .12); }
.tuile-delta.neutre .tuile-delta-valeur { color: var(--text-soft); background: rgba(11, 65, 122, .1); }

/* --- L'infobulle ----------------------------------------------------------- */
#graphes-infobulle {
  position: fixed;
  z-index: 9000;
  max-width: 280px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--card);
  font-size: var(--txt-xs);
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .12s ease, transform .12s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
#graphes-infobulle.visible { opacity: 1; transform: none; }

/* --- L'entrée des encadrés : ils se posent l'un après l'autre ------------- */
@keyframes gr-entre {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.stats-vivantes .stats-bloc,
.stats-vivantes .tuile-stat {
  animation: gr-entre .45s cubic-bezier(.22, .61, .36, 1) both;
}
.stats-vivantes .tuile-stat:nth-child(1) { animation-delay: 0ms; }
.stats-vivantes .tuile-stat:nth-child(2) { animation-delay: 40ms; }
.stats-vivantes .tuile-stat:nth-child(3) { animation-delay: 80ms; }
.stats-vivantes .tuile-stat:nth-child(4) { animation-delay: 120ms; }
.stats-vivantes .tuile-stat:nth-child(5) { animation-delay: 160ms; }
.stats-vivantes .tuile-stat:nth-child(6) { animation-delay: 200ms; }
.stats-vivantes .tuile-stat:nth-child(7) { animation-delay: 240ms; }
.stats-vivantes .tuile-stat:nth-child(8) { animation-delay: 280ms; }
.stats-vivantes .tuile-stat:nth-child(9) { animation-delay: 320ms; }
.stats-vivantes .tuile-stat:nth-child(10) { animation-delay: 360ms; }
.stats-vivantes .stats-bloc:nth-of-type(1) { animation-delay: 120ms; }
.stats-vivantes .stats-bloc:nth-of-type(2) { animation-delay: 200ms; }
.stats-vivantes .stats-bloc:nth-of-type(3) { animation-delay: 280ms; }
.stats-vivantes .stats-bloc:nth-of-type(4) { animation-delay: 360ms; }
.stats-vivantes .stats-bloc:nth-of-type(5) { animation-delay: 440ms; }
.stats-vivantes .stats-bloc:nth-of-type(6) { animation-delay: 520ms; }
.stats-vivantes .stats-bloc:nth-of-type(7) { animation-delay: 600ms; }

/* Le rendu se rafraîchit à chaque changement de filtre : l'ancien contenu
   reste en place, un peu estompé, le temps que le nouveau arrive. */
.stats-vivantes.rafraichit .stats-bloc { opacity: .55; transition: opacity .15s ease; }

/* --- Les encadrés de l'écran Statistiques ---------------------------------- */
.stats-tuiles {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stats-bloc .sub { color: var(--text-soft); font-size: var(--txt-sm); margin-bottom: 14px; }
.stats-bloc h3 .stats-compte {
  font-size: var(--txt-xs);
  font-weight: 600;
  color: var(--text-soft);
  background: rgba(11, 65, 122, .1);
  border-radius: 20px;
  padding: 2px 8px;
}
.stats-bloc .list-row .score { white-space: nowrap; }
.stats-comparatif-graphe { margin-bottom: 18px; }
.stats-meilleurs .list-row { cursor: pointer; }
.stats-meilleurs .rang {
  width: 26px;
  font-size: var(--txt-sm);
  font-weight: 700;
  color: var(--text-soft);
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1200px) {
  .stats-tuiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .stats-tuiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gr-etincelle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gr-col-barre, .gr-barre-remplissage, .gr-segment, .gr-jauge-remplissage { transform: none; transition: none; }
  .gr-ligne, .gr-etincelle-trace { stroke-dashoffset: 0; transition: none; }
  .gr-aire { opacity: .1; transition: none; }
  .gr-etincelle-aire { opacity: .12; transition: none; }
  .gr-point, .gr-etincelle-point, .gr-segment span { opacity: 1; transition: none; }
  .stats-vivantes .stats-bloc, .stats-vivantes .tuile-stat { animation: none; }
}

/* Le sous-titre d'un graphique quand un encadré en porte deux. */
.stats-sous-titre {
  font-size: var(--txt-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-soft);
  margin-bottom: 4px;
}
