/** 
 * Стили для popup категорий
 */

/* Стили скроллбаров */
.mobile-categories-popup ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.mobile-categories-popup ::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.mobile-categories-popup ::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.mobile-categories-popup ::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Для Firefox */
.mobile-categories-popup * {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

.mobile-categories-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10005 !important;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    overflow: hidden;
}

.mobile-categories-popup.active {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Для мобильных устройств popup должен занимать весь экран */
@media (max-width: 768px) {
    .mobile-categories-popup.active {
        display: block !important;
    }
    
    .mobile-categories-popup.active .popup-content-wrapper {
        position: absolute !important;
        inset: 0 !important;
    }
}

.mobile-categories-popup.active ~ .mobile-navbar-wrapper {
    z-index: 10006;
}


.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10004;
}

.popup-content-wrapper {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10005 !important;
    pointer-events: auto;
}

.popup-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    padding: 16px 14px 80px 16px;
    min-height: 0;
}

/* Верхний контейнер */
.popup-header-container {
    position: relative;
    z-index: 1000000 !important;
    background: rgba(211, 227, 140, 1);
    padding: 12px 16px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 0;
    flex-shrink: 0;
}

/* Первая строка: Шорткод язык и Кнопка закрытия */
.popup-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

/* Для PC версии кнопка закрытия всегда справа */
@media (min-width: 769px) {
    .popup-header-row {
        justify-content: flex-end;
    }
}

.popup-language-shortcode {
    flex: 1;
    min-width: 0;
}

.popup-language-shortcode * {
    max-width: 100%;
}

.popup-close {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    bottom: auto !important;
    z-index: 1000001 !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    flex-shrink: 0;
    border: none;
    background: rgba(255, 255, 255, 0.95) !important;
    border-radius: 50% !important;
    color: #000 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    padding: 0 !important;
    margin: 0;
    direction: ltr !important;
}

.popup-close:hover {
    background: rgba(255, 255, 255, 1) !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.popup-close:active {
    transform: scale(0.95);
}

.popup-close svg {
    width: 20px !important;
    height: 20px !important;
    stroke: #000 !important;
    stroke-width: 2.5 !important;
    fill: none !important;
    display: block !important;
    opacity: 1 !important;
}

/* Вторая строка: Поиск */
.popup-search-row {
    width: 100%;
}

.popup-search {
    width: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
}

.popup-search * {
    max-width: 100%;
}

/* Рекламные баннеры */
.popup-banners {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 24px;
}

.banner-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
}

.banner-link {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
}

.banner-item img,
.banner-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    color: #fff;
    padding: 8px;
    font-size: 12px;
    font-weight: 600;
}

/* Для PC версии увеличиваем размер текста баннеров */
@media (min-width: 769px) {
    .banner-title {
        font-size: 16px;
        padding: 12px;
    }
}

/* Категории */
.popup-categories {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.category-item {
    position: relative;
}

.category-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #333;
    border-radius: 8px;
    transition: background 0.2s;
}

.category-link:active {
    background: #f5f5f5;
}

.category-image {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5 !important;
    position: relative;
}

.category-image-label {
    position: absolute;
    top: 10px;
    left: 13px;
    font-size: 10px;
    color: #000000;
    line-height: 1.2;
    max-width: calc(100% - 40px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: pre-line;
    z-index: 2;
}

.category-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.category-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #999;
}

.category-name {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
}

.category-arrow {
    position: absolute;
    top: 8px;
    right: 8px;
    color: #ffffff;
    background: orange;
    border-radius: 12px;
}

/* Дочерние категории */
.category-children {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 1000000 !important;
    padding: 0;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: none;
    flex-direction: column;
}

.category-children.active {
    transform: translateX(0);
    display: flex;
}

.children-header {
    position: relative;
    top: 0;
    background: #fff;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    margin-bottom: 0;
    z-index: 10;
    flex-shrink: 0;
}

.children-back {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    padding: 8px 0;
}

.children-list {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    padding-top: 16px;
    min-height: 0;
    max-height: 100%;
    padding-bottom: 160px;
}

.child-category-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
    text-decoration: none;
    color: #333;
    transition: background 0.2s;
    position: relative;
}

