/* ---------------------------------------------------------------------------
   Mega-menu open/close performance contract
   ---------------------------------------------------------------------------
   Goal: zero layout, zero paint on open/close. Composite-only animation.

   1. content-visibility: hidden when closed -> browser skips layout + paint of
      the entire panel subtree (60+ DOM nodes) until needed.
   2. Backdrop transitions opacity only. background-color is set once.
   3. Panel transforms (scale + translate) on the GPU layer.
   4. cubic-bezier(0.16, 1, 0.3, 1) is "ease-out-quart" - snappier than ease.
   5. No body class colour transitions on the navbar (was forcing a paint on
      navbar at the same moment as the panel animation).
   --------------------------------------------------------------------------- */

.mega-menu-page {
    position: fixed;
    inset: 0;
    background: rgba(11, 23, 38, 0.5);
    font-family: 'Red Hat Display', sans-serif;
    color: #0b1726;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    /* GPU layer + skip subtree work entirely while closed */
    will-change: opacity;
    transform: translateZ(0);
    contain: layout paint style;
    content-visibility: hidden;
    transition: opacity 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

.mega-menu-page:not(.mega-menu-page--closed) {
    opacity: 1;
    pointer-events: auto;
    content-visibility: visible;
}

.mega-menu-panel {
    position: absolute;
    top: calc(72px + 0.15rem);
    left: 1.5rem;
    right: 1.5rem;
    width: auto;
    background: #fff;
    border-radius: 16px;
    padding: 2.5rem 2.5rem 1.25rem;
    box-shadow: 0 12px 40px rgba(9, 21, 54, 0.18);
    max-height: 84vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    justify-content: flex-start;
    will-change: transform, opacity;
    transform-origin: top center;
    transform: translate3d(0, 0, 0) scale(1);
    transition:
        opacity 0.16s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    /* Hide scrollbar gutter so it never reflows the layout when content overflows */
    scrollbar-gutter: stable;
}

.mega-menu-page--closed .mega-menu-panel {
    opacity: 0;
    pointer-events: none;
    /* Subtle pop-in: scale from 99% + translate -6px. Smaller distance reads
       as snappier than an 8-12px slide. */
    transform: translate3d(0, -6px, 0) scale(0.99);
}

/* Pre-baked nav-overlay state. display:block always so opacity can transition;
   pointer-events disabled so it never blocks clicks while closed. */
.nav-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}
.mega-menu-mode .nav-overlay {
    opacity: 1;
}

/* Navbar text colour while menu is open. Composite-only: pre-position both
   colours via CSS custom property + transition the property itself, so the
   browser doesn't trigger a paint on every nav link individually. */
.nav-link.white a {
    color: var(--nav-link-color, #fff);
    transition: color 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}
.mega-menu-mode .nav-link.white a {
    --nav-link-color: #0b1726;
    font-weight: 600;
}
.mega-menu-mode .nav-link.white a.active,
.mega-menu-mode .nav-link.white a:hover {
    --nav-link-color: #003d82;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .mega-menu-page,
    .mega-menu-panel,
    .nav-overlay,
    .nav-link.white a {
        transition-duration: 0s !important;
    }
    .mega-menu-page--closed .mega-menu-panel {
        transform: none;
    }
}

.mega-menu-content {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.mega-menu-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 1rem;
    width: 100%;
    padding: 0; /* override global section { padding: 40px 0 } from styles.css */
}

.mega-menu-pill-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: nowrap;
    flex: 1;
}

.mega-menu-pill,
.mega-menu-small-pill {
    border-radius: 999px;
    border: 1px solid #d8dfe9;
    background: #fff;
    color: #192336;
    padding: 0.45rem 1.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.mega-menu-pill.active {
    border-color: transparent;
    background: #003d82;
    color: #fff;
    box-shadow: 0 12px 30px rgba(0, 61, 130, 0.35);
}

.mega-menu-pill.active:hover {
    border-color: transparent;
    background: #003d82;
    color: #fff;
}

.mega-menu-pill:hover,
.mega-menu-small-pill:hover {
    border-color: #003d82;
    color: #003d82;
    transform: translateY(-2px);
}

.mega-menu-small-pill:hover {
    background: #fff;
}

.mega-menu-filter-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
    justify-content: flex-end;
    flex: 0;
}
.mega-menu-looking {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
    color: #4b556c;
    font-size: 0.75rem;
    white-space: nowrap;
}
.mega-menu-looking span {
    font-size: 0.75rem;
}

.mega-menu-small-pills {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

.mega-menu-search {
    border-radius: 30px;
    border: 1px solid #d9dee9;
    padding: 0.35rem 0.95rem;
    display: flex;
    align-items: center;
    width: 220px;
    min-width: 220px;
    gap: 0.55rem;
    background: #fff;
    box-shadow: inset 0 0 0 1px #f2f3fb;
}

.mega-menu-search input {
    border: none;
    outline: none;
    font-size: 0.75rem;
    font-weight: 500;
    flex: 1;
    background: transparent;
}

.mega-menu-search-icon {
    font-size: 1rem;
    color: #8f9ab7;
}

.mega-menu-columns {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 1.25rem;
    padding: 0; /* override global section { padding: 40px 0 } from styles.css */
    align-items: start; /* each column shrinks to its content — prevents active card from having empty highlighted space */
}

.mega-menu-column {
    border-radius: 12px;
    padding: 1.25rem;
    background: #ffffff;
    border: 1px solid #e9edf5;
    border-left: 1px solid transparent;
    min-height: auto;
    box-shadow: 0 8px 24px rgba(9, 21, 54, 0.06);
    transition: border 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.mega-menu-column:first-child {
    border-left: 1px solid transparent;
}

.mega-menu-column .column-heading h2 {
    margin: 0;
    font-size: 0.875rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #0b1726;
    font-weight: 700;
}

.mega-menu-column .column-heading p {
    margin: 0.3rem 0 0.85rem;
    color: #5c657d;
    font-size: 0.78rem;
    line-height: 1.5;
}

.mega-menu-column ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.mega-menu-column ul li a {
    text-decoration: none;
    color: #11121a;
    font-weight: 500;
    font-size: 0.78rem;
    transition: color 0.15s ease, font-weight 0.15s ease;
    display: inline-block;
}

.mega-menu-column ul li a:hover {
    color: #003d82;
    font-weight: 600;
    text-decoration: underline;
}

.badge {
    margin-left: 0.4rem;
    font-size: 0.65rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: #ffffff;
    color: #1b3f7f;
    border: 1px solid #9fb1d7;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.mega-menu-column--active {
    background: #f3f6ff;
    border-color: #003d82;
    border-left: 4px solid #003d82;
    box-shadow: 0 22px 50px rgba(0, 61, 130, 0.16);
    z-index: 2;
}

.mega-menu-column--active:first-child {
    border-left: 4px solid #003d82;
}

.mega-menu-bottom {
    border-top: 1px solid #e6e9f2;
    padding: 1rem 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: transparent;
    box-shadow: none;
}

.recently-viewed {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    font-size: 0.72rem;
    color: #4a5366;
}

.recently-viewed strong {
    font-size: 0.72rem;
    font-weight: 600;
}

.recent-chip {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    border: 1px solid #d3daea;
    font-weight: 600;
    background: #fff;
    color: #1f2a42;
    font-size: 0.72rem;
    box-shadow: 0 6px 18px rgba(21, 35, 66, 0.08);
}

.recently-viewed-chips {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mega-menu-buttons {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.bottom-top {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 1rem;
}

.bottom-top .bottom-close {
    justify-self: center;
}

.bottom-top .mega-menu-buttons {
    justify-self: end;
}

.bottom-top .bottom-close {
    display: flex;
    justify-content: center;
    align-items: center;
}

@media (max-width: 768px) {
    .bottom-top {
        grid-template-columns: 1fr;
    }
    .bottom-top .bottom-close,
    .bottom-top .mega-menu-buttons {
        justify-self: start;
    }
}

.mega-menu-buttons a {
    text-decoration: none;
    border-radius: 999px;
    padding: 0.45rem 1.25rem;
    font-weight: 600;
    font-size: 0.75rem;
    border: 1px solid transparent;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pill-button {
    border-color: #dfe5f0;
    background: #fff;
    color: #3a4561;
}

.pill-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 61, 130, 0.12);
}

.solid-button {
    background: #003d82;
    color: #fff;
    box-shadow: 0 12px 26px rgba(0, 61, 130, 0.3);
}

.solid-button:hover {
    transform: translateY(-2px);
}

.ghost-button {
    background: transparent;
    color: #003d82;
    border-color: #003d82;
}

.ghost-button:hover {
    background: #f1f4ff;
    box-shadow: 0 12px 20px rgba(0, 61, 130, 0.15);
}

/* Bottom close button */
.mega-menu-close-btn {
    border-radius: 999px;
    border: 1px solid #dfe5f0;
    padding: 0.45rem 1.75rem;
    background: #fff;
    color: #3a4561;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.mega-menu-close-btn:hover {
    background: #f1f4ff;
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 61, 130, 0.12);
}

@media (max-width: 1320px) {
    .mega-menu-columns {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .mega-menu-panel {
        padding: 2rem 2rem 1.75rem;
        left: 1rem;
        right: 1rem;
    }
}

@media (max-width: 940px) {
    .mega-menu-filters {
        flex-direction: column;
        align-items: flex-start;
    }

    .mega-menu-filter-actions {
        justify-content: space-between;
        width: 100%;
    }

    .mega-menu-search {
        width: 100%;
    }

    .mega-menu-panel {
        padding: 1.75rem 1.5rem 1.5rem;
        left: 0.75rem;
        right: 0.75rem;
    }
}

@media (max-width: 640px) {
    .mega-menu-panel {
        padding: 1.75rem 1rem 1.25rem;
        left: 0;
        right: 0;
        border-radius: 0 0 16px 16px;
        top: calc(72px + 0.1rem);
        max-height: 88vh;
    }

    .mega-menu-filters {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .mega-menu-pill-row {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .mega-menu-filter-actions {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: 0.5rem;
    }

    .mega-menu-search {
        width: 100%;
        min-width: unset;
    }

    .mega-menu-bottom {
        flex-direction: column;
        align-items: flex-start;
    }

    .mega-menu-columns {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    /* Mobile accordion: columns collapse by default, tap heading to expand */
    .mega-menu-column {
        padding: 0;
        overflow: hidden;
        border-radius: 8px;
    }

    .mega-menu-column .column-heading {
        cursor: pointer;
        padding: 0.85rem 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0;
        user-select: none;
    }

    .mega-menu-column .column-heading h2 {
        font-size: 0.8rem;
        letter-spacing: 0.06em;
    }

    /* Hide description text on mobile to save space */
    .mega-menu-column .column-heading p {
        display: none;
    }

    /* Collapse indicator */
    .mega-menu-column .column-heading::after {
        content: '+';
        font-size: 1.1rem;
        font-weight: 700;
        color: #003d82;
        flex-shrink: 0;
        margin-left: 0.5rem;
        transition: transform 0.25s ease;
        line-height: 1;
    }

    .mega-menu-column.mobile-open .column-heading::after {
        transform: rotate(45deg);
    }

    .mega-menu-column ul {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0 1rem;
        gap: 0.5rem;
    }

    .mega-menu-column.mobile-open ul {
        max-height: 600px;
        padding: 0 1rem 1rem;
    }
}

/* Mobile burger-menu trigger for mega menu */
.burger-mega-trigger {
    display: none;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

@media (max-width: 991px) {
    .burger-mega-trigger {
        display: block;
    }
}
