/**
 * Стили для страницы каталога
 * СибСнаб24
 * Использует CSS переменные из unique-design.css: --primary, --secondary, --accent
 */

/* Bootstrap primary color override */
:root {
    --bs-primary: #bf372b;
    --bs-primary-rgb: 191, 55, 43;
}

/* Body Styles */
body {
    background: #f8f9fa;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Typography */
h1, h2, h3 {
    font-family: 'Alegreya Sans SC', sans-serif;
    font-weight: 900;
}

/* Navbar */
.navbar-brand {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.8rem;
    letter-spacing: 0.0625rem;
}

.navbar-dark {
    background-color: var(--primary) !important;
}

/* Buttons - переопределение Bootstrap */
body .btn-primary {
    --bs-btn-bg: #bf372b;
    --bs-btn-border-color: #bf372b;
    --bs-btn-hover-bg: #263940;
    --bs-btn-hover-border-color: #263940;
    --bs-btn-active-bg: #263940;
    --bs-btn-active-border-color: #263940;
    background-color: #bf372b !important;
    border-color: #bf372b !important;
    color: white !important;
}

body .btn-primary:hover,
body .btn-primary:focus,
body .btn-primary:active {
    background-color: #263940 !important;
    border-color: #263940 !important;
    color: white !important;
}

/* Prices */
.price {
    color: var(--accent);
    font-weight: bold;
}

.old-price {
    color: #6c757d;
    text-decoration: line-through;
}

/* Product Details */
.product-details .badge {
    font-size: 0.8em;
}

/* Cart Indicator */
.cart-indicator {
    position: fixed;
    top: 5rem;
    right: 1.25rem;
    z-index: 1000;
    box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.15);
}

.cart-item {
    border-bottom: 0.0625rem solid #dee2e6;
}

.cart-item:last-child {
    border-bottom: none;
}

/* Product Images */
img.product-image,
img.card-img-top.product-image {
    width: 100%;
    height: 23.4375rem; /* До 61.9375rem в px (4:5 ratio) */
    object-fit: contain;
    object-position: center;
}

.product-image.d-flex {
    width: 100%;
    height: 23.4375rem;
}

/* От 62rem и больше - переход на rem */
@media (min-width: 992px) {
    img.product-image,
    img.card-img-top.product-image {
        height: 31.25rem; /* 31.25rem - 4:5 ratio */
    }
    .product-image.d-flex {
        height: 31.25rem;
    }
}

/* Category Cards */
.category-card {
    transition: all 0.3s ease;
    border: none;
    overflow: hidden;
    border-radius: 0.75rem;
}

.category-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 0.75rem 2.1875rem rgba(0,0,0,0.2) !important;
}

/* Для экранов 62rem и больше */
@media (min-width: 992px) {
    .category-card {
        border-radius: 0.75rem;
    }

    .category-card:hover {
        transform: translateY(-0.5rem);
        box-shadow: 0 0.75rem 2.2rem rgba(0,0,0,0.2) !important;
    }
}

.category-card-image-wrapper {
    position: relative;
    width: 100%;
    /* Fallback для iOS Safari < 15 */
    padding-top: 100%; /* 1:1 ratio */
    aspect-ratio: 1 / 1;
    overflow: hidden;
    display: block;
    height: 0;
}

/* Для современных браузеров с поддержкой aspect-ratio */
@supports (aspect-ratio: 1 / 1) {
    .category-card-image-wrapper {
        height: auto;
        padding-top: 0;
    }
}

.category-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

.category-card-no-image {
    width: 100%;
    /* Fallback для iOS Safari < 15 */
    height: 0;
    padding-top: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: flex-end;
    padding: 1.875rem;
    position: relative;
}

@supports (aspect-ratio: 1 / 1) {
    .category-card-no-image {
        height: auto;
        padding-top: 0;
        padding: 1.875rem;
    }
}

/* Для экранов 62rem и больше */
@media (min-width: 992px) {
    .category-card-no-image {
        padding: 2rem;
    }
}

