/*
 * Component: header
 *
 * Header global Rabuel Construction. Fixe en haut de viewport, fond blanc
 * semi-transparent au repos, opaque dès qu'on scrolle (classe `.is-scrolled`
 * appliquée par header.js). Le header natif de Divi est masqué.
 *
 * Nesting natif uniquement (cf. CLAUDE.md). Chemin complet pour chaque
 * élément BEM, jamais de `&__`.
 */

/* Masquer le header natif de Divi (parent) — on injecte le notre via wp_body_open. */
#main-header,
#top-header,
#et-secondary-nav,
#et-top-navigation {
    display: none !important;
}

body.et-fixed-header #page-container {
    padding-top: 0 !important;
}

.rc-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-xxl);
    padding: var(--s-small) var(--s-xl);
    background-color: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background-color 0.25s ease, box-shadow 0.25s ease, padding 0.25s ease;
    font-family: var(--font-body);
    color: var(--color-primary);
    border-bottom:1px solid var(--color-primary);

    &.is-scrolled {
        background-color: #fff;
    }

    .rc-header__left {
        display: flex;
        align-items: center;
        flex: 0 0 auto;
    }

    .rc-header__burger {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        background: transparent;
        border: 0;
        padding: var(--s-xxs);
        cursor: pointer;
        color: inherit;
        font: inherit;

        &:focus-visible {
            outline: 2px solid var(--color-tertiary);
            outline-offset: 2px;
        }

        &:hover .rc-header__burger-label,
        &:focus-visible .rc-header__burger-label {
            text-decoration: underline;
            text-underline-offset: 0.25em;
        }
    }

    .rc-header__burger-icon {
        display: inline-flex;
        flex-direction: column;
        justify-content: space-between;
        width: 26px;
        height: 20px;

        span {
            display: block;
            height: 2px;
            width: 100%;
            background-color: currentColor;
            border-radius: 2px;
        }
    }

    .rc-header__burger-label {
        font-size: 0.7rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        color: inherit;
    }

    .rc-header__metiers {
        flex: 1 1 auto;
        display: flex;
        min-width: 0;
    }

    .rc-header__metiers-list {
        display: flex;
        flex-wrap: wrap;
        gap: var(--s-xl);
        list-style: none;
        margin: 0;
        padding: 0;

        li {
            margin: 0;
        }

        li a {
            display: inline-flex;
            align-items: center;
            gap: var(--s-xs);
            color: var(--color-primary);
            font-size: 0.85rem;
            font-weight: 600;
            text-transform: uppercase;
            text-decoration: underline transparent;
            text-underline-offset: 0.4em;
            text-decoration-thickness: 1.5px;
            transition: text-decoration-color 0.2s ease;
        }

        li a::before {
            content: "";
            display: inline-block;
            width: 0.65em;
            height: 0.65em;
            border-radius: 50%;
            background-color: var(--rc-metier-color, var(--color-primary));
            flex: 0 0 auto;
        }

        li a:hover,
        li a:focus-visible {
            text-decoration-color: currentColor;
        }

        li a:focus-visible {
            outline: 2px solid var(--color-tertiary);
            outline-offset: 3px;
        }

        li.rc-metier-construction a { --rc-metier-color: var(--color-tertiary); }
        li.rc-metier-renovation   a { --rc-metier-color: var(--color-renovation); }
        li.rc-metier-piscines     a { --rc-metier-color: var(--color-piscine); }
        li.rc-metier-archi        a { --rc-metier-color: var(--color-archi); }
    }

    .rc-header__right {
        display: flex;
        align-items: center;
        gap: var(--s-large);
        flex: 0 0 auto;
    }

    .rc-header__logo {
        display: inline-flex;
        align-items: center;

        img {
            display: block;
            max-height: 64px;
            width: auto;
        }
    }

    .rc-header__social {
        display: flex;
        align-items: center;
        gap: var(--s-small);
        list-style: none;
        align-self: stretch;
        margin: calc(var(--s-small) * -1) 0;
        padding: var(--s-small) 0 var(--s-small) var(--s-large);
        border-left: 1px solid var(--color-primary);

        li {
            margin: 0;
        }

        li a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: var(--color-primary);
            transition: color 0.2s ease, opacity 0.2s ease;
            width: 28px;
            height: 28px;
        }

        li a:hover {
            color: var(--color-tertiary);
        }

        li a:focus-visible {
            outline: 2px solid var(--color-tertiary);
            outline-offset: 3px;
            border-radius: 2px;
        }

        li a svg {
            width: 20px;
            height: 20px;
            display: block;
        }
    }
}

/* Décalage admin-bar — la barre WP se superpose sinon. */
body.admin-bar .rc-header {
    top: 32px;
}

/* === Backdrop === */
.rc-header__backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;

    &.is-open {
        opacity: 1;
        pointer-events: auto;
    }
}

