/* ==========================================================================
   product-gallery.css
   Dedicated CSS for the product page image / video gallery system.
   Class names prefixed with .pg-* are new; legacy classes from products_store.css
   (.product__images_wrap, .video-container, .play_icon, etc.) are preserved
   so the existing product_info.php and product_images_ajax.php continue to work.

   Layout model:
     Desktop — vertical strip of thumbnails beside a large primary viewer.
     Mobile  — full-width scroll-snap carousel with dot indicators.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. DESKTOP GALLERY LAYOUT
   -------------------------------------------------------------------------- */

.pg-desktop-gallery {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

/* Primary viewer (large image or embedded video) */
.pg-primary {
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 500px;
    overflow: hidden;
    border-radius: 6px;
    cursor: zoom-in;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.pg-primary img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: opacity 0.15s ease;
}

/* When the primary viewer holds a video instead of an image */
.pg-primary .pg-video-wrap {
    position: absolute;
    inset: 0;
    cursor: default;
}
/* YT IFrame API replaces #pg-yt-player with an iframe — keep it filling the wrap */
.pg-primary .pg-video-wrap > div,
.pg-primary .pg-video-wrap > div > iframe {
    width: 100% !important;
    height: 100% !important;
}

/* Thumbnail strip
   6 columns: 5 additional + 1 show-more (or primary when ≤5 additional).
   gap: 6px × 5 inter-item gaps = 30px; each item = (100% - 30px) / 6      */
.product__images_wrap {                 /* legacy class — keep for JS hooks */
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.product__images_wrap .pg-thumb {
    position: relative;
    width: calc((100% - 30px) / 6);
    min-width: 52px;
    height: 62px;
    overflow: hidden;
    border-radius: 5px;
    border: 2px solid transparent;
    background: #f0f0f0;
    cursor: pointer;
    transition: border-color 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

.product__images_wrap .pg-thumb:hover {
    border-color: #bbb;
    opacity: 0.88;
}

.product__images_wrap .pg-thumb img.active_image,
.product__images_wrap .pg-thumb:has(img.active_image) {
    border-color: #1a1a1a;
}

.product__images_wrap .pg-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* Primary image thumbnail (last in strip, always pre-selected) */
.product__images_wrap .pg-thumb--primary img.active_image {
    border: 2px solid #1a1a1a;
}

/* "Show more" button — same size as a thumbnail, opens the image browser */
.product__images_wrap .pg-thumb--more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: 2px dashed #ccc;
    border-radius: 5px;
    color: #555;
    font-size: 11px;
    line-height: 1.2;
    gap: 2px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.product__images_wrap .pg-thumb--more:hover {
    background: #e8e8e8;
    border-color: #999;
    color: #222;
}

.pg-thumb-more-count {
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.pg-thumb-more-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------------
   2. YOUTUBE THUMBNAIL OVERLAY
   -------------------------------------------------------------------------- */

/* Play button overlay on YouTube thumbnails */
.pg-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.28);
    color: #fff;
    pointer-events: none;
    z-index: 1;
    border-radius: 3px;
    transition: background 0.15s;
}

.pg-thumb--video:hover .pg-play-overlay {
    background: rgba(0, 0, 0, 0.45);
}

.pg-play-overlay svg {
    filter: drop-shadow(0 1px 3px rgba(0,0,0,.5));
    width: 28px;
    height: 28px;
}

/* Legacy play icon class — kept for compatibility with product_images_ajax.php */
.play_icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: auto;
    pointer-events: none;
    z-index: 1;
    opacity: 0.85;
}

/* --------------------------------------------------------------------------
   3. EMBEDDED VIDEO (16:9 aspect-ratio wrapper)
   Used when a YouTube video is the active primary item,
   in the mobile carousel, and in the SEO video section below the description.
   -------------------------------------------------------------------------- */

.pg-video-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 6px;
    overflow: hidden;
}

