/**
 * Mega menu: header bar, a sliding highlight, and one floating panel that morphs between items.
 */

.terra-mega-menu {
    --terra-mm-hl-color: #e6ecf4;
    --terra-mm-hl-radius: 8px;
    --terra-mm-panel-bg: #ffffff;
    --terra-mm-mobile-bg: #ffffff;
    --terra-mm-border: #e3e8ef;
    --terra-mm-divider: #e3e8ef;
    --terra-mm-panel-radius: 20px;
    --terra-mm-plate-bg: #f5f7fa;
    --terra-mm-plate-radius: 14px;
    --terra-mm-tile-bg: #e6ecf4;
    --terra-mm-tile-radius: 12px;
    --terra-mm-icon-color: #001b3a;
    --terra-mm-row-hover: #ffffff;
    --terra-mm-width-catalog: 880px;
    --terra-mm-width-links: 720px;
    --terra-mm-intro-w: 220px;
    --terra-mm-gap: 16px;
    --terra-mm-shift: 28px;
    --terra-mm-dur: 380ms;
    --terra-mm-ease: cubic-bezier(0.22, 1, 0.36, 1);

    position: relative;
    z-index: 30;
    width: 100%;
    box-sizing: border-box;
}

.terra-mega-menu *,
.terra-mega-menu *::before,
.terra-mega-menu *::after {
    box-sizing: border-box;
}

.terra-mega-menu__toggle {
    display: none;
}

/* Bar */

.terra-mega-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
}

.terra-mega-menu__item {
    margin: 0;
    padding: 0;
    list-style: none;
}

.terra-mega-menu .terra-mega-menu__list .terra-mega-menu__trigger {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    margin: 0;
    padding: 10px 16px;
    border: 0;
    border-radius: var(--terra-mm-hl-radius);
    background: none;
    box-shadow: none;
    color: inherit;
    font: inherit;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
}

.terra-mega-menu .terra-mega-menu__list .terra-mega-menu__trigger:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

.terra-mega-menu__caret {
    display: none;
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
}

.terra-mega-menu__item.is-open > .terra-mega-menu__trigger .terra-mega-menu__caret {
    transform: translateY(2px) rotate(-135deg);
}

/* Sliding highlight: one shared indicator that glides between items. */

.terra-mega-menu__highlight {
    --terra-mm-x: 0px;
    --terra-mm-y: 0px;
    --terra-mm-w: 0px;
    --terra-mm-h: 0px;

    position: absolute;
    z-index: 0;
    top: 0;
    left: 0;
    width: var(--terra-mm-w);
    height: var(--terra-mm-h);
    border-radius: var(--terra-mm-hl-radius);
    background: var(--terra-mm-hl-color);
    opacity: 0;
    pointer-events: none;
    transform: translate3d(var(--terra-mm-x), var(--terra-mm-y), 0);
    transition:
        transform var(--terra-mm-dur) var(--terra-mm-ease),
        width var(--terra-mm-dur) var(--terra-mm-ease),
        height var(--terra-mm-dur) var(--terra-mm-ease),
        opacity 0.2s ease;
}

.terra-mega-menu__highlight.is-visible {
    opacity: 1;
}

.terra-mega-menu__highlight.is-instant {
    transition: opacity 0.2s ease;
}

/* Panel content, shared by desktop and mobile. */

.terra-mega-menu__panel {
    color: inherit;
}

.terra-mega-menu__intro {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 18px 14px 14px 16px;
}

.terra-mega-menu .terra-mega-menu__heading {
    margin: 0 0 10px;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.25;
}

.terra-mega-menu .terra-mega-menu__intro-text {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.5;
    opacity: 0.7;
}

.terra-mega-menu .terra-mega-menu__view-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--terra-mm-divider);
    color: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.terra-mega-menu .terra-mega-menu__view-all::after {
    content: "";
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}

.terra-mega-menu .terra-mega-menu__view-all:hover::after,
.terra-mega-menu .terra-mega-menu__view-all:focus-visible::after {
    transform: translateX(3px) rotate(45deg);
}

