/* ═══════════════════════════════════════════
   Header Saint-Joseph — Mega-menu
   ═══════════════════════════════════════════ */

/* ── Variables header ──────────────────── */
:root {
  --sj-header-topbar-h: 36px;
  --sj-header-main-h: 72px;
  --sj-header-total-h: calc(
    var(--sj-header-topbar-h) + var(--sj-header-main-h)
  );
  --sj-megamenu-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Structure générale ────────────────── */
.sj-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.sj-header.is-hidden {
  transform: translateY(-100%);
}

.sj-header.is-scrolled {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Le spacer évite que le contenu passe sous le header fixed */
.sj-header__spacer {
  height: var(--sj-header-total-h);
}

/* ── Barre supérieure ──────────────────── */
.sj-header__topbar {
  background: var(--wp--preset--color--primary, #9b2f3c);
  height: var(--sj-header-topbar-h);
  display: flex;
  align-items: center;
}

.sj-header__topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.sj-header__topbar-contact {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
}

.sj-header__topbar-contact span,
.sj-header__topbar-contact a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  transition: color 0.15s;
}

.sj-header__topbar-contact a:hover {
  color: var(--wp--preset--color--accent, #e8a020);
}

/* ── Boutons externes ──────────────────── */
.sj-header__topbar-boutons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sj-header__btn-ext {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.85rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--btn-color, #e8a020);
  color: #fff;
  transition:
    opacity 0.15s,
    transform 0.15s;
  white-space: nowrap;
}

.sj-header__btn-ext:hover {
  opacity: 0.88;
  transform: translateY(-1px);
  color: #fff;
}

/* ── Barre principale ──────────────────── */
.sj-header__main {
  height: var(--sj-header-main-h);
  display: flex;
  align-items: center;
  background: #fff;
}

.sj-header__main-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 2rem;
  max-height: 72px;
}

/* ── Logo ──────────────────────────────── */
.sj-header__logo {
  flex-shrink: 0;
  text-decoration: none;
  display: flex;
  align-items: center;
  max-height: 72px;
}

.sj-header__logo img,
.sj-header__logo .custom-logo {
  max-height: 62px !important;
  width: auto;
  display: block;
}

img.custom-logo {
  max-height: 62px !important;
  width: auto;
  display: block;
}

@media (max-width: 1024px) {
  .sj-header__logo img,
  .sj-header__logo .custom-logo {
    max-height: 58px !important;
  }

  img.custom-logo {
    max-height: 58px !important;
  }
}

.sj-header__logo-text {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--wp--preset--color--primary, #9b2f3c);
  font-family: "Playfair Display", serif;
}

/* ── Navigation principale ─────────────── */
.sj-header__nav {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.sj-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}

/* ── Item de navigation ────────────────── */
.sj-nav__item {
  position: static; /* mega-menu est positionné par rapport au header */
}

.sj-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  text-decoration: none;
  border-radius: 6px;
  transition:
    color 0.15s,
    background 0.15s;
  white-space: nowrap;
  position: relative;
}

.sj-nav__link:hover,
.sj-nav__item.is-open > .sj-nav__link {
  color: var(--item-color, var(--wp--preset--color--primary, #9b2f3c));
  background: rgba(0, 0, 0, 0.04);
}

/* Indicateur de couleur en bas au hover */
.sj-nav__link::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0.75rem;
  right: 0.75rem;
  height: 2px;
  background: var(--item-color, #9b2f3c);
  border-radius: 2px;
  transform: scaleX(0);
  transition: transform 0.2s ease;
}

.sj-nav__link:hover::after,
.sj-nav__item.is-open > .sj-nav__link::after {
  transform: scaleX(1);
}

.sj-nav__link-emoji {
  font-size: 1rem;
  line-height: 1;
}

.sj-nav__chevron {
  transition: transform 0.2s ease;
  color: #9ca3af;
  flex-shrink: 0;
}

.sj-nav__item.is-open > .sj-nav__link .sj-nav__chevron {
  transform: rotate(180deg);
}

/* Lien simple (sans mega-menu) */
.sj-nav__link--simple {
  color: #6b7280;
  font-size: 0.85rem;
}

.sj-nav__link--simple::after {
  background: var(--wp--preset--color--primary, #9b2f3c);
}

/* ── Mega-menu ─────────────────────────── */
.sj-megamenu {
  position: fixed;
  top: var(--sj-header-total-h);
  left: 0;
  right: 0;
  background: #fff;
  border-top: 3px solid var(--filiere-color, --wp--preset--color--primary);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  z-index: 999;

  /* État fermé */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition:
    opacity var(--sj-megamenu-transition),
    visibility var(--sj-megamenu-transition),
    transform var(--sj-megamenu-transition);
  pointer-events: none;
}

/* État ouvert */
.sj-nav__item.is-open > .sj-megamenu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.sj-megamenu__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2rem;
  align-items: start;
}

/* En-tête du mega-menu */
.sj-megamenu__header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem;
  background: color-mix(in srgb, var(--filiere-color, #9b2f3c) 8%, white);
  border-radius: 12px;
  border-left: 4px solid var(--filiere-color, #9b2f3c);
}

.sj-megamenu__emoji {
  font-size: 2.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.sj-megamenu__titre {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 0.25rem;
}

.sj-megamenu__desc {
  font-size: 0.82rem;
  color: #6b7280;
}

/* Liens du mega-menu */
.sj-megamenu__liens {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.25rem;
  align-content: start;
}

.sj-megamenu__lien {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #374151;
  text-decoration: none;
  transition:
    background 0.15s,
    color 0.15s;
}

.sj-megamenu__lien svg {
  color: #d1d5db;
  flex-shrink: 0;
  transition:
    color 0.15s,
    transform 0.15s;
}

.sj-megamenu__lien:hover {
  background: color-mix(in srgb, var(--filiere-color, #9b2f3c) 8%, white);
  color: var(--filiere-color, #9b2f3c);
}

.sj-megamenu__lien:hover svg {
  color: var(--filiere-color, #9b2f3c);
  transform: translateX(3px);
}

/* Lien "Voir tout" */
.sj-megamenu__voir-tout {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f0f2f5;
}

.sj-megamenu__lien--voir-tout {
  font-weight: 700;
  color: var(--filiere-color, #9b2f3c);
  font-size: 0.85rem;
}

.sj-megamenu__lien--voir-tout:hover {
  background: color-mix(in srgb, var(--filiere-color, #9b2f3c) 12%, white);
}

/* ── Overlay ───────────────────────────── */
.sj-header__overlay {
  position: fixed;
  inset: var(--sj-header-total-h) 0 0 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.22s ease,
    visibility 0.22s ease;
  backdrop-filter: blur(2px);
}

.sj-header__overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

/* ── Burger mobile ─────────────────────── */
.sj-header__burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
  border-radius: 8px;
  transition: background 0.15s;
}

.sj-header__burger:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sj-burger__bar {
  display: block;
  width: 22px;
  height: 2px;
  background: #374151;
  border-radius: 2px;
  transition:
    transform 0.25s ease,
    opacity 0.25s ease,
    width 0.25s ease;
  transform-origin: center;
}

.sj-header__burger[aria-expanded="true"] .sj-burger__bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.sj-header__burger[aria-expanded="true"] .sj-burger__bar:nth-child(2) {
  opacity: 0;
  width: 0;
}

.sj-header__burger[aria-expanded="true"] .sj-burger__bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Menu mobile ───────────────────────── */
@media (max-width: 1024px) {
  :root {
    --sj-header-main-h: 64px;
  }

  .sj-header__burger {
    display: flex;
  }

  .sj-header__nav {
    position: fixed;
    top: var(--sj-header-total-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 999;
    padding: 1rem 0 2rem;
  }

  .sj-header__nav.is-open {
    transform: translateX(0);
  }

  .sj-nav__list {
    flex-direction: column;
    align-items: stretch;
    padding: 0 1rem;
    gap: 0;
  }

  .sj-nav__item {
    border-bottom: 1px solid #f0f2f5;
  }

  .sj-nav__link {
    padding: 1rem 0.5rem;
    font-size: 1rem;
    justify-content: space-between;
    border-radius: 0;
    width: 100%;
    justify-content: left;
  }

  .sj-nav__link::after {
    display: none;
  }

  /* Mega-menu en accordéon mobile */
  .sj-megamenu {
    position: static;
    border-top: none;
    border-left: 3px solid var(--filiere-color, #9b2f3c);
    box-shadow: none;
    margin: 0 0 0 1rem;
    transform: none;
    max-height: 0;
    overflow: hidden;
    transition:
      max-height 0.3s ease,
      opacity 0.2s ease;

    display: none;
    opacity: 0;
  }

  /* État ouvert quand JS ajoute la classe */
  .sj-nav__item.is-open > .sj-megamenu {
    display: block; /* On l'affiche */
    opacity: 1;
    max-height: 2000px; /* Valeur haute pour laisser passer le contenu */
    transform: none;
  }

  .sj-megamenu__inner {
    grid-template-columns: 1fr;
    padding: 0.75rem 0.75rem 1rem;
    gap: 1rem;
  }

  .sj-megamenu__header {
    padding: 0.75rem;
  }

  .sj-megamenu__emoji {
    font-size: 1.5rem;
  }

  .sj-megamenu__liens {
    grid-template-columns: 1fr;
  }

  /* Cacher la topbar sur très petit écran */
  .sj-header__topbar-contact {
    display: none;
  }

  .sj-megamenu__header {
    display: none;
  }
}

@media (max-width: 480px) {
  .sj-header__topbar {
    display: none;
  }
  :root {
    --sj-header-topbar-h: 0px;
  }
}

/* Uniquement pour les ordinateurs avec une souris */
@media (hover: hover) {
  .sj-nav__item:hover .sj-megamenu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
  }
}
