/*
 * Product category mega menu.
 * Desktop: a rail of root categories on the right (RTL start) with the selected
 * branch spread into columns beside it. Mobile: a drill-down stack inside the
 * existing drawer. Both are built from the same shell tokens as the header.
 */

/* ── Desktop ────────────────────────────────────────────────────────────── */

/* The dropdown spans the page container, so it anchors to the header row rather
   than to the nav item it hangs from. */
.site-header__inner {
    position: relative;
}

.site-nav__item.mega-menu {
    position: static;
}

.mega-menu__trigger {
    cursor: pointer;
}

.mega-menu.is-open .site-nav__caret,
.mega-menu:not(.is-js):hover .site-nav__caret,
.mega-menu:not(.is-js):focus-within .site-nav__caret {
    color: var(--ava-primary-1000);
    transform: rotate(180deg);
}

.mega-menu__dropdown {
    position: absolute;
    z-index: 140;
    inset-block-start: 100%;
    inset-inline: 0;
    padding: 8px;
    border: 1px solid var(--ava-primary-200);
    border-radius: var(--ava-radius-md);
    background: #fff;
    box-shadow: 0 18px 44px -22px rgba(50, 52, 143, .34);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity .14s ease, transform .14s ease, visibility .14s;
}

/* Carries the pointer across the gap between the header and the dropdown. */
.mega-menu__dropdown::before {
    position: absolute;
    inset-block-start: -20px;
    inset-inline: 0;
    height: 20px;
    content: "";
}

.mega-menu.is-open .mega-menu__dropdown,
.mega-menu:not(.is-js):hover .mega-menu__dropdown,
.mega-menu:not(.is-js):focus-within .mega-menu__dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.mega-menu__inner {
    position: relative;
    display: flex;
    /* A steady height keeps the panel from jumping as branches are switched. */
    min-height: 296px;
    max-height: min(68vh, 520px);
}

.mega-menu__rail {
    display: grid;
    flex: 0 0 248px;
    align-content: start;
    gap: 2px;
    margin: 0;
    padding: 0;
    padding-inline-end: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--ava-primary-400) transparent;
    border-inline-end: 1px solid var(--ava-primary-200);
    list-style: none;
}

/* site.css styles every anchor inside .site-nav as a stacked nav entry, so each
   link in here restates the layout it actually needs. */
.mega-menu .mega-menu__dropdown a + a {
    border-inline-start: 0;
}

.mega-menu .mega-menu__dropdown a span {
    color: inherit;
    font: inherit;
}

.mega-menu .mega-menu__rail-link {
    position: static;
    min-height: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--ava-radius-sm);
    color: #1d1e61;
    font-size: 14px;
    line-height: 24px;
    font-weight: 500;
    letter-spacing: -.3px;
    text-decoration: none;
    outline-offset: 0;
    transition: background-color .14s ease, color .14s ease;
}

.mega-menu__rail-title {
    /* Long Persian names wrap to a second line rather than being cut short. */
    display: -webkit-box;
    min-width: 0;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.mega-menu__rail-caret {
    width: 13px;
    height: 13px;
    flex: 0 0 13px;
    opacity: 0;
    /* Points along the reading direction, so toward the panel on the left. */
    transform: rotate(90deg);
    transition: opacity .14s ease;
}

.mega-menu__rail-item:not(.mega-menu__rail-item--extra) + .mega-menu__rail-item--extra {
    margin-block-start: 6px;
    padding-block-start: 6px;
    border-block-start: 1px solid var(--ava-primary-200);
}

.mega-menu .mega-menu__rail-item--extra .mega-menu__rail-link {
    color: var(--ava-neutral-500);
    font-size: 13px;
    font-weight: 400;
}

.mega-menu .mega-menu__rail-item.is-active > .mega-menu__rail-link,
.mega-menu .mega-menu__rail-link:hover,
.mega-menu .mega-menu__rail-link:focus-visible {
    color: var(--ava-primary-1000);
    background: var(--ava-primary-200);
}

.mega-menu .mega-menu__rail-item.is-active > .mega-menu__rail-link {
    font-weight: 600;
}

.mega-menu__rail-item.is-active > .mega-menu__rail-link .mega-menu__rail-caret,
.mega-menu__rail-link:hover .mega-menu__rail-caret,
.mega-menu__rail-link:focus-visible .mega-menu__rail-caret {
    opacity: 1;
}

.mega-menu__panel {
    position: absolute;
    inset-block: 0;
    /* The rail holds the inline start (the right in RTL); the branch fills the rest. */
    inset-inline-start: 248px;
    inset-inline-end: 0;
    padding: 4px 16px 12px;
    /* Hidden branches leave the layout entirely, so a closed menu never holds
       focusable links and switching branches cannot flicker. */
    display: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--ava-primary-400) transparent;
}