.child-category-item.has-children {
    padding-right: 40px;
}

.child-category-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    flex-shrink: 0;
}

.child-category-wrapper {
    position: relative;
}

.child-category-children {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 1000001 !important;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    pointer-events: auto;
    display: none;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.child-category-children.active {
    transform: translateX(0);
    display: flex;
}

.child-category-item:active {
    background: #f0f0f0;
}

/* Стиль для элемента "Все [категория]" в мобильной версии */
.child-category-all-item {
    background: #e8f5e9;
    border: 1px solid #4caf50;
}

.child-category-all-item .child-name {
    font-weight: 600;
    color: #2e7d32;
}

.child-category-all-item:active {
    background: #c8e6c9;
}

.child-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    position: relative;
    min-width: 60px;
    min-height: 60px;
}

.child-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

.child-image .category-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #999;
    position: absolute;
    top: 0;
    left: 0;
}

.child-name {
    font-size: 14px;
    font-weight: 500;
    flex: 1;
}

/* Адаптация для PC версии */
@media (min-width: 769px) {
    .mobile-categories-popup.active {
        /* На PC popup может быть модальным окном по центру экрана */
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-categories-popup.active .popup-content-wrapper {
        /* Ограничиваем ширину на PC и центрируем */
        position: relative !important;
        inset: auto !important;
        max-width: 1200px;
        max-height: 85vh;
        overflow: hidden;
        width: 90%;
        margin: auto;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        transform: translateY(0);
    }
    
    .popup-content-desktop {
        display: flex;
        flex-direction: column;
        height: auto; /* Изменено с 100% на auto для отображения всех категорий */
        max-height: 85vh; /* Ограничиваем только максимальную высоту popup */
        padding: 0 !important;
        overflow-y: hidden; /* Скроллим только правую колонку со списком подкатегорий */
    }
    
    /* Двухколоночный layout для PC */
    .popup-desktop-layout {
        display: flex;
        flex: 1;
        min-height: 0;
        border-bottom: 1px solid #ddd;
        overflow: visible; /* Убираем ограничения для отображения всех категорий */
    }
    
    /* Левая колонка: Родительские категории */
    .popup-parent-categories {
        width: 300px;
        min-width: 300px;
        border-right: 1px solid #ddd;
        background: #f9f9f9;
        overflow-y: auto;
        padding: 20px;
    }
    
    .popup-section-title {
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 15px 0;
        color: #333;
    }
    
    .parent-categories-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    .parent-category-item {
        margin-bottom: 8px;
    }
    
    .parent-category-link {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 7px;
        background: #fff;
        border-radius: 8px;
        text-decoration: none;
        color: #333;
        transition: all 0.2s ease;
        border: 1px solid transparent;
    }
    
    .parent-category-link:hover {
        background: #f0f0f0;
        border-color: #ddd;
    }
    
    .parent-category-item.active .parent-category-link {
        background: #f5ede8;
        border-color: #af634c;
        color: #7d4e2e;
    }
    
    .parent-category-image {
        width: 40px;
        height: 40px;
        object-fit: cover;
        border-radius: 6px;
        flex-shrink: 0;
    }
    
    .parent-category-name {
        flex: 1;
        font-size: 15px;
        font-weight: 500;
    }
    
    .parent-category-arrow {
        flex-shrink: 0;
        color: #666;
    }
    
    /* Правая колонка: Дочерние категории */
    .popup-child-categories {
        flex: 1;
        padding: 20px;
        overflow: visible; /* Изменено с hidden на visible, чтобы popup списки были видны */
        background: #fff;
        display: flex;
        flex-direction: column;
        min-height: 0; /* Позволяем контейнеру расширяться */
        height: auto; /* Автоматическая высота для отображения всех категорий */
        max-height: none; /* Убираем ограничение максимальной высоты */
    }
    
    .child-categories-content {
        min-height: 200px;
        flex: 1 1 auto; /* Даём занять доступную высоту внутри правой колонки */
        margin-bottom: 20px;
        clear: both;
        overflow-y: auto; /* Скролл только внутри списка подкатегорий */
        overflow-x: visible;
        max-height: none;
        min-height: 0; /* Нужно для корректной работы flex-контейнера со скроллом */
    }
    
    .child-categories-placeholder {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 200px;
        color: #999;
        font-size: 16px;
    }
    
    .child-categories-banners {
        display: block;
    }
    
    .child-categories-banners .popup-banners {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
    
    .child-categories-banners .banner-item {
        aspect-ratio: 1;
    }
    
    .child-categories-banners .banner-title {
        font-size: 16px;
        padding: 12px;
    }
    
    .child-categories-list {
        display: block; /* Убрали grid, теперь обычный блок */
        overflow: visible;
    }
    
    /* Ссылка "Все [категория]" - вне grid, обычный блок */
    .child-categories-list > .child-category-all-link {
        display: block;
        margin-bottom: 12px;
    }
    
    /* Grid для дочерных категорий */
    .child-categories-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
        overflow: visible;
        grid-auto-rows: minmax(150px, auto); /* Фикс: не даём строкам схлопываться при отсутствии изображения */
    }
    
    .child-categories-list .child-categories-banners {
        margin-bottom: 12px;
    }
    
    /* Скрываем баннеры внутри списка дочерных категорий для PC */
    @media (min-width: 769px) {
        .child-categories-list .child-categories-banners {
            display: none !important;
        }
    }
    
    .child-categories-list .child-categories-banners .popup-banners {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
    
    .child-category-link {
        display: block;
        text-decoration: none;
        color: #333;
        border-radius: 8px;
        transition: background 0.2s;
        position: relative;
        overflow: hidden;
        background: #ededed;
        /* Фикс: карточки без изображения должны иметь высоту, чтобы ряд не схлопывался */
        aspect-ratio: 1;
        min-height: 150px;
    }
    
    .child-category-link:active {
        opacity: 0.9;
    }
    
    /* Специальный дизайн для категорий с дочерными элементами на PC */
    .child-category-with-children {
        position: relative;
        border-radius: 8px;
        overflow: visible; /* Изменено с hidden на visible, чтобы popup список был виден */
    }
    
    .child-category-parent {
        position: relative;
    }
    
    .child-category-link-parent {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        text-decoration: none;
        color: #1f2937;
        transition: background-color 0.2s ease;
        background-color: #e5e7eb;
        width: 100%;
        aspect-ratio: 1;
        cursor: pointer;
        border-radius: 8px;
        overflow: hidden;
    }
    
    .child-category-link-parent:hover {
        background-color: #d1d5db;
    }
    
    /* Стрелка в правом верхнем углу */
    .child-category-link-parent::after {
        content: '';
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        background: #dfdfdf;
        border-radius: 50%;
        width: 1.5rem;
        height: 1.5rem;
        background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='9 18 15 12 9 6' stroke='%23ef4444' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }
    
    .child-category-link-parent .child-category-image {
        width: 100%;
        aspect-ratio: 1;
        border-radius: 0;
        overflow: hidden;
        background: transparent;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .child-category-link-parent .child-category-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .child-category-link-parent .image-placeholder {
        color: #9ca3af;
        font-size: 0.875rem;
    }
    
    .child-category-link-parent .child-category-name {
        font-size: 12px;
        font-weight: 700;
        text-align: left;
        line-height: 1.3;
        color: #1f2937;
        margin-bottom: 0.5rem;
    }
    
    /* Список подкатегорий справа */
    .child-category-children-list {
        position: absolute;
        left: 100%;
        top: 0;
        margin-left: 1rem;
        z-index: 10;
        background-color: #ffffff;
        border-radius: 8px;
        border: 2px solid #ef4444;
        padding: 1rem;
        box-shadow: 6px 5px 16px -5px gray, 0 4px 6px -2px gray;
        min-width: 300px;
        max-width: 400px;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .child-category-children-list ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    
    .child-category-children-list .child-category-link-child {
        display: flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
        color: #374151;
        text-decoration: none;
        border-radius: 0.25rem;
        transition: background-color 0.2s ease;
        margin-bottom: 0.5rem;
    }
    
    .child-category-children-list .child-category-link-child:last-child {
        margin-bottom: 0;
    }
    
    .child-category-children-list .child-category-link-child:hover {
        background-color: #f3f4f6;
    }
    
    .child-category-children-list .child-category-image-small {
        display: block;
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        margin-right: 0.75rem;
        border-radius: 4px;
        overflow: hidden;
        background-color: #f5f5f5;
    }
    
    /* Унифицируем background для всех вариантов child-category-image */
    .child-category-link-parent .child-category-image {
        background-color: #f5f5f5;
    }
    
    .child-category-children-list .child-category-image-small img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .child-category-children-list .child-category-link-child {
        display: flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }
    
    .child-category-children-list .child-category-name-small {
        font-size: 14px;
        font-weight: 400;
        text-align: left;
        line-height: 1.4;
        flex: 1;
    }
    
    .child-category-children-list .child-category-all-link {
        font-weight: 500; /* Немного жирнее для выделения */
    }
    
    .child-category-children-list .child-category-all-link .child-category-name-small {
        font-weight: 500;
    }
    
    .child-category-image {
        width: 100%;
        aspect-ratio: 1;
        border-radius: 8px;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f5f5f5;
        position: relative;
    }
    
    .child-category-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .child-category-name {
        position: absolute;
        top: 0;
        left: 0;
        font-size: 12px;
        font-weight: 700;
        text-align: left;
        line-height: 1.3;
        padding: 8px 10px;
        z-index: 2;
        color: #333;
    }
    
    /* Ссылка "Все [категория]" - только текст, без изображения, вне grid */
    .child-category-all-link {
        display: flex;
        align-items: center;
        padding: 12px 16px;
        background: #f5f5f5;
        border-radius: 8px;
        margin-bottom: 12px;
        width: 100%;
        text-decoration: none;
        color: #333;
        transition: background 0.2s;
        /* Не наследуем квадратные размеры от .child-category-link */
        aspect-ratio: auto;
        min-height: 0;
        height: auto;
    }
    
    .child-category-all-link .child-category-name {
        position: static;
        font-size: 14px;
        font-weight: 600;
        padding: 0;
        color: #2e7d32;
        width: 100%;
    }
    
    .child-category-all-link:hover {
        background: #e8f5e9;
        text-decoration: none;
    }
    
    .child-category-all-link:active {
        background: #c8e6c9;
    }
    
    /* Баннеры внизу для PC в правой колонке */
    .popup-child-categories .popup-banners-desktop {
        padding: 20px 0 0 0;
        margin-top: auto;
        border-top: 1px solid #ddd;
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 10;
        clear: both;
    }
    
    .popup-child-categories .popup-banners-desktop .popup-section-title {
        margin-bottom: 15px;
        font-size: 18px;
        font-weight: 600;
    }
    
    .popup-banners-desktop .popup-banners {
        display: flex;
        flex-direction: row;
        gap: 15px;
        width: 100%;
        justify-content: flex-start;
    }
    
    .popup-banners-desktop .banner-item {
        display: flex;
        flex-direction: column;
        width: 267px;
        height: 150px;
        border-radius: 8px;
        overflow: visible;
        background: transparent;
        border: none;
        box-shadow: none;
        transition: transform 0.2s ease;
        flex-shrink: 0;
        gap: 8px;
    }
    
    .popup-banners-desktop .banner-item:hover {
        transform: translateY(-2px);
    }
    
    .popup-banners-desktop .banner-title {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        font-size: 13px;
        padding: 0;
        background: transparent;
        color: #333;
        font-weight: 600;
        text-align: left;
        flex-shrink: 0;
        border: none;
        line-height: 1.3;
        min-height: auto;
        height: auto;
        margin-bottom: 0;
    }
    
    .popup-banners-desktop .banner-link {
        display: block;
        width: 267px;
        height: 150px;
        overflow: hidden;
        flex-shrink: 0;
        background: #f5f5f5;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        transition: box-shadow 0.2s ease;
    }
    
    .popup-banners-desktop .banner-item:hover .banner-link {
        box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    }
    
    .popup-banners-desktop .banner-link img,
    .popup-banners-desktop .banner-link video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }
    
    /* Скрываем стандартные элементы для мобильной версии на PC */
    .popup-content-desktop .popup-categories {
        display: none;
    }
    
    .popup-content-desktop .popup-banners:not(.popup-banners-desktop .popup-banners) {
        display: none;
    }
}

