/* ============================================
   CUSTOM CATALOG MENU — MEGA DROPDOWN
   ============================================ */

/* --- Контейнер --- */
.custom-catalog-menu {
    position: relative;
    width: 100%;
    background: #ffffff;
    z-index: 1000;
    font-family: inherit;
}

.custom-catalog-menu *,
.custom-catalog-menu *::before,
.custom-catalog-menu *::after {
    box-sizing: border-box;
}

/* --- Первый уровень --- */
.menu-level-1 {
    display: flex;
    gap: 20px;
    flex-wrap: nowrap;
    align-items: stretch;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.menu-level-1 > .menu-item {
    position: static; /* Ключевое! Dropdown будет относительно .custom-catalog-menu */
}

.menu-level-1 > .menu-item > .level-1-link {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: #000000;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    transition: background-color 0.2s ease, color 0.2s ease;
    height: 100%;
    box-sizing: border-box;
}

.menu-item.level-1.has-children {
    margin: 0;
}

.menu-level-1 > .menu-item > .level-1-link:hover,
.menu-level-1 > .menu-item:hover > .level-1-link,
.menu-level-1 > .menu-item.is-open > .level-1-link {
    background-color: #f5f5f5;
    color: #000000;
}

.menu-level-1 > .menu-item.active > .level-1-link {
    color: #000000;
}

/* Стрелка */
.menu-arrow {
    flex-shrink: 0;
    transition: transform 0.25s ease;
    margin-left: 2px;
}

.menu-level-1 > .menu-item:hover > .level-1-link .menu-arrow,
.menu-level-1 > .menu-item.is-open > .level-1-link .menu-arrow {
    transform: rotate(180deg);
}

/* Картинка 1-го уровня */
.level-1-img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    flex-shrink: 0;
}

/* --- Второй уровень (dropdown) --- */
.menu-level-2 {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: #ffffff;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
    border-top: 1px solid #eeeeee;
    padding: 28px 32px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
    z-index: 999;
    pointer-events: none;
}

/* Показ dropdown при наведении (десктоп) */
.menu-level-1 > .menu-item:hover > .menu-level-2,
.menu-level-1 > .menu-item.is-open > .menu-level-2 {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0s;
}

.menu-level-2 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.level-2-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: #333333;
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    border-radius: 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.level-2-link:hover {
    background-color: #f2f2f2;
    color: #000000;
}

.level-2-link.active {
    background-color: #f0f0f0;
    color: #000000;
    font-weight: 500;
}

.level-2-img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: #f5f5f5;
    margin-right: 0;
    margin-left: 0;
}

.mobile-back-button {
    display: none
}

@media (max-width: 1024px) {
    .menu-level-1 {
        flex-wrap: wrap;
    }

    .menu-level-1 > .menu-item > .level-1-link {
        padding: 12px 14px;
        font-size: 14px;
    }

    .menu-level-2 {
        padding: 20px 16px;
    }

    .menu-level-2 {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 6px 16px;
    }
}

/* --- Адаптив: мобильные --- */
@media (max-width: 767px) {
    .mobile-catalog-bar {
        width: 100%;
        max-width: 100%;
        overflow-x: clip; 
        overflow-y: visible; 
        background: #fff;
        border-bottom: 1px solid #e5e5e5;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
        position: relative;
        z-index: 99;
    }
    
    .mobile-catalog-bar .menu-level-1 {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scrollbar-width: none;
        padding: 12px 16px;
        gap: 12px;
    }
    
    .mobile-catalog-bar .menu-level-1::-webkit-scrollbar {
        display: none;
    }
    
    .mobile-catalog-bar .menu-item.level-1 {
        flex: 0 0 auto;
    }

    .menu-level-2 .menu-item.level-2::before {
        content: none;
    } 
    
    .menu-level-2 .mobile-back-button::before {
        content: none;
    }

    .mobile-catalog-bar .menu-item.level-1:before {
        content: none;
    }

    .mobile-catalog-bar .menu-level-2 {
        position: absolute;
        top: 100%;
        left: 0;
        overflow-x: hidden; 
        right: auto;  
        max-width: 100%; 
        width: 100%;
        height: 100vh;
        padding: 0px 20px 20px;
        margin: 0;
        box-shadow: none;
        border-top: 2px solid #000;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transform: translateX(100%);
        transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .mobile-catalog-bar .menu-level-2 .menu-level-2-wrapper {
        display: flex; 
        flex-wrap: wrap;
        max-width: 100%; 
    }

    .mobile-catalog-bar .mobile-back-button {
        display: block;
        margin: 0;
        list-style: none;
        padding: 12px 0;
        margin-bottom: 12px;
        border-bottom: 1px solid #e5e5e5;
        cursor: pointer;
    }
    
    .mobile-catalog-bar .mobile-back-button .back-text {
        font-size: 15px;
        font-weight: 600;
        color: #000;
        display: block;
    }
    
    .mobile-catalog-bar .mobile-back-button:active {
        opacity: 0.7;
    }
    
    .mobile-catalog-bar .menu-item.level-2 {
        display: flex;
        flex-direction: row;
        margin: 0;
        max-width: 100%;  
    }
    
    .mobile-catalog-bar .menu-link.level-2-link {
        max-width: 100%;  
        display: flex;
        flex-direction: row;
        align-items: center;
        width: 100%;
        max-width: 100%; 
        padding: 12px;
        background: #f9f9f9;
        border-radius: 8px;
        color: #333;
        text-decoration: none;
    }
    
    .mobile-catalog-bar .menu-link.level-2-link:active {
        background: #eee;
    }
    
    .mobile-catalog-bar .menu-img.level-2-img {
        width: 48px;
        height: 48px;
        object-fit: cover;
        border-radius: 8px;
        flex-shrink: 0;
        margin-right: 20px;
        background: #f0f0f0;
    }
    
    .mobile-catalog-bar .menu-item.level-2 .menu-text {
        font-size: 14px;
        line-height: 1.3;
        text-align: left;
        color: #333;
    }
    
    .custom-catalog-menu-overlay {
        display: none !important;
    }

    .menu-level-1 > .menu-item:hover > .menu-level-2, .menu-level-1 > .menu-item.is-open > .menu-level-2 {
        opacity: 0;
        transform: translateY(0);
        pointer-events: auto;
        transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0s;
    }

    .mobile-catalog-bar .menu-item.level-1.is-open > .menu-level-2 {
        opacity: 1;
        visibility: visible;
        transform: translateX(0);
    }

    .menu-level-1 > .menu-item > .level-1-link:hover, .menu-level-1 > .menu-item:hover {
        background-color: #fff;
    }

    .menu-level-1 > .menu-item.is-open > .level-1-link {
        background-color: #f5f5f5;
    }

    .menu-level-1 > .menu-item:hover > .level-1-link .menu-arrow {
        transform: none;
    }
    .menu-level-1 > .menu-item.is-open > .level-1-link .menu-arrow {
        transform: rotate(180deg);
    }
}