.category-card-overlay {
    position: absolute;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    min-height: 5.5rem;
    background: linear-gradient(to top,
        rgba(0,0,0,0.95) 0%,
        rgba(0,0,0,0.75) 40%,
        rgba(0,0,0,0.3) 70%,
        rgba(0,0,0,0) 100%
    );
    display: flex;
    align-items: flex-end;
    padding: 1rem;
    transition: all 0.35s ease;
    z-index: 1;
}

.category-card:hover .category-card-overlay {
    background: linear-gradient(to top,
        rgba(0,0,0,0.9) 0%,
        rgba(0,0,0,0.7) 50%,
        rgba(0,0,0,0.1) 100%
    );
    min-height: 7.5rem;
}

.category-card-content {
    width: 100%;
}

.category-title {
    color: #ffffff;
    font-size: 1.125rem;
    font-weight: 700;
    margin: 0 0 0.25rem 0;
    line-height: 1.2;
    text-shadow: 0 0.125rem 0.5rem rgba(0,0,0,0.9), 0 0.25rem 1rem rgba(0,0,0,0.6);
}

.category-count {
    color: rgba(255,255,255,0.95);
    font-size: 0.75rem;
    font-weight: 500;
    margin: 0;
    text-shadow: 0 0.0625rem 0.375rem rgba(0,0,0,0.9), 0 0.125rem 0.5rem rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.category-overlay-content {
    width: 100%;
}

.category-overlay-title {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.375rem 0;
    line-height: 1.3;
    text-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.4);
}

.category-overlay-count {
    display: inline-block;
    color: rgba(255,255,255,0.9);
    font-size: 0.8125rem;
    font-weight: 500;
}

/* Для экранов 62rem и больше - используем rem */
@media (min-width: 992px) {
    .category-card-overlay {
        padding: 1.25rem;
    }

    .category-overlay-title {
        font-size: 1.25rem;
        margin-bottom: 0.375rem;
        text-shadow: 0 0.125rem 0.375rem rgba(0,0,0,0.4);
    }

    .category-overlay-count {
        font-size: 0.8125rem;
    }
}

/* Subcategories */
.subcategories-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.subcategory-link {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    background: #f8f9fa;
    border-radius: 1rem;
    color: #495057;
    text-decoration: none;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    border: 0.0625rem solid #e9ecef;
}

