/* =====================================================
   Barre de navigation des habitants
   Une seule ligne parfaitement alignée : logo | navigation | actions.
   Si la place manque, nav.js active le mode compact (.compacte).
   ===================================================== */

.entete-habitants { position: sticky; top: 0; z-index: 50; }
.entete-habitants .barre {
  display: flex; align-items: center; flex-wrap: nowrap;
  gap: 24px; min-height: 72px; padding-top: 0; padding-bottom: 0;
}

/* Logo */
.barre-logo { flex: none; white-space: nowrap; font-size: 1.2rem; }

/* Zone navigation + actions */
.barre-menu { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex: 1 1 auto; min-width: 0; }
.barre-liste { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; list-style: none; margin: 0; padding: 0; }
.barre-liste > li { display: flex; }

/* Liens et boutons de premier niveau : même hauteur, même alignement */
.barre-lien {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 44px; padding: 0 14px; border: none; border-radius: var(--rayon); background: none;
  color: var(--texte-doux); font: inherit; font-weight: 500; line-height: 1;
  text-decoration: none; white-space: nowrap; cursor: pointer;
}
.barre-lien:hover { color: var(--texte); background: var(--carte); }
.barre-lien[aria-current="page"], .barre-lien.actif { color: var(--texte); }
.barre-lien[aria-current="page"]::after, .barre-lien.actif::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 4px; height: 3px;
  border-radius: 3px; background: var(--degrade);
}
.barre-deroulant[aria-expanded="true"] { color: var(--texte); background: var(--carte); }
.chevron { flex: none; transition: transform .2s; }
.barre-deroulant[aria-expanded="true"] .chevron { transform: rotate(180deg); }

