/* ==========================================================================
   Product Gallery — обычный слайдер + полноэкранный режим
   Использует Swiper.js. Все размеры адаптивны (clamp / %).
   ========================================================================== */

.pgallery,
.pgallery *,
.pfullscreen,
.pfullscreen * {
    box-sizing: border-box;
}

:root {
    --pg-gap: 10px;
    --pg-thumb-size: 64px;
    --pg-thumb-size-mobile: 52px;
    --pg-thumb-padding: 2px;
    --pg-radius: 4px;
    --pg-border: #e5e5e5;
    --pg-border-active: #c32e91;
    --pg-border-hover: #e6e6e6;
    --pg-bg: #fff;
    --pg-icon-bg: rgba(20, 20, 20, 0.55);
    --pg-icon-bg-hover: rgba(20, 20, 20, 0.75);
    --pg-z-fullscreen: 9999;
}

/* -------------------------------------------------------------------- */
/* Обычный слайдер                                                      */
/* -------------------------------------------------------------------- */

.pgallery {
    display: flex;
    gap: var(--pg-gap);
    width: 100%;
}

/* Колонка превью слева */
.pgallery__thumbs-wrap {
    position: relative;
    flex: 0 0 var(--pg-thumb-size);
    width: var(--pg-thumb-size);
}

.pgallery__thumbs {
    width: 100%;
    height: 100%;
    max-height: 700px;
}

.pgallery__thumb {
    position: relative;
    width: 100%;
    /*height: var(--pg-thumb-size);*/
    height: auto;
    border-radius: var(--pg-radius);
    padding: var(--pg-thumb-padding);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    background: var(--pg-bg);
    transition: border-color 0.15s ease;
}

.pgallery__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pgallery__thumb--active,
.pgallery__thumb.swiper-slide-thumb-active {
    border-color: var(--pg-border-active);
}

.pgallery__thumb:not(.pgallery__thumb--active):hover,
.pgallery__video-thumb:not(.pgallery__video-thumb--active):hover {
    border-color: var(--pg-border-hover);
}

.pgallery__thumb--video .pgallery__play-icon,
.pgallery__play-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25);
    top: -33px;
}

.pgallery__play-icon::before {
    content: "";
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 10px;
    border-color: transparent transparent transparent #fff;
    margin-left: 2px;
}

.pgallery__thumb-extra-count {
    position: absolute;
    bottom: 2px;
    right: 2px;
    left: 2px;
    text-align: center;
    font-size: 10px;
    line-height: 1.4;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 3px;
    padding: 0 2px;
}

.pgallery__thumbs-nav {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 18px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    color: #6b6b6b;
    background: linear-gradient(#fff, rgba(255, 255, 255, 0));
}

/* Стрелки управляются вручную из JS:
   верхняя — появляется, когда список превью проскроллен вниз;
   нижняя — появляется, только если превью-изображений больше порога. */
.pgallery__thumbs-nav.is-visible {
    display: flex;
}

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

.pgallery__thumbs-nav--prev {
    top: -2px;
}
.pgallery__thumbs-nav--prev::before {
    transform: rotate(-45deg);
    margin-top: 4px;
}

.pgallery__thumbs-nav--next {
    bottom: -2px;
}
.pgallery__thumbs-nav--next::before {
    transform: rotate(135deg);
    margin-bottom: 4px;
}

/* Отдельная (не-swiper) миниатюра видео под превью изображений */
.pgallery__video-thumb {
    position: relative;
    width: 100%;
    height: var(--pg-thumb-size);
    margin-top: 8px;
    border-radius: var(--pg-radius);
    padding: var(--pg-thumb-padding);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    background: var(--pg-bg);
    flex-shrink: 0;
}

.pgallery__video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pgallery__video-thumb--active {
    border-color: var(--pg-border-active);
}

.pgallery__thumbs-wrap {
    display: flex;
    flex-direction: column;
}

.pgallery__thumbs-scroll {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.pgallery__thumbs-scroll .pgallery__thumbs {
    height: 100%;
}

/* Область основного просмотра */
.pgallery__main-wrap {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.pgallery__main {
    width: 100%;
    aspect-ratio: 1 / 1.33333;
    border-radius: var(--pg-radius);
    overflow: hidden;
    background: var(--pg-bg);
}

.pgallery__slide {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pgallery__img,
.pgallery__video {
    width: 100%;
    height: 100%;
    display: block;
}

.pgallery__img {
    object-fit: cover;
}

.pgallery__video {
    object-fit: contain;
}

.pgallery__slide[data-type="image"] {
    cursor: zoom-in;
}

.pgallery__fullscreen-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--pg-icon-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
    display: none;
}

.pgallery__fullscreen-btn:hover {
    background: var(--pg-icon-bg-hover);
}

.pgallery__fullscreen-btn svg {
    width: 18px;
    height: 18px;
}

.pgallery__main-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
    display: none;
}

.pgallery__main-nav::before {
    content: "";
    width: 9px;
    height: 9px;
    border-top: 2px solid #333;
    border-right: 2px solid #333;
}

.pgallery__main-nav--prev {
    left: 10px;
}
.pgallery__main-nav--prev::before {
    transform: rotate(-135deg);
    margin-left: 3px;
}

.pgallery__main-nav--next {
    right: 10px;
}
.pgallery__main-nav--next::before {
    transform: rotate(45deg);
    margin-right: 3px;
}

.pgallery__main-nav.swiper-button-disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* -------------------------------------------------------------------- */
/* Полноэкранный режим                                                  */
/* -------------------------------------------------------------------- */

.pfullscreen {
    position: fixed;
    inset: 0;
    z-index: var(--pg-z-fullscreen);
    background: #fff;
    display: none;
}

.pfullscreen.is-open {
    display: flex;
}

.pfullscreen__close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--pg-bg);
    cursor: pointer;
    z-index: 5;
}

