/*
 * Mega menu.
 *
 * Net-new: the design prototype has no dropdown of any kind. Built entirely from the existing
 * :root tokens and the .card vocabulary scaled down, so the panel reads as a row of mini
 * category cards — the one pattern the design already teaches the visitor.
 */

/* ---------------------------------------------------------------- the item */

/*
 * position: static on the item is what lets the mega panel span the header instead of being
 * clipped to the width of a nav link — the panel is position: absolute with left/right: 0, so
 * it resolves against the nearest positioned ancestor, and that has to be .nav__links, not the
 * item itself.
 *
 * The :not() is load-bearing. The nav walker puts BOTH classes on a mega item
 * (class="has-dropdown has-mega has-mega--products"), and these two selectors have identical
 * specificity — so whichever is written last wins. Without the :not(), position: relative won
 * and the panel laid out 77px wide and 1215px tall inside the <li>, which looked like the menu
 * was not opening at all. Excluding the class is order-independent; reordering the rules would
 * have worked until someone moved one.
 */
.nav__links .has-mega {
    position: static;
}

.nav__links .has-dropdown:not(.has-mega) {
    position: relative;
}

.nav__links li > a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav__chev {
    flex: none;
    transition: transform 0.25s ease;
}

.nav__links .is-expanded > a .nav__chev {
    transform: rotate(180deg);
}

/* ------------------------------------------------------------- the panel */

.mega,
.nav__sub {
    position: absolute;
    top: 100%;
    z-index: 80;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.26s ease, transform 0.26s ease, visibility 0s linear 0.26s;
}

/*
 * A full-bleed band with 1440-aligned content, like every other section of the design.
 *
 * position: FIXED, not absolute, and this is the whole trick. An absolutely positioned panel
 * resolves left/right against its nearest positioned ancestor, and that is .nav__links — which
 * the design lays out as `position: absolute` centred on the header. The panel therefore came
 * out as wide as the row of nav links (423px) and 1195px tall, a narrow column down the middle
 * of the page instead of a band across it.
 *
 * Fixed takes the viewport as its containing block, so left/right: 0 spans the window exactly
 * like the header above it — which is itself fixed, so the two stay locked together while the
 * page scrolls. top is the header height token rather than 100%%, because a fixed element has
 * no parent box to be 100%% of.
 */
.mega {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: calc(100vh - var(--gp-header-h));
    overflow-y: auto;
    background: #fff;
    border-top: 1px solid rgba(20, 31, 95, 0.08);
    box-shadow: 0 18px 40px -12px rgba(6, 35, 63, 0.18);
}

.mega__inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 120px 24px;
}

/* A plain submenu, for menu items that are not one of the two generated panels. */
.nav__sub {
    left: 0;
    min-width: 240px;
    padding: 10px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 40px -12px rgba(6, 35, 63, 0.18);
}

.nav__sub a {
    display: block;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 21px;
    font-weight: 600;
    color: var(--navy);
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.nav__sub a:hover,
.nav__sub a:focus-visible {
    background: var(--sky);
    color: var(--rust-dark);
}

/*
 * Three ways in: pointer, keyboard (navigation.js sets .is-expanded), and anything inside the
 * panel taking focus. :focus-within alone is not enough, because the panel is hidden and
 * therefore unfocusable until something opens it.
 */
/* A plain dropdown still lives inside its own item. */
.nav__links li:hover > .nav__sub,
.nav__links li.is-expanded > .nav__sub,
.nav__links li:focus-within > .nav__sub,

/*
 * A mega panel does not: it is a child of .site-header, so nothing inside .nav__links can be
 * its ancestor selector. :has() on their common ancestor is what bridges the two, matching the
 * panel whose data-panel name matches the hovered item s has-mega--<name> class.
 */
.site-header:has(.has-mega--products:hover) .mega[data-panel="products"],
.site-header:has(.has-mega--products.is-expanded) .mega[data-panel="products"],
.site-header:has(.has-mega--products:focus-within) .mega[data-panel="products"],
.site-header:has(.has-mega--innovative:hover) .mega[data-panel="innovative"],
.site-header:has(.has-mega--innovative.is-expanded) .mega[data-panel="innovative"],
.site-header:has(.has-mega--innovative:focus-within) .mega[data-panel="innovative"],

/* And the panel keeps itself open while the pointer or focus is inside it. */
.mega:hover,
.mega:focus-within {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
}

/*
 * A hover bridge across the gap between the nav item and the panel below it. Without this the
 * pointer leaves the item before it reaches the panel and the menu closes under the cursor —
 * navigation.js's close delay covers the rest.
 */
/*
 * Only plain dropdowns need the bridge now. A mega item is position: static, so an absolute
 * ::after on it would resolve against .nav__links and lay a 22px strip across the whole nav
 * row — swallowing clicks on every other link. The mega panel is flush under the header and
 * needs no bridge at all.
 */
.nav__links .has-dropdown:not(.has-mega)::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 22px;
}

