/* ==========================================================================
   TuApp Theme - Vertical Gallery Styles (TikTok-Style)

   Sistema completo de estilos para la galería vertical de producto.
   Inspirado en TikTok/Instagram Reels para una experiencia inmersiva.

   Componentes:
   - .vertical-gallery: Contenedor principal (thumbs izquierda + visor).
   - .vertical-gallery__thumbs-wrapper: Carrusel vertical de miniaturas.
   - .vertical-gallery__main: Visor principal con snap-scroll vertical.
   - .vertical-gallery__slide: Cada slide (imagen o video).
   - .vertical-gallery__zoom-container: Contenedor para efecto lupa.
   - .vertical-gallery__zoom-lens: Lente de aumento (magnifier).
   - .horizontal-gallery: Galería horizontal alternativa.
   - .gallery-mode-toggle: Toggle vertical ↔ horizontal.

   Usa CSS custom properties del design system (style.css).
   ========================================================================== */

/* ==========================================================================
   Gallery Mode Toggle
   ========================================================================== */

.gallery-mode-toggle {
    position: absolute;
    top: var(--space-sm);
    left: var(--space-sm);
    z-index: 20;
    display: flex;
    gap: 2px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--radius-md);
    padding: 3px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.gallery-mode-toggle__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 30px;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-md) - 3px);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-mode-toggle__btn:hover {
    color: var(--color-text);
    background: var(--color-surface-alt);
}

.gallery-mode-toggle__btn.is-active {
    background: var(--color-accent);
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.gallery-mode-toggle__btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Vertical Gallery - Layout Principal
   ========================================================================== */

.vertical-gallery {
    position: relative;
    display: flex;
    gap: var(--space-sm);
    align-items: stretch;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.vertical-gallery--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

/* ==========================================================================
   Vertical Gallery - Thumbnails Wrapper (Izquierda)
   ========================================================================== */

.vertical-gallery__thumbs-wrapper {
    position: relative;
    flex-shrink: 0;
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    overflow: hidden;
    padding: var(--space-xs) 0;
}

.vertical-gallery__thumbs-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    z-index: 2;
}

.vertical-gallery__thumbs-arrow:hover {
    color: var(--color-accent);
    background: rgba(var(--color-accent-rgb), 0.06);
}

.vertical-gallery__thumbs-arrow:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

/* Track de miniaturas (scrollable) */
.vertical-gallery__thumbs-track {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
    padding: var(--space-2xs);
}

.vertical-gallery__thumbs-track::-webkit-scrollbar {
    display: none;
}

/* Miniatura individual */
.vertical-gallery__thumb {
    position: relative;
    width: 64px;
    height: 85px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    background: var(--color-surface);
    cursor: pointer;
    padding: 0;
    transition: all var(--transition-fast);
}

.vertical-gallery__thumb:hover {
    border-color: var(--color-border);
    transform: scale(1.03);
}

.vertical-gallery__thumb.is-active {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb), 0.25);
}

.vertical-gallery__thumb:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Ícono de play sobre miniaturas de video */
.vertical-gallery__thumb-play-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.vertical-gallery__thumb-active-indicator {
    position: absolute;
    left: -2px;
    top: 10%;
    bottom: 10%;
    width: 3px;
    background: var(--color-accent);
    border-radius: 0 2px 2px 0;
    pointer-events: none;
}

/* ==========================================================================
   Vertical Gallery - Main Viewer (Snap Scroll)
   ========================================================================== */

.vertical-gallery__main {
    flex: 1;
    position: relative;
    overflow-y: scroll;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: var(--color-surface-dark);
    border-radius: var(--radius-md);
    min-height: 0;
}

.vertical-gallery__main::-webkit-scrollbar {
    display: none;
}

/* ==========================================================================
   Vertical Slide
   ========================================================================== */

.vertical-gallery__slide {
    position: relative;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--color-surface-dark);
    container-type: inline-size;
}