.pfullscreen__close::before,
.pfullscreen__close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 2px;
    background: #333;
}
.pfullscreen__close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}
.pfullscreen__close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* Левая колонка со списком превью (не Swiper — обычный скролл) */
.pfullscreen__thumbs {
    flex: 0 0 180px;
    width: 180px;
    height: 100%;
    overflow-y: auto;
    padding: 56px 16px 16px;
    border-right: 1px solid var(--pg-border);
}

.pfullscreen__thumbs-group + .pfullscreen__thumbs-group {
    margin-top: 20px;
}

.pfullscreen__thumbs-title {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
}

.pfullscreen__thumbs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pfullscreen__thumbs-list:empty,
.pfullscreen__thumbs-group:has(.pfullscreen__thumbs-list:empty) {
    display: none;
}

.pfullscreen__thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--pg-radius);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
}

.pfullscreen__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pfullscreen__thumb--active {
    border-color: var(--pg-border-active);
}

/* Правая область просмотра */
.pfullscreen__main-wrap {
    position: relative;
    flex: 1 1 auto;
    height: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.pfullscreen__main {
    width: 100%;
    height: 100%;
}

.pfullscreen__main .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
}

.pfullscreen__main img,
.pfullscreen__main video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.pfullscreen__main-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 4;
    display: none;
}

.pfullscreen__main-nav::before {
    content: "";
    width: 11px;
    height: 11px;
    border-top: 2px solid #333;
    border-right: 2px solid #333;
}

.pfullscreen__main-nav--prev {
    left: 16px;
}
.pfullscreen__main-nav--prev::before {
    transform: rotate(-135deg);
    margin-left: 4px;
}

.pfullscreen__main-nav--next {
    right: 16px;
}
.pfullscreen__main-nav--next::before {
    transform: rotate(45deg);
    margin-right: 4px;
}

.pfullscreen__main-nav.swiper-button-disabled {
    opacity: 0.35;
    pointer-events: none;
}

body.pfullscreen-open {
    overflow: hidden;
}

/* -------------------------------------------------------------------- */
/* Fallback без JS: показываем только колонку с одним превью и главное
   изображение, слайдер не активен (нет data-swiper-initialized).        */
/* -------------------------------------------------------------------- */

.pgallery:not(.is-initialized) .pgallery__thumbs-nav,
.pgallery:not(.is-initialized) .pgallery__main-nav {
    display: none;
}

/* -------------------------------------------------------------------- */
/* Адаптив                                                              */
/* -------------------------------------------------------------------- */

@media (max-width: 767px) {
    .pgallery {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .pgallery__thumbs-wrap {
        width: 100%;
        flex: 0 0 auto;
    }

    .pgallery__thumbs {
        max-height: none;
    }

    .pgallery__thumb {
        height: var(--pg-thumb-size-mobile);
    }

    .pgallery__thumbs-nav,
    .pgallery__thumbs-wrap {
        display: none;
    }

    .pfullscreen {
        flex-direction: column-reverse;
    }

    .pfullscreen__thumbs {
        flex: 0 0 88px;
        width: 100%;
        height: 88px;
        overflow-x: auto;
        overflow-y: hidden;
        display: flex;
        padding: 8px 12px;
        border-right: none;
        border-top: 1px solid var(--pg-border);
    }

    .pfullscreen__thumbs-group {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }

    .pfullscreen__thumbs-group + .pfullscreen__thumbs-group {
        margin-top: 0;
        margin-left: 16px;
    }

    .pfullscreen__thumbs-title {
        display: none;
    }

    .pfullscreen__thumbs-list {
        flex-direction: row;
    }

    .pfullscreen__thumb {
        width: 60px;
        flex-shrink: 0;
    }

    .pfullscreen__close {
        top: 8px;
        right: 8px;
    }
}
