/* ==========================================================================
   Product Gallery — gallery.css  (v2: Swiper + Zoom + Lightbox)
   ========================================================================== */

/* ─── SWIPER BUNDLE OVERRIDE ─────────────────────────────────────────────── */
/* Bring in Swiper base; the actual CDN link is injected by PHP */

/* ─── GALLERY ROOT ───────────────────────────────────────────────────────── */
.pg-gallery {
    --gap: 10px;
    --pg-zoom-scale: 2.5;

    display: flex;
    gap: var(--gap);
    width: 100%;
    grid-column: span 12;
    position: relative;
}

/* ─── MAIN COLUMN ────────────────────────────────────────────────────────── */
.pg-main-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
    min-width: 0;
}

/* ─── MAIN IMAGE ─────────────────────────────────────────────────────────── */
.pg-main {
    position: relative;
    display: flex;
    align-items: center;
}

.pg-main-frame {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: var(--pg-main-border, none);
    border-radius: var(--pg-main-radius, 10px);
    background: #f5f5f5;
    cursor: crosshair;          /* signals zoom is available */
    position: relative;
}

.pg-main-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1);
    transform-origin: 50% 50%;
    transition: transform 0.08s linear;
    will-change: transform;
    display: block;
}

/* ── ZOOM BUTTON — the only trigger for the lightbox ────────────────────── */
/* Shared by gallery mode (.pg-main-frame > .pg-zoom-btn)                    */
/* and slider mode        (.pg-main > .pg-zoom-btn)                          */
.pg-zoom-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.88);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 5;          /* above the image and zoom transform */
    padding: 0;
    pointer-events: auto;
}
/* Show on hover of the immediate interactive container */
.pg-main-frame:hover .pg-zoom-btn,
.pg-main:hover > .pg-zoom-btn {
    opacity: 1;
}
.pg-zoom-btn:hover {
    background: rgba(255, 255, 255, 1);
}
.pg-zoom-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: #444;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ─── ARROWS (shared by main gallery & slider) ───────────────────────────── */
.pg-arrow {
    position: absolute;
    z-index: 4;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: #444;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    padding: 0;
    user-select: none;
}
.pg-arrow:hover {
    background: #000;
    border-color: #000;
    color: #fff;
}

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

.pg-hide-arrows .pg-arrow { display: none; }

/* ─── THUMBNAILS — Swiper container ─────────────────────────────────────── */
.pg-thumbs-swiper {
    /* sizing handled by layout classes below */
    flex-shrink: 0;
}

/* horizontal thumb strip (bottom / top layouts) */
.pg-layout-bottom .pg-thumbs-swiper,
.pg-layout-top    .pg-thumbs-swiper {
    width: 100%;
    height: var(--pg-thumb-size, 80px);
}

/* vertical thumb strip (left / right layouts) */
.pg-layout-left  .pg-thumbs-swiper,
.pg-layout-right .pg-thumbs-swiper {
    width: var(--pg-thumb-size, 80px);
    height: 100%;
    max-height: 520px;
}

/* individual thumb slide */
.pg-thumb-slide {
    width: var(--pg-thumb-size, 80px) !important;
    height: var(--pg-thumb-size, 80px) !important;
}

.pg-layout-left  .pg-thumb-slide,
.pg-layout-right .pg-thumb-slide {
    height: var(--pg-thumb-size, 80px) !important;
    width: 100% !important;
}

.pg-thumb {
    width: 100%;
    height: 100%;
    border: var(--pg-thumb-border, 1px solid #ddd);
    border-radius: var(--pg-thumb-radius, 6px);
    object-fit: cover;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.25s, border-color 0.25s, transform 0.15s;
    display: block;
}
.pg-thumb:hover {
    opacity: 0.85;
    transform: scale(1.04);
}
.pg-thumb.active {
    border: var(--pg-thumb-active-border, 2px solid #000);
    opacity: 1;
}

/* ─── DOTS ───────────────────────────────────────────────────────────────── */
.pg-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 4px 0;
}

.pg-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}
.pg-dot.active,
.pg-dot.swiper-pagination-bullet-active {
    background: #000;
    transform: scale(1.25);
}

.pg-hide-dots .pg-dots,
.pg-hide-dots .swiper-pagination { display: none; }

/* ─── LAYOUT: BOTTOM (default) ───────────────────────────────────────────── */
.pg-layout-bottom {
    flex-direction: column;
}
.pg-layout-bottom .pg-thumbs-swiper { order: 2; }
.pg-layout-bottom .pg-main-col      { order: 1; }

/* ─── LAYOUT: TOP ────────────────────────────────────────────────────────── */
.pg-layout-top {
    flex-direction: column;
}
.pg-layout-top .pg-thumbs-swiper { order: 0; }
.pg-layout-top .pg-main-col      { order: 1; }

/* ─── LAYOUT: LEFT ───────────────────────────────────────────────────────── */
.pg-layout-left {
    flex-direction: row;
    align-items: flex-start;
}
.pg-layout-left .pg-thumbs-swiper { order: 0; }
.pg-layout-left .pg-main-col      { order: 1; }