/* Transición de opacidad entre slides */
.vertical-gallery__slide:not(.is-active) {
    opacity: 0.45;
    transition: opacity 0.4s ease;
}

.vertical-gallery__slide.is-active {
    opacity: 1;
}

/* ==========================================================================
   Zoom Container & Magnifier Lens
   ========================================================================== */

.vertical-gallery__zoom-container {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: zoom-in;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vertical-gallery__zoom-container:hover {
    cursor: none; /* El cursor se oculta para que la lupa sea la guía */
}

.vertical-gallery__zoom-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity var(--transition-fast);
    user-select: none;
    -webkit-user-drag: none;
}

/* Lente de Aumento (Lupa) */
.vertical-gallery__zoom-lens {
    position: absolute;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(0, 0, 0, 0.08),
        inset 0 0 0 1px rgba(255, 255, 255, 0.15);
    pointer-events: none;
    z-index: 10;
    background-repeat: no-repeat;
    will-change: background-position, transform, opacity;
    opacity: 0;
    transition: opacity 0.15s ease-out;
}

.vertical-gallery__zoom-lens.is-visible {
    opacity: 1;
}

/* Zoom activo: escala 3x */
.vertical-gallery__zoom-container.is-zooming .vertical-gallery__zoom-lens {
    transform: scale(1.05);
    transition: transform 0.1s ease-out;
}

/* ==========================================================================
   Fullscreen Button
   ========================================================================== */

.vertical-gallery__fullscreen-btn {
    position: absolute;
    bottom: var(--space-sm);
    right: var(--space-sm);
    width: 38px;
    height: 38px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 8;
    opacity: 0;
    transition: all var(--transition-fast);
}

.vertical-gallery__slide:hover .vertical-gallery__fullscreen-btn,
.vertical-gallery__slide:focus-within .vertical-gallery__fullscreen-btn {
    opacity: 1;
}

.vertical-gallery__fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.08);
}

.vertical-gallery__fullscreen-btn:focus-visible {
    opacity: 1;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ==========================================================================
   Slide Caption
   ========================================================================== */

.vertical-gallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--space-lg) var(--space-md) var(--space-md);
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: #ffffff;
    font-size: var(--text-xs);
    line-height: 1.5;
    z-index: 5;
    pointer-events: none;
}

/* ==========================================================================
   Slide Number Indicator
   ========================================================================== */

.vertical-gallery__slide-number {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #ffffff;
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    z-index: 8;
    letter-spacing: 0.02em;
    pointer-events: none;
}

/* ==========================================================================
   Video Container & Poster
   ========================================================================== */

.vertical-gallery__video-container {
    width: 100%;
    height: 100%;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vertical-gallery__video-poster {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: opacity var(--transition-base);
}

.vertical-gallery__video-poster:hover .vertical-gallery__video-poster-play {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.65);
}

.vertical-gallery__video-poster-play {
    width: 72px;
    height: 72px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 3;
}

.vertical-gallery__video-embed {
    position: absolute;
    inset: 0;
}

/* ==========================================================================
   Navigation Arrows (Up/Down)
   ========================================================================== */

.vertical-gallery__nav {
    position: absolute;
    right: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    z-index: 15;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.vertical-gallery:hover .vertical-gallery__nav,
.vertical-gallery:focus-within .vertical-gallery__nav {
    opacity: 1;
}

.vertical-gallery__nav-btn {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.vertical-gallery__nav-btn:hover {
    background: #ffffff;
    box-shadow: var(--shadow-md);
    transform: scale(1.08);
}

.vertical-gallery__nav-btn:active {
    transform: scale(0.95);
}

.vertical-gallery__nav-btn:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Dots Indicators (Vertical)
   ========================================================================== */

.vertical-gallery__dots {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 12;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: var(--space-xs);
}

.vertical-gallery__dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.4);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
    flex-shrink: 0;
}