/* === Drawer === */
.rc-header__drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 60vw;
    min-width: 320px;
    background-color: var(--color-primary);
    color: var(--color-tertiary);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 10001;
    padding: var(--s-large) var(--s-xxl) var(--s-xxl);
    overflow-y: auto;
    font-family: var(--font-body);

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

    /* === Barre du haut : close (gauche) + social (droite) === */
    .rc-header__drawer-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--s-medium);
        padding-bottom: var(--s-medium);
        margin-bottom: var(--s-xxl);
        border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    }

    .rc-header__drawer-close {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        gap: var(--s-xxs);
        background: transparent;
        border: 0;
        padding: 0;
        cursor: pointer;
        color: #DBD2B1;
        font: inherit;

        &:focus-visible {
            outline: 2px solid var(--color-tertiary);
            outline-offset: 3px;
        }

        &:hover .rc-header__drawer-close-label,
        &:focus-visible .rc-header__drawer-close-label {
            text-decoration: underline;
            text-underline-offset: 0.25em;
        }
    }

    .rc-header__drawer-close-icon {
        font-size: 3rem;
        line-height: 1;
        color: inherit;
    }

    .rc-header__drawer-close-label {
        font-size: 0.65rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        color: inherit;
    }

    /* === Logo === */
    .rc-header__drawer-logo {
        display: inline-flex;
        margin-bottom: var(--s-xxl);
        padding-left: clamp(1.5rem, 0.5rem + 4vw, 5rem);

        img {
            display: block;
            max-width: 180px;
            width: 100%;
            height: auto;
        }
    }

    /* === Menu principal === */
    .rc-header__drawer-nav {
        margin-top: 0;
        padding-left: clamp(1.5rem, 0.5rem + 4vw, 5rem);
    }

    .rc-header__drawer-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: var(--s-medium);

        li {
            margin: 0;
        }

        > li > a {
            display: inline-block;
            color: #DBD2B1;
            font-size: var(--fs-h4);
            font-weight: 500;
            letter-spacing: 0.02em;
            text-transform: uppercase;
            padding: var(--s-xxs) 0;
            text-decoration: underline transparent;
            text-underline-offset: 0.25em;
            text-decoration-thickness: 2px;
            transition: text-decoration-color 0.2s ease;
        }

        > li > a:hover,
        > li > a:focus-visible {
            text-decoration-color: #DBD2B1;
        }

        > li > a:focus-visible {
            outline: 2px solid var(--color-tertiary);
            outline-offset: 3px;
        }

        /* Item top-level avec une classe métier → couleur du texte */
        > li.rc-metier-construction > a { color: var(--color-tertiary); }
        > li.rc-metier-renovation   > a { color: var(--color-renovation); }
        > li.rc-metier-piscines     > a { color: var(--color-piscine); }
        > li.rc-metier-archi        > a { color: var(--color-archi); }

        /* === Sous-menus : dots colorés + texte blanc === */
        .sub-menu {
            list-style: none;
            margin: var(--s-xs) 0 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            gap: var(--s-xxs);

            li {
                margin: 0;
            }

            li a {
                display: inline-flex;
                align-items: center;
                gap: var(--s-xs);
                color: #DBD2B1;
                font-size: var(--fs-body);
                font-weight: 400;
                padding: var(--s-xxs) 0;
                text-decoration: underline transparent;
                text-underline-offset: 0.3em;
                text-decoration-thickness: 1.5px;
                transition: text-decoration-color 0.2s ease;
            }

            li a::before {
                content: "";
                display: inline-block;
                width: 0.6em;
                height: 0.6em;
                border-radius: 50%;
                background-color: var(--rc-metier-color, currentColor);
                flex: 0 0 auto;
            }

            li a:hover,
            li a:focus-visible {
                text-decoration-color: #DBD2B1;
            }

            li a:focus-visible {
                outline: 2px solid var(--color-tertiary);
                outline-offset: 3px;
            }

            li.rc-metier-construction a { --rc-metier-color: var(--color-tertiary); }
            li.rc-metier-renovation   a { --rc-metier-color: var(--color-renovation); }
            li.rc-metier-piscines     a { --rc-metier-color: var(--color-piscine); }
            li.rc-metier-archi        a { --rc-metier-color: var(--color-archi); }
        }
    }

    /* === Social override : pas de bordure, icônes blanches, plus grosses === */
    .rc-header__social--drawer {
        display: flex;
        align-self: auto;
        margin: 0;
        padding: 0;
        border-left: 0;
        gap: var(--s-medium);
        flex-direction: row;

        li a {
            color: #fff;
            width: 40px;
            height: 40px;
        }

        li a:hover {
            color: rgba(255, 255, 255, 0.7);
        }

        li a svg {
            width: 28px;
            height: 28px;
        }
    }
}

body.admin-bar .rc-header__drawer {
    top: 32px;
}

/* === Lock scroll quand drawer ouvert === */
body.rc-header-locked {
    overflow: hidden;
}

/* === Responsive === */
@media (max-width: 1024px) {
    .rc-header__drawer {
        width: 100vw;
        max-width: none;
        min-width: 0;
    }
}

@media (max-width: 980px) {
    .rc-header {
        padding: var(--s-xs) var(--s-medium);
        gap: var(--s-small);

        .rc-header__metiers {
            display: none;
        }

        .rc-header__logo img {
            max-height: 40px;
        }
    }
}

@media (max-width: 600px) {
    .rc-header {
        .rc-header__burger-label {
            display: none;
        }

        .rc-header__social {
            gap: var(--s-xs);

            li a {
                width: 24px;
                height: 24px;
            }

            li a svg {
                width: 18px;
                height: 18px;
            }
        }
    }

    .rc-header__drawer {
        .rc-header__drawer-logo,
        .rc-header__drawer-nav {
            padding-left: 0;
        }
    }
}

@media (max-width: 782px) {
    body.admin-bar .rc-header,
    body.admin-bar .rc-header__drawer {
        top: 46px;
    }
}
