
/* Settings */
.nav-header,
.nav-header-mobile {
  --nav-fade-color: var(--beton);                          /* Couleur du fondu */
  --nav-fade-rest-height: 120px;                           /* Hauteur du fondu au repos */
  --nav-fade-rest-opacity: 0.8;                              /* Opacité du fondu au repos */
  --nav-fade-height: 420px;                                /* Hauteur du fondu à l'ouverture d'un menu */
  --nav-fade-open-opacity: 0.8;                           /* Opacité du fondu ouvert (Figma : 75 %) */
  --nav-submenu-min-width: 500px;                          /* Largeur minimale des sous-menus */
  --nav-submenu-padding: 16px;                             /* Marge en haut et en bas des sous-menus */
  --nav-submenu-offset: 18px;                              /* Décalage des sous-menus : le padding gauche des liens du menu */
  --nav-arrow-gap: 16px;                                   /* Espace entre le texte et la flèche */
  --nav-underline-width: 1px;                              /* Épaisseur du soulignement */
  --nav-open-duration: 350ms;                              /* Durée de l'ouverture */
  --nav-close-duration: 350ms;                             /* Durée de la fermeture */
  --nav-item-stagger: 45ms;                                /* Décalage entre l'apparition de chaque option */
  --nav-open-easing: cubic-bezier(0.65, 0, 0.35, 1);
  --nav-close-easing: cubic-bezier(0.4, 0, 0.2, 1);
  --nav-hover-duration: 300ms;
  --nav-hover-easing: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Layout */
/* The fade replaces the header background set in Elementor, on the desktop and the mobile header alike */
.nav-header,
.nav-header-mobile {
  background: none !important;
}

/* Header background at rest, stretched further down while a menu is open, for more contrast with the page.
   Closing uses this transition, opening the one of the open state below */
.nav-header::before,
.nav-header-mobile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  z-index: 0;
  height: var(--nav-fade-rest-height);
  /* Stops of the design: opacity 100%, 47%, 28%, 8%, 0% */
  background: linear-gradient(
    to bottom,
    var(--nav-fade-color) 0%,
    color-mix(in srgb, var(--nav-fade-color) 47%, transparent) 38%,
    color-mix(in srgb, var(--nav-fade-color) 28%, transparent) 54%,
    color-mix(in srgb, var(--nav-fade-color) 8%, transparent) 78%,
    transparent 100%
  );
  opacity: var(--nav-fade-rest-opacity);
  transition:
    height var(--nav-close-duration) var(--nav-close-easing),
    opacity var(--nav-close-duration) var(--nav-close-easing);
  pointer-events: none;
}

/* The header content stays above the fade (flex items: z-index works without moving them) */
.nav-header > *,
.nav-header-mobile > * {
  z-index: 1;
}

/* Media queries */
/* Everything applies above the mobile width only (same value as MOBILE_MAX_WIDTH in the script below):
   on mobile and tablet the header and its menu stay as set in Elementor */
