.header {
    /* Desktop : styles de base */
    position: relative;
    z-index: 1;
    /* --app-height est figé en JS à la hauteur du chargement (cf. viewport.js)
       pour que la barre d'adresse iOS qui se masque au scroll ne l'agrandisse pas. */
    height: calc(var(--app-height, 100vh) - var(--wpadminbar-height));
    min-height: 530px;
    width: 100%;

    display: flex;
    flex-direction: column;

    background: var(--color-bg);
}

.header .header__bg {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(var(--header-overlay), var(--header-overlay)), var(--header-bg);
    background-size: cover;
    background-position: center;
    z-index: -2;

    mask-image: url(/wp-content/themes/domainegregoire/assets/img/header-mask.png);
    mask-size: cover;
    mask-position: bottom;
    mask-repeat: no-repeat;
}

.header .header__burger {
    display: none;
}

.header .header__bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 87px;
}

.header .header__bar .header__burger {
    position: fixed;
    top: calc(0px + var(--wpadminbar-height));
    left: 0px;

    flex-direction: column;
    justify-content: space-between;
    width: 40px;
    height: 28px;
    padding: 16px 10px;
    background: none;
    border: 0;
    cursor: pointer;
    box-sizing: content-box;
}

.header .header__bar .header__burger span {
    display: block;
    height: 4px;
    background: var(--color-white);
    border-radius: 4px;
    transition: transform 0.3s ease, opacity 0.3s ease, background-color 0.2s ease;
    transform-origin: center;
}

.header .header__bar .header__logo {
    width: 20vw;
    min-width: 80px;
    max-width: 168px;
    aspect-ratio: 1;
}

.header .header__bar .header__nav {
    flex: 1;
}

.header .header__bar .header__menu {
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: center;

    gap: 1.5rem;
}

.header .header__bar .header__menu a {
    position: relative;
    color: var(--color-white);
    padding-bottom: 1.5em;
    text-decoration: none;
    letter-spacing: 0.08em;
}

/* Survol : gras + espacement des lettres + soulignement fin */
.header .header__bar .header__menu a:hover {
    color: var(--color-white);
    font-weight: 700;
}

/* Page courante : gras seul (le soulignement n'apparaît qu'au survol) */
.header .header__bar .header__menu .current-menu-item > a,
.header .header__bar .header__menu .current_page_item > a {
    font-weight: 700;
}

.header .header__bar .header__menu a:hover::after,
.header .header__bar .header__menu .current-menu-item > a::after,
.header .header__bar .header__menu .current_page_item > a::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 1em;
    width: 100%;
    height: 2px;
    background: var(--color-white);
}

/* Sous-menu (liste des cuvées) — desktop : déroulant au survol */
.header .header__bar .header__menu .menu-item-has-children {
    position: relative;
}

.header .header__bar .header__menu .sub-menu {
    position: absolute;
    top: calc(100% + 1em);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;

    margin: 0;
    padding: 1.25rem 1.75rem;
    list-style: none;
    white-space: nowrap;

    background: var(--header-overlay);
    backdrop-filter: blur(8px);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.header .header__bar .header__menu .sub-menu a {
    font-size: 0.9em;
    padding-bottom: 0.35em;
}
.header .header__bar .header__menu .sub-menu a:after {
    bottom: 0;
}

.header .header__bar .header__menu .menu-item-has-children:hover > .sub-menu,
.header .header__bar .header__menu .menu-item-has-children:focus-within > .sub-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Boutons injectés (retour + accès page) : utiles seulement au drill-down mobile */
.header .header__bar .header__menu .sub-menu__back,
.header .header__bar .header__menu .sub-menu__cta {
    display: none;
}

.header .header__actions {
    position: absolute;
    top: calc(50px + var(--wpadminbar-height));
    right: 50px;

    display: flex;
    gap: 0.5em;

    .header__lang {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 0.5em;
    }

    a {
        color: var(--color-white);
        border-bottom: 2px solid transparent;
    }

    a:hover {
        color: var(--color-white);
        border-color: var(--color-white);
    }

    .current-lang {
        display: none;
    }

    .header__contact {
        display: flex;
        justify-content: center;
        align-items: center;

        a {
            display: block;
            width: 1em;
            height: 1em;
            text-indent: -9999px;
            overflow: hidden;
            background: url('../img/contact.svg') no-repeat center / contain;
            border-bottom: none;
        }
    }

    @media screen and (max-width: 900px) {
        position: fixed;
        top: calc(0px + var(--wpadminbar-height));
        right: 0px;
        padding: 10px;
        min-height: 60px;

        /* Slug de langue et icône contact agrandis (trop petits en mobile).
           Les liens ont leur propre taille (a { font-size: var(--fs-a) }, ~14px
           en mobile) : on cible donc directement le lien et on dimensionne
           l'icône en rem pour ne pas dépendre de cette taille. */
        gap: 0.75em;

        .header__lang a {
            font-size: 1rem;
        }

        .header__contact a {
            width: 1.4rem;
            height: 1.4rem;
            margin: 0 0.5em;
        }
    }
}

.header .header__hero {
    flex: 1;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;

    padding: 0 15vw 15vw;

    text-align: center;
    color: var(--color-white);
}

.header .header__title {
    margin: 0;
    font-family: "Baskervville";
    font-weight: 400;
    font-size: clamp(1.75rem, 3vw, 3.5rem);
    line-height: 1.2;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--color-white);
}

