/**
 * Hémicycle interactif — shortcode [hemicycle].
 * Version 1.0.0
 *
 * Styles repris du dossier Législatives 2026, rendus autonomes : le préfixe
 * passe de .el-hemicycle à .lb-hemi et les variables --el-* sont redéclarées
 * sur .lb-hemi. Le module peut donc vivre dans n'importe quel article, sans
 * dépendre du conteneur .dossier-elections ni de css-elections2026.css.
 *
 * ATTENTION : les assets sont mis en cache un an (.htaccess). Toute
 * modification exige un bump de LEBRIEF_HEMI_VERSION dans
 * inc/hemicycle/hemicycle.php, sinon les lecteurs gardent l'ancienne version.
 */

.lb-hemi {
  /* Redéclarées ici : le module ne suppose aucune variable héritée de la page. */
  --lbh-black: #030303;
  --lbh-white: #FFFFFF;
  --lbh-yellow: #FFCB22;
  --lbh-text-secondary: #717578;
  --lbh-gray-light: #F4F3F1;
  --lbh-gray-border: #DEDCD7;
  --lbh-radius-sm: 3px;
  /* Sièges pas encore attribués : gris neutre, lisible sans attirer l'œil. */
  --lbh-vacant: #D6D7DB;

  margin: 0 0 24px;
  color: var(--lbh-black);
}

/* Épouse exactement le SVG : sert de repère pour positionner l'infobulle.
   Sans lui, les pourcentages porteraient sur le conteneur entier (légende et
   phrase d'aide comprises) et le repère serait faux, surtout sur mobile. */
.lb-hemi__zone {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.lb-hemi__svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.lb-hemi__group { cursor: pointer; }

.lb-hemi__group circle {
  transition: opacity .18s ease;
  /* Par défaut, le clic est capté sur le groupe entier, pas point par point :
     395 cibles individuelles alourdiraient le survol pour rien. */
  pointer-events: none;
}

/* Un groupe porteur de noms de députés : chaque point redevient une cible,
   pour que l'infobulle puisse afficher l'élu survolé. */
.lb-hemi__group.has-noms circle.has-nom {
  pointer-events: auto;
}

/* Un parti isolé : les autres groupes s'estompent — y compris les sièges
   non attribués, qui sinon domineraient visuellement la sélection. */
.lb-hemi.is-filtered .lb-hemi__group circle,
.lb-hemi.is-filtered .lb-hemi__group--vacant circle { opacity: .12; }
.lb-hemi.is-filtered .lb-hemi__group.is-active circle { opacity: 1; }

/* Sièges pas encore attribués : gris, et sans curseur « cliquable » puisqu'il
   n'y a pas de parti à isoler derrière. */
.lb-hemi__group--vacant { fill: var(--lbh-vacant); cursor: default; }

/* Le point survolé, quand il porte un nom. */
.lb-hemi__group circle.is-hovered {
  stroke: var(--lbh-black);
  stroke-width: 2.5;
  paint-order: stroke;
}

/* Compteur au creux de l'arc — texte SVG, donc à l'échelle du viewBox : il
   reste centré dans le demi-disque vide quelle que soit la largeur d'écran.
   Masqué (classe posée par le JS) quand l'infobulle occupe le même espace. */
.lb-hemi__total {
  pointer-events: none;
  transition: opacity .15s ease;
}
.lb-hemi.has-tip .lb-hemi__total { opacity: 0; }

.lb-hemi__total-num {
  font-weight: 700;
  font-size: 86px;
  fill: var(--lbh-black);
}
.lb-hemi__total-label {
  font-weight: 600;
  font-size: 26px;
  letter-spacing: .12em;
  fill: var(--lbh-text-secondary);
}

/* Infobulle : parti + sièges, ou nom du député sur un point nommé.
   Positionnée dans .lb-hemi__zone, qui épouse exactement le SVG (ratio
   1000/518) : 77 % de sa hauteur correspond au centre du creux de l'arc, donc
   au même endroit que le compteur qu'elle remplace. */
.lb-hemi__tip {
  position: absolute;
  left: 50%;
  top: 77%;
  transform: translate(-50%, -50%);
  background: var(--lbh-black);
  color: var(--lbh-white);
  padding: 10px 18px;
  border-radius: var(--lbh-radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
  text-align: center;
  /* Une sélection multiple peut aligner plusieurs noms : on autorise le retour
     à la ligne et on borne la largeur pour rester dans le creux de l'arc. */
  max-width: 72%;
  z-index: 2;
}
.lb-hemi__tip[hidden] { display: none; }

.lb-hemi__tip-nom {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
}
.lb-hemi__tip-val {
  font-weight: 600;
  font-size: 12px;
  color: var(--lbh-yellow);
}

.lb-hemi__hint {
  font-size: 12px;
  color: var(--lbh-text-secondary);
  margin: 12px 0 0;
  text-align: center;
}

.lb-hemi__note {
  font-size: 12px;
  color: var(--lbh-text-secondary);
  margin: 12px 0 0;
  /* Centrée comme la phrase d'aide juste au-dessus : le module est un bloc
     centré, une note alignée à gauche rompait cet axe. */
  text-align: center;
}

/* ---------- Légende cliquable ---------- */
.lb-hemi-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
}
.lb-hemi-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
/* Certains thèmes posent une puce sur les li d'articles : on la neutralise. */
.lb-hemi-legend li::before,
.lb-hemi-legend li::marker { content: none; }

.lb-hemi-legend__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lb-hemi-legend__btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--lbh-gray-light);
  border: 1.5px solid transparent;
  padding: 5px 10px;
  border-radius: 999px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: inherit;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, opacity .15s ease;
}
.lb-hemi-legend__btn:hover { border-color: var(--lbh-black); }
.lb-hemi-legend__btn.is-active {
  background: var(--lbh-black);
  color: var(--lbh-white);
  border-color: var(--lbh-black);
}
/* Quand des partis sont isolés, les autres boutons s'atténuent. */
.lb-hemi-legend.is-filtered .lb-hemi-legend__btn:not(.is-active) { opacity: .45; }