@media (width > 1199px) {
  /* Only the categories with a sub-menu open the fade. SmartMenus marks the open category link with .highlighted,
     which also covers keyboard and touch, and keeps the fade during the short delay before a sub-menu closes */
  .nav-header:has(.elementor-nav-menu--main .menu-item-has-children:hover, .elementor-nav-menu--main a.highlighted)::before {
    height: var(--nav-fade-height);
    opacity: var(--nav-fade-open-opacity);
    transition-duration: var(--nav-open-duration);
    transition-timing-function: var(--nav-open-easing);
  }

  /* Components */
  /* Category arrow turning upside down while its menu is open */
  .nav-header .elementor-nav-menu--main .sub-arrow svg {
    transition: transform var(--nav-close-duration) var(--nav-close-easing);
  }

  .nav-header .elementor-nav-menu--main .menu-item-has-children:hover > a .sub-arrow svg,
  .nav-header .elementor-nav-menu--main a.highlighted .sub-arrow svg {
    transform: rotate(180deg);
    transition: transform var(--nav-open-duration) var(--nav-open-easing);
  }

  /* Narrow desktop: tighter links keep the menu on one line down to the switch to the mobile menu at 1199px.
     !important: the padding comes from the settings of the Elementor widget. The sub-menus follow through the variable */
  @media (max-width: 1360px) {
    .nav-header {
      --nav-submenu-offset: 12px;
    }

    .nav-header .elementor-nav-menu--main .elementor-item {
      padding-inline: var(--nav-submenu-offset) !important;
    }

    /* The logo and links group is 77 % wide in Elementor: on a narrow desktop that pushes the button past the page margin */
    .nav-header > .e-con {
      width: auto !important;
    }
  }

  /* Small desktop (a 1920 px screen zoomed to 150 % is 1280 px wide): smaller links keep the menu and the button on one line down to 1200px */
  @media (max-width: 1280px) {
    .nav-header {
      --nav-submenu-offset: 6px;
    }

    .nav-header .elementor-nav-menu--main .elementor-item {
      font-size: 15px !important;
    }
  }

  /* Sub-menu: the min-width overrides the inline value set by SmartMenus */
  .nav-header .elementor-nav-menu--main .sub-menu {
    /* --nav-submenu-fit, set by the script, narrows a list that would leave the screen: its left edge stays on the text */
    min-width: min(var(--nav-submenu-min-width), var(--nav-submenu-fit, var(--nav-submenu-min-width))) !important;
    /* The list starts where the text of its category starts, not where its transparent link does.
       !important: SmartMenus sets margin-left inline when it opens the list */
    margin-left: var(--nav-submenu-offset) !important;
    padding-block: var(--nav-submenu-padding);
    box-sizing: border-box;
    /* Plays every time the list is shown: the box grows from its top-left corner, keeping its proportions */
    animation: nav-submenu-grow var(--nav-open-duration) var(--nav-open-easing) both;
  }

  /* Options appearing one after the other once the box has started growing (index set by the script) */
  .nav-header .elementor-nav-menu--main .sub-menu > li {
    animation: nav-item-in var(--nav-open-duration) var(--nav-hover-easing) both;
    animation-delay: calc(var(--nav-open-duration) * 0.3 + var(--nav-item-index, 0) * var(--nav-item-stagger));
  }

  /* clip-path also clips the pointer: while the list grows, the part not revealed yet lets the cursor fall
     through to the page and SmartMenus closes the menu. This invisible area, added to the category item and
     sized by the script, covers the whole list from the start so the opening goes on. It sits under the list
     (SmartMenus gives the list a higher z-index), so the links stay clickable.
     A dedicated element rather than li::after, which Elementor uses for its menu dividers */
  .nav-header .elementor-nav-menu--main .nav-submenu-hit {
    position: absolute;
    z-index: 0;
    /* Also covers the space under the link left of the list, so the pointer can go straight down from there */
    margin-left: calc(var(--nav-submenu-offset) * -1);
    padding-left: var(--nav-submenu-offset);
  }

  /* Copy of the list playing the closing animation, while SmartMenus has already hidden the real one */
  .nav-header .elementor-nav-menu--main .sub-menu.nav-submenu-ghost {
    display: block !important;
    pointer-events: none;
    animation: nav-submenu-shrink var(--nav-close-duration) var(--nav-close-easing) both;
  }

  .nav-header .elementor-nav-menu--main .sub-menu.nav-submenu-ghost > li {
    animation: nav-item-out calc(var(--nav-close-duration) * 0.5) var(--nav-close-easing) both;
  }

  @keyframes nav-submenu-grow {
    from {
      clip-path: inset(0 100% 100% 0);
    }

    to {
      clip-path: inset(0);
    }
  }

  @keyframes nav-submenu-shrink {
    from {
      clip-path: inset(0);
    }

    to {
      clip-path: inset(0 100% 100% 0);
    }
  }

  @keyframes nav-item-in {
    from {
      opacity: 0;
      transform: translateY(-6px);
    }
  }

  @keyframes nav-item-out {
    to {
      opacity: 0;
    }
  }

  .nav-header .elementor-nav-menu--main .elementor-sub-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--nav-arrow-gap);
  }

  /* Underline drawn from the left, under the text only */
  .nav-header .nav-sub-label {
    padding-bottom: 2px;
    background: linear-gradient(currentColor, currentColor) no-repeat 0 100% / 0 var(--nav-underline-width);
    transition: background-size var(--nav-hover-duration) var(--nav-hover-easing);
  }

  /* Same triangle as the buttons, in the text colour */
  .nav-header .nav-sub-arrow {
    display: block;
    flex: 0 0 auto;
    width: 10px;
    height: 11px;
  }

  /* States */
  .nav-header .elementor-sub-item:is(:hover, :focus-visible) .nav-sub-label {
    background-size: 100% var(--nav-underline-width);
  }
}

/* Arrow added by the script, kept hidden on mobile and tablet */
@media (width <= 1199px) {
  .nav-header .nav-sub-arrow {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-header {
    --nav-open-duration: 0ms;
    --nav-close-duration: 0ms;
    --nav-item-stagger: 0ms;
  }
}
