/* ========== БАЗА ========== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, system-ui, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    background-color: #f5f5f7;
    color: #111827;
}

body {
    -webkit-font-smoothing: antialiased;
}

/* Контейнер по центру, адаптивный */
.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 16px 16px 32px;
}

/* ========== КАТАЛОГ ========== */

.catalog-page {
    min-height: 100vh;
}

.catalog-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
    text-align: left;
}

.catalog-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #111827;
}

.catalog-meta {
    font-size: 13px;
    color: #6b7280;
}

/* Контролы фильтра */
.product-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.product-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #374151;
}

.product-filter label {
    white-space: nowrap;
}

.product-filter select {
    min-width: 150px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background-color: #fff;
    font-size: 14px;
    color: #111827;
    outline: none;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #9ca3af 50%),
                      linear-gradient(135deg, #9ca3af 50%, transparent 50%);
    background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

.product-filter select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

/* Прелоадер */
.product-loading {
    font-size: 14px;
    color: #6b7280;
    text-align: center;
    padding: 12px 0;
}

/* ========== СЕТКА ТОВАРОВ ========== */

.products {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

/* На очень узких экранах по одному в ряд */
@media (max-width: 440px) {
    .products {
        grid-template-columns: 1fr;
    }
}

/* На планшетах и выше — 3 в ряд */
@media (min-width: 768px) {
    .products {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px;
    }
}

/* На десктопе — 4 в ряд */
@media (min-width: 1024px) {
    .products {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 18px;
    }
}

/* ========== КАРТОЧКА ТОВАРА ========== */

.product-card {
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

/* Обёртка для изображения, фиксированная пропорция */
.product-card-image-wrapper {
    position: relative;
    width: 100%;
    padding-top: 75%; /* 4:3 — норм для мини-превью */
    overflow: hidden;
    background: linear-gradient(145deg, #e5e7eb, #f9fafb);
}

.product-card-image-wrapper img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Содержимое карточки */
.product-card-body {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    color: #111827;
    margin: 0;
}

.product-card-price {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.product-card-currency {
    font-weight: 500;
    font-size: 12px;
    color: #6b7280;
}

/* Нет товаров */
.products-empty {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 14px;
    color: #6b7280;
    padding: 16px 0 8px;
}

/* ========== МОДАЛЬНОЕ ОКНО ========== */

.modal {
    display: none; /* показывается через JS как flex */
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    justify-content: center;
    align-items: center;
    padding: 12px;
}

/* Контент модалки — мобильный full-screen, на больших max-width */
.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 480px;
    max-height: 100%;
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 14px 40px rgba(15, 23, 42, 0.35);
    overflow: hidden;
}

/* Верхняя часть модалки: картинка + заголовок + цена */
.modal-header {
    padding: 12px 14px 8px;
    border-bottom: 1px solid #e5e7eb;
    position: relative;
}

/* Крестик */
.close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    z-index: 3;
}

.close:hover {
    color: #111827;
}

/* ========== СЛАЙДЕР ИЗОБРАЖЕНИЙ (ПРАВКИ: кнопки поверх картинки, на всю высоту, еле-сероватые) ========== */

/* Контейнер: делаем относительным, убираем gap и выравнивание под "кнопки сбоку" */
.image-slider {
    position: relative;
    display: flex;
    justify-content: center;
    margin-top: 4px;
    margin-bottom: 8px;
    /* чтобы абсолютные кнопки совпадали по высоте с картинкой */
    align-items: stretch;
}

/* Картинка остаётся как есть */
#modal-img {
    display: block;
    max-width: 100%;
    max-height: 52vh;
    border-radius: 12px;
    object-fit: contain;
    transition: opacity 0.2s ease-out;
    background-color: #f3f4f6;
}

/* Общие стили кнопок: поверх изображения, на всю высоту изображения */
.image-slider button {
    position: absolute;
    top: 0;
    bottom: 0;               /* на всю высоту области слайдера (по факту — по высоте img) */
    width: 20%;              /* большая зона тапа */
    border: none;
    background: transparent; /* сама зона прозрачная */
    padding: 0;
    margin: 0;
    cursor: pointer;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
    /* убираем старые "кнопочные" стили */
    border-radius: 0;
    height: auto;
    font-size: 0;
    color: transparent;
    flex-shrink: unset;
    transition: none;
}

/* Позиционирование */
#prev-img { left: 0; }
#next-img { right: 0; }

/* "Еле-еле сероватая" подсказка по краям (очень мягкий градиент) */
#prev-img {
    background: linear-gradient(90deg, rgba(17, 24, 39, 0.06), rgba(17, 24, 39, 0));
}
#next-img {
    background: linear-gradient(270deg, rgba(17, 24, 39, 0.06), rgba(17, 24, 39, 0));
}

/* Кружок со стрелкой — ненавязчивый и полупрозрачный */
.image-slider button::before {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.18); /* очень мягко-серый */
    backdrop-filter: blur(4px);
    opacity: 0.75;
    transition: opacity 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

/* Сами стрелки (SVG маской) */
.image-slider button::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    opacity: 0.75;
    background: rgba(255, 255, 255, 0.95);
    mask-size: 12px 12px;
    mask-repeat: no-repeat;
    mask-position: center;
    -webkit-mask-size: 12px 12px;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
}

