/**
 * Frontend CSS
 *
 * @package OTW_Variation_Gallery
 */

/* ===========================
   Gallery Wrapper Container
   =========================== */

.otw-vg-gallery-wrapper-container {
    margin-bottom: 30px;
    position: relative;
}

/* Hide default WooCommerce gallery when variation gallery is active */
.otw-vg-gallery-wrapper-container.active ~ .woocommerce-product-gallery,
.otw-vg-gallery-wrapper-container.active + .woocommerce-product-gallery {
    display: none !important;
}

/* For Elementor widget wrapper */
.otw-vg-widget-wrapper .otw-vg-gallery-wrapper-container.active ~ .otw-vg-default-gallery-wrapper,
.otw-vg-widget-wrapper .otw-vg-default-gallery-wrapper.hidden {
    display: none !important;
}

.otw-vg-widget-wrapper .otw-vg-default-gallery-wrapper {
    display: block;
}

/* Gallery wrapper - applies to both default and variation galleries */
.otw-vg-gallery-wrapper {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 100%;
    position: relative;
}

/* Thumbnail Position Variants */
.otw-vg-gallery-wrapper.thumbnails-left {
    flex-direction: row-reverse; /* Thumbnails on left, main on right */
}

.otw-vg-gallery-wrapper.thumbnails-right {
    flex-direction: row; /* Main on left, thumbnails on right */
}

.otw-vg-gallery-wrapper.thumbnails-top {
    flex-direction: column-reverse; /* Thumbnails on top, main below */
}

.otw-vg-gallery-wrapper.thumbnails-bottom {
    flex-direction: column; /* Main on top, thumbnails below */
}

.otw-vg-gallery-wrapper.thumbnails-on_image {
    flex-direction: column; /* Stack layout with thumbnails on image */
}

/* RTL Support */
.otw-vg-gallery-wrapper.rtl {
    direction: rtl;
}

/* ===========================
   Aspect Ratio Support
   =========================== */

/* 1:1 Square */
.otw-vg-gallery-wrapper.aspect-ratio-1-1 .otw-vg-main-gallery-container {
    position: relative;
    padding-bottom: 100%;
}