/* Sous-menus */
.barre-groupe { position: relative; }
.sous-menu {
  position: absolute; top: calc(100% + 10px); left: 0; z-index: 70;
  min-width: 290px; margin: 0; padding: 8px; list-style: none;
  display: grid; gap: 2px;
  background: var(--carte); border: 1px solid var(--contour); border-radius: var(--rayon-carte);
  box-shadow: var(--ombre);
}
.sous-menu[hidden] { display: none; }
.sous-menu-droite { left: auto; right: 0; min-width: 260px; }
.sous-menu a { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; color: var(--texte); text-decoration: none; }
.sous-menu a:hover, .sous-menu a:focus-visible { background: var(--carte-survol); color: var(--texte); }
.sous-menu a[aria-current="page"] { background: var(--violet-fond); }
.sous-menu-titre { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.sous-menu-aide { font-size: .85rem; color: var(--texte-doux); }
.sous-menu-separateur { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--contour); }
.sous-menu-separateur form { margin: 0; }
.sous-menu-bouton {
  width: 100%; padding: 10px 12px; border: none; border-radius: 10px; background: none;
  color: var(--erreur); font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.sous-menu-bouton:hover, .sous-menu-bouton:focus-visible { background: var(--erreur-fond); }

/* Actions à droite : toutes à 44 px de haut */
.barre-actions { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: nowrap; }
.barre-actions > .btn, .barre-actions summary.btn, .barre-compte > .btn { height: 44px; min-height: 44px; padding-top: 0; padding-bottom: 0; white-space: nowrap; }
.barre-actions .btn-icone { width: 44px; padding: 0; }
.barre-compte > .btn { gap: 8px; padding-left: 6px; padding-right: 12px; }
.barre-compte .avatar { width: 30px; height: 30px; font-size: .85rem; }
.barre-compte .barre-deroulant[aria-expanded="true"] { background: var(--carte-survol); }
.barre-compte .barre-deroulant.actif { border-color: var(--violet); }

/* Éléments réservés au mode compact */
.entete-habitants .menu-bouton, .entete-habitants .urgence-compacte { display: none; }
.menu-bouton .icone-fermer { display: none; }

/* =====================================================
   Mode compact : petit écran ou texte agrandi
   ===================================================== */
.entete-habitants.compacte .barre { flex-wrap: wrap; gap: 8px 10px; min-height: 64px; padding-top: 10px; padding-bottom: 10px; }
.entete-habitants.compacte .barre-logo { margin-right: auto; }
.entete-habitants.compacte .menu-bouton,
.entete-habitants.compacte .urgence-compacte { display: inline-flex; width: 44px; height: 44px; padding: 0; justify-content: center; }
.entete-habitants.compacte.ouvert .menu-bouton .icone-ouvrir { display: none; }
.entete-habitants.compacte.ouvert .menu-bouton .icone-fermer { display: block; }

.entete-habitants.compacte .barre-menu {
  display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 14px;
  padding: 10px 0 16px; border-top: 1px solid var(--contour);
  max-height: calc(100vh - 80px); overflow-y: auto;
}
.entete-habitants.compacte.ouvert .barre-menu { display: flex; }
.entete-habitants.compacte .barre-liste { flex-direction: column; align-items: stretch; gap: 2px; }
.entete-habitants.compacte .barre-liste > li { flex-direction: column; }
.entete-habitants.compacte .barre-lien { width: 100%; height: 48px; justify-content: space-between; font-size: 1.05rem; }
.entete-habitants.compacte .barre-lien[aria-current="page"]::after,
.entete-habitants.compacte .barre-lien.actif::after { left: 0; right: auto; top: 10px; bottom: 10px; width: 3px; height: auto; }
.entete-habitants.compacte .sous-menu {
  position: static; min-width: 0; box-shadow: none; margin: 4px 0 8px 14px;
  border: none; border-left: 2px solid var(--contour); border-radius: 0; padding: 0 0 0 8px; background: none;
}
.entete-habitants.compacte .barre-actions { flex-wrap: wrap; gap: 8px; }
.entete-habitants.compacte .barre-compte { width: 100%; }
.entete-habitants.compacte .barre-compte > .btn { width: 100%; justify-content: flex-start; }
.entete-habitants.compacte .barre-compte .chevron { margin-left: auto; }
.entete-habitants.compacte .panneau-a11y-contenu { position: static; width: 100%; margin-top: 8px; }

/* Contraste élevé : repères bien visibles */
html[data-contraste] .barre-lien[aria-current="page"]::after, html[data-contraste] .barre-lien.actif::after { background: currentColor; }
html[data-contraste] .sous-menu { border-width: 2px; }
html[data-liens] .barre-lien, html[data-liens] .sous-menu a .sous-menu-titre { text-decoration: underline; }

/* Correctif : les sous-menus passent au-dessus du bandeau d'alerte
   (aucun parent de la barre ne doit couper ce qui dépasse) */
.entete-habitants,
.entete-habitants .barre,
.entete-habitants .barre-menu,
.entete-habitants .barre-nav,
.entete-habitants .barre-liste,
.entete-habitants .barre-groupe,
.entete-habitants .barre-actions { overflow: visible !important; contain: none !important; clip-path: none !important; }
.entete-habitants { position: sticky; top: 0; z-index: 100 !important; isolation: isolate; }
.entete-habitants .sous-menu, .entete-habitants .panneau-a11y-contenu { z-index: 110; }
.bandeaux-alertes { position: relative; z-index: 1; }
/* En mode compact, seul le panneau déroulé défile */
.entete-habitants.compacte .barre-menu { overflow-y: auto !important; }

/* Correctif : menu compact sur petit écran
   Le menu déplié devient un panneau plein écran, opaque, placé juste sous la barre.
   Il ne dépend plus de la hauteur ni du style (arrondi, transparent) de l'en-tête. */
.entete-habitants.compacte .barre-menu { display: none !important; }
.entete-habitants.compacte.ouvert,
.entete-habitants.compacte.ouvert .barre {
  /* Un parent avec flou, filtre ou transformation « enferme » les éléments fixes : on les retire pendant que le menu est ouvert */
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  filter: none !important;
  transform: none !important;
  contain: none !important;
  will-change: auto !important;
}
.entete-habitants.compacte.ouvert .barre-menu {
  display: flex !important;
  position: fixed !important;
  top: var(--hauteur-entete, 72px) !important;
  left: 0 !important; right: 0 !important; bottom: 0 !important;
  width: auto !important; max-height: none !important; height: auto !important;
  margin: 0 !important; padding: 16px 20px 40px !important;
  flex-direction: column; align-items: stretch; justify-content: flex-start !important; gap: 16px;
  background: var(--fond) !important; opacity: 1 !important;
  border-top: 1px solid var(--contour); border-radius: 0 !important;
  overflow-y: auto !important; overscroll-behavior: contain;
  z-index: 1000 !important;
}
.entete-habitants.compacte.ouvert .sous-menu { background: transparent !important; }
.entete-habitants.compacte.ouvert .panneau-a11y-contenu { background: var(--carte) !important; }
/* La page derrière ne défile plus pendant que le menu est ouvert */
html.menu-ouvert, html.menu-ouvert body { overflow: hidden; }
