/*
 * Product page media: gallery stage + thumbnails + full-screen lightbox (images and YouTube).
 * Loaded by purchase.html. Logical properties are used throughout so the page works in both
 * RTL (Arabic) and LTR (English); chevrons are mirrored for RTL.
 */

/* ── gallery ────────────────────────────────────────────────────────────── */
.pg {
    position: sticky;
    top: 110px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.pg[hidden] {
    display: none;
}

/* grid columns must be allowed to shrink, or the scrollable thumbnail strip widens the page */
.product-detail-section .product-detail-grid > * {
    min-width: 0;
}

@media (max-width: 900px) {
    .product-detail-section .product-detail-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* give the pictures the larger half of the page on desktop */
@media (min-width: 901px) {
    .product-detail-section .product-detail-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.18fr);
        gap: 44px;
    }
}

.pg-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 22px;
    overflow: hidden;
    background: #07070a;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(139, 92, 246, 0.06);
    isolation: isolate;
    cursor: zoom-in;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.pg-stage.is-video {
    cursor: default;
}

.pg-stage:focus-visible {
    outline: 2px solid #a78bfa;
    outline-offset: 3px;
}

/* the same picture, blurred, fills the letterbox around images of any shape */
.pg-backdrop {
    position: absolute;
    inset: -40px;
    z-index: 0;
    background-position: center;
    background-size: cover;
    filter: blur(34px) saturate(1.25) brightness(0.42);
    transform: scale(1.1);
    transition: background-image 0.25s;
}

.pg-img {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: pgFade 0.28s ease;
}

.pg-img[hidden],
.pg-video[hidden] {
    display: none;
}

@keyframes pgFade {
    from { opacity: 0; transform: scale(0.985); }
    to { opacity: 1; transform: none; }
}

/* the video sits as a real 16:9 player on the blurred backdrop (9:16 for Shorts) */
.pg-video {
    position: absolute;
    z-index: 1;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.pg-video.is-vertical {
    top: 0;
    bottom: 0;
    left: 50%;
    right: auto;
    height: 100%;
    aspect-ratio: 9 / 16;
    transform: translateX(-50%);
}

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

/* YouTube cover: thumbnail + big play button, the player loads only when asked */
.pg-facade {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: #000;
    cursor: pointer;
    display: block;
    color: #fff;
    font: inherit;
}

.pg-facade img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease, filter 0.3s;
}

.pg-facade::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.05) 30%, rgba(0, 0, 0, 0.55) 100%);
}

.pg-facade:hover img {
    transform: scale(1.03);
    filter: brightness(1.08);
}

.pg-play {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.pg-play-circle {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(239, 35, 35, 0.92);
    box-shadow: 0 10px 30px rgba(239, 35, 35, 0.45), 0 0 0 8px rgba(255, 255, 255, 0.08);
    transition: transform 0.2s;
}

.pg-facade:hover .pg-play-circle {
    transform: scale(1.08);
}

.pg-play-circle svg {
    width: 34px;
    height: 34px;
    margin-inline-start: 4px;
    fill: #fff;
}

[dir="rtl"] .pg-play-circle svg {
    margin-inline-start: 0;
    margin-inline-end: 4px;
}

.pg-play-label {
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.62);
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(6px);
    white-space: nowrap;
}

/* stage controls */
.pg-nav,
.pg-expand {
    position: absolute;
    z-index: 3;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(10, 10, 14, 0.62);
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: opacity 0.2s, background 0.2s, transform 0.15s;
}

.pg-nav {
    top: 50%;
    width: 44px;
    height: 44px;
    margin-top: -22px;
    border-radius: 50%;
    opacity: 0;
}

.pg-prev { inset-inline-start: 14px; }
.pg-next { inset-inline-end: 14px; }

.pg-nav[hidden],
.pg-counter[hidden] {
    display: none;
}

.pg-stage:hover .pg-nav,
.pg-stage:focus-within .pg-nav {
    opacity: 1;
}

.pg-nav:hover,
.pg-expand:hover {
    background: rgba(139, 92, 246, 0.85);
}

.pg-nav:active {
    transform: scale(0.94);
}

.pg-nav svg,
.pg-expand svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

[dir="rtl"] .pg-nav svg,
[dir="rtl"] .lb-nav svg {
    transform: scaleX(-1);
}

.pg-expand {
    top: 12px;
    inset-inline-end: 12px;
    height: 36px;
    padding: 0 12px;
    border-radius: 11px;
    grid-auto-flow: column;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: inherit;
}

