/*
 * Галерея товара (собственная замена плагина nickx).
 * Размеры и цвета повторяют прежнюю галерею: рамка #E9E1D6, радиус 20px,
 * колонка миниатюр 158px на десктопе / 120px на планшете, лента снизу на мобайле.
 */

.styl-pgallery {
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

/* ── Главный слайдер ─────────────────────────────────────── */

.styl-pgallery__main {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 1px solid #E9E1D6;
    border-radius: 20px;
    background-color: #fefefe;
}

.styl-pgallery__main .swiper-wrapper,
.styl-pgallery__slide {
    height: 100%;
    border-radius: inherit;
}

.styl-pgallery__slide {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    background-color: #fefefe;
}

/*
 * Селектор длинный намеренно: WooCommerce задаёт
 * `.woocommerce div.product div.images img { height: auto }`, и правило
 * покороче проигрывает ему по специфичности — картинка вылезала из слайда.
 */
.woocommerce div.product .images.styl-pgallery .styl-pgallery__slide img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.styl-pgallery__slide--video {
    position: relative;
    background-color: #000;
}

/* Крупная кнопка play по центру кадра */
.styl-pgallery__video-play {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 76px;
    height: 76px;
    margin: 0;
    padding: 0;
    transform: translate(-50%, -50%);
    border: 0;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.styl-pgallery__video-play:hover,
.styl-pgallery__video-play:focus-visible {
    background-color: rgba(0, 0, 0, 0.75);
    transform: translate(-50%, -50%) scale(1.06);
}

.styl-pgallery__video-play[hidden] {
    display: none;
}

.styl-pgallery__video-play svg {
    width: 46px;
    height: 46px;
}

@media screen and (max-width: 767px) {
    .styl-pgallery__video-play {
        width: 62px;
        height: 62px;
    }

    .styl-pgallery__video-play svg {
        width: 38px;
        height: 38px;
    }
}

.woocommerce div.product .images.styl-pgallery .styl-pgallery__video {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
    background-color: #000;
}

/* ── Стрелки ─────────────────────────────────────────────── */

.styl-pgallery__arrow {
    position: absolute;
    top: 50%;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 30px;
    height: 50px;
    margin: 0;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    background-color: #fff;
    color: #000;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.styl-pgallery__arrow--prev {
    left: 10px;
}

.styl-pgallery__arrow--next {
    right: 10px;
}

.styl-pgallery__arrow::before {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
}

.styl-pgallery__arrow--prev::before {
    transform: translateX(2px) rotate(-135deg);
}

.styl-pgallery__arrow--next::before {
    transform: translateX(-2px) rotate(45deg);
}

.styl-pgallery__main:hover .styl-pgallery__arrow,
.styl-pgallery__arrow:focus-visible {
    opacity: 1;
}

.styl-pgallery__arrow.swiper-button-disabled {
    pointer-events: none;
    opacity: 0 !important;
}

/* Пальцем стрелки не нужны — на слайдере работает свайп. */
@media (hover: none) {
    .styl-pgallery__arrow {
        display: none;
    }
}

/* ── Миниатюры ───────────────────────────────────────────── */

.styl-pgallery__thumbs {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

/*
 * Стрелки ленты миниатюр. Основную подсказку даёт срезанная плитка у края
 * (slidesPerView дробный, см. product-gallery.js), стрелки — для тех,
 * кто намёк не считывает. Swiper сам вешает swiper-button-lock, когда
 * прокручивать нечего, и swiper-button-disabled на краях.
 */
.styl-pgallery__thumbs-arrow {
    position: absolute;
    left: 50%;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 40px;
    height: 22px;
    margin: 0;
    padding: 0;
    transform: translateX(-50%);
    border: 1px solid #E9E1D6;
    border-radius: 11px;
    background-color: rgba(254, 254, 254, 0.94);
    color: #8B6A4F;
    cursor: pointer;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.styl-pgallery__thumbs-arrow--prev {
    top: 4px;
}

.styl-pgallery__thumbs-arrow--next {
    bottom: 4px;
}

.styl-pgallery__thumbs-arrow::before {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
}

.styl-pgallery__thumbs-arrow--prev::before {
    transform: translateY(2px) rotate(-45deg);
}

.styl-pgallery__thumbs-arrow--next::before {
    transform: translateY(-2px) rotate(135deg);
}

.styl-pgallery__thumbs-arrow:hover {
    background-color: #fff;
}

.styl-pgallery__thumbs-arrow.swiper-button-disabled,
.styl-pgallery__thumbs-arrow.swiper-button-lock {
    display: none;
}

/*
 * Стрелки нарисованы под вертикальную ленту (сверху и снизу). Ниже 768px
 * лента горизонтальная, и там ориентируемся на свайп и срезанную плитку.
 * На тач-устройствах стрелки не нужны в любой ширине.
 */
@media screen and (max-width: 767px), (hover: none) {
    .styl-pgallery__thumbs-arrow {
        display: none;
    }
}

/*
 * Размер плитки задаём здесь, а не через slidesPerView: так она остаётся
 * квадратной при любой высоте колонки, а последняя видимая сама оказывается
 * срезанной — это и есть подсказка, что лента листается.
 */
.styl-pgallery__thumb {
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    width: 96px;
    height: 96px;
    border: 1px solid #E9E1D6;
    border-radius: 12px;
    background-color: #fefefe;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

.woocommerce div.product .images.styl-pgallery .styl-pgallery__thumb img {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.styl-pgallery__thumb.swiper-slide-thumb-active,
.styl-pgallery__thumb:hover {
    border-color: #8B6A4F;
    opacity: 1;
}

/*
 * Кадр из видео почти никогда не квадратный (ролики снимают вертикально),
 * и при contain плитка наполовину пустая. Здесь режем по центру —
 * фотографиям товара contain оставляем, они и так вписаны в квадрат.
 */
.woocommerce div.product .images.styl-pgallery .styl-pgallery__thumb--video img {
    object-fit: cover;
}

/* Иконка play поверх превью видео */
.styl-pgallery__play {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 38px;
    height: 38px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
    pointer-events: none;
}

.styl-pgallery__play svg {
    width: 26px;
    height: 26px;
}

/* ── Планшет и десктоп: миниатюры колонкой слева ──────────── */

/*
 * Высота обоих столбцов задаётся явно: вертикальный Swiper считает высоту
 * слайда от высоты контейнера, а при height:auto контейнер зависит от слайдов —
 * получается цикл, и лента растягивается в бесконечность.
 */
@media screen and (min-width: 768px) {
    .styl-pgallery {
        flex-direction: row-reverse;
        align-items: flex-start;
        justify-content: flex-end;
        gap: 27px;
    }

    .styl-pgallery__main {
        flex: 1 1 0;
        width: auto;
        aspect-ratio: auto;
        height: min(55vh, 495px);
    }

    .styl-pgallery__thumbs {
        flex: 0 0 120px;
        width: 120px;
        min-width: 120px;
        max-width: 120px;
        height: min(55vh, 495px);
    }

    .styl-pgallery__thumb {
        width: 100%;
        height: 120px;
        border-radius: 20px;
    }
}

@media screen and (min-width: 1025px) {
    .single-product.woocommerce-page .new-custom-product .product-top > .images.styl-pgallery {
        flex: 1 1 0;
        width: auto;
        max-width: calc(100% - 470px);
    }

    .styl-pgallery__main {
        max-width: 620px;
    }

    .styl-pgallery__thumbs {
        flex: 0 0 158px;
        width: 158px;
        min-width: 158px;
        max-width: 158px;
    }

    .styl-pgallery__thumb {
        height: 158px;
    }
}

@media screen and (min-width: 768px) and (max-width: 1024px) {
    .single-product.woocommerce-page .new-custom-product .product-top > .images.styl-pgallery {
        flex: 1 1 0;
        width: calc(50% - 15px);
        max-width: calc(50% - 15px);
    }
}
