/* ================================================================
   AmazonImageSlider — External Stylesheet
   Extracted from injectStyles() to prevent CLS from JS-injected CSS.
   Load this in <head> before the slider JS.
   ================================================================ */

/* ── Skeleton placeholder (prevents CLS before JS loads) ───── */
.ais-skeleton { width: 100%; }

.ais-skeleton-main {
    aspect-ratio: 1 / 1;
    background: #f0f0f0;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}
.ais-skeleton-main::after,
.ais-skeleton-thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.6) 50%, transparent 100%);
    animation: ais-shimmer 1.4s infinite;
}
@keyframes ais-shimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.ais-skeleton-thumbs {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    overflow: hidden;
}
.ais-skeleton-thumb {
    width: 85px;
    height: 85px;
    flex-shrink: 0;
    background: #e8e8e8;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

/* ── Slider core ─────────────────────────────────────────────── */
.amazon-slider {
    --slider-radius: 8px;
    --slider-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --slider-accent: #1e4fa0;
    --slider-accent-light: rgba(30, 79, 160, 0.1);
    max-width: 100%;
    margin: 0 auto;
    font-family: inherit;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
}

/* ── Vertical layout (desktop only via CSS) ──────────────────── */
@media (min-width: 769px) {
    .amazon-slider.vertical-layout .slider-content {
        display: flex;
        gap: 16px;
    }
    .amazon-slider.vertical-layout .thumbnails-container {
        order: -1;
        width: 95px;
        flex-shrink: 0;
    }
    .amazon-slider.vertical-layout .main-image-container {
        flex: 1;
        min-width: 0;
        margin-bottom: 0;
    }
}

/* ── Main image ──────────────────────────────────────────────── */
.main-image-container {
    position: relative;
    margin-bottom: 12px;
}

.main-image-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: var(--slider-radius);
    background: #f8f9fa;
    cursor: grab;
    user-select: none;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    aspect-ratio: var(--slide-aspect-ratio, 1 / 1);
}
.main-image-wrapper:active { cursor: grabbing; }

.image-track {
    display: flex;
    width: 100%;
    height: 100%;
    will-change: transform;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.slide {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.slide img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    transform: translateZ(0);
}

/* ── Navigation arrows ───────────────────────────────────────── */
.navigation-arrows {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 12px;
    pointer-events: none;
    z-index: 10;
}

.nav-arrow {
    background: rgba(255,255,255,0.95);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
    transition: opacity 0.2s ease-out, transform 0.15s ease-out, box-shadow 0.15s ease-out;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    color: #333;
    opacity: 0;
    transform: translateZ(0);
}
.nav-arrow svg { width: 22px; height: 22px; }
.main-image-container:hover .nav-arrow { opacity: 1; }
.nav-arrow:hover {
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateZ(0) scale(1.08);
}
.nav-arrow:active { transform: translateZ(0) scale(0.95); }
.nav-arrow:focus-visible { outline: 2px solid var(--slider-accent); outline-offset: 2px; }

/* ── Indicators ──────────────────────────────────────────────── */
.indicators {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 2px;
    z-index: 10;
}
.indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease-out;
    padding: 0;
    transform: translateZ(0);
    position: relative;
}
.indicator::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 8px; height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    transition: background 0.15s ease-out, transform 0.15s ease-out;
}
.indicator:hover::after { background: rgba(255,255,255,0.8); }
.indicator.active::after {
    background: var(--slider-accent);
    transform: translate(-50%, -50%) scale(1.3);
}
.indicator:focus-visible { outline: 2px solid var(--slider-accent); outline-offset: 2px; }

/* ── Thumbnails ──────────────────────────────────────────────── */
.thumbnails-container {
    display: flex;
    align-items: center;
    gap: 8px;
}
.thumbnails-container.vertical {
    flex-direction: column;
    height: 100%;
    max-height: 500px;
}

