/**
 * BMC Product Gallery Styles
 * Optimized for performance with CSS Grid and containment
 */

/* Gallery Container */
.bmc-gallery-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    contain: layout style paint;
}

/* Main Gallery Figure */
.bmc-gallery-main {
    position: relative;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Aspect Ratio Fallback for older browsers */
@supports not (aspect-ratio: 1) {
    .bmc-gallery-main {
        position: relative;
        padding-bottom: 100%; /* Default 1:1 ratio */
        height: 0;
    }
    
    .bmc-gallery-main .bmc-gallery-image {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
}

/* Gallery Image */
.bmc-gallery-image {
    width: 100%;
    height: auto;
    display: block;
    max-width: 100%;
    transition: opacity 200ms ease-in-out;
    will-change: opacity;
}

/* Lightbox enabled state */
.bmc-gallery-lightbox-enabled .bmc-gallery-image {
    cursor: zoom-in;
}

.bmc-gallery-lightbox-enabled .bmc-gallery-image:hover {
    opacity: 0.95;
}

/* Image Loading State */
.bmc-gallery-main.loading .bmc-gallery-image {
    opacity: 0.5;
}

/* Screen Reader Text (for SEO and Accessibility) */
.screen-reader-text {
    position: absolute !important;
    clip: rect(1px, 1px, 1px, 1px);
    padding: 0 !important;
    border: 0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden;
    word-wrap: normal !important;
}

/* MicroModal Lightbox Styles */
.micromodal-slide {
    display: none;
}

.micromodal-slide.is-open {
    display: block;
}

.micromodal-slide .modal__overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999;
    cursor: zoom-out;
}

.micromodal-slide .modal__container {
    background-color: transparent;
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
    position: relative;
    overflow: visible;
}

.micromodal-slide .modal__content {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.micromodal-slide .modal__image {
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.micromodal-slide .modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 200ms ease;
}

.micromodal-slide .modal__close:hover {
    background: rgba(255, 255, 255, 1);
}

.micromodal-slide .modal__close:before,
.micromodal-slide .modal__close:after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: #333;
    transform: rotate(45deg);
}

.micromodal-slide .modal__close:after {
    transform: rotate(-45deg);
}

/* Modal Spinner */
.modal__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 14px;
    z-index: 1;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.micromodal-slide[aria-hidden="false"] .modal__overlay {
    animation: fadeIn 200ms cubic-bezier(0.02, 0.01, 0.47, 1);
}

.micromodal-slide[aria-hidden="true"] .modal__overlay {
    animation: fadeOut 200ms cubic-bezier(0.02, 0.01, 0.47, 1);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .bmc-gallery-container {
        max-width: 100%;
    }
    
    .micromodal-slide .modal__container {
        padding: 10px;
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .micromodal-slide .modal__image {
        max-height: 80vh;
    }
    
    .micromodal-slide .modal__close {
        width: 35px;
        height: 35px;
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .bmc-gallery-container {
        max-width: 100%;
    }
}

/* Print Styles */
@media print {
    .bmc-gallery-container {
        max-width: 100%;
    }
    
    .micromodal-slide,
    .modal__spinner,
    .modal__close {
        display: none !important;
    }
    
    .bmc-gallery-image {
        cursor: default !important;
    }
}

/* High DPI Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .bmc-gallery-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* CSS Grid Layout for Gallery (future use with thumbnails if needed) */
.bmc-gallery-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
}

/* Accessibility - Focus Styles */
.bmc-gallery-image:focus,
.modal__close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .bmc-gallery-image,
    .micromodal-slide .modal__overlay,
    .micromodal-slide .modal__close {
        transition: none !important;
        animation: none !important;
    }
}

/* WooCommerce Integration - Hide default gallery when ours is present */
.single-product .bmc-gallery-container ~ .woocommerce-product-gallery {
    display: none;
}

/* Loading State Animation */
@keyframes pulse {
    0% {
        opacity: 0.6;
    }
    50% {
        opacity: 0.4;
    }
    100% {
        opacity: 0.6;
    }
}

.bmc-gallery-main.loading {
    animation: pulse 1.5s ease-in-out infinite;
}