/**
 * Custom Product Gallery Styles
 * Professional gallery with main image and scrollable thumbnails
 */

/* ===========================
   GALLERY CONTAINER
   =========================== */

.custom-product-gallery {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* ===========================
   MAIN IMAGE
   =========================== */

.gallery-main-image {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #fafafa;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-large);
    overflow: hidden;
}

.main-image-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
}

.main-image-item.active {
    opacity: 1;
    visibility: visible;
    z-index: 1;
}

.main-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: zoom-in;
}

/* ===========================
   NAVIGATION ARROWS
   =========================== */

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition-base);
    z-index: 10;
    box-shadow: var(--shadow-md);
}

.gallery-nav:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

.gallery-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.gallery-prev {
    left: var(--spacing-md);
}

.gallery-next {
    right: var(--spacing-md);
}

/* ===========================
   IMAGE COUNTER
   =========================== */

.gallery-counter {
    position: absolute;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border-radius: var(--border-radius-medium);
    font-size: var(--font-sm);
    font-weight: var(--font-semibold);
    z-index: 10;
    backdrop-filter: blur(8px);
}

.current-image {
    color: var(--accent-color);
}

/* ===========================
   THUMBNAILS
   =========================== */

.gallery-thumbnails-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.gallery-thumbnails {
    display: flex;
    gap: var(--spacing-sm);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: var(--spacing-xs) 0;
    flex: 1;
}

.gallery-thumbnails::-webkit-scrollbar {
    display: none;
}

.thumbnail-item {
    flex: 0 0 auto;
    width: 80px;
    height: 80px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-base);
    background: #fafafa;
    padding: 8px;
}

.thumbnail-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.thumbnail-item.active {
    border-color: var(--primary-color);
    border-width: 3px;
    padding: 7px;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ===========================
   THUMBNAIL NAVIGATION
   =========================== */

.thumb-nav {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition-base);
}

.thumb-nav:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

.thumb-nav:active {
    transform: scale(0.95);
}

.thumb-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===========================
   ZOOM EFFECT
   =========================== */

.main-image-item.zoomed {
    cursor: zoom-out;
}

.main-image-item.zoomed .main-image {
    cursor: zoom-out;
    transform: scale(1.5);
    transition: transform 0.3s ease;
}

/* ===========================
   LOADING STATE
   =========================== */

.gallery-main-image::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid var(--secondary-bg);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 0;
}

.main-image-item.active ~ .gallery-main-image::before {
    display: none;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ===========================
   RESPONSIVE
   =========================== */

@media (max-width: 768px) {
    .gallery-main-image {
        aspect-ratio: 1 / 1;
    }
    
    .gallery-nav {
        width: 36px;
        height: 36px;
    }
    
    .gallery-prev {
        left: var(--spacing-sm);
    }
    
    .gallery-next {
        right: var(--spacing-sm);
    }
    
    .gallery-counter {
        bottom: var(--spacing-sm);
        right: var(--spacing-sm);
        padding: 6px 12px;
        font-size: var(--font-xs);
    }
    
    .thumbnail-item {
        width: 60px;
        height: 60px;
    }
    
    .thumb-nav {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 480px) {
    .gallery-thumbnails-wrapper {
        gap: var(--spacing-xs);
    }
    
    .thumbnail-item {
        width: 50px;
        height: 50px;
    }
    
    .thumb-nav {
        display: none;
    }
    
    .gallery-thumbnails {
        gap: var(--spacing-xs);
    }
}

/* ===========================
   TOUCH GESTURES
   =========================== */

@media (hover: none) and (pointer: coarse) {
    .gallery-main-image {
        touch-action: pan-y pinch-zoom;
    }
    
    .main-image {
        cursor: default;
    }
}

/* ===========================
   ACCESSIBILITY
   =========================== */

.gallery-nav:focus,
.thumb-nav:focus,
.thumbnail-item:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===========================
   ANIMATIONS
   =========================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.main-image-item.active {
    animation: fadeIn 0.4s ease;
}

/* ===========================
   LIGHTBOX (Optional)
   =========================== */

.gallery-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
}

.gallery-lightbox.active {
    display: flex;
}

.lightbox-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: none;
    border-radius: 50%;
    color: var(--text-color);
    cursor: pointer;
    font-size: 24px;
    transition: all var(--transition-base);
}

.lightbox-close:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}
