﻿/* Theme-aware mobile-first */
#top-menu-list .mobile-megamenu,
#top-menu-list li.dropdown > ul {
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    padding: 0;
    background: var(--surface-color);
    color: var(--default-color);
    box-shadow: none;
    transition: max-height 320ms ease, opacity 200ms ease, visibility 200ms;
}

/* Mobile open state */
@media (max-width: 991px) {
    #top-menu-list li.open > .mobile-megamenu,
    #top-menu-list li.open > ul,
    #top-menu-list li.open > ul.mobile-megamenu,
    #top-menu-list li.dropdown.open > ul {
        max-height: 60vh;
        opacity: 1;
        visibility: visible;
        overflow: auto;
        padding: 0.25rem 0;
        box-shadow: var(--shadow-md);
    }

    #top-menu-list > li {
        display: block;
    }

        #top-menu-list > li > a {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.75rem 1rem;
            min-height: 44px;
            color: var(--default-color);
        }

    #top-menu-list li.open > .mobile-megamenu {
        max-height: calc(60vh - 2rem);
        overflow-y: auto;
    }
}

/* Desktop */
@media (min-width: 992px) {
    #top-menu-list .mobile-megamenu {
        max-height: 0;
        opacity: 0;
        visibility: hidden;
        overflow: hidden;
        transition: none;
    }

    #top-menu-list li.open > .desktop-megamenu {
        display: block;
        background: var(--surface-color);
        color: var(--default-color);
        box-shadow: var(--shadow-md);
    }

    .desktop-megamenu {
        position: absolute;
        left: 0;
        top: 100%;
        z-index: 1000;
        display: none;
    }
}

#top-menu-list a:hover {
    color: var(--accent-color);
}


/* Mobile only fix */
@media (max-width: 991px) {
    #top-menu-list .mobile-megamenu,
    #top-menu-list li.dropdown > ul {
        max-height: 0;
        opacity: 0;
        visibility: hidden;
        overflow: hidden;
        padding: 0;
        margin: 0;
        list-style: none;
        background: var(--surface-color);
        color: var(--default-color);
        box-shadow: none;
        transition: max-height 320ms ease, opacity 200ms ease, visibility 200ms ease, padding 200ms ease;
        display: block;
    }

        #top-menu-list > li,
        #top-menu-list li.dropdown,
        #top-menu-list .mobile-megamenu li {
            display: block;
            width: 100%;
        }

            #top-menu-list > li > a,
            #top-menu-list li.dropdown > a,
            #top-menu-list .mobile-megamenu li > a,
            #top-menu-list li.dropdown > ul li > a {
                display: flex;
                align-items: center;
                justify-content: space-between;
                width: 100%;
                min-height: 44px;
                padding: 0.75rem 1rem;
                color: var(--default-color);
            }

    #top-menu-list .toggle-dropdown,
    #top-menu-list .bi-chevron-down {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 36px;
        min-height: 36px;
        cursor: pointer;
        flex-shrink: 0;
    }

    #top-menu-list li.open > .mobile-megamenu,
    #top-menu-list li.open > ul,
    #top-menu-list li.open > ul.mobile-megamenu,
    #top-menu-list li.dropdown.open > ul {
        max-height: 60vh;
        opacity: 1;
        visibility: visible;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0.25rem 0;
        box-shadow: var(--shadow-md);
    }

    #top-menu-list li.open > .mobile-megamenu {
        max-height: calc(60vh - 2rem);
    }

    #top-menu-list li.open > a .toggle-dropdown,
    #top-menu-list li.open > a .bi-chevron-down {
        transform: rotate(180deg);
        transition: transform 0.25s ease;
    }
}

/* ============================================================
   Mobile storefront preferences
   INSIDE the hamburger navigation list
   ============================================================ */