.thumb-nav {
    background: transparent;
    border: none;
    border-radius: 4px;
    width: 32px; height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s, color 0.18s, opacity 0.18s;
    color: #888;
    padding: 0;
}
.thumb-nav svg {
    width: 20px; height: 20px;
    transition: transform 0.18s;
    display: block;
}
.thumb-nav:hover:not(:disabled) { background: #f0f0f0; color: #333; }
.thumb-nav:focus-visible { outline: 2px solid var(--slider-accent); outline-offset: 2px; }

/* ── Arrow rotation theo layout ──────────────────────────────── */
/* Horizontal layout: ← prev, → next */
.thumbnails-container.horizontal .thumb-prev svg { transform: rotate(0deg); }
.thumbnails-container.horizontal .thumb-next svg { transform: rotate(180deg); }
/* Vertical layout: ↑ prev, ↓ next */
.thumbnails-container.vertical .thumb-prev svg { transform: rotate(90deg); }
.thumbnails-container.vertical .thumb-next svg { transform: rotate(-90deg); }
/* Vertical ≤768px switches to horizontal via CSS */
@media (max-width: 768px) {
    .thumbnails-container.vertical .thumb-prev svg { transform: rotate(0deg); }
    .thumbnails-container.vertical .thumb-next svg { transform: rotate(180deg); }
}

/* ── Disabled state ──────────────────────────────────────────── */
.thumb-nav:disabled,
.thumb-nav[aria-disabled="true"] {
    opacity: 0.28;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Hidden when all thumbs fit (no scrolling needed) ─────────── */
.thumb-nav--hidden {
    visibility: hidden;  /* giữ layout, không gây reflow */
    pointer-events: none;
}

.thumbnails-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
}
.thumbnails-container.vertical .thumbnails-wrapper {
    overflow-y: auto;
    overflow-x: hidden;
}
.thumbnails-container.horizontal .thumbnails-wrapper {
    overflow-x: auto;
    overflow-y: hidden;
}
.thumbnails-wrapper::-webkit-scrollbar { width: 3px; height: 3px; }
.thumbnails-wrapper::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.thumbnails {
    display: flex;
    gap: 8px;
    padding: 4px 0;
    transform: translateZ(0);
}
.thumbnails-container.vertical .thumbnails {
    flex-direction: column;
    padding: 0 4px;
}

.thumbnail {
    position: relative;
    flex-shrink: 0;
    width: 85px; height: 85px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s ease-out, box-shadow 0.15s ease-out;
    background: #fff;
    padding: 0;
    transform: translateZ(0);
}
.thumbnail:hover { border-color: var(--slider-accent); }
.thumbnail.active {
    border-color: var(--slider-accent);
    box-shadow: 0 0 0 2px var(--slider-accent-light);
}
.thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.thumbnail[data-type="video"] { border-color: #e74c3c; }
.thumbnail[data-type="video"].active { border-color: #c0392b; }
.thumbnail:focus-visible { outline: 2px solid var(--slider-accent); outline-offset: 2px; }

/* Placeholder khi video không có thumbnail (native video không có poster) */
.thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    color: rgba(255,255,255,0.7);
}

.video-thumb-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.65);
    border-radius: 50%;
    width: 24px; height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    /* Không dùng font-size vì dùng SVG inline, không phụ thuộc Font Awesome */
    pointer-events: none;
}

/* ── Zoom overlay ────────────────────────────────────────────── */
.zoom-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.main-image-wrapper:hover .zoom-overlay[style*="flex"] { opacity: 1; }
.zoom-message {
    background: rgba(0,0,0,0.75);
    color: white;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
}