.mega-menu__rail-item.is-active > .mega-menu__panel {
    display: block;
}

.mega-menu .mega-menu__view-all {
    position: static;
    min-height: 0;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    /* Pulled back by its own padding so the label lines up with the columns. */
    margin-block-end: 12px;
    margin-inline-start: -10px;
    padding: 6px 10px;
    border-radius: var(--ava-radius-sm);
    color: var(--ava-primary-1000);
    font-size: 13px;
    line-height: 22px;
    font-weight: 600;
    letter-spacing: -.2px;
    text-decoration: none;
    outline-offset: 0;
    transition: background-color .14s ease, color .14s ease;
}

.mega-menu__view-all svg {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
}

.mega-menu .mega-menu__view-all:hover,
.mega-menu .mega-menu__view-all:focus-visible {
    color: var(--ava-secondary-900);
    background: var(--ava-neutral-100);
}

.mega-menu__empty {
    margin: 0;
    padding-inline-start: 0;
    color: var(--ava-neutral-500);
    font-size: 13px;
    line-height: 24px;
}

.mega-menu__groups {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
    align-items: start;
    gap: 18px 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mega-menu__group {
    min-width: 0;
}

.mega-menu__branch {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mega-menu__branch--level-0 {
    margin-block-start: 2px;
}

.mega-menu__branch--level-1,
.mega-menu__branch--level-2 {
    padding-inline-start: 10px;
}

.mega-menu .mega-menu__node {
    position: static;
    min-height: 0;
    display: block;
    padding-inline: 0;
    border-radius: 6px;
    text-decoration: none;
    outline-offset: 0;
    overflow-wrap: anywhere;
    transition: color .14s ease;
}

.mega-menu .mega-menu__node--level-0 {
    padding: 2px 0 4px;
    color: #1d1e61;
    font-size: 14px;
    line-height: 24px;
    font-weight: 600;
    letter-spacing: -.3px;
}

.mega-menu .mega-menu__node--level-1 {
    padding: 3px 0;
    color: var(--ava-neutral-600);
    font-size: 13px;
    line-height: 22px;
    font-weight: 400;
    letter-spacing: -.2px;
}

.mega-menu .mega-menu__node--level-2 {
    padding: 2px 0;
    color: var(--ava-neutral-500);
    font-size: 12px;
    line-height: 20px;
    font-weight: 400;
    letter-spacing: -.1px;
}

.mega-menu .mega-menu__node:hover,
.mega-menu .mega-menu__node:focus-visible {
    color: var(--ava-primary-1000);
}

.mega-menu .mega-menu__node--level-0:hover,
.mega-menu .mega-menu__node--level-0:focus-visible {
    color: var(--ava-secondary-900);
}

/* Without the script the first branch shows until another root is hovered. */
.mega-menu:not(.is-js) .mega-menu__rail-item:hover > .mega-menu__panel,
.mega-menu:not(.is-js) .mega-menu__rail-item:focus-within > .mega-menu__panel {
    display: block;
}

.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:hover) .mega-menu__rail-item.is-active:not(:hover) > .mega-menu__panel,
.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:focus-within) .mega-menu__rail-item.is-active:not(:focus-within) > .mega-menu__panel {
    display: none;
}

.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:hover) .mega-menu__rail-item.is-active:not(:hover) > .mega-menu__rail-link,
.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:focus-within) .mega-menu__rail-item.is-active:not(:focus-within) > .mega-menu__rail-link {
    color: #1d1e61;
    background: transparent;
    font-weight: 500;
}

.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:hover) .mega-menu__rail-item.is-active:not(:hover) .mega-menu__rail-caret,
.mega-menu:not(.is-js) .mega-menu__rail:has(.mega-menu__rail-item:focus-within) .mega-menu__rail-item.is-active:not(:focus-within) .mega-menu__rail-caret {
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .mega-menu__dropdown,
    .mega-menu__rail-link,
    .mega-menu__rail-caret,
    .mega-menu__view-all,
    .mega-menu__node {
        transition: none;
    }
}

/* ── Mobile drill-down ──────────────────────────────────────────────────── */

.mega-drawer {
    display: none;
}

