/*
 * Header mega menu (template-parts/header/mega-menu/view.php).
 *
 * Desktop first, like style.css. From 1024px each top-level item opens a full-width panel
 * under the header bar; at 1023px and below the whole menu is the off-canvas panel that
 * the header burger opens, with the top-level items as an accordion.
 *
 * script.js keeps --mega-menu-offset equal to the bottom edge of the header bar.
 */

.mega-menu {
    --mega-menu-offset: 83px;
}

.mega-menu__list {
    display: flex;
    align-items: center;
    gap: 40px;
}

/* Top level: panel triggers and plain links */

.mega-menu__trigger,
.mega-menu__top-link {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 32px 0 31px;
    background: none;
    border: 0;
    border-radius: 0;
    font-family: 'Chalet Custom', sans-serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 20px;
    color: var(--main-color);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: color .3s;
}

.mega-menu__trigger:hover,
.mega-menu__item.is-open > .mega-menu__trigger,
.mega-menu__top-link:hover,
.mega-menu__top-link.is-current {
    color: var(--red);
}

.mega-menu__trigger:focus-visible,
.mega-menu__top-link:focus-visible,
.mega-menu__link:focus-visible,
.mega-menu__group-title:focus-visible,
.mega-menu__subgroup-title:focus-visible {
    outline: 2px solid var(--lightblue);
    outline-offset: 3px;
}

/* The Figma chevron points up; closed items show it turned down. */
.mega-menu__chevron {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    background-color: currentColor;
    -webkit-mask: url('icons/chevron.svg') center / contain no-repeat;
    mask: url('icons/chevron.svg') center / contain no-repeat;
    transform: rotate(180deg);
    transition: transform .3s;
}

.mega-menu__item.is-open > .mega-menu__trigger .mega-menu__chevron {
    transform: none;
}

/* Panel */

.mega-menu__panel {
    display: none;
    position: fixed;
    top: var(--mega-menu-offset);
    left: 0;
    right: 0;
    z-index: 1;
    min-height: 50vh;
    max-height: calc(100vh - var(--mega-menu-offset));
    max-height: calc(100dvh - var(--mega-menu-offset));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: linear-gradient(to bottom, rgba(91, 129, 161, .15), rgba(91, 129, 161, 0) 20px) no-repeat, #fff;
    box-shadow: 0 5px 8px rgba(91, 129, 161, .25);
}

.mega-menu__item.is-open > .mega-menu__panel {
    display: block;
}

/* Without script.js (it adds .mega-menu--js) the panels still open on hover and focus. */
@media (min-width: 1024px) {
    .mega-menu:not(.mega-menu--js) .mega-menu__item:hover > .mega-menu__panel,
    .mega-menu:not(.mega-menu--js) .mega-menu__item:focus-within > .mega-menu__panel {
        display: block;
    }
}

.mega-menu__panel-inner {
    display: grid;
    grid-template-columns: 285px minmax(0, 1fr);
    column-gap: 21px;
    width: 95%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 0 48px;
}

.mega-menu__intro {
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: var(--main-color);
}

.mega-menu__title {
    font-family: 'Zurich', sans-serif;
    font-size: 40px;
    font-weight: 700;
    line-height: 1;
}

.mega-menu__description {
    font-size: 18px;
    font-weight: 400;
    line-height: 1.5;
}

.mega-menu__columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: 20px;
    align-items: start;
}

.mega-menu__column > * + * {
    margin-top: 30px;
}

/* Groups, subgroups and links */

.mega-menu__group-title {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 12px;
    background: rgba(210, 223, 232, .6);
    border-radius: 4px;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--main-color);
}

.mega-menu__group-body {
    margin-top: 14px;
    padding-left: 12px;
}

.mega-menu__group-body > * + * {
    margin-top: 20px;
}

.mega-menu__subgroup-title {
    display: block;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--main-color);
}

