/* ========================================= */
/* 0. ЗМІННІ ТА БАЗА                         */
/* ========================================= */
@import url('../shared/theme.css');

:root {
    --bg: var(--color-bg-dark);
    --card: var(--color-bg-card-alt);
    --border: var(--color-border);
    --accent: var(--color-primary-soft);
    --accent-glow: var(--color-primary-glow);
    --gold: var(--color-warning);
    
    /* Змінні для нового дизайну */
    --sidebar-bg: var(--color-bg-panel);
    --input-bg: var(--color-bg-input);
    
    /* 🔥 Fix for iOS dark mode elements */
    color-scheme: dark;
    --sidebar-gradient: linear-gradient(145deg, var(--color-bg-panel), var(--color-bg-panel-alt));
    --sidebar-border: var(--color-border);
    --surface-hover: var(--color-bg-chip-soft);
    --muted-strong: var(--color-text-strong-muted);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg);
    color: white;
    font-family: 'Inter', 'Montserrat', sans-serif;
    overflow-x: hidden;
}

.main-content { padding-top: 90px; }
.shop-container { max-width: 1920px; margin: 0 auto; padding: 20px 30px; }
.shop-layout { display: flex; gap: 40px; }

/* ========================================= */
/* 1. НОВИЙ ДИЗАЙН САЙДБАРУ (DESKTOP)        */
/* ========================================= */
.filters-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--sidebar-gradient);
    border: 1px solid var(--sidebar-border);
    box-shadow: 0 4px 15px var(--color-overlay-black-30);
    border-radius: 16px;
    padding: 25px;
    color: var(--muted-strong);
    
    position: sticky;
    top: 110px;
    height: fit-content;
    max-height: calc(100vh - 130px);
    overflow-y: hidden;
    transition: all 0.3s ease;
}

/* Приховуємо скролбар контейнера */
.filters-sidebar::-webkit-scrollbar { width: 0px; }

.filter-group { 
    margin-bottom: 25px; 
    padding-bottom: 20px;
    border-bottom: 1px solid var(--color-border-faint);
}
.filter-group:last-child { margin-bottom: 0; border-bottom: none; }

.filter-group h3 { 
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--accent);
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    text-shadow: 0 0 8px var(--color-primary-glow);
}

/* Інпути та селекти */
.filter-input, .filter-select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--color-border-strong);
    color: white;
    padding: 12px 15px;
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
    font-family: 'Inter', sans-serif;
}

.filter-input:hover, .filter-select:hover { background: var(--surface-hover); }
.filter-input:focus, .filter-select:focus {
    border-color: var(--accent);
    background: var(--surface-hover);
    box-shadow: 0 0 0 3px var(--color-primary-surface);
}

.filter-select { 
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a2be2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 35px;
}
.filter-select option { background-color: var(--color-bg-input); color: white; padding: 10px; }

.price-range { display: flex; align-items: center; gap: 12px; }
.price-range input { text-align: center; }
.price-range span { color: var(--color-text-subtle); font-weight: bold; }

/* ========================================= */
/* СПИСОК КАТЕГОРІЙ (DESKTOP)                */
/* ========================================= */
@media (min-width: 901px) {
    #categorySelect { display: none; }
    .custom-category-container { display: block; }
    .mobile-category-popup { display: none !important; } /* Ховаємо попап на ПК */
}

@media (max-width: 900px) {
    .custom-category-container { display: none !important; }
    #categorySelect { display: block; }
}

.custom-category-container {
    display: flex;
    flex-direction: column;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 10px;
}

.custom-category-container::-webkit-scrollbar { width: 6px; }
.custom-category-container::-webkit-scrollbar-track { background: var(--color-overlay-white-05); border-radius: 3px; }
.custom-category-container::-webkit-scrollbar-thumb { background: var(--color-bg-chip-hover); border-radius: 3px; border: 1px solid var(--sidebar-border); }
.custom-category-container::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.custom-cat-group {
    color: var(--color-text-dim);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 1.2px;
    margin: 20px 0 10px 15px;
    text-transform: uppercase;
    opacity: 0.8;
    pointer-events: none;
}
.custom-cat-group:first-child { margin-top: 0; }