/* vertical Swiper inside left/right layouts */
.pg-layout-left  .pg-thumbs-swiper .swiper-wrapper,
.pg-layout-right .pg-thumbs-swiper .swiper-wrapper {
    flex-direction: column;
}

/* ─── LAYOUT: RIGHT ──────────────────────────────────────────────────────── */
.pg-layout-right {
    flex-direction: row;
    align-items: flex-start;
}
.pg-layout-right .pg-thumbs-swiper { order: 2; }
.pg-layout-right .pg-main-col      { order: 1; }

/* ─── LAYOUT: SLIDER ─────────────────────────────────────────────────────── */
.pg-layout-slider .pg-thumbs-swiper { display: none; }

/* Swiper main slider container (slider mode) */
.pg-main-swiper {
    width: 100%;
    position: relative;
}
.pg-main-swiper .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    border-radius: var(--pg-main-radius, 10px);
    overflow: hidden;
}
.pg-main-swiper .pg-main-img {
    /* In slider mode, zoom is disabled; reset overrides */
    cursor: default;
    transform: none !important;
    transition: none !important;
}

/* Dots inside Swiper pagination (slider mode) */
.pg-layout-slider .pg-dots {
    position: relative;
    margin-top: 8px;
}

/* Position arrows inside the Swiper wrapper for slider mode */
.pg-layout-slider .pg-prev { left: 10px; }
.pg-layout-slider .pg-next { right: 10px; }

/* ─── LIGHTBOX ────────────────────────────────────────────────────────────
   Fixed overlay rendered by JS and appended to <body>.
   ─────────────────────────────────────────────────────────────────────── */
.pg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.pg-lightbox.open {
    visibility: visible;
    opacity: 1;
}

.pg-lb-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    cursor: pointer;
}

.pg-lb-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 90vw;
    max-width: 900px;
    max-height: 92vh;
    padding: 20px;
    box-sizing: border-box;
}

/* Close button */
.pg-lb-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #222;
    z-index: 2;
    transition: background 0.2s, color 0.2s;
    padding: 0;
}
.pg-lb-close:hover {
    background: #000;
    color: #fff;
}

/* Lightbox main Swiper */
.pg-lb-main-swiper {
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    flex: 1 1 auto;
    max-height: calc(92vh - 120px);
}
.pg-lb-main-swiper .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
}
.pg-lb-img {
    max-width: 100%;
    max-height: calc(92vh - 130px);
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    border-radius: 4px;
}

/* Lightbox prev/next */
.pg-lb-prev,
.pg-lb-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
    user-select: none;
}
.pg-lb-prev:hover,
.pg-lb-next:hover {
    background: rgba(255, 255, 255, 0.35);
}
.pg-lb-prev { left: 10px; }
.pg-lb-next { right: 10px; }

/* Lightbox thumb Swiper (no dots, no navs, just slides) */
.pg-lb-thumbs-swiper {
    width: 100%;
    height: var(--pg-lb-thumb-size, 68px);
    flex-shrink: 0;
}
.pg-lb-thumbs-swiper .swiper-slide {
    width: var(--pg-lb-thumb-size, 68px) !important;
    height: var(--pg-lb-thumb-size, 68px) !important;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    opacity: 0.55;
    transition: opacity 0.2s, outline-offset 0.1s;
    outline: 2px solid transparent;
    outline-offset: 0px;
}
.pg-lb-thumbs-swiper .swiper-slide.swiper-slide-thumb-active,
.pg-lb-thumbs-swiper .swiper-slide.pg-lb-thumb-active {
    opacity: 1;
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.pg-lb-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* ─── RESPONSIVE ADJUSTMENTS ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .pg-layout-left,
    .pg-layout-right {
        flex-direction: column;
    }

    .pg-layout-left  .pg-thumbs-swiper,
    .pg-layout-right .pg-thumbs-swiper {
        width: 100%;
        height: var(--pg-thumb-size, 80px);
    }

    .pg-layout-left  .pg-thumbs-swiper .swiper-wrapper,
    .pg-layout-right .pg-thumbs-swiper .swiper-wrapper {
        flex-direction: row;
    }

    .pg-layout-left  .pg-thumb-slide,
    .pg-layout-right .pg-thumb-slide {
        width: var(--pg-thumb-size, 80px) !important;
        height: var(--pg-thumb-size, 80px) !important;
    }

    .pg-lb-content {
        width: 96vw;
        padding: 12px;
    }
    .pg-lb-close {
        top: 4px;
        right: 4px;
    }
}

@media (max-width: 480px) {
    .pg-lb-img {
        max-height: calc(90vh - 100px);
    }
    .pg-lb-thumbs-swiper {
        height: 52px;
    }
    .pg-lb-thumbs-swiper .swiper-slide {
        width: 52px !important;
        height: 52px !important;
    }
}