/* ------------------------------------------------------- category tiles */

.mega__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.mega__tile {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mega__tile-head {
    display: grid;
    grid-template-columns: 76px auto;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.mega__tile-img {
    display: block;
    overflow: hidden;
    border-radius: 6px;
    aspect-ratio: 76 / 52;
}

.mega__tile-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.mega__tile-head:hover .mega__tile-img img {
    transform: scale(1.08);
}

.mega__tile-text {
    display: block;
    min-width: 0;
}

.mega__tile-title {
    display: block;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 15px;
    line-height: 21px;
    font-weight: 500;
    letter-spacing: -0.4px;
    color: var(--navy);
}

.mega__tile-count {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--amber);
}

.mega__tile-desc {
    margin: 0;
    font-size: 12px;
    line-height: 19px;
    color: var(--body);

    /* Two lines, so tiles stay the same height whatever the editor writes. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mega__tile-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mega__tile-list a {
    display: block;
    padding: 3px 0;
    font-size: 13px;
    line-height: 19px;
    color: var(--body);
    text-decoration: none;
    transition: color 0.2s ease, padding-left 0.2s ease;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mega__tile-list a:hover,
.mega__tile-list a:focus-visible {
    padding-left: 4px;
    color: var(--rust-dark);
}

.mega__tile-all {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: auto;
    padding-top: 4px;
    font-size: 12px;
    line-height: 18px;
    font-weight: 700;
    color: var(--green);
    text-decoration: none;
}

/* ---------------------------------------------------- the innovative list */

.mega--list .mega__inner {
    max-width: 1440px;
}

.mega__eyebrow {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 0 0 16px;
    font-size: 11px;
    line-height: 16px;
    font-weight: 700;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--rust);
}

.mega__eyebrow::before {
    content: '';
    width: 24px;
    height: 1px;
    background: currentColor;
}

.mega__items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 6px 24px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mega__item a {
    display: grid;
    grid-template-columns: 56px auto;
    align-items: center;
    gap: 12px;
    padding: 7px 10px 7px 0;
    border-radius: 8px;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.mega__item a:hover,
.mega__item a:focus-visible {
    background: var(--sky);
}

.mega__item-img {
    display: block;
    overflow: hidden;
    border-radius: 6px;
    aspect-ratio: 4 / 3;
    background: var(--mist);
}

.mega__item-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mega__item-text {
    display: block;
    min-width: 0;
}

.mega__item-title {
    display: block;
    font-size: 13px;
    line-height: 19px;
    font-weight: 600;
    color: var(--navy);

    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mega__item-code {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    line-height: 16px;
    color: var(--body);
}

/* ---------------------------------------------------------------- footer */

.mega__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid rgba(20, 31, 95, 0.08);
}

.mega__foot-link {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    line-height: 20px;
    font-weight: 700;
    color: var(--navy);
    text-decoration: none;
}

.mega__foot-cta {
    padding: 10px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--grad-blue);
    font-family: 'Geist', sans-serif;
    font-size: 13px;
    line-height: 20px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
}

/* ------------------------------------------------- condensed header state */

/* The panel follows the header's height when it condenses, or it would float detached. */
.site-header.is-scrolled .mega__inner {
    padding-top: 22px;
    padding-bottom: 20px;
}

/* ---------------------------------------------------------- narrow widths */

@media (max-width: 1320px) {
    .mega__inner {
        padding-inline: 48px;
    }
}

/*
 * Below the drawer breakpoint the panels are not rendered as panels at all — the mobile walker
 * emits the same categories and products as ordinary accordion children, because there is no
 * room for a panel and an accordion is the familiar pattern at this width.
 */
@media (max-width: 1000px) {
    .mega,
    .nav__sub {
        display: none;
    }
}