.custom-cat-item {
    display: flex !important;
    align-items: center;
    gap: 14px;
    color: var(--color-text-quiet);
    text-decoration: none;
    padding: 10px 15px;
    border-radius: 10px;
    transition: all 0.2s ease;
    font-size: 15px;
    font-weight: 500;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.custom-cat-item:hover {
    background: var(--color-overlay-white-05);
    color: white;
    padding-left: 20px;
    border-left-color: var(--accent);
}

.custom-cat-item.active {
    background: var(--color-primary-surface-soft);
    color: white;
    padding-left: 20px;
    border-left-color: var(--accent);
    font-weight: 700;
}

.custom-cat-item[data-value="all"] {
    background: var(--color-primary-surface-soft);
    border: 1px solid var(--color-primary-border-soft);
    color: var(--color-primary-soft);
    margin-bottom: 15px;
    font-weight: 700;
}
.custom-cat-item[data-value="all"]:hover {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 15px var(--color-primary-glow-strong);
    border-left-color: transparent;
    padding-left: 15px;
    transform: translateY(-2px);
}

/* ========================================= */
/* 2. КОНТЕНТ ТА ГРІДИ                       */
/* ========================================= */
.shop-content { flex: 1; min-width: 0; }
.products-section { margin-bottom: 50px; }
.section-title { font-size: 1.5rem; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; text-transform: uppercase; font-weight: 800; }

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 25px;
}

.products-grid.horizontal-scroll {
    display: flex;
    overflow-x: auto;
    gap: 20px;
    padding-bottom: 15px;
}
.products-grid.horizontal-scroll .product-card { min-width: 260px; max-width: 260px; flex-shrink: 0; }
.products-grid.horizontal-scroll::-webkit-scrollbar { height: 6px; }
.products-grid.horizontal-scroll::-webkit-scrollbar-track { background: var(--color-border-faint); border-radius: 10px; }
.products-grid.horizontal-scroll::-webkit-scrollbar-thumb { background: var(--color-bg-chip-hover); border-radius: 10px; }
.products-grid.horizontal-scroll::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ========================================= */
/* 3. КАРТКА ТОВАРУ                          */
/* ========================================= */
.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    transition: 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}

.product-card:hover { transform: translateY(-5px); box-shadow: 0 10px 30px var(--color-overlay-black-50); border-color: var(--accent); }

.image-box {
    width: 100%; aspect-ratio: 16/10; background: var(--color-bg-input-deep); position: relative; overflow: hidden; border-bottom: 1px solid var(--color-border-faint);
}
.image-box img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.product-card:hover .image-box img { transform: scale(1.1); }

.product-info { padding: 15px; flex-grow: 1; display: flex; flex-direction: column; }
.product-info h3 { font-size: 0.95rem; margin-bottom: 6px; font-weight: 700; line-height: 1.4; color: white; }

.seller-name { font-size: 0.75rem; color: var(--color-text-light); margin-bottom: 8px; display: flex; align-items: center; gap: 5px; opacity: 0.7; }
.seller-name i { color: var(--accent); font-size: 0.8rem; }
.description { font-size: 0.75rem; color: var(--color-text-soft); margin-bottom: 15px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.price-row { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--color-border-faint); }
.price { font-size: 1.1rem; font-weight: 800; }
.buy-btn {
    padding: 8px 20px; background: var(--accent); color: white; border: none; border-radius: 8px; cursor: pointer;
    font-size: 0.8rem; font-weight: 800; transition: 0.3s; text-transform: uppercase;
}
.buy-btn:hover { background: var(--color-primary); box-shadow: 0 0 15px var(--color-primary-border); transform: translateY(-2px); }

.product-card.premium { border-color: var(--gold); background: radial-gradient(circle at top right, var(--color-warning-haze), transparent 70%), var(--card); }
.product-card.premium .buy-btn { background: var(--gold); color: black; }
.product-card.premium .buy-btn:hover { background: var(--color-warning-soft); box-shadow: 0 0 15px var(--color-warning-glow); }