.otw-vg-gallery-wrapper.aspect-ratio-1-1 .otw-vg-main-gallery {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 8:6 Portrait */
.otw-vg-gallery-wrapper.aspect-ratio-8-6 .otw-vg-main-gallery-container {
    position: relative;
    padding-bottom: 75%; /* 6/8 = 0.75 */
}

.otw-vg-gallery-wrapper.aspect-ratio-8-6 .otw-vg-main-gallery {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 6:8 Landscape */
.otw-vg-gallery-wrapper.aspect-ratio-6-8 .otw-vg-main-gallery-container {
    position: relative;
    padding-bottom: 133.33%; /* 8/6 = 1.3333 */
}

.otw-vg-gallery-wrapper.aspect-ratio-6-8 .otw-vg-main-gallery {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Aspect ratio images should cover the container */
.otw-vg-gallery-wrapper.aspect-ratio-1-1 .otw-vg-slide img,
.otw-vg-gallery-wrapper.aspect-ratio-8-6 .otw-vg-slide img,
.otw-vg-gallery-wrapper.aspect-ratio-6-8 .otw-vg-slide img {
    object-fit: cover;
    width: 100%;
    height: 100%;
}

/* ===========================
   Loading Animation
   =========================== */

.otw-vg-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
    display: none;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.otw-vg-loading img {
    width: 60px;
    height: 60px;
    display: block;
    opacity: 1;
}

/* ===========================
   Main Gallery Container
   =========================== */

.otw-vg-main-gallery-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    max-width: 100%;
}

.otw-vg-main-gallery {
    width: 100%;
    height: auto;
    background: #f9f9f9;
    border-radius: 8px;
    overflow: hidden;
}

/* Default aspect ratio when none is set */
.otw-vg-gallery-wrapper.aspect-ratio-none .otw-vg-main-gallery {
    aspect-ratio: auto;
}

.otw-vg-main-gallery .swiper-wrapper {
    align-items: center;
}

.otw-vg-main-gallery .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.otw-vg-main-gallery .swiper-slide img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Lazy Loading State */
.otw-vg-slide.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Video Slides */
.otw-vg-video-slide {
    background: #000;
    cursor: default !important;
}

.otw-vg-video-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
}

.otw-vg-video-container iframe,
.otw-vg-video-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Zoom Icon */
.otw-vg-zoom-icon {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.otw-vg-main-gallery:hover .otw-vg-zoom-icon {
    opacity: 1;
}

.otw-vg-zoom-icon svg {
    width: 20px;
    height: 20px;
    color: #333;
}

/* ===========================
   Thumbnail Gallery Container
   =========================== */

.otw-vg-thumbs-gallery-container {
    flex-shrink: 0;
}

/* Left/Right Thumbnail Layout */
.thumbnails-left .otw-vg-thumbs-gallery-container,
.thumbnails-right .otw-vg-thumbs-gallery-container {
    width: 100px;
}

/* Top/Bottom Thumbnail Layout */
.thumbnails-top .otw-vg-thumbs-gallery-container,
.thumbnails-bottom .otw-vg-thumbs-gallery-container {
    width: 100%;
    height: 100px;
}

/* On Image Thumbnail Layout */
.thumbnails-on_image .otw-vg-main-gallery-container {
    position: relative;
}

.thumbnails-on_image .otw-vg-thumbs-gallery-container {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: calc(100% - 20px);
    z-index: 10;
    height: auto;
    direction: ltr; /* Force LTR for on_image positioning */
}

/* Shopify-Style Layout - Completely Static Display */
.thumbnails-shopify {
    flex-direction: column;
    gap: 15px;
}

/* Hide all swiper elements for Shopify layout */
.thumbnails-shopify .otw-vg-main-gallery-container,
.thumbnails-shopify .otw-vg-thumbs-gallery-container,
.thumbnails-shopify .swiper-button-next,
.thumbnails-shopify .swiper-button-prev,
.thumbnails-shopify .otw-vg-zoom-icon {
    display: none !important;
}

/* Static image grid container */
.thumbnails-shopify .otw-vg-static-gallery {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

/* First image (large) */
.thumbnails-shopify .otw-vg-static-image.first-image {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.thumbnails-shopify .otw-vg-static-image.first-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* Remaining images grid (2 columns) */
.thumbnails-shopify .otw-vg-static-images-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}

.thumbnails-shopify .otw-vg-static-image {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.thumbnails-shopify .otw-vg-static-image img {
    width: 100%;
    height: auto;
    display: block;
}

.thumbnails-on_image .otw-vg-thumbs-gallery {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    border-radius: 8px;
    padding: 8px;
}

.thumbnails-on_image .otw-vg-thumbs-gallery .swiper-wrapper {
    gap: 8px;
}

.thumbnails-on_image .otw-vg-thumbs-gallery .swiper-slide {
    width: auto !important;
    flex-shrink: 0;
}

.thumbnails-on_image .otw-vg-thumb {
    width: var(--otw-vg-on-image-thumb-size, 80px);
    height: var(--otw-vg-on-image-thumb-size, 80px);
}

.otw-vg-thumbs-gallery {
    position: relative;
    overflow: hidden;
}

.otw-vg-thumbs-gallery .swiper-slide {
    opacity: 0.6;
    cursor: pointer;
    transition: opacity 0.3s ease;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    background: #f9f9f9;
    position: relative;
}

.otw-vg-thumbs-gallery .swiper-slide:hover {
    opacity: 0.8;
}

.otw-vg-thumbs-gallery .swiper-slide-thumb-active {
    opacity: 1;
    border-color: #0073aa;
}

/* On Image thumbnails styling */
.thumbnails-on_image .otw-vg-thumbs-gallery .swiper-slide {
    border-color: rgba(255, 255, 255, 0.3);
}

.thumbnails-on_image .otw-vg-thumbs-gallery .swiper-slide-thumb-active {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.otw-vg-thumb {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* Video Icon on Thumbnails */
.otw-vg-video-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.otw-vg-video-icon svg {
    width: 16px;
    height: 16px;
    color: #fff;
    margin-left: 2px;
}

/* ===========================
   Swiper Navigation Buttons
   =========================== */

.otw-vg-gallery-wrapper .swiper-button-next,
.otw-vg-gallery-wrapper .swiper-button-prev {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    color: #333;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.otw-vg-gallery-wrapper .swiper-button-next:hover,
.otw-vg-gallery-wrapper .swiper-button-prev:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.1);
}

.otw-vg-gallery-wrapper .swiper-button-next::after,
.otw-vg-gallery-wrapper .swiper-button-prev::after {
    font-size: 18px;
    font-weight: bold;
}

.otw-vg-gallery-wrapper .swiper-button-disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Thumbnail Navigation Buttons */
.otw-vg-thumbs-gallery .swiper-button-next,
.otw-vg-thumbs-gallery .swiper-button-prev {
    width: 30px;
    height: 30px;
}

.otw-vg-thumbs-gallery .swiper-button-next::after,
.otw-vg-thumbs-gallery .swiper-button-prev::after {
    font-size: 14px;
}

/* ===========================
   Lightbox Modal
   =========================== */

.otw-vg-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: none;
}

.otw-vg-lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
}

.otw-vg-lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.otw-vg-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.otw-vg-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: rotate(90deg);
}

.otw-vg-lightbox-close svg {
    width: 24px;
    height: 24px;
    color: #fff;
}

.otw-vg-lightbox-gallery {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: calc(100vh - 120px);
}

.otw-vg-lightbox-gallery .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
}

.otw-vg-lightbox-gallery .swiper-slide img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: zoom-in;
}