@media (max-width: 1199px) {
    body .mega-drawer {
        display: block;
        margin-block-end: 4px;
    }

    body .mega-drawer__open {
        display: none;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
        min-height: 64px;
        padding: 0 8px;
        border: 0;
        border-block-end: 1px solid var(--ava-neutral-100);
        color: var(--ava-primary-1000);
        background: none;
        font-size: 15px;
        font-weight: 600;
        text-align: start;
        cursor: pointer;
    }

    body .mega-drawer.is-js .mega-drawer__open {
        display: flex;
    }

    body .mega-drawer__open svg {
        width: 16px;
        height: 16px;
        flex: 0 0 16px;
        color: var(--ava-neutral-400);
    }

    /* The stack takes over the drawer body instead of floating above it, so the
       drawer keeps its own scrolling and its logo header stays reachable. */
    body .mobile-drawer__links.has-mega-open > *:not(.mega-drawer) {
        display: none;
    }

    body .mega-drawer.is-js .mega-drawer__stack {
        display: none;
    }

    body .mega-drawer.is-js.is-open .mega-drawer__stack {
        display: block;
    }

    body .mega-drawer.is-js.is-open .mega-drawer__open {
        display: none;
    }

    body .mega-drawer__bar {
        position: sticky;
        z-index: 1;
        inset-block-start: 0;
        display: none;
        align-items: center;
        gap: 10px;
        min-height: 52px;
        margin-block-end: 4px;
        border-block-end: 1px solid var(--ava-neutral-100);
        background: #fff;
    }

    body .mega-drawer.is-js .mega-drawer__bar {
        display: flex;
    }

    body .mega-drawer__back {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-height: 40px;
        padding: 0 10px 0 12px;
        border: 1px solid var(--ava-neutral-200);
        border-radius: 12px;
        color: var(--ava-primary-1000);
        background: #fff;
        font-size: 13px;
        font-weight: 500;
        cursor: pointer;
    }

    body .mega-drawer__back svg {
        width: 14px;
        height: 14px;
        flex: 0 0 14px;
    }

    body .mega-drawer__current {
        min-width: 0;
        margin: 0;
        overflow: hidden;
        color: var(--ava-neutral-800);
        font-size: 14px;
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body .mega-drawer__level {
        display: grid;
        align-content: start;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    body .mega-drawer.is-js .mega-drawer__level {
        display: none;
    }

    body .mega-drawer.is-js .mega-drawer__level.is-current {
        display: grid;
        animation: mega-drawer-forward .18s ease-out both;
    }

    body .mega-drawer.is-js .mega-drawer__level.is-current.is-back {
        animation-name: mega-drawer-back;
    }

    body .mega-drawer__heading {
        padding: 14px 8px 6px;
        color: var(--ava-neutral-400);
        font-size: 12px;
        font-weight: 600;
    }

    body .mega-drawer.is-js .mega-drawer__heading {
        display: none;
    }

    body .mega-drawer__item {
        display: flex;
        align-items: center;
        gap: 4px;
        border-block-end: 1px solid var(--ava-neutral-100);
    }

    body .mega-drawer__item:last-child {
        border-block-end: 0;
    }

    body .mega-drawer .mega-drawer__link {
        min-height: 56px;
        display: flex;
        flex: 1 1 auto;
        align-items: center;
        min-width: 0;
        margin: 0;
        padding-inline: 8px;
        color: var(--ava-neutral-800);
        font-size: 14px;
        font-weight: 500;
        text-decoration: none;
        overflow-wrap: anywhere;
    }

    body .mega-drawer .mega-drawer__link--all {
        color: var(--ava-primary-1000);
        font-weight: 600;
    }

    body .mega-drawer__into {
        width: 40px;
        height: 40px;
        display: grid;
        flex: 0 0 40px;
        place-items: center;
        margin: 0;
        padding: 0;
        border: 1px solid var(--ava-neutral-200);
        border-radius: 12px;
        color: var(--ava-primary-1000);
        background: #fff;
        cursor: pointer;
    }

    body .mega-drawer__into svg {
        width: 16px;
        height: 16px;
    }

    body .mega-drawer:not(.is-js) .mega-drawer__into {
        display: none;
    }
}

@keyframes mega-drawer-forward {
    from { opacity: .4; transform: translateX(-14px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes mega-drawer-back {
    from { opacity: .4; transform: translateX(14px); }
    to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
    body .mega-drawer.is-js .mega-drawer__level.is-current {
        animation: none;
    }
}