/* ========================================= */
/* 4. АДАПТИВНІСТЬ (MOBILE) + POPUP ПОВЕРНУВСЯ! */
/* ========================================= */
@media (max-width: 900px) {
    body { padding-top: 70px !important; }
    .main-content { padding-top: 70px !important; }
    .shop-layout { flex-direction: column; gap: 20px; }
    .shop-container { padding: 15px; }

    /* Ховаємо ПК список категорій */
    .custom-category-container { display: none !important; }
    /* Ховаємо старий селект, якщо він є */
    #categorySelect { display: none !important; }

    /* === 🔥 ПОВЕРНЕННЯ МОДАЛЬНОГО ВІКНА (POPUP) 🔥 === */
    /* Оновлений дизайн вікна */
    .mobile-category-popup {
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: var(--color-bg-dark-overlay); /* Напівпрозорий темний фон */
        backdrop-filter: blur(15px); /* Ефект розмиття */
        z-index: 10000;
        display: none; /* JS перемкне на flex */
        flex-direction: column;
        animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    .mobile-category-popup.active { display: flex; }
    
    @keyframes slideUp { 
        from { transform: translateY(100%); opacity: 0; } 
        to { transform: translateY(0); opacity: 1; } 
    }

    /* Шапка модального вікна */
    .mobile-popup-header {
        padding: 20px;
        background: var(--color-bg-card-overlay);
        border-bottom: 1px solid var(--color-border-soft);
        display: flex; justify-content: space-between; align-items: center;
        position: sticky; top: 0; z-index: 10;
    }

    .mobile-popup-header h3 { 
        font-size: 1.1rem; color: white; margin: 0; 
        font-family: 'Inter', sans-serif; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
    }

    /* Кнопка закриття */
    .mobile-popup-close {
        background: var(--color-overlay-white-08);
        border: 1px solid var(--color-border-soft);
        color: white;
        width: 36px; height: 36px;
        border-radius: 10px;
        display: flex; align-items: center; justify-content: center;
        cursor: pointer;
        font-size: 1.2rem;
        transition: 0.2s;
    }
    .mobile-popup-close:active { transform: scale(0.9); background: var(--accent); }

    /* Контент вікна */
    .mobile-popup-content { padding: 20px; overflow-y: auto; flex: 1; }

    /* Заголовки груп всередині вікна */
    .mobile-cat-group-title {
        color: var(--accent);
        font-size: 0.75rem; font-weight: 800;
        margin: 20px 0 10px 5px; text-transform: uppercase;
    }
    .mobile-cat-group:first-child .mobile-cat-group-title { margin-top: 0; }

    /* Кнопки категорій всередині вікна */
    .mobile-cat-item {
        display: block; width: 100%; padding: 15px; margin-bottom: 10px;
        background: var(--color-bg-card-deep); 
        border: 1px solid var(--color-overlay-white-08);
        border-radius: 12px; 
        color: white; font-size: 1rem; text-align: left;
        font-family: 'Inter', sans-serif;
    }
    
    .mobile-cat-item:active { background: var(--color-primary-surface); border-color: var(--accent); transform: scale(0.98); }
    .mobile-cat-item.active { background: var(--color-primary-surface); border-color: var(--accent); color: var(--accent); font-weight: 700; }

    /* === РЕШТА ЕЛЕМЕНТІВ САЙДБАРУ (ІНПУТИ) === */
    /* Робимо сайдбар на мобільному прозорим, щоб видно було тільки фільтри (ціна, сорт) */
    .filters-sidebar { 
        width: 100% !important; 
        position: relative !important; top: auto !important;
        padding: 0 !important; margin-bottom: 20px !important; 
        background: transparent !important; border: none !important; 
        box-shadow: none !important; max-height: none !important; overflow: visible !important;
    }
    
    /* Секція категорії в сайдбарі - робимо КНОПКОЮ для відкриття POPUP */
    .filter-group:first-child h3 {
        padding: 16px 20px !important; margin: 0 !important;
        background: linear-gradient(90deg, var(--color-primary-surface), var(--color-primary-faint)) !important;
        border: 1px solid var(--color-primary-border-soft) !important;
        border-radius: 12px !important;
        color: var(--accent) !important;
        font-size: 0.95rem !important;
        cursor: pointer;
        display: flex; justify-content: space-between; align-items: center;
        transition: 0.2s;
    }
    
    .filter-group:first-child h3:active { transform: scale(0.98); background: var(--accent) !important; color: white !important; }
    
    /* Додаємо іконку стрілки для кнопки відкриття */
    .filter-group:first-child h3::after {
        content: '\f054'; /* fa-chevron-right */
        font-family: 'Font Awesome 6 Free'; font-weight: 900;
        font-size: 0.9rem;
    }
    
    /* Ховаємо стандартний список під заголовком, бо буде відкриватися Popup */
    .filter-group:first-child > *:not(h3) { display: none !important; }

    /* Інші фільтри (Ціна, Сорт) - як акордеонів */
    .filter-group:not(:first-child) {
        background: var(--color-bg-control-alt) !important;
        border: 1px solid var(--color-overlay-white-08) !important;
        border-radius: 12px; margin-bottom: 12px; overflow: hidden;
    }
    
    .filter-group:not(:first-child) h3 {
        padding: 15px !important; margin: 0 !important;
        background: transparent !important; border-bottom: 1px solid var(--color-border-faint);
        color: white !important; font-size: 0.9rem !important;
    }
    
    .filter-input, .filter-select { background: var(--color-bg-input-deep) !important; border-color: var(--color-overlay-white-15) !important; }
    
    /* СІТКИ ТОВАРІВ */
    #productsGrid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 12px !important; }
    #productsGrid .product-card { width: 100% !important; margin: 0 !important; }
    #productsGrid .image-box { aspect-ratio: 1/1 !important; }
    #productsGrid .product-info { padding: 10px !important; }
    #productsGrid h3 { font-size: 0.85rem !important; height: 2.4em; overflow: hidden; }
    #productsGrid .description, #productsGrid .seller-name { display: none !important; }
    #productsGrid .price-row { flex-direction: column !important; align-items: flex-start !important; gap: 5px !important; }
    #productsGrid .buy-btn { width: 100% !important; padding: 8px 0 !important; font-size: 0.75rem !important; }
    
    #donationGrid, #popularGrid, #recommendedGrid {
        display: flex !important; overflow-x: scroll !important; gap: 12px !important; padding-right: 20px;
    }
    #donationGrid .product-card { min-width: 200px !important; }
}