/* ── Video slides ────────────────────────────────────────────── */
.video-slide { background: #000; }
.video-container {
    position: relative;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.video-container video,
.video-container iframe { width: 100%; height: 100%; object-fit: contain; }
.video-container iframe { aspect-ratio: 16 / 9; border: none; display: block; }
.video-play-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    color: rgba(255,255,255,0.9);
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    padding: 0;
}
.video-play-overlay:hover {
    transform: translate(-50%, -50%) scale(1.1);
    color: white;
}

/* ── YouTube Facade (thumbnail + play btn, no iframe until click) ─ */
.yt-facade {
    cursor: pointer;
    background: #000;
}
.yt-facade .yt-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* YouTube-branded play button */
.yt-facade .yt-play-btn {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.18s ease-out, filter 0.18s ease-out;
    filter: drop-shadow(0 2px 10px rgba(0,0,0,0.5));
    line-height: 0;
    /* override .video-play-overlay font-size for SVG button */
    font-size: 0;
}
.yt-facade:hover .yt-play-btn {
    transform: translate(-50%, -50%) scale(1.1);
    filter: drop-shadow(0 4px 16px rgba(0,0,0,0.6));
}
/* Red button hover darkens on hover */
.yt-facade:hover .yt-play-btn svg path:first-child { fill: #cc0000; }

.yt-active { background: #000; }
.yt-iframe { width: 100%; height: 100%; border: none; display: block; }

/* ── Lightbox ────────────────────────────────────────────────── */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: background 0.25s ease-out;
    will-change: background;
}
.lightbox-overlay.active { background: rgba(0,0,0,0.92); }

.lightbox-container {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    transform: scale3d(0.92, 0.92, 1);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.25s ease-out;
    will-change: transform, opacity;
    backface-visibility: hidden;
}
.lightbox-overlay.active .lightbox-container {
    transform: scale3d(1, 1, 1);
    opacity: 1;
}

.lightbox-close {
    position: absolute;
    top: -48px; right: 0;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 40px; height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s;
}
.lightbox-close svg { width: 22px; height: 22px; }
.lightbox-close:hover { background: rgba(255,255,255,0.25); }
.lightbox-close:focus-visible,
.lightbox-prev:focus-visible,
.lightbox-next:focus-visible { outline: 2px solid white; outline-offset: 2px; }

.lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
    pointer-events: none;
}
.lightbox-prev,
.lightbox-next {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 48px; height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    pointer-events: all;
    transition: background 0.2s;
}
.lightbox-prev svg, .lightbox-next svg { width: 28px; height: 28px; }
.lightbox-prev:hover, .lightbox-next:hover { background: rgba(255,255,255,0.28); }

.lightbox-counter {
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.8);
    font-size: 14px;
}

/* ── Scrollbar shift compensation when lightbox opens ────────── */
body.ais-lightbox-open {
    overflow: hidden;
    /* padding-right injected by JS to compensate scrollbar width */
}

/* ── Responsive — Tablet ≤ 768px ────────────────────────────── */
@media (max-width: 768px) {
    .amazon-slider.vertical-layout .slider-content { display: block; }
    .amazon-slider.vertical-layout .thumbnails-container {
        order: 0;
        width: 100% !important;
        height: auto;
        max-height: none;
    }
    .amazon-slider.vertical-layout .thumbnails { flex-direction: row; }
    .main-image-container { margin-bottom: 8px; }
    .main-image-wrapper { border-radius: 4px; }
    .navigation-arrows { padding: 0 4px; }
    .nav-arrow {
        width: 36px; height: 36px;
        opacity: 0.85;
        background: rgba(255,255,255,0.9);
    }
    .nav-arrow svg { width: 18px; height: 18px; }
    .thumb-nav { display: none; }
    .thumbnails-container { gap: 0; }
    .thumbnails-wrapper {
        width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .thumbnails-wrapper::-webkit-scrollbar { display: none; }
    .thumbnails { padding: 4px 0; gap: 6px; }
    .thumbnail { width: 70px; height: 70px; border-radius: 4px; }
    .zoom-overlay { display: none !important; }
    .indicators { bottom: 6px; gap: 0; }
    .indicator { width: 24px; height: 24px; }
    .indicator::after { width: 6px; height: 6px; }
    .lightbox-container { max-width: 98vw; }
    .lightbox-prev, .lightbox-next { width: 40px; height: 40px; }
    .lightbox-nav { padding: 0 8px; }
    .ais-skeleton-thumb { width: 70px; height: 70px; }
}

/* ── Responsive — Mobile ≤ 480px ────────────────────────────── */
@media (max-width: 480px) {
    .main-image-container { margin-bottom: 6px; }
    .navigation-arrows { padding: 0 2px; }
    .nav-arrow { width: 32px; height: 32px; opacity: 0.8; }
    .nav-arrow svg { width: 16px; height: 16px; }
    .thumbnails { gap: 4px; padding: 2px 0; }
    .thumbnail { width: 60px; height: 60px; }
    .indicators { bottom: 4px; }
    .indicator::after { width: 5px; height: 5px; }
    .lightbox-nav { padding: 0 4px; }
    .lightbox-prev, .lightbox-next { width: 36px; height: 36px; }
    .lightbox-prev svg, .lightbox-next svg { width: 20px; height: 20px; }
    .ais-skeleton-thumb { width: 60px; height: 60px; }
    .ais-skeleton-thumbs { gap: 4px; }
}
