/* ═══════════════════════════════════════════════════════════════════════════
 * JBN PRODUCT VIEWER — Premium Lightbox with Zoom + Pan + Carousel
 * Phase A: works on every product image with single source today
 * Phase B: auto-upgrades to multi-angle carousel when data-jbn-gallery is set
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ─── 1 · BACKDROP ───────────────────────────────────────────────────────── */
.jbn-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 11, 24, 0.85);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 320ms cubic-bezier(0.4, 0, 0.2, 1);
}
.jbn-lightbox.is-open {
    opacity: 1;
    pointer-events: auto;
}
body.jbn-lightbox-open {
    overflow: hidden;
    touch-action: none;
}

/* ─── 2 · IMAGE STAGE ────────────────────────────────────────────────────── */
.jbn-lightbox__stage {
    position: relative;
    width: min(94vw, 1200px);
    height: min(82vh, 800px);
    overflow: hidden;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
    touch-action: none;
    cursor: grab;
    transform: scale(0.92);
    transition: transform 360ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.jbn-lightbox.is-open .jbn-lightbox__stage {
    transform: scale(1);
}
.jbn-lightbox__stage.is-zoomed { cursor: grab; }
.jbn-lightbox__stage.is-panning { cursor: grabbing; }

.jbn-lightbox__img {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: 100%;
    max-height: 100%;
    transform-origin: center;
    transform: translate(-50%, -50%) scale(1);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
    will-change: transform;
}
.jbn-lightbox__stage.is-panning .jbn-lightbox__img {
    transition: none;
}

/* ─── 3 · CONTROLS (close, zoom, fullscreen) ─────────────────────────────── */
.jbn-lightbox__controls {
    position: absolute;
    top: 18px;
    right: 18px;
    display: flex;
    gap: 8px;
    z-index: 2;
}
.jbn-lightbox__btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 200ms, border-color 200ms, transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 0;
}
.jbn-lightbox__btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.jbn-lightbox__btn:hover {
    background: rgba(99, 102, 241, 0.35);
    border-color: rgba(99, 102, 241, 0.6);
    transform: translateY(-2px);
}
.jbn-lightbox__btn:active { transform: translateY(0) scale(0.96); }
.jbn-lightbox__btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ─── 4 · ZOOM INDICATOR ─────────────────────────────────────────────────── */
.jbn-lightbox__zoom-pill {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 999px;
    color: rgba(226, 232, 240, 0.9);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.4px;
    font-variant-numeric: tabular-nums;
    opacity: 0;
    transition: opacity 240ms;
    pointer-events: none;
    z-index: 2;
}
.jbn-lightbox.is-zoomed .jbn-lightbox__zoom-pill {
    opacity: 1;
}

/* ─── 5 · CAROUSEL (Phase B — for multi-angle galleries) ─────────────────── */
.jbn-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    opacity: 0;
    transition: opacity 280ms, transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1), background 200ms;
}
.jbn-lightbox.has-gallery .jbn-lightbox__nav { opacity: 1; }
.jbn-lightbox__nav--prev { left: -68px; }
.jbn-lightbox__nav--next { right: -68px; }
.jbn-lightbox__nav:hover {
    background: rgba(99, 102, 241, 0.35);
    transform: translateY(-50%) scale(1.08);
}
.jbn-lightbox__nav:disabled { opacity: 0.25; cursor: not-allowed; }

@media (max-width: 900px) {
    .jbn-lightbox__nav--prev { left: 10px; }
    .jbn-lightbox__nav--next { right: 10px; }
    .jbn-lightbox__nav { width: 42px; height: 42px; }
}

/* ─── 6 · THUMBNAIL STRIP (Phase B) ──────────────────────────────────────── */
.jbn-lightbox__thumbs {
    position: absolute;
    bottom: -84px;
    left: 0;
    right: 0;
    display: none;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.jbn-lightbox.has-gallery .jbn-lightbox__thumbs { display: flex; }
.jbn-lightbox__thumbs::-webkit-scrollbar { height: 4px; }
.jbn-lightbox__thumbs::-webkit-scrollbar-thumb { background: rgba(99, 102, 241, 0.4); border-radius: 2px; }

.jbn-lightbox__thumb {
    flex: 0 0 64px;
    height: 64px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.6);
    cursor: pointer;
    transition: border-color 200ms, transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 0;
}
.jbn-lightbox__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.jbn-lightbox__thumb:hover { transform: translateY(-2px); }
.jbn-lightbox__thumb.is-active {
    border-color: var(--jbn-cta, #0066cc);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.3);
}

/* Phase B carousel layout adjustment — make room for thumbnails */
.jbn-lightbox.has-gallery .jbn-lightbox__stage {
    height: min(74vh, 700px);
}

@media (max-width: 600px) {
    .jbn-lightbox.has-gallery .jbn-lightbox__stage {
        height: min(66vh, 600px);
    }
    .jbn-lightbox__thumb { flex: 0 0 52px; height: 52px; }
    .jbn-lightbox__thumbs { bottom: -72px; padding: 8px 12px; }
}

/* ─── 7 · CAPTION / LABEL (angle name like "Front", "Back") ──────────────── */
.jbn-lightbox__caption {
    position: absolute;
    top: 18px;
    left: 18px;
    padding: 6px 14px;
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 999px;
    color: rgba(226, 232, 240, 0.9);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
    z-index: 2;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 240ms, transform 240ms;
    pointer-events: none;
}
.jbn-lightbox.has-caption .jbn-lightbox__caption {
    opacity: 1;
    transform: translateY(0);
}

/* ─── 8 · CLICKABILITY HINT on product images ────────────────────────────── */
.article-prose figure img,
.article-prose .jbn-product-img {
    cursor: zoom-in;
    transition: filter 240ms, transform 480ms cubic-bezier(0.4, 0, 0.2, 1);
}
.article-prose figure {
    position: relative;
}
.article-prose figure::before {
    content: "";
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(148, 163, 184, 0.22);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/><path d='M11 8v6'/><path d='M8 11h6'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 280ms, transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 1;
}
.article-prose figure:hover::before {
    opacity: 1;
    transform: scale(1);
}

/* ─── 9 · ENTRY/EXIT animations (respects reduced-motion via JS) ─────────── */
.jbn-lightbox__stage { animation: jbn-lb-pop 360ms cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
@keyframes jbn-lb-pop {
    0%   { transform: scale(0.82); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.jbn-lightbox.is-closing .jbn-lightbox__stage {
    transform: scale(0.94);
    opacity: 0;
    transition: opacity 220ms, transform 220ms cubic-bezier(0.4, 0, 1, 1);
}

/* ─── 10 · REDUCED MOTION ────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .jbn-lightbox,
    .jbn-lightbox__stage,
    .jbn-lightbox__img,
    .jbn-lightbox__btn,
    .jbn-lightbox__nav,
    .jbn-lightbox__thumb,
    .article-prose figure::before {
        transition: none !important;
        animation: none !important;
    }
    .jbn-lightbox__stage { transform: scale(1); }
}