.subcategory-link:hover {
    background: var(--bs-primary, #bf372b);
    color: white;
    border-color: var(--bs-primary, #bf372b);
    transform: translateY(-2px);
}

/* Для экранов 62rem и больше */
@media (min-width: 992px) {
    .subcategory-link:hover {
        transform: translateY(-0.125rem);
    }
}

.subcategory-count {
    opacity: 0.7;
    font-size: 0.8125rem;
    margin-left: 0.25rem;
}

/* Для экранов 62rem и больше - используем rem */
@media (min-width: 992px) {
    .subcategories-list {
        gap: 0.5rem;
    }

    .subcategory-link {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
        border-radius: 1.25rem;
    }

    .subcategory-count {
        font-size: 0.8125rem;
        margin-left: 0.25rem;
    }
}

/* Product Cards */
.product-card {
    transition: transform 0.3s, box-shadow 0.3s;
    border: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.product-card .card-body {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.product-card .card-body .d-grid {
    margin-top: auto;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.25rem 1.25rem rgba(0,0,0,0.1);
}

.product-card-img {
    width: 100%;
    height: 23.4375rem; /* Fallback для iOS Safari < 15 (4:5 ratio) */
    aspect-ratio: 4 / 5;
    object-fit: contain;
}

@media (min-width: 992px) {
    .product-card-img {
        height: 31.25rem; /* 31.25rem - 4:5 ratio */
    }
}

@supports (aspect-ratio: 4 / 5) {
    .product-card-img {
        height: auto;
    }
    @media (min-width: 992px) {
        .product-card-img {
            height: auto;
        }
    }
}

.product-card-placeholder {
    width: 100%;
    height: 23.4375rem; /* Fallback для iOS Safari < 15 (4:5 ratio) */
    aspect-ratio: 4 / 5;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Для экранов 62rem и больше */
@media (min-width: 992px) {
    .product-card:hover {
        transform: translateY(-0.3125rem);
        box-shadow: 0 0.25rem 1.25rem rgba(0,0,0,0.1);
    }
}

/* 4 columns grid for products */
.row-cols-lg-4 > * {
    flex: 0 0 auto;
    width: 50%; /* 2 колонки на мобильном */
}

@media (min-width: 992px) {
    .row-cols-lg-4 > * {
        width: 25%; /* 4 колонки на десктопе (100% / 4 = 25%) */
    }
}

/* Кастомный класс для 4 колонок */
.col-lg-custom-4 {
    flex: 0 0 auto;
    width: 50%; /* 2 колонки на мобильном */
}

@media (min-width: 768px) {
    .col-lg-custom-4 {
        width: 33.333%; /* 3 колонки на планшете */
    }
}

@media (min-width: 992px) {
    .col-lg-custom-4 {
        width: 25%; /* 4 колонки на десктопе */
    }
}

/* Sticky filters on desktop */
@media (min-width: 992px) {
    .catalog-filters-sticky {
        position: sticky;
        top: 6.25rem;
    }
}

/* Filter scroll */
.filter-scroll {
    max-height: 12.5rem;
    overflow-y: auto;
}

/* Alert info - используем фирменные цвета */
.alert-info {
    background-color: rgba(38, 57, 64, 0.1);
    border-color: #263940;
    color: #263940;
}

.alert-info a {
    color: #bf372b;
    font-weight: 600;
}

.alert-info a:hover {
    color: #263940;
}

/* Responsive adjustments - mobile only */
@media (max-width: 767px) {
    .category-card-no-image {
        height: 220px;
    }

    .category-title {
        font-size: 20px;
    }

    .category-count {
        font-size: 14px;
    }
}

/* Анимация добавления в корзину */
@keyframes cart-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.cart-bounce {
    animation: cart-bounce 0.5s ease;
}

/* Летящая точка к корзине */
.flying-to-cart {
    transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Стили аккордеона товара */
.accordion-button::after {
    margin-left: auto;
}

@media (max-width: 767px) {
    .accordion-button::after {
        position: absolute;
        right: 15px;
    }
}

.accordion-button:not(.collapsed) {
    background-color: rgb(238 239 43 / 23%) !important;
}

.accordion-button:hover {
    background-color: rgb(238 239 43 / 23%) !important;
}

.accordion-button:focus {
    box-shadow: 0 0 0 0.25rem rgb(253 253 175 / 25%) !important;
}

/* Отступ между иконкой и текстом в аккордеоне (только на десктопе) */
@media (min-width: 992px) {
    .accordion-button svg {
        margin-right: 0.75rem;
    }
}

/* Стили счетчика количества для размеров в товаре */
.size-quantity-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: #f8f9fa;
    border-radius: 0.5rem;
    padding: 0.5rem;
}

.size-quantity-control .qty-btn {
    background: var(--color-accent, #db6d30);
    border: none;
    border-radius: 0.5rem;
    width: 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 600;
    font-family: 'Roboto', 'Arial', sans-serif;
    color: var(--color-primary, #bf372b);
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    line-height: 1;
}

.size-quantity-control .qty-btn:disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.size-quantity-control .qty-btn.plus {
    background: #ffe30e69;
    color: var(--color-primary, #bf372b);
}

.size-quantity-control .qty-btn.minus {
    background: #ffe30e69;
    color: var(--color-primary, #bf372b);
}

.size-quantity-control .quantity {
    font-weight: 600;
    color: #1a1a1a;
    min-width: 1.5rem;
    text-align: center;
}

/* Стиль кнопки "В корзину" после добавления товара */
.btn-primary.add-to-cart-size.in-cart,
.btn-primary.add-to-cart-no-size.in-cart {
    background-color: #bf372b !important;
    border-color: #bf372b !important;
    color: white !important;
}

.btn-primary.add-to-cart-size.in-cart:hover,
.btn-primary.add-to-cart-no-size.in-cart:hover {
    background-color: #a02f24 !important;
    border-color: #a02f24 !important;
}

.add-to-cart-size.in-cart svg,
.add-to-cart-no-size.in-cart svg {
    width: 24px !important;
    height: 24px !important;
}

@media (min-width: 992px) {
    .add-to-cart-size.in-cart svg,
    .add-to-cart-no-size.in-cart svg {
        width: 1.5rem !important;
        height: 1.5rem !important;
    }
}

/* Адаптивная таблица размеров для мобильных устройств */
@media (max-width: 767px) {
    /* Скрываем thead */
    .table-responsive table thead {
        display: none;
    }

    /* Убираем табличные стили */
    .table-responsive table,
    .table-responsive tbody {
        display: block;
        width: 100%;
    }

    /* Создаем карточный вид для размеров */
    .table-responsive tbody tr {
        display: block;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        margin-bottom: 1rem;
        padding: 1rem;
    }

    /* Эффект наведения на мобильных */
    .table-responsive .table-hover tbody tr:hover {
        background-color: var(--bs-table-hover-bg) !important;
    }

    .table-responsive tbody tr td {
        display: block;
        border: none;
        padding: 0.5rem 0;
    }

    /* Размер - крупный и заметный */
    .table-responsive tbody tr td:first-child {
        font-size: 1.125rem;
        font-weight: 700;
        color: var(--color-primary, #bf372b);
        margin-bottom: 0.5rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e5e7eb;
    }

    /* Наличие и цена в одну строку */
    .table-responsive tbody tr td:nth-child(2),
    .table-responsive tbody tr td:nth-child(3) {
        display: inline-block;
        width: 50%;
        padding: 0.25rem 0;
    }

    .table-responsive tbody tr td:nth-child(2) {
        padding-right: 0.5rem;
    }

    /* Контейнер с количеством и кнопкой */
    .table-responsive tbody tr td:nth-child(4) {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid #e5e7eb;
    }

    .table-responsive tbody tr td:nth-child(4) .d-flex {
        flex-direction: column;
        gap: 0.75rem !important;
    }

    /* Счетчик количества на всю ширину */
    .table-responsive .size-quantity-control {
        width: 100%;
        justify-content: space-between;
        padding: 0.75rem 1rem;
    }

    .table-responsive .size-quantity-control .qty-btn {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.5rem;
    }

    .table-responsive .size-quantity-control .quantity {
        font-size: 1.125rem;
        min-width: 2rem;
    }

    /* Кнопка "В корзину" на всю ширину без переноса */
    .table-responsive .add-to-cart-size {
        width: 100%;
        white-space: nowrap;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .table-responsive .add-to-cart-size svg {
        flex-shrink: 0;
        width: 1.25rem !important;
        height: 1.25rem !important;
    }
}

/* ==============================================
   Catalog Filters Accordion (Mobile)
   ============================================== */

/* Аккордеон фильтров */
.catalog-filters-accordion .accordion-item {
    border: none;
    border-bottom: 1px solid #e5e7eb;
}

.catalog-filters-accordion .accordion-item:last-child {
    border-bottom: none;
}

.catalog-filters-accordion .accordion-button {
    padding: 0.75rem 0;
    font-weight: 600;
    font-size: 0.9375rem;
    background: transparent;
    box-shadow: none;
    color: #263940;
}

.catalog-filters-accordion .accordion-button:not(.collapsed) {
    background-color: #fff !important;
    background: transparent;
    color: var(--primary, #bf372b);
}

.catalog-filters-accordion .accordion-button::after {
    width: 1rem;
    height: 1rem;
    background-size: 1rem;
}

.catalog-filters-accordion .accordion-body {
    padding: 0 0 0.75rem 0;
}

/* На десктопе (992px+) - все секции открыты, без аккордеона */
@media (min-width: 992px) {
    .catalog-filters-accordion .accordion-button {
        pointer-events: none;
        padding: 0 0 0.5rem 0;
    }
    
    .catalog-filters-accordion .accordion-button::after {
        display: none;
    }
    
    .catalog-filters-accordion .accordion-collapse {
        display: block !important;
    }
    
    .catalog-filters-accordion .accordion-body {
        padding: 0 0 1rem 0;
    }
    
    .catalog-filters-accordion .accordion-item {
        border-bottom: none;
        margin-bottom: 0.5rem;
    }
}

/* На мобильном (до 991px) - кнопка фильтров и аккордеон */
@media (max-width: 991px) {
    .catalog-filters-sticky .card-header {
        cursor: pointer;
    }
    
    .catalog-filters-sticky .card-body {
        padding: 0.75rem 1rem;
    }
    
    .catalog-filters-accordion .accordion-button {
        font-size: 1rem;
    }
}

/* Кнопки OK в фильтрах - не переносить текст */
.category-search-form .btn,
.category-price-form .btn {
    white-space: nowrap;
    flex-shrink: 0;
}

/* Кнопка показать/скрыть фильтры на мобильном (до 991px) */
@media (max-width: 991px) {
    .filters-toggle-btn {
        font-weight: 600;
        padding: 0.75rem 1rem;
        border-radius: 0.5rem;
        transition: all 0.2s ease;
    }
    
    .filters-toggle-btn:not(.collapsed) .filters-toggle-icon {
        transform: rotate(180deg);
    }
    
    .filters-toggle-icon {
        transition: transform 0.3s ease;
    }
    
    .catalog-filters-sticky .card-header {
        padding: 0.75rem;
        background: transparent;
        border-bottom: none;
    }
    
    #filtersCollapse {
        transition: height 0.35s ease;
    }
}


/* Белый фон для заголовков аккордеона фильтров на мобильном */
@media (max-width: 991px) {
    .catalog-filters-accordion .accordion-header {
        background: #fff;
    }
}

/* Убрать желтоватый фон у активной кнопки аккордеона */
.catalog-filters-accordion .accordion-button:not(.collapsed) {
    background-color: #fff !important;
    
    box-shadow: none;
}

.catalog-filters-accordion .accordion-button:focus {
    box-shadow: none;
    border-color: transparent;
}

/* Переопределение желтого фона для фильтров каталога */
.catalog-filters-accordion .accordion-button:hover {
    background-color: #fff !important;
}

.catalog-filters-accordion .accordion-button:focus {
    box-shadow: none !important;
}

/* ============================================
   Дерево подкатегорий (как на Ozon)
   ============================================ */
.subcat-tree-container {
    padding: 0;
}

/* Кнопка "Назад ко всем" */
.subcat-tree-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
    color: #bf372b;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid #eee;
}

.subcat-tree-back:hover {
    color: #263940;
}

.subcat-tree-back svg {
    flex-shrink: 0;
}

/* Основной список */
.subcat-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Дочерние списки */
.subcat-tree-children {
    list-style: none;
    padding: 0 0 0 1rem;
    margin: 0;
    display: none;
    border-left: 2px solid #eee;
    margin-left: 0.5rem;
}

.subcat-tree-children.expanded {
    display: block;
}

/* Элемент списка */
.subcat-tree-item {
    margin: 0;
    padding: 0.25rem 0;
}

/* Родительский элемент с дочерними */
.subcat-tree-parent {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Ссылка на подкатегорию */
.subcat-tree-link {
    display: block;
    flex: 1;
    padding: 0.375rem 0;
    color: #333;
    font-size: 0.9rem;
    text-decoration: none;
    line-height: 1.3;
    transition: color 0.15s ease;
}

.subcat-tree-link:hover {
    color: #bf372b;
}

.subcat-tree-link.active {
    color: #bf372b;
    font-weight: 600;
}

/* Кнопка раскрытия */
.subcat-tree-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: #f5f5f5;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.subcat-tree-toggle:hover {
    background: #e8e8e8;
}

.subcat-tree-toggle svg {
    color: #666;
}

.subcat-tree-toggle[aria-expanded="true"] svg {
    transform: rotate(-180deg);
}

/* Количество товаров */
.subcat-tree-count {
    color: #666;
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

/* Дочерние элементы меньше */
.subcat-tree-children .subcat-tree-link {
    font-size: 0.85rem;
    padding: 0.25rem 0;
}

/* Скролл если много подкатегорий */
.subcat-tree-container {
    max-height: 400px;
    overflow-y: auto;
}

/* Красивый скроллбар */
.subcat-tree-container::-webkit-scrollbar {
    width: 4px;
}

.subcat-tree-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}

.subcat-tree-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.subcat-tree-container::-webkit-scrollbar-thumb:hover {
    background: #999;
}