.pg-counter {
    position: absolute;
    z-index: 3;
    bottom: 12px;
    inset-inline-end: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.pg-hint {
    position: absolute;
    z-index: 3;
    bottom: 12px;
    inset-inline-start: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.88);
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.pg-hint svg {
    width: 14px;
    height: 14px;
}

.pg-stage:hover .pg-hint {
    opacity: 1;
}

.pg-stage.is-video .pg-hint {
    display: none;
}

/* thumbnails */
.pg-thumbs {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 2px 6px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.pg-thumbs:empty {
    display: none;
}

.pg-thumbs::-webkit-scrollbar {
    height: 6px;
}

.pg-thumbs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
}

.pg-thumb {
    position: relative;
    flex: 0 0 auto;
    width: 112px;
    aspect-ratio: 16 / 10;
    padding: 0;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    background: #0a0a0d;
    overflow: hidden;
    cursor: pointer;
    scroll-snap-align: start;
    opacity: 0.72;
    transition: opacity 0.2s, border-color 0.2s, transform 0.15s;
}

.pg-thumb:hover {
    opacity: 1;
}

.pg-thumb.is-active {
    opacity: 1;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

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

.pg-thumb-play {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.35);
}

.pg-thumb-play span {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(239, 35, 35, 0.92);
}

.pg-thumb-play svg {
    width: 14px;
    height: 14px;
    fill: #fff;
    margin-inline-start: 2px;
}

/* ── lightbox ───────────────────────────────────────────────────────────── */
html.lb-open,
html.lb-open body {
    overflow: hidden !important;
}

.lb {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    flex-direction: column;
    background: rgba(4, 4, 7, 0.96);
    backdrop-filter: blur(10px);
    color: #fff;
    animation: lbIn 0.22s ease;
}

.lb[hidden] {
    display: none;
}

@keyframes lbIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lb-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top));
}

.lb-counter {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    font-variant-numeric: tabular-nums;
}

.lb-title {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s;
}

.lb-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

.lb-btn svg {
    width: 22px;
    height: 22px;
    pointer-events: none;
}

.lb-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 72px 8px;
    overflow: hidden;
    touch-action: none;
}

.lb-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    cursor: zoom-in;
    transition: transform 0.25s ease;
    -webkit-user-drag: none;
    user-select: none;
    animation: pgFade 0.25s ease;
}

.lb-img.is-zoomed {
    transform: scale(2.4);
    cursor: zoom-out;
    transition: transform 0.25s ease, transform-origin 0s;
    border-radius: 0;
}

.lb-img[hidden],
.lb-video[hidden] {
    display: none;
}

.lb-video {
    width: min(1280px, 100%, calc((100vh - 200px) * 16 / 9));
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.lb-video.is-vertical {
    width: auto;
    height: min(86vh, 920px);
    max-width: 100%;
    aspect-ratio: 9 / 16;
}

.lb-video iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.lb-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 52px;
    height: 52px;
    margin-top: -26px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.lb-nav:hover {
    background: rgba(139, 92, 246, 0.85);
}

.lb-nav:active {
    transform: scale(0.94);
}

.lb-nav svg {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

.lb-prev { inset-inline-start: 14px; }
.lb-next { inset-inline-end: 14px; }

.lb-nav[hidden] {
    display: none;
}

.lb-thumbs {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    overflow-x: auto;
}

.lb-thumbs:empty {
    display: none;
}

.lb-thumbs .pg-thumb {
    width: 84px;
}

.lb-hint {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
    white-space: nowrap;
    transition: opacity 0.3s;
}

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .pg {
        position: static;
    }

    /* pictures first on phones and tablets */
    .product-detail-grid .product-media {
        order: -1;
    }
}

@media (hover: none) {
    .pg-nav {
        opacity: 1;
        width: 38px;
        height: 38px;
        margin-top: -19px;
    }

    .pg-hint {
        opacity: 1;
    }
}

@media (max-width: 640px) {
    .pg-stage {
        aspect-ratio: 4 / 3;
        border-radius: 18px;
    }

    .pg-thumb {
        width: 86px;
    }

    .pg-play-circle {
        width: 64px;
        height: 64px;
    }

    .pg-play-circle svg {
        width: 28px;
        height: 28px;
    }

    .pg-expand span {
        display: none;
    }

    .pg-expand {
        width: 38px;
        padding: 0;
    }

    .lb-stage {
        padding: 0 8px 8px;
    }

    .lb-nav {
        width: 42px;
        height: 42px;
        margin-top: -21px;
        background: rgba(0, 0, 0, 0.5);
    }

    .lb-thumbs {
        display: none;
    }

    .lb-video {
        width: 100%;
    }

    .product-info {
        padding: 24px 18px !important;
        border-radius: 20px !important;
    }

    .product-title {
        font-size: 1.85rem !important;
    }

    .product-price {
        font-size: 2.4rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pg-img,
    .lb-img,
    .lb,
    .pg-facade img {
        animation: none !important;
        transition: none !important;
    }
}