/* Лево */
#prev-img::before { left: 10px; }
#prev-img::after  {
    left: 10px;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M15 18l-6-6 6-6'/%3E%3C/svg%3E");
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M15 18l-6-6 6-6'/%3E%3C/svg%3E");
}

/* Право */
#next-img::before { right: 10px; }
#next-img::after  {
    right: 10px;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M9 6l6 6-6 6'/%3E%3C/svg%3E");
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M9 6l6 6-6 6'/%3E%3C/svg%3E");
}

/* Hover/Active — чуть заметнее, но всё равно деликатно */
.image-slider button:hover::before {
    opacity: 0.95;
    background: rgba(17, 24, 39, 0.22);
}
.image-slider button:hover::after {
    opacity: 0.9;
}

.image-slider button:active::before,
.image-slider button:active::after {
    transform: translateY(-50%) scale(0.96);
}

/* Фокус с клавиатуры */
.image-slider button:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
    border-radius: 10px;
}

/* ========== Заголовок и цена в модалке ========== */

#modal-title {
    margin: 6px 0 4px;
    font-size: 16px;
    font-weight: 700;
    color: #111827;
}

#modal-price {
    margin: 0 0 2px;
    font-size: 14px;
    font-weight: 600;
    color: #16a34a;
}

/* Тело модалки со скроллом */
.modal-body {
    padding: 10px 14px 14px;
    overflow-y: auto;
}

/* Внутреннее описание — форматируем контент из WP */
.modal-description {
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
}

.modal-description p {
    margin: 0 0 8px;
}

.modal-description ul,
.modal-description ol {
    margin: 0 0 8px 18px;
    padding: 0;
}

.modal-description li {
    margin-bottom: 4px;
}

.modal-description strong {
    font-weight: 600;
}

/* Видео в описании */
.modal-description video {
    width: 100%;
    max-height: 45vh;
    border-radius: 10px;
    margin: 8px 0;
    background-color: #000;
}

/* ========== КНОПКА "ЗАКАЗАТЬ" ========== */

.buy-button {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 11px 14px;
    border-radius: 999px;
    border: none;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #ffffff;
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.35);
    transition: transform 0.1s ease-out, box-shadow 0.15s ease-out, background 0.15s ease-out;
}

.buy-button:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.45);
    transform: translateY(-1px);
}

.buy-button:active {
    transform: translateY(1px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.35);
}

/* ========== АДАПТИВ ДЛЯ БОЛЬШИХ ЭКРАНОВ ========== */

@media (min-width: 640px) {
    .catalog-header h1 {
        font-size: 26px;
    }

    .modal-content {
        max-width: 520px;
    }
}

@media (min-width: 1024px) {
    .catalog-header {
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
    }

    .catalog-header h1 {
        font-size: 28px;
    }

    .catalog-meta {
        font-size: 14px;
    }

    .modal-content {
        max-width: 560px;
    }
}

/* ========== СКРОЛЛБАРЫ (не обязательно, но приятнее) ========== */

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.8);
    border-radius: 999px;
}

/* ========== МЕЛОЧИ ДЛЯ TELEGRAM WEBVIEW ========== */

@supports (-webkit-touch-callout: none) {
    body {
        -webkit-text-size-adjust: 100%;
    }
}

/* Чуть меньше паддинги на совсем маленьких экранах */
@media (max-width: 360px) {
    .container {
        padding: 12px 10px 24px;
    }
    .modal-content {
        border-radius: 12px;
    }
}