.header .header__tagline {
    margin: 0;
    text-align: center;
    color: var(--color-white);
}

/* Mobile : < 767px */
@media screen and (max-width: 900px) {

    .header.is-over-light {
        z-index: 2;
    }

    .header.is-over-light:before {
        content: '';

        position: fixed;
        top: calc(0px + var(--wpadminbar-height));
        left: 0;
        width: 100%;
        height: 60px;
        background: var(--color-red);
    }

    .header .header__burger {
        display: inline-flex;
    }

    .header .header__nav {
        display: none;
    }

    .header .header__logo {
        position: absolute;
        top: 87px;
    }

    /* État ouvert (mobile) */
    .header.is-open {
        position: fixed;
        top: var(--wpadminbar-height);
    }

    .header.is-open .header__bar {
        position: absolute;

        flex-direction: column;
        /* « safe center » : centré quand ça tient, mais bascule en haut
           (sans rogner le 1er item) dès que le contenu dépasse. */
        justify-content: safe center;
        gap: 8vh;

        width: 100%;
        height: calc(var(--app-height, 100vh) - var(--wpadminbar-height));
        box-sizing: border-box;

        /* Menu défilable si trop long (ex. drill-down avec beaucoup de cuvées). */
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;

        background: var(--header-overlay);
        /* Pas de backdrop-filter ici : il créerait un bloc englobant qui piège
           les descendants position:fixed (burger + actions) et les ferait défiler
           avec le menu. Le flou est porté par .header.is-open::before (ci-dessous). */
    }

    /* Flou d'arrière-plan du menu, sur un pseudo-élément fixe : il n'est PAS
       ancêtre du burger ni des actions, donc ne les ancre pas au scroll. */
    .header.is-open::before {
        content: '';
        position: fixed;
        inset: 0;
        z-index: -1;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        pointer-events: none;
    }

    .header.is-open .header__nav {
        display: block;
        width: 100%;
        flex: none;
    }

    .header.is-open .header__menu {
        flex-direction: column;
        gap: 8vh;
        text-align: center;
    }

    /* --- Sous-menu mobile : navigation en drill-down --- */

    /* Replié par défaut : on ne voit que le 1er niveau. */
    .header.is-open .header__menu .sub-menu {
        display: none;
    }

    /* Panneau ouvert : on masque le reste du 1er niveau (autres entrées,
       autre colonne de menu et logo) pour ne garder que le sous-menu actif. */
    .header.is-open.is-submenu-open .header__menu > li:not(.is-submenu-active) {
        display: none;
    }

    .header.is-open.is-submenu-open .header__nav:not(.has-open-submenu) {
        display: none;
    }

    .header.is-open.is-submenu-open .header__logo {
        display: none;
    }

    /* On masque le lien de 1er niveau de l'item actif (remplacé par le bouton retour). */
    .header.is-open.is-submenu-open .is-submenu-active > a {
        display: none;
    }

    /* Le sous-menu actif devient le panneau, en flux normal. */
    .header.is-open.is-submenu-open .is-submenu-active > .sub-menu {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4vh;

        position: static;
        transform: none;
        z-index: auto;
        padding: 0;
        white-space: normal;

        background: none;
        backdrop-filter: none;

        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        padding-bottom: 60px;
    }

    /* Bouton retour « ‹ Titre ». */
    .header.is-open.is-submenu-open .is-submenu-active > .sub-menu .sub-menu__back {
        display: block;
    }

    .header .header__menu .sub-menu__back button {
        background: none;
        border: 0;
        padding: 0;
        color: var(--color-white);
        font: inherit;
        letter-spacing: 0.08em;
        cursor: pointer;
    }

    .header .header__menu .sub-menu__back button span {
        margin-right: 0.25em;
    }

    /* Bouton d'accès à la page parente. */
    .header.is-open.is-submenu-open .is-submenu-active > .sub-menu .sub-menu__cta {
        display: block;
        margin-top: 2vh;
    }

    .header .header__menu .sub-menu__cta a {
        display: inline-block;
        padding: 0.6em 1.6em;
        border: 1px solid var(--color-white);
        border-radius: 999px;
        font-size: 0.9em;
    }

    .header .header__menu .sub-menu__cta a::after {
        display: none;
    }

    .header.is-open .header__hero {
        display: none;
    }

    .header.is-open .header__burger span:nth-child(1) {
        transform: translateY(12px) rotate(45deg);
    }

    .header.is-open .header__burger span:nth-child(2) {
        opacity: 0;
    }

    .header.is-open .header__burger span:nth-child(3) {
        transform: translateY(-12px) rotate(-45deg);
    }

    .header.is-open.is-over-light:before {
        display: none;
    }

    .header .header__hero {
        br {
            display: none;
        }
    }
}

/* Mobile with small height : < 600px */
@media screen and (max-height: 600px) {
    .header .header__logo {
        top: 5vh;
    }
}