.vertical-gallery__dot:hover {
    background: rgba(255, 255, 255, 0.7);
}

.vertical-gallery__dot.is-active {
    background: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(var(--color-accent-rgb), 0.3);
    transform: scale(1.3);
}

.vertical-gallery__dot:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ==========================================================================
   Horizontal Gallery (Alternativa)
   ========================================================================== */

.horizontal-gallery {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.horizontal-gallery__main {
    display: flex;
    gap: var(--space-2xs);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: var(--color-surface-dark);
    border-radius: var(--radius-md);
    aspect-ratio: 1;
}

.horizontal-gallery__main::-webkit-scrollbar {
    display: none;
}

.horizontal-gallery__slide {
    min-width: 100%;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    background: var(--color-surface-dark);
}

.horizontal-gallery__slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    user-select: none;
    -webkit-user-drag: none;
}

.horizontal-gallery__video-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #fff;
}

/* Miniaturas de galería horizontal */
.horizontal-gallery__thumbs {
    display: flex;
    gap: var(--space-2xs);
    margin-top: var(--space-xs);
    padding: 0 var(--space-sm) var(--space-sm);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.horizontal-gallery__thumb {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    background: var(--color-surface-alt);
    transition: all var(--transition-fast);
}

.horizontal-gallery__thumb:hover {
    border-color: var(--color-border);
}

.horizontal-gallery__thumb.is-active {
    border-color: var(--color-accent);
}

.horizontal-gallery__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================================================
   Animaciones
   ========================================================================== */

/* Fade-in para slides al activarse */
@keyframes vg-slide-fade-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.vertical-gallery__slide.is-active {
    animation: vg-slide-fade-in 0.4s ease-out both;
}

/* Sutil parallax en la imagen al hacer scroll */
@keyframes vg-subtle-zoom {
    from { transform: scale(1); }
    to   { transform: scale(1.03); }
}

/* ==========================================================================
   Estados: Loading, Error
   ========================================================================== */

.vertical-gallery__slide--loading {
    pointer-events: none;
}

.vertical-gallery__slide--loading .vertical-gallery__zoom-image {
    filter: blur(8px);
    transition: filter 0.3s ease;
}

.vertical-gallery__slide--loaded .vertical-gallery__zoom-image {
    filter: blur(0);
}

/* ==========================================================================
   Responsive: Tablet
   ========================================================================== */

@media (max-width: 1024px) {
    .vertical-gallery {
        gap: var(--space-xs);
    }

    .vertical-gallery__thumbs-wrapper {
        width: 68px;
    }

    .vertical-gallery__thumb {
        width: 54px;
        height: 72px;
    }

    .vertical-gallery__nav-btn {
        width: 34px;
        height: 34px;
    }

    .vertical-gallery__zoom-lens {
        width: 140px;
        height: 140px;
    }
}

/* ==========================================================================
   Responsive: Mobile
   ========================================================================== */

@media (max-width: 768px) {
    .gallery-mode-toggle {
        top: var(--space-xs);
        left: var(--space-xs);
    }

    .gallery-mode-toggle__btn {
        width: 30px;
        height: 26px;
    }

    .vertical-gallery {
        flex-direction: column-reverse;
        gap: var(--space-xs);
    }

    /* Miniaturas pasan a estar debajo del visor en horizontal */
    .vertical-gallery__thumbs-wrapper {
        flex-direction: row;
        width: 100%;
        height: auto;
        padding: var(--space-xs);
        gap: var(--space-xs);
        overflow-x: auto;
        overflow-y: hidden;
        flex-shrink: 0;
    }

    .vertical-gallery__thumbs-arrow {
        display: none;
    }

    .vertical-gallery__thumbs-track {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .vertical-gallery__thumb {
        width: 56px;
        height: 56px;
        flex-shrink: 0;
    }

    .vertical-gallery__thumb-active-indicator {
        left: 10%;
        right: 10%;
        top: auto;
        bottom: -2px;
        width: auto;
        height: 3px;
    }

    .vertical-gallery__main {
        aspect-ratio: auto;
        max-height: 55vh;
    }

    /* En móvil, ocultar lupa (se usa pinch-zoom nativo) */
    .vertical-gallery__zoom-lens {
        display: none !important;
    }

    .vertical-gallery__zoom-container {
        cursor: default;
    }

    .vertical-gallery__zoom-container:hover {
        cursor: default;
    }

    .vertical-gallery__nav {
        display: none; /* En móvil se usa swipe, no flechas */
    }

    .vertical-gallery__dots {
        right: 4px;
        gap: 6px;
    }

    .vertical-gallery__dot {
        width: 6px;
        height: 6px;
    }

    .vertical-gallery__slide-number {
        top: var(--space-xs);
        right: var(--space-xs);
        font-size: 0.7rem;
        padding: 2px 8px;
    }

    .horizontal-gallery__main {
        aspect-ratio: 3/4;
    }
}

/* ==========================================================================
   Responsive: Mobile pequeño
   ========================================================================== */

@media (max-width: 480px) {
    .vertical-gallery__thumbs-wrapper {
        gap: 4px;
        padding: 4px;
    }

    .vertical-gallery__thumb {
        width: 48px;
        height: 48px;
        border-width: 1.5px;
    }

    .vertical-gallery__main {
        max-height: 50vh;
    }

    .vertical-gallery__slide-number {
        font-size: 0.65rem;
    }

    .horizontal-gallery__thumbs {
        gap: 4px;
    }

    .horizontal-gallery__thumb {
        width: 48px;
        height: 48px;
    }
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .vertical-gallery__main {
        scroll-behavior: auto;
    }

    .vertical-gallery__zoom-lens {
        transition: none;
    }

    .vertical-gallery__slide.is-active {
        animation: none;
    }

    .vertical-gallery__nav-btn {
        transition: none;
    }

    .vertical-gallery__dot {
        transition: none;
    }

    .horizontal-gallery__main {
        scroll-behavior: auto;
    }
}

/* ==========================================================================
   Accessibility: Focus Visible
   ========================================================================== */

.vertical-gallery:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--radius-lg);
}