/* ========================================= */
/* 768px: одна колонка, відступи, типографіка */
/* ========================================= */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        width: 100%;
    }

    .main-content {
        width: 100%;
        overflow-x: hidden;
    }

    .shop-container {
        width: 100%;
        max-width: 100%;
        padding: 14px 16px 24px;
        box-sizing: border-box;
    }

    .shop-layout {
        flex-direction: column;
        gap: 18px;
    }

    .filters-sidebar,
    .shop-content,
    .products-section,
    .product-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .shop-container img {
        max-width: 100%;
        height: auto;
    }

    .products-grid,
    #productsGrid,
    .products-grid.horizontal-scroll,
    #donationGrid,
    #popularGrid,
    #recommendedGrid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 16px !important;
        overflow-x: visible !important;
        padding-right: 0 !important;
        padding-bottom: 0 !important;
    }

    .products-grid .product-card,
    #productsGrid .product-card,
    .products-grid.horizontal-scroll .product-card,
    #donationGrid .product-card,
    #popularGrid .product-card,
    #recommendedGrid .product-card {
        width: 100% !important;
        max-width: 100%;
        min-width: 0 !important;
        box-sizing: border-box;
    }

    .products-grid .image-box,
    #productsGrid .image-box,
    .products-grid.horizontal-scroll .image-box {
        aspect-ratio: 16 / 10 !important;
    }

    #productsGrid .product-info {
        padding: 14px !important;
    }

    #productsGrid h3 {
        height: auto;
        overflow: visible;
        font-size: 0.95rem !important;
    }

    .image-box .category-pill {
        max-width: calc(100% - 20px);
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .product-info {
        padding: 14px !important;
    }

    .product-info h3 {
        font-size: 0.95rem !important;
        line-height: 1.35;
        overflow-wrap: anywhere;
    }

    .section-title {
        font-size: 1.1rem !important;
        line-height: 1.25;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 8px;
        overflow-wrap: anywhere;
    }

    .filter-group {
        margin-bottom: 16px;
        padding-bottom: 14px;
    }

    .price-range {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .price-range span {
        display: none;
    }

    .price-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    #productsGrid .price-row {
        align-items: stretch !important;
        gap: 10px !important;
    }

    .price {
        font-size: 1rem;
    }

    .buy-btn,
    #loadMoreContainer .load-more-btn,
    .mobile-cat-item,
    .filter-group:first-child h3,
    .filter-group:not(:first-child) h3 {
        min-height: 44px;
    }

    .buy-btn {
        width: 100% !important;
        padding: 12px 16px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem !important;
    }

    #productsGrid .buy-btn {
        padding: 12px 16px !important;
        font-size: 0.85rem !important;
    }

    .filter-input,
    .filter-select {
        width: 100%;
        box-sizing: border-box;
        min-height: 44px;
        padding-left: 14px;
        padding-right: 14px;
    }

    #loadMoreContainer {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .shop-container {
        padding: 10px 14px 20px;
    }

    .shop-layout {
        gap: 14px;
    }

    .filters-sidebar {
        margin-bottom: 16px !important;
    }

    .filter-group:first-child h3 {
        padding: 14px 16px !important;
        font-size: 0.88rem !important;
    }

    .filter-group:not(:first-child) h3 {
        padding: 14px 16px !important;
        font-size: 0.85rem !important;
    }

    .mobile-popup-header {
        padding: 16px;
    }

    .mobile-popup-header h3 {
        font-size: 1rem;
        letter-spacing: 0.6px;
    }

    .mobile-popup-content {
        padding: 16px 14px 20px;
    }

    .mobile-cat-item {
        padding: 14px;
        font-size: 0.95rem;
    }

    .section-title {
        font-size: 1rem !important;
        margin-bottom: 16px;
    }

    .product-info {
        padding: 12px !important;
    }

    #productsGrid .product-info {
        padding: 12px !important;
    }

    .product-info h3 {
        font-size: 0.9rem !important;
    }

    #productsGrid h3 {
        font-size: 0.9rem !important;
    }

    .price {
        font-size: 0.95rem;
    }

    .buy-btn {
        padding: 11px 14px !important;
        font-size: 0.8rem !important;
    }

    #productsGrid .buy-btn {
        padding: 11px 14px !important;
        font-size: 0.8rem !important;
    }

    .filter-input,
    .filter-select {
        font-size: 16px;
    }

    .price-range {
        gap: 8px;
    }
}