/* « Tous les partis » : légèrement distinct, sans pastille de couleur. */
.lb-hemi-legend__btn--all {
  border-color: var(--lbh-gray-border);
  font-weight: 700;
}

/* « Non attribués » : informatif, pas un filtre — d'où l'absence de survol. */
.lb-hemi-legend__btn--vacant {
  cursor: default;
  color: var(--lbh-text-secondary);
}
.lb-hemi-legend__btn--vacant:hover { border-color: transparent; }
.lb-hemi-legend__btn--vacant .lb-hemi-legend__dot { background: var(--lbh-vacant); }

/* Mention « Résultats provisoires » : une pastille centrée au-dessus du
   graphique, assez visible pour qu'aucun lecteur ne prenne ces chiffres pour
   définitifs, sans pour autant concurrencer le compteur central. */
.lb-hemi__statut {
  display: block;
  width: fit-content;
  margin: 0 auto 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--lbh-yellow);
  color: var(--lbh-black);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: center;
}

/* Décompte des sièges attribués, au-dessus du graphique. */
.lb-hemi__progres {
  font-size: 13px;
  color: var(--lbh-text-secondary);
  margin: 0 0 10px;
  text-align: center;
}

/* Message d'aide à la rédaction (visible des seuls administrateurs). */
.lb-hemi-vide {
  border-left: 3px solid var(--lbh-yellow, #FFCB22);
  background: #F4F3F1;
  padding: 10px 14px;
  font-size: 13px;
}

@media (max-width: 600px) {
  .lb-hemi__total-num { font-size: 104px; }
  .lb-hemi__total-label { font-size: 30px; }
  .lb-hemi__tip { padding: 8px 14px; max-width: 80%; }
  .lb-hemi__tip-nom { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .lb-hemi__group circle,
  .lb-hemi__total,
  .lb-hemi-legend__btn { transition: none; }
}