@media (max-width: 991px) {

    #top-menu-list > li.mobile-storefront-preferences {
        display: block;
        width: 100%;
        margin: 0;
        padding: 0 1rem 1rem;
        list-style: none;
        background: var(--nav-mobile-background-color, var(--surface-color));
        color: var(--default-color);
    }

    .mobile-preference-divider {
        height: 1px;
        margin: 0.5rem 0 0.35rem;
        background-color: var(--border-color);
    }

    .mobile-preference-row {
        width: 100%;
        border-bottom: 1px solid var(--border-color);
    }

        .mobile-preference-row:last-child {
            border-bottom: 0;
        }

    .mobile-preference-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        width: 100%;
        min-height: 48px;
        padding: 0.75rem 0.25rem;
        border: 0;
        border-radius: var(--radius-md);
        background: transparent;
        color: var(--default-color);
        font: inherit;
        text-align: start;
        cursor: pointer;
        transition: color 0.18s ease, background-color 0.18s ease;
    }

        .mobile-preference-toggle:hover,
        .mobile-preference-toggle:focus {
            color: var(--accent-color);
            background-color: var(--accent-soft);
            outline: none;
        }

        .mobile-preference-toggle:focus-visible {
            outline: 2px solid var(--accent-color);
            outline-offset: 2px;
        }

    .mobile-preference-label,
    .mobile-preference-current {
        display: inline-flex;
        align-items: center;
    }

    .mobile-preference-label {
        gap: 0.65rem;
        font-weight: 600;
    }

        .mobile-preference-label > i {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 1.25rem;
            color: var(--accent-color);
            font-size: 1rem;
        }

    .mobile-preference-current {
        gap: 0.45rem;
        color: var(--muted-color);
        font-size: 0.9rem;
        font-weight: 500;
    }

        .mobile-preference-current .bi-chevron-down {
            font-size: 0.75rem;
            transition: transform 0.2s ease;
        }

    .mobile-preference-toggle[aria-expanded="true"]
    .mobile-preference-current .bi-chevron-down {
        transform: rotate(180deg);
    }

    .mobile-preference-panel {
        position: static !important;
        inset: auto !important;
        transform: none !important;
        float: none !important;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0.1rem 0 0.7rem;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

        .mobile-preference-panel[hidden] {
            display: none !important;
        }

    #mobileCurrencyMenu,
    #mobileLanguageMenu {
        position: static !important;
        width: 100%;
        max-height: min(260px, 38vh);
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0.15rem 0;
        background: transparent;
        scrollbar-width: thin;
        scrollbar-color: color-mix(in srgb, var(--accent-color), transparent 35%) transparent;
    }

    .mobile-preference-option {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        width: 100%;
        min-height: 42px;
        margin: 0.15rem 0;
        padding: 0.6rem 0.75rem;
        border: 1px solid transparent;
        border-radius: var(--radius-md);
        background: transparent;
        color: var(--default-color);
        font: inherit;
        font-size: 0.9rem;
        text-align: start;
        cursor: pointer;
        transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
    }

        .mobile-preference-option:hover,
        .mobile-preference-option:focus {
            color: var(--accent-color);
            background-color: var(--accent-soft);
            outline: none;
        }

        .mobile-preference-option.active {
            color: var(--accent-color);
            background-color: var(--accent-soft-2);
            border-color: color-mix(in srgb, var(--accent-color), transparent 55%);
            font-weight: 600;
        }

            .mobile-preference-option.active .bi-check2 {
                color: var(--accent-color);
                font-size: 1rem;
            }

    .mobile-preference-loading {
        padding: 0.65rem 0.75rem;
        color: var(--muted-color);
        font-size: 0.85rem;
    }

    #mobileCurrencyMenu::-webkit-scrollbar,
    #mobileLanguageMenu::-webkit-scrollbar {
        width: 7px;
    }

    #mobileCurrencyMenu::-webkit-scrollbar-thumb,
    #mobileLanguageMenu::-webkit-scrollbar-thumb {
        border-radius: 999px;
        background: color-mix(in srgb, var(--accent-color), transparent 35%);
    }

    html[dir="rtl"] .mobile-preference-toggle,
    html[dir="rtl"] .mobile-preference-option {
        text-align: right;
    }
}

@media (min-width: 992px) {
    #top-menu-list > li.mobile-storefront-preferences {
        display: none !important;
    }
}