.otw-vg-lightbox-gallery .swiper-slide.swiper-slide-zoomed img {
    cursor: zoom-out;
}

/* Lightbox Navigation */
.otw-vg-lightbox-gallery .swiper-button-next,
.otw-vg-lightbox-gallery .swiper-button-prev {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #fff;
}

.otw-vg-lightbox-gallery .swiper-button-next:hover,
.otw-vg-lightbox-gallery .swiper-button-prev:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.otw-vg-lightbox-gallery .swiper-button-next::after,
.otw-vg-lightbox-gallery .swiper-button-prev::after {
    font-size: 24px;
}

/* ===========================
   Responsive Design
   =========================== */

@media (max-width: 768px) {
    .otw-vg-gallery-wrapper {
        gap: 15px;
    }

    /* Force vertical layout on mobile */
    .otw-vg-gallery-wrapper.thumbnails-left,
    .otw-vg-gallery-wrapper.thumbnails-right {
        flex-direction: column;
    }

    .thumbnails-left .otw-vg-thumbs-gallery-container,
    .thumbnails-right .otw-vg-thumbs-gallery-container {
        width: 100%;
        height: 80px;
    }

    /* Shopify layout on mobile - keep 2-column grid or make it 1 column */
    .thumbnails-shopify .otw-vg-static-images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* Shopify mobile carousel mode - make static gallery scrollable */
    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-gallery {
        display: flex !important;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-gallery::-webkit-scrollbar {
        display: none;
    }

    /* Flatten the structure - all images same level and same size */
    /* Peek amount is controlled by inline CSS based on widget setting */
    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image.first-image,
    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-images-grid .otw-vg-static-image {
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }

    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-images-grid {
        display: contents; /* Remove the grid wrapper from layout */
    }

    /* Make all images same size and fill container */
    .thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image img {
        width: 100%;
        height: 400px;
        object-fit: cover;
        display: block;
    }

    /* Apply aspect ratio heights to mobile carousel images */
    /* 1:1 Square */
    .otw-vg-gallery-wrapper.aspect-ratio-1-1.thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image img {
        aspect-ratio: 1 / 1;
        height: auto;
    }

    /* 8:6 Portrait */
    .otw-vg-gallery-wrapper.aspect-ratio-8-6.thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image img {
        aspect-ratio: 8 / 6;
        height: auto;
    }

    /* 6:8 Landscape */
    .otw-vg-gallery-wrapper.aspect-ratio-6-8.thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image img {
        aspect-ratio: 6 / 8;
        height: auto;
    }

    /* None/Natural aspect ratio */
    .otw-vg-gallery-wrapper.aspect-ratio-none.thumbnails-shopify.shopify-mobile-carousel .otw-vg-static-image img {
        height: auto;
        aspect-ratio: auto;
    }

    /* On Image responsive adjustments */
    .thumbnails-on_image .otw-vg-thumbs-gallery-container {
        bottom: 5px;
        max-width: calc(100% - 10px);
    }

    .thumbnails-on_image .otw-vg-thumbs-gallery {
        padding: 5px;
    }

    .thumbnails-on_image .otw-vg-thumb {
        width: 60px;
        height: 60px;
    }

    .thumbnails-on_image .otw-vg-thumbs-gallery .swiper-wrapper {
        gap: 5px;
    }

    .otw-vg-main-gallery {
        aspect-ratio: 1 / 1;
    }

    .otw-vg-gallery-wrapper .swiper-button-next,
    .otw-vg-gallery-wrapper .swiper-button-prev {
        width: 35px;
        height: 35px;
    }

    .otw-vg-gallery-wrapper .swiper-button-next::after,
    .otw-vg-gallery-wrapper .swiper-button-prev::after {
        font-size: 16px;
    }

    .otw-vg-zoom-icon {
        width: 35px;
        height: 35px;
        bottom: 10px;
        right: 10px;
    }

    .otw-vg-zoom-icon svg {
        width: 18px;
        height: 18px;
    }

    .otw-vg-lightbox-content {
        padding: 80px 10px 40px;
    }

    .otw-vg-lightbox-close {
        width: 40px;
        height: 40px;
        top: 15px;
        right: 15px;
    }
}

@media (max-width: 480px) {
    .otw-vg-gallery-wrapper {
        gap: 10px;
    }

    .thumbnails-top .otw-vg-thumbs-gallery-container,
    .thumbnails-bottom .otw-vg-thumbs-gallery-container,
    .thumbnails-left .otw-vg-thumbs-gallery-container,
    .thumbnails-right .otw-vg-thumbs-gallery-container {
        height: 70px;
    }

    .otw-vg-loading {
        padding: 20px;
    }

    .otw-vg-loading img {
        width: 50px;
        height: 50px;
    }
}

/* ===========================
   Animations
   =========================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.otw-vg-gallery-wrapper-container {
    animation: fadeIn 0.4s ease;
}

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

@media print {
    .otw-vg-gallery-wrapper .swiper-button-next,
    .otw-vg-gallery-wrapper .swiper-button-prev,
    .otw-vg-zoom-icon,
    .otw-vg-lightbox {
        display: none !important;
    }
}

/* ===========================
   Accessibility
   =========================== */

.otw-vg-gallery-wrapper *:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.otw-vg-gallery-wrapper .swiper-button-next:focus,
.otw-vg-gallery-wrapper .swiper-button-prev:focus {
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.3);
}

/* Screen reader only text */
.otw-vg-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===========================
   High Contrast Mode Support
   =========================== */

@media (prefers-contrast: high) {
    .otw-vg-thumbs-gallery .swiper-slide-thumb-active {
        border-color: currentColor;
        border-width: 3px;
    }

    .otw-vg-gallery-wrapper .swiper-button-next,
    .otw-vg-gallery-wrapper .swiper-button-prev {
        border: 2px solid currentColor;
    }
}

/* ===========================
   Center Mode
   =========================== */

.otw-vg-gallery-wrapper.center-mode-enabled .otw-vg-main-gallery {
    overflow: visible;
}

.otw-vg-gallery-wrapper.center-mode-enabled .otw-vg-main-gallery .swiper-slide {
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.otw-vg-gallery-wrapper.center-mode-enabled .otw-vg-main-gallery .swiper-slide-active {
    opacity: 1;
}

/* ===========================
   Reduced Motion Support
   =========================== */

@media (prefers-reduced-motion: reduce) {
    .otw-vg-gallery-wrapper *,
    .otw-vg-lightbox * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