.terra-mega-menu__tiles {
    min-width: 0;
    padding: 8px;
    border-radius: var(--terra-mm-plate-radius);
    background: var(--terra-mm-plate-bg);
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item {
    align-items: center;
    gap: 14px;
    padding: 10px;
    border-radius: 12px;
    transition:
        background-color 0.2s ease,
        box-shadow 0.2s ease;
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item:hover,
.terra-mega-menu .terra-mega-menu__panel .terra-menu-item:focus-visible {
    background-color: var(--terra-mm-row-hover);
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.06),
        0 0 0 1px rgba(15, 23, 42, 0.05);
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item::after {
    content: "";
    flex: 0 0 auto;
    align-self: center;
    width: 7px;
    height: 7px;
    margin-left: auto;
    border-top: 1.5px solid currentColor;
    border-right: 1.5px solid currentColor;
    opacity: 0;
    transform: translateX(-4px) rotate(45deg);
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item:hover::after,
.terra-mega-menu .terra-mega-menu__panel .terra-menu-item:focus-visible::after {
    opacity: 0.45;
    transform: translateX(0) rotate(45deg);
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item__media {
    padding: 10px;
    border-radius: var(--terra-mm-tile-radius);
    background: var(--terra-mm-tile-bg);
    color: var(--terra-mm-icon-color);
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item__fallback {
    background: transparent;
    font-size: 16px;
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item__title {
    font-size: 15px;
    font-weight: 600;
}

.terra-mega-menu .terra-mega-menu__panel .terra-menu-item__text {
    font-size: 13px;
}

.terra-mega-menu .terra-mega-menu__link-item {
    align-items: flex-start;
    padding: 12px 14px;
}

.terra-mega-menu .terra-mega-menu__link-item::after {
    margin-top: 8px;
    align-self: flex-start;
}

.terra-mega-menu__link-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: break-word;
}

.terra-mega-menu__link-text {
    display: block;
    margin-top: 2px;
    opacity: 0.7;
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: break-word;
}

.terra-mega-menu__empty {
    margin: 0;
    color: #64748b;
    font-size: 13px;
}

/* Desktop: one floating surface and panels in the top layer, so no ancestor can clip them. */

@media (min-width: 1025px) {
    .terra-mega-menu__surface,
    .terra-mega-menu__panel {
        position: fixed;
        inset: auto;
        left: 0;
        top: 0;
        margin: 0;
        border: 0;
        overflow: visible;
        background: transparent;
    }

    .terra-mega-menu__surface {
        width: var(--terra-mm-sw, 0px);
        height: var(--terra-mm-sh, 0px);
        padding: 0;
        border: 1px solid var(--terra-mm-border);
        border-radius: var(--terra-mm-panel-radius);
        background: var(--terra-mm-panel-bg);
        box-shadow:
            0 1px 2px rgba(15, 23, 42, 0.04),
            0 28px 60px -18px rgba(15, 23, 42, 0.3);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translate3d(var(--terra-mm-sx, 0px), var(--terra-mm-sy, 0px), 0) scale(var(--terra-mm-ss, 0.96));
        transform-origin: var(--terra-mm-snx, 50%) 0;
        transition:
            transform var(--terra-mm-dur) var(--terra-mm-ease),
            width var(--terra-mm-dur) var(--terra-mm-ease),
            height var(--terra-mm-dur) var(--terra-mm-ease),
            opacity 0.22s ease;
    }

    .terra-mega-menu__surface.is-shown {
        visibility: visible;
    }

    .terra-mega-menu__surface.is-open {
        --terra-mm-ss: 1;

        opacity: 1;
        pointer-events: auto;
    }

    .terra-mega-menu__surface.is-instant {
        transition: opacity 0.22s ease;
    }

    /* Keeps the pointer inside the menu while it crosses the gap under the bar. */
    .terra-mega-menu__surface::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        height: calc(var(--terra-mm-gap) + 4px);
    }

    .terra-mega-menu__notch {
        display: none;
        position: absolute;
        top: -6px;
        left: calc(var(--terra-mm-snx, 50%) - 6px);
        width: 12px;
        height: 12px;
        border-top: 1px solid var(--terra-mm-border);
        border-left: 1px solid var(--terra-mm-border);
        border-top-left-radius: 3px;
        background: var(--terra-mm-panel-bg);
        transform: rotate(45deg);
        transition: left var(--terra-mm-dur) var(--terra-mm-ease);
    }

    .terra-mega-menu.has-notch .terra-mega-menu__notch {
        display: block;
    }

    .terra-mega-menu__surface.is-instant .terra-mega-menu__notch {
        transition: none;
    }

    .terra-mega-menu__panel {
        --terra-mm-pw: var(--terra-mm-width-catalog);

        width: var(--terra-mm-pw);
        max-width: calc(100vw - 32px);
        padding: 10px;
        visibility: hidden;
        pointer-events: none;
    }

    .terra-mega-menu__panel--links {
        --terra-mm-pw: var(--terra-mm-width-links);
    }

    .terra-mega-menu__panel.is-active,
    .terra-mega-menu__panel.is-leaving {
        visibility: visible;
    }

    .terra-mega-menu__panel.is-active {
        pointer-events: auto;
    }

    .terra-mega-menu__panel-inner {
        display: grid;
        grid-template-columns: var(--terra-mm-intro-w) minmax(0, 1fr);
        gap: 10px;
        max-height: var(--terra-mm-max-h, none);
        overflow-y: auto;
        opacity: 0;
        transform: translate3d(calc(var(--terra-mm-dir, 0) * var(--terra-mm-shift) * -1), var(--terra-mm-lift, 0px), 0);
        transition:
            opacity 0.18s ease,
            transform 0.18s ease;
    }

    .terra-mega-menu__panel.is-active .terra-mega-menu__panel-inner {
        opacity: 1;
        transform: none;
        transition:
            opacity calc(var(--terra-mm-dur) * 0.8) ease 0.05s,
            transform var(--terra-mm-dur) var(--terra-mm-ease);
    }

    .terra-mega-menu__panel.is-leaving .terra-mega-menu__panel-inner {
        opacity: 0;
        transform: translate3d(calc(var(--terra-mm-dir, 0) * var(--terra-mm-shift)), 0, 0);
        transition:
            opacity 0.16s ease,
            transform 0.2s ease;
    }

    .terra-mega-menu__panel .terra-menu-list {
        --terra-menu-track: var(--terra-menu-cols, 2);

        gap: 2px;
    }
}

/* Tablet and phone: a menu button and a stacked accordion. */

@media (max-width: 1024px) {
    .terra-mega-menu__surface {
        display: none;
    }

    .terra-mega-menu__toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 8px;
        background: transparent;
        box-shadow: none;
        color: inherit;
        cursor: pointer;
    }

    .terra-mega-menu .terra-mega-menu__toggle:focus-visible {
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }

    .terra-mega-menu__toggle-icon {
        position: relative;
        display: block;
        width: 22px;
        height: 16px;
    }

    .terra-mega-menu__toggle-icon span {
        position: absolute;
        left: 0;
        width: 100%;
        height: 2px;
        border-radius: 1px;
        background: currentColor;
    }

    .terra-mega-menu__toggle-icon span:nth-child(1) {
        top: 0;
    }

    .terra-mega-menu__toggle-icon span:nth-child(2) {
        top: 7px;
    }

    .terra-mega-menu__toggle-icon span:nth-child(3) {
        top: 14px;
    }

    .terra-mega-menu.is-menu-open .terra-mega-menu__toggle-icon span:nth-child(1) {
        top: 7px;
        transform: rotate(45deg);
    }

    .terra-mega-menu.is-menu-open .terra-mega-menu__toggle-icon span:nth-child(2) {
        opacity: 0;
    }

    .terra-mega-menu.is-menu-open .terra-mega-menu__toggle-icon span:nth-child(3) {
        top: 7px;
        transform: rotate(-45deg);
    }

    .terra-mega-menu__bar {
        display: none;
        background: var(--terra-mm-mobile-bg);
    }

    .terra-mega-menu.is-menu-open .terra-mega-menu__bar {
        display: block;
    }

    .terra-mega-menu__highlight {
        display: none;
    }

    .terra-mega-menu__list {
        flex-direction: column;
        align-items: stretch;
    }

    .terra-mega-menu .terra-mega-menu__list .terra-mega-menu__trigger {
        width: 100%;
        min-height: 48px;
        white-space: normal;
    }

    .terra-mega-menu__caret {
        display: block;
    }

    .terra-mega-menu__panel {
        display: none;
        padding: 4px 12px 16px;
    }

    .terra-mega-menu__item.is-open > .terra-mega-menu__panel {
        display: block;
    }

    .terra-mega-menu__panel-inner {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .terra-mega-menu__intro {
        display: contents;
    }

    .terra-mega-menu .terra-mega-menu__heading {
        order: 1;
        margin: 8px 4px 0;
    }

    .terra-mega-menu .terra-mega-menu__intro-text {
        order: 2;
        margin: -6px 4px 0;
    }

    .terra-mega-menu__tiles {
        order: 3;
    }

    .terra-mega-menu .terra-mega-menu__view-all {
        order: 4;
        margin: 0 4px;
        padding-top: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .terra-mega-menu__highlight,
    .terra-mega-menu__highlight.is-instant {
        transition: none;
    }

    .terra-mega-menu__surface,
    .terra-mega-menu__surface.is-instant {
        --terra-mm-ss: 1;

        transition: opacity 0.12s linear;
    }

    .terra-mega-menu__notch {
        transition: none;
    }

    .terra-mega-menu__panel-inner,
    .terra-mega-menu__panel.is-active .terra-mega-menu__panel-inner,
    .terra-mega-menu__panel.is-leaving .terra-mega-menu__panel-inner {
        transform: none;
        transition: opacity 0.12s linear;
    }
}