.mega-menu__subgroup-title + .mega-menu__links {
    margin-top: 8px;
}

.mega-menu__links {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mega-menu__link {
    display: inline;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--main-color);
    text-decoration: none;
    transition: color .3s;
}

a.mega-menu__group-title:hover,
a.mega-menu__subgroup-title:hover,
a.mega-menu__link:hover {
    color: var(--lightblue);
    text-decoration: underline;
    text-decoration-skip-ink: none;
    text-underline-position: from-font;
}

.mega-menu__link.is-current {
    color: var(--red);
}

@media (max-width: 1499px) {
    .mega-menu__panel-inner {
        max-width: 1200px;
    }
}

@media (max-width: 1249px) {
    .mega-menu__list {
        gap: 24px;
    }

    .mega-menu__panel-inner {
        grid-template-columns: 220px minmax(0, 1fr);
        width: 90%;
    }

    .mega-menu__title {
        font-size: 34px;
    }
}

@media (min-width: 1024px) and (max-width: 1199px) {
    .mega-menu__list {
        gap: 18px;
    }

    .mega-menu__trigger,
    .mega-menu__top-link {
        gap: 4px;
        font-size: 16px;
    }

    .mega-menu__chevron {
        width: 16px;
        height: 16px;
    }
}

/* Mobile: off-canvas panel opened by the header burger, top level as an accordion */

@media (max-width: 1023px) {
    .mega-menu {
        --mega-menu-offset: 66px;
        position: fixed;
        top: var(--mega-menu-offset);
        left: -110%;
        z-index: 9999;
        width: 100%;
        height: calc(100vh - var(--mega-menu-offset));
        height: calc(100dvh - var(--mega-menu-offset));
        padding: 22px 5% 140px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: linear-gradient(to bottom, rgba(91, 129, 161, .15), rgba(91, 129, 161, 0) 20px) no-repeat, #fff;
        transition: left .5s;
    }

    /* The :has() rule follows the legacy burger even if script.js did not run. */
    .mega-menu.is-open,
    .header-right-menu:has(> .mobile-menu-btn.active) > .mega-menu {
        left: 0;
    }

    .mega-menu__list {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .mega-menu__item + .mega-menu__item {
        margin-top: 26px;
        padding-top: 26px;
        border-top: 2px solid var(--red);
    }

    .mega-menu__trigger,
    .mega-menu__top-link {
        justify-content: space-between;
        width: 100%;
        padding: 0;
        font-size: 22px;
        line-height: 1.2;
        text-align: left;
    }

    /* In the mobile design an open item keeps the text color; only the chevron turns. */
    .mega-menu__trigger:hover,
    .mega-menu__item.is-open > .mega-menu__trigger {
        color: var(--main-color);
    }

    .mega-menu__top-link {
        display: block;
    }

    .mega-menu__chevron {
        width: 22px;
        height: 22px;
    }

    .mega-menu__panel {
        position: static;
        min-height: 0;
        max-height: none;
        padding-top: 26px;
        overflow: visible;
        background: none;
        box-shadow: none;
    }

    .mega-menu__panel-inner {
        display: block;
        width: auto;
        max-width: none;
        padding: 0;
    }

    .mega-menu__intro {
        display: none;
    }

    .mega-menu__columns {
        display: block;
    }

    .mega-menu__column + .mega-menu__column,
    .mega-menu__column > * + * {
        margin-top: 26px;
    }

    .mega-menu__group-title {
        display: block;
        min-height: 0;
        padding: 0;
        background: none;
        border-radius: 0;
        font-size: 20px;
    }

    .mega-menu__group-body {
        margin-top: 18px;
    }

    .mega-menu__group-body > * + * {
        margin-top: 26px;
    }

    .mega-menu__subgroup .mega-menu__links {
        gap: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mega-menu,
    .mega-menu__trigger,
    .mega-menu__top-link,
    .mega-menu__chevron,
    .mega-menu__link {
        transition: none;
    }
}