.pg-video-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Legacy class — preserved for backwards compatibility */
.video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 30px;
    height: 0;
    overflow: hidden;
}

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* --------------------------------------------------------------------------
   4. SEO VIDEO SECTION (shown below product description)
   -------------------------------------------------------------------------- */

.pg-video-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 20px 0;
    max-width: 680px;
}

.pg-video-section .pg-video-wrap {
    max-height: 460px;
}

/* Legacy class */
.products_description.videos {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 0;
    flex-direction: column;
    margin: 20px auto;
    max-width: 80%;
}

.products_description.videos iframe {
    aspect-ratio: 16 / 9;
    width: 100%;
    max-height: 500px;
}

/* --------------------------------------------------------------------------
   5. MOBILE CAROUSEL
   -------------------------------------------------------------------------- */

.pg-mobile-gallery {
    display: none; /* hidden on desktop; shown via media query */
}

.pg-mobile-carousel {
    width: 100%;
    overflow: hidden;
    position: relative;
}

.pg-mobile-carousel > ul {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: scroll;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 0;
    /* hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.pg-mobile-carousel > ul::-webkit-scrollbar {
    display: none;
}

.pg-slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    min-height: 280px;
}

.pg-slide--image img {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    object-position: center;
    display: block;
}

.pg-slide--video {
    background: #000;
    min-height: 220px;
}

.pg-slide--video .pg-video-wrap {
    width: 100%;
    border-radius: 0;
}

/* Carousel controls */
.pg-carousel-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    gap: 8px;
}

.pg-carousel-indicators {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.dot.active {
    background: #333;
    transform: scale(1.25);
}

.pg-prev-btn,
.pg-next-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    transition: border-color 0.15s, color 0.15s;
    flex-shrink: 0;
}

.pg-prev-btn:hover,
.pg-next-btn:hover {
    border-color: #888;
    color: #111;
}

/* Legacy button classes — kept for compatibility */
.prev-button,
.next-button {
    background: none;
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    color: #555;
    transition: border-color 0.15s, color 0.15s;
}

.prev-button:hover,
.next-button:hover {
    border-color: #888;
    color: #111;
}

/* --------------------------------------------------------------------------
   6. LIGHTBOX / IMAGE POPUP
   -------------------------------------------------------------------------- */

/* Outer container — exists in the page DOM, hidden by default.
   product_images_ajax.php injects two children into it:
     .product__image_popup_container  – dark backdrop (click-to-close)
     .product__image_popup_wrap       – the visible popup box
*/
.product__image_popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999990;
    overflow-y: auto;
}

/* Dark backdrop — clicking it closes the popup */
.product__image_popup_container {
    position: fixed;
    inset: 0;
    z-index: 999991;
    background: rgba(0, 0, 0, 0.72);
    cursor: pointer;
}

/* The popup box — vertical stack: name → main image → thumbnail strip.
   A fixed height is required so flex children can resolve percentage-based
   max-height/height on their own children (the selected image).
   Using clamp() gives a sensible range across viewport sizes. */
.product__image_popup_wrap {
    position: relative;
    z-index: 999992;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px;
    padding: 0;
    cursor: default;
    width: 92%;
    max-width: 1800px;
    height: clamp(420px, 90vh, 1200px);
    margin: 40px auto;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

/* Top bar: product name + close button.
   The panel is first in the AJAX DOM, so it naturally sits at the top
   of the column-flex wrap — no CSS order override needed. */
.product__image_popup_panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 10px 16px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
    /* reset legacy overrides */
    margin-top: 0;
    border-radius: 0;
    background: transparent;
    width: initial;
    min-width: initial;
}

.product__image_popup_panel h1 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
    color: #222;
    flex: 1;
    padding: 0;
    text-align: left;
}

.product__image_popup_wrap button.close_image_window {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    line-height: 1.4;
    /* reset legacy overrides */
    position: initial;
    height: initial;
}

.product__image_popup_wrap button.close_image_window:hover {
    background: #f0f0f0;
}

