/**
 * Mega Menu — chevron toggle, panel, and the nav-cascade reset.
 *
 * The panel sits inside a nav <li> (for focus and reading order), so the nav's
 * own styles reach it. What leaks and how it's handled:
 *   - Nav typography (size, weight, case, letter-spacing, colour) → reset on the
 *     panel to theme.json's body styles (styles.typography / styles.color.text).
 *   - Theme `.oi-site-navigation > ul > li a` padding + radius → the theme rule
 *     now skips panel links; the plain-link reset below covers older themes.
 *   - Transparent-header nav colours (palette-9) → only reach a Navigation block
 *     placed inside a panel; its links inherit the panel's colour instead.
 *   - Core's `.wp-block-navigation ul` list reset is left alone on purpose:
 *     link lists in a mega menu read better without bullets.
 * The panel has no background of its own — the mega menu's content supplies it
 * (the starter designs use a palette-9 card).
 */

/* Nav Item Spacing variables set on the host <nav> would otherwise reach a
   Navigation block inside the panel that has none of its own; unset them so
   it renders like a stand-alone nav. */
.has-oi-megamenu > .oi-megamenu__panel {
    --oi-nav-item-padding: initial;
    --oi-nav-item-gap: initial;
}

/* ── Toggle ────────────────────────────────────────────────────────────────
   Hidden until megamenu-view.js activates the item at desktop widths, so
   without JS or below the collapse breakpoint the item is a plain link.
   The chevron matches core's submenu icon (.wp-block-navigation__submenu-icon):
   0.6em square, 0.25em after the link, nudged down 0.075em. The 0.35em padding
   is hit area only; the -0.1em margin puts the chevron at core's 0.25em. */

.has-oi-megamenu > .oi-megamenu__toggle {
    display: none;
}

.has-oi-megamenu.is-oi-megamenu-active > .oi-megamenu__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 0 -0.1em;
    padding: 0.35em;
    background: none;
    border: 0;
    border-radius: 0.25rem;
    color: inherit;
    font-size: inherit;
    line-height: 1;
    cursor: pointer;
}

.has-oi-megamenu > .oi-megamenu__toggle svg {
    position: relative;
    top: 0.075em;
    width: 0.6em;
    height: 0.6em;
    pointer-events: none;
    transition: transform 0.2s ease;
}

.has-oi-megamenu.is-oi-megamenu-open > .oi-megamenu__toggle svg {
    transform: rotate( 180deg );
}

.has-oi-megamenu > .oi-megamenu__toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ── Panel ─────────────────────────────────────────────────────────────────
   Position comes from megamenu-view.js (measured against the header on open). */

.has-oi-megamenu > .oi-megamenu__panel {
    position: absolute;
    top: var( --oi-megamenu-top, 100% );
    left: var( --oi-megamenu-left, 0 );
    z-index: var( --oi-z-dropdown, 100 );
    box-sizing: border-box;
    width: var( --oi-megamenu-width, max-content );
    max-width: 100vw;
    color: var( --wp--preset--color--palette-3 );
    font-family: var( --wp--preset--font-family--body );
    font-size: var( --wp--preset--font-size--medium );
    font-style: normal;
    font-weight: 400;
    line-height: 1.6;
    letter-spacing: normal;
    text-align: start;
    text-transform: none;
    white-space: normal;
}

.has-oi-megamenu > .oi-megamenu__panel[hidden] {
    display: none;
}

.has-oi-megamenu.is-oi-megamenu-open > .oi-megamenu__panel {
    animation: oi-megamenu-in 0.2s ease-out;
}

@keyframes oi-megamenu-in {
    from {
        opacity: 0;
        transform: translateY( -6px );
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* Hover bridge — fills the gap between the item and the panel (under the item
   only) so moving the pointer down doesn't close it. */
.has-oi-megamenu > .oi-megamenu__panel::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: var( --oi-megamenu-bridge-left, 0 );
    width: var( --oi-megamenu-bridge-width, 0 );
    height: var( --oi-megamenu-bridge-height, 0 );
}

/* Sticky/fixed header with a panel taller than the viewport. */
.has-oi-megamenu.is-oi-megamenu-scroll > .oi-megamenu__panel > .oi-megamenu__inner {
    max-height: var( --oi-megamenu-max-height );
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Card used by the starter designs — clips the cover to the radius and lifts
   the panel off the page. Loads in the editor canvas too. */
.oi-megamenu-card {
    overflow: hidden;
    box-shadow: 0 1rem 2.5rem color-mix( in srgb, var( --wp--preset--color--palette-3 ) 16%, transparent );
}

/* ── Nav-cascade reset ───────────────────────────────────────────────────── */

/* Older themes: nav padding + radius on every link inside a top-level item.
   Plain links only — buttons keep their own padding on current themes. */
.oi-site-navigation.wp-block-navigation > ul > li.has-oi-megamenu .oi-megamenu__panel a:where(:not(.wp-element-button, .wp-block-navigation-item__content)) {
    padding: 0;
    border-radius: 0;
}

/* Transparent headers force nav links to palette-9 — a Navigation block inside
   a panel inherits the panel's colour instead. */
body[class*="header-transparent"] .oi-site-header .has-oi-megamenu > .oi-megamenu__panel .wp-block-navigation-item__content:not(:hover) {
    color: inherit;
}

/* ── Editor canvas — chevron after mapped links (megamenu-editor.js) ───────── */

.oi-has-megamenu > .wp-block-navigation-item__content .wp-block-navigation-item__label::after {
    content: "";
    display: inline-block;
    width: 0.6em;
    height: 0.6em;
    margin-inline-start: 0.4em;
    vertical-align: middle;
    background: currentColor;
    -webkit-mask: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 4 6 8l4.5-4' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E" ) center / contain no-repeat;
    mask: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 4 6 8l4.5-4' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E" ) center / contain no-repeat;
}

@media ( prefers-reduced-motion: reduce ) {
    .has-oi-megamenu.is-oi-megamenu-open > .oi-megamenu__panel {
        animation: none;
    }
    .has-oi-megamenu > .oi-megamenu__toggle svg {
        transition: none;
    }
}
