/* Contexte et pile d'empilement sûrs */
#mainNav { position: relative; z-index: 100; }
#menuItems { position: relative; z-index: 200; overflow: visible !important; }
.ituContainer { overflow: visible !important; }

/* Les LI parents doivent être relatifs */
#menuItems #real-nav-items > li,
#menuItems #displayed-nav-items > li,
#menuItems .displayed-nav-items > li { position: relative; }

/* Sous-menus (ul ou .dropdown-menu) */
#menuItems li > ul,
#menuItems li > .dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  display: none;                              /* contrôlé par .is-open ou :hover */
  background: #fff;
  min-width: 280px;
  max-width: 460px;                           /* défaut (non-mega) */
  margin: 0;
  padding: 0 !important;                      /* padding géré sur les <a> */
  list-style: none;
  z-index: 9999;
  border-radius: 0;

  /* Ombre sur bas + côtés, pas en haut */
  box-shadow:
    0 8px 1.5rem rgba(169, 202, 216, .078),         /* bas */
    -8px 0 1.5rem -6px rgba(169, 202, 216, .078),   /* gauche */
    8px 0 1.5rem -6px rgba(169, 202, 216, .078);    /* droite */
}

/* Items */
#menuItems li > ul > li > a,
#menuItems li > .dropdown-menu > li > a {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 20px 20px !important;                  /* espace vertical + décalage gauche */
  text-decoration: none;
  color: black;

  /* ⬇️ forcer le retour à la ligne et éviter la coupe */
  white-space: normal !important;
  overflow-wrap: anywhere;                     /* casse même les très longues chaînes */
  word-break: break-word;
  hyphens: auto;

  line-height: 1.25;
  border-left: 2px solid transparent;          /* réserve la place pour la barre bleue */
  transition: padding .15s ease, background .15s ease, border-color .15s ease;
}

/* Hover : petit slide + fond bleu clair + barre bleue */
#menuItems li > ul > li > a:hover,
#menuItems li > .dropdown-menu > li > a:hover {
  background: #e5f5fb !important;
  color: black !important;
  padding-left: 30px;                           /* slide agréable */
  border-left: 3px solid #009cd6 !important;
}

/* Ouverture (JS ajoute .is-open) */
#menuItems li.is-open > ul,
#menuItems li.is-open > .dropdown-menu { display: block; }

/* Hover desktop : UNIQUEMENT sur le menu affiché pour éviter les doublons */
@media (hover: hover) and (pointer: fine) {
  #menuItems .displayed-nav-items li:hover > ul,
  #menuItems .displayed-nav-items li:hover > .dropdown-menu {
    display: block;
  }
}

/* "More" (si c’est un <span>) */
#menuItems .more-dropdown > span {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  user-select: none;
}

/* Aligner à droite les derniers sous-menus pour éviter les débordements */
#menuItems .displayed-nav-items > li:nth-last-child(-n+2) > ul,
#menuItems .displayed-nav-items > li:nth-last-child(-n+2) > .dropdown-menu {
  left: auto;
  right: 0;
}

/* Barre bleue du parent (uniquement s'il a un sous-menu) — position relevée */
#menuItems > ul > li > a,
#menuItems > ul > li > span { position: relative; }

#menuItems .displayed-nav-items > li:has(> ul):hover > a::after,
#menuItems .displayed-nav-items > li:has(> .dropdown-menu):hover > a::after,
#menuItems .displayed-nav-items > li:has(> ul).is-open > a::after,
#menuItems .displayed-nav-items > li:has(> .dropdown-menu).is-open > a::after,
#menuItems .displayed-nav-items > li:has(> ul):hover > span::after,
#menuItems .displayed-nav-items > li:has(> .dropdown-menu):hover > span::after,
#menuItems .displayed-nav-items > li:has(> ul).is-open > span::after,
#menuItems .displayed-nav-items > li:has(> .dropdown-menu).is-open > span::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: #009cd6;
  bottom: 5px;                                  /* ajuste la hauteur */
}

/* ===== Mega dropdown via classes (plus fiable) ===== */
#menuItems li > .dropdown-menu.mega-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 440px;                              /* 2 × 200 + gaps */
  max-width: 720px;
  padding: 8px 12px !important;                  /* padding interne */
}

#menuItems li > .dropdown-menu.mega-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 660px;
  max-width: 980px;
  padding: 8px 12px !important;
}

/* Empêche la casse entre colonnes et occupe toute la cellule */
#menuItems li > .dropdown-menu.mega-2 > li,
#menuItems li > .dropdown-menu.mega-3 > li { break-inside: avoid; }
#menuItems li > .dropdown-menu.mega-2 > li > a,
#menuItems li > .dropdown-menu.mega-3 > li > a { width: 100%; box-sizing: border-box; }

/* Mobile / écrans étroits : repasse en 1 colonne */
@media (max-width: 900px) {
  #menuItems li > .dropdown-menu.mega-2,
  #menuItems li > .dropdown-menu.mega-3 {
    display: block !important;                   /* colonne unique */
    min-width: 240px !important;
    max-width: 420px !important;
    padding: 0 !important;
  }
}

/* 2 colonnes */
#menuItems .displayed-nav-items > li.is-open > .dropdown-menu.mega-2,
#menuItems .displayed-nav-items > li:hover  > .dropdown-menu.mega-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 440px;
  max-width: 680px;
  padding: 8px 12px !important;
}

/* 3 colonnes */
#menuItems .displayed-nav-items > li.is-open > .dropdown-menu.mega-3,
#menuItems .displayed-nav-items > li:hover  > .dropdown-menu.mega-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 660px;
  max-width: 980px;
  padding: 8px 12px !important;
}

#menuItems .dropdown-menu > li { position: relative; }

#menuItems .dropdown-menu > li > ul,
#menuItems .dropdown-menu > li > .dropdown-menu {
  position: absolute;
  top: 0;
  left: calc(100% + 8px);
  display: none;
  background: #fff;
  min-width: 240px;
  margin: 0;
  padding: 0 !important;
  list-style: none;
  z-index: 10000;
  box-shadow:
    0 8px 1.5rem rgba(169, 202, 216, .078),
    -8px 0 1.5rem -6px rgba(169, 202, 216, .078),
    8px 0 1.5rem -6px rgba(169, 202, 216, .078);
  max-height: calc(100vh - 24px);
  overflow: auto;
}

/* ouvre au survol (desktop) */
@media (hover: hover) and (pointer: fine) {
  #menuItems .dropdown-menu > li:hover > ul,
  #menuItems .dropdown-menu > li:hover > .dropdown-menu { display: block; }
}

/* flip à gauche si .fly-left est posé par le JS */
#menuItems .dropdown-menu > li.fly-left > ul,
#menuItems .dropdown-menu > li.fly-left > .dropdown-menu {
  left: auto;
  right: calc(100% + 8px);
}

#menuItems .displayed-nav-items > li > .dropdown-menu.mega-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 880px;      /* 4 × 200 + gaps */
  max-width: 1240px;
  padding: 8px 12px !important;
}
#menuItems .displayed-nav-items > li > .dropdown-menu.mega-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(200px, 1fr));
  column-gap: 20px;
  row-gap: 6px;
  min-width: 880px;
  max-width: 1240px;
  padding: 8px 12px !important;
}