/* Main image area — fills the available height between panel and strip.
   flex: 1 + min-height: 0 ensures it respects the wrap's fixed height
   and doesn't grow to fit its content (which would break the layout). */
.product__image_popup_main {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    overflow: hidden;
    padding: 12px;
}

/* width/height 100% + object-fit: contain keeps the image within the
   computed dimensions of the parent without overflow or distortion. */
.product__image_popup_main img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

.product__image_popup_main .embed-youtube {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.product__image_popup_main .embed-youtube iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Thumbnail strip — horizontal carousel at the bottom */
.pg-popup-strip {
    display: flex;
    align-items: center;
    gap: 0;
    border-top: 1px solid #e8e8e8;
    background: #f5f5f5;
    flex-shrink: 0;
    padding: 6px 4px;
}

.pg-popup-strip .pg-popup-strip-btn {
    flex-shrink: 0;
    width: 36px;
    height: 52px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    letter-spacing: normal;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #444;
    transition: background 0.15s, border-color 0.15s;
    margin: 0 4px;
    padding: 0;
    /* reset legacy overrides */
    position: initial;
}

.pg-popup-strip .pg-popup-strip-btn:hover {
    background: #f0f0f0;
    border-color: #999;
    color: #111;
}

.product__image_popup_images {
    flex: 1;
    list-style: none;
    margin: 0;
    padding: 0 2px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 5px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;   /* Firefox */
    -ms-overflow-style: none;
}

.product__image_popup_images::-webkit-scrollbar {
    display: none;
}

.product__image_popup_images li {
    flex-shrink: 0;
    width: 64px;
    height: 48px;
    overflow: hidden;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s;
}

.product__image_popup_images li:hover {
    border-color: #aaa;
}

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

.product__image_popup_images li img.active_image,
.product__image_popup_images li.pg-popup-active {
    border-color: #222;
}

/* --------------------------------------------------------------------------
   7. DEV-PAGE DEBUGGING PANEL
   Shown only in product_info_development.php, not on production.
   -------------------------------------------------------------------------- */

.pg-dev-panel {
    background: #f8f5f0;
    border: 1px solid #e0d8cc;
    border-radius: 6px;
    padding: 16px 20px;
    margin-bottom: 24px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.55;
}

.pg-dev-panel h4 {
    margin: 0 0 8px;
    font-size: 13px;
    font-family: -apple-system, sans-serif;
    color: #5a3e00;
}

.pg-dev-panel table {
    width: 100%;
    border-collapse: collapse;
}

.pg-dev-panel td {
    padding: 2px 8px 2px 0;
    vertical-align: top;
    color: #333;
}

.pg-dev-panel td:first-child {
    color: #888;
    white-space: nowrap;
    padding-right: 16px;
}

.pg-dev-label {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pg-dev-label--image   { background: #dbeafe; color: #1e40af; }
.pg-dev-label--youtube { background: #fee2e2; color: #991b1b; }
.pg-dev-label--legacy  { background: #fef3c7; color: #92400e; }
.pg-dev-label--new     { background: #dcfce7; color: #166534; }

/* --------------------------------------------------------------------------
   8. RESPONSIVE BREAKPOINTS
   -------------------------------------------------------------------------- */

/* Desktop — right-side padding so gallery doesn't butt up against adjacent panels */
@media (min-width: 651px) {
    .pg-desktop-gallery {
        padding-right: 20px;
    }
}

/* Tablet / mid-width — keep 6-column layout but reduce height */
@media (max-width: 1100px) {
    .product__images_wrap .pg-thumb {
        height: 56px;
    }
}

/* Mobile — show carousel, hide desktop gallery */
@media (max-width: 650px) {
    .pg-desktop-gallery {
        display: none;
    }

    .pg-mobile-gallery {
        display: block;
    }

    .pg-slide {
        min-height: 240px;
    }

    .pg-slide--image img {
        max-height: 300px;
    }
}

/* Wide screens — taller primary viewer */
@media (min-width: 1600px) {
    .pg-primary {
        max-height: 600px;
    }
}