/* Asegurar que todos los elementos interactivos tengan focus visible */
.vertical-gallery button:focus-visible,
.horizontal-gallery button:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   High Contrast Mode (Windows)
   ========================================================================== */

@media (forced-colors: active) {
    .vertical-gallery__thumb.is-active {
        border-color: Highlight;
    }

    .vertical-gallery__dot.is-active {
        background: Highlight;
    }

    .gallery-mode-toggle__btn.is-active {
        background: Highlight;
        color: HighlightText;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .vertical-gallery,
    .horizontal-gallery {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .vertical-gallery__zoom-lens,
    .vertical-gallery__nav,
    .vertical-gallery__dots,
    .gallery-mode-toggle {
        display: none !important;
    }

    .vertical-gallery__main {
        overflow: visible;
        max-height: none;
    }

    .vertical-gallery__slide {
        min-height: auto;
        break-inside: avoid;
    }
}

/* ==========================================================================
   Dark Mode Preparation
   ========================================================================== */

/*
.is-dark-mode .vertical-gallery {
    background: var(--color-surface-dark);
}

.is-dark-mode .vertical-gallery__thumbs-wrapper {
    background: rgba(255, 255, 255, 0.03);
}

.is-dark-mode .vertical-gallery__thumb {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

.is-dark-mode .gallery-mode-toggle {
    background: rgba(30, 30, 40, 0.9);
    border-color: rgba(255, 255, 255, 0.08);
}

.is-dark-mode .vertical-gallery__nav-btn {
    background: rgba(30, 30, 40, 0.9);
    color: var(--color-text-on-dark);
    border-color: rgba(255, 255, 255, 0.1);
}
*/
