/* Custom Product Gallery – Fotorama replacement */

.cpg-gallery {
    --cpg-gap: 12px;
    --cpg-thumb-size: 72px;
    --cpg-radius: 0px;
    --cpg-border: #e5e5e5;
    --cpg-accent: #333;
    --cpg-bg: #fff;
    width: 100%;
    max-width: 100%;
}

.cpg-gallery__inner {
    display: flex;
    gap: var(--cpg-gap);
}

/* Thumbnail position: bottom (default) */
.cpg-gallery--thumbs-bottom .cpg-gallery__inner {
    flex-direction: column;
}

.cpg-gallery--thumbs-bottom .cpg-gallery__thumbs {
    order: 2;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 8px;
    padding: 4px 0;
}

/* Thumbnail position: left */
.cpg-gallery--thumbs-left .cpg-gallery__inner {
    flex-direction: row;
}

.cpg-gallery--thumbs-left .cpg-gallery__thumbs {
    order: -1;
    flex-direction: column;
    flex-shrink: 0;
    width: var(--cpg-thumb-size);
    max-height: 520px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding: 0 4px;
}

.cpg-gallery--thumbs-left .cpg-gallery__main {
    flex: 1;
    min-width: 0;
}

.cpg-gallery__main {
    position: relative;
    width: 100%;
}

.cpg-gallery__stage {
    position: relative;
    background: var(--cpg-bg);
    border: 1px solid var(--cpg-border);
    border-radius: var(--cpg-radius);
    overflow: hidden;
    aspect-ratio: 1 / 1;
    touch-action: pan-y pinch-zoom;
}

.cpg-gallery__slides {
    position: relative;
    width: 100%;
    height: 100%;
    opacity: 1;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.cpg-gallery__slides--fading {
    opacity: 0;
}

.cpg-gallery__slide {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--cpg-bg);
    will-change: opacity;
}

.cpg-gallery__slide--active {
    opacity: 1;
    pointer-events: auto;
    z-index: 2;
}

.cpg-gallery__slide--leaving {
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.cpg-gallery__slide-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
    opacity: 1;
}

.cpg-gallery__slide-image--loading {
    opacity: 0;
}

.cpg-gallery__stage--zoomed .cpg-gallery__slide-image {
    cursor: zoom-out;
    max-width: none;
    max-height: none;
}

.cpg-gallery__video-wrap {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
}

.cpg-gallery__video-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Thumbnails */
.cpg-gallery__thumb {
    flex-shrink: 0;
    width: var(--cpg-thumb-size);
    height: var(--cpg-thumb-size);
    padding: 0;
    border: 2px solid transparent;
    border-radius:0;
    background: var(--cpg-bg);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
    opacity: 0.7;
}

.cpg-gallery__thumb:hover,
.cpg-gallery__thumb:focus-visible {
    opacity: 1;
    border-color: #999;
    outline: none;
}

.cpg-gallery__thumb--active {
    opacity: 1;
    border-color: var(--cpg-accent);
}

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

/* Arrows */
.cpg-gallery__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.cpg-gallery__stage:hover .cpg-gallery__arrow,
.cpg-gallery__arrow:focus-visible {
    opacity: 1;
}

.cpg-gallery__arrow:hover {
    background: #fff;
}

.cpg-gallery__arrow svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: var(--cpg-accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cpg-gallery__arrow--prev { left: 10px; }
.cpg-gallery__arrow--next { right: 10px; }

/* Toolbar */
.cpg-gallery__toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cpg-gallery__stage:hover .cpg-gallery__toolbar {
    opacity: 1;
}

.cpg-gallery__btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpg-gallery__btn svg {
    width: 20px;
    height: 20px;
    fill: var(--cpg-accent);
}

.cpg-gallery__btn:hover {
    background: #fff;
}

/* Counter */
.cpg-gallery__counter {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
    pointer-events: none;
}

/* Lightbox */
.cpg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpg-lightbox[hidden] {
    display: none !important;
}

.cpg-lightbox__backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.cpg-lightbox__content {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 16px 100px;
    box-sizing: border-box;
    pointer-events: none;
}

.cpg-lightbox__close,
.cpg-lightbox__arrow,
.cpg-lightbox__thumbs,
.cpg-lightbox__counter,
.cpg-lightbox__stage,
.cpg-lightbox__image-wrap {
    pointer-events: auto;
}

.cpg-lightbox__stage {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    cursor: pointer;
}

.cpg-lightbox__image-wrap {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}

.cpg-lightbox__image-wrap--zoomed {
    cursor: grab;
}

.cpg-lightbox__image {
    max-width: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
    transition: transform 0.1s ease-out, opacity 0.4s ease;
    user-select: none;
    -webkit-user-drag: none;
    opacity: 1;
}

.cpg-lightbox__image--fading {
    opacity: 0;
}

.cpg-lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 5;
    cursor: pointer;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpg-lightbox__close svg {
    width: 24px;
    height: 24px;
    fill: #fff;
}

.cpg-lightbox__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cpg-lightbox__arrow svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cpg-lightbox__arrow--prev { left: 12px; }
.cpg-lightbox__arrow--next { right: 12px; }

.cpg-lightbox__thumbs {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    max-width: calc(100% - 32px);
    overflow-x: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.cpg-lightbox__thumb {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 4px;
    background: none;
    cursor: pointer;
    overflow: hidden;
    opacity: 0.6;
}

.cpg-lightbox__thumb--active {
    border-color: #fff;
    opacity: 1;
}

.cpg-lightbox__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cpg-lightbox__counter {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
}

body.cpg-lightbox-open {
    overflow: hidden;
}

/* Mobile */
@media (max-width: 767px) {
    .cpg-gallery {
        --cpg-thumb-size: 60px;
    }

    /* Force bottom thumbnails on mobile for left layout */
    .cpg-gallery--thumbs-left .cpg-gallery__inner {
        flex-direction: column;
    }

    .cpg-gallery--thumbs-left .cpg-gallery__thumbs {
        order: 2;
        flex-direction: row;
        width: 100%;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .cpg-gallery__arrow {
        opacity: 1;
        width: 36px;
        height: 36px;
    }

    .cpg-gallery__toolbar {
        opacity: 1;
    }

    .cpg-gallery__stage {
        aspect-ratio: 4 / 5;
    }

    .cpg-lightbox__arrow {
        width: 40px;
        height: 40px;
    }

    .cpg-lightbox__thumbs {
        bottom: 8px;
    }

    .cpg-lightbox__thumb {
        width: 48px;
        height: 48px;
    }
}

@media (hover: none) {
    .cpg-gallery__arrow,
    .cpg-gallery__toolbar {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cpg-gallery__slides,
    .cpg-gallery__slide,
    .cpg-gallery__slide-image,
    .cpg-gallery__thumb,
    .cpg-lightbox__image {
        transition: none;
    }
}
