/**
 * Image Fix CSS
 *
 * CRITICAL: Fixes image bleed bug where product images overflow
 * and overlap footer across multiple pages.
 *
 * Date: 2025-01-14
 */

/* ========================================
   PRODUCT GRID IMAGE CONSTRAINTS
   ======================================== */

/**
 * Product card image wrapper - Shop grid
 * Enforces square aspect ratio and clips overflow
 */
.product-card-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1; /* CRITICAL: Enforces square ratio */
    overflow: hidden; /* CRITICAL: Clips image overflow */
    background: #f9fafb; /* Placeholder background */
}

.product-card-image {
    width: 100%; /* CRITICAL: Constrain width */
    height: 100%; /* CRITICAL: Fill container */
    object-fit: cover; /* CRITICAL: Cover without distortion */
    max-width: 100%; /* Safeguard */
    max-height: 100%; /* Safeguard */
    display: block; /* Remove inline spacing */
}

/**
 * Fallback for browsers without aspect-ratio support
 */
.product-card-image-wrapper::before {
    content: '';
    display: block;
    padding-top: 100%; /* Creates 1:1 aspect ratio */
}

@supports (aspect-ratio: 1 / 1) {
    .product-card-image-wrapper::before {
        display: none; /* Remove fallback if aspect-ratio is supported */
    }
}

/* ========================================
   PRODUCT DETAIL PAGE IMAGE CONSTRAINTS
   ======================================== */

/**
 * Main product image gallery container
 * Prevents images from exceeding viewport height
 */
.gallery-main-container {
    width: 100%;
    max-height: 70vh; /* CRITICAL: Never exceed 70% of viewport */
    overflow: hidden; /* CRITICAL: Clip overflow */
    background: #f9fafb;
    border-radius: 12px;
}

.main-image {
    width: 100%;
    height: auto;
    max-height: 70vh; /* CRITICAL: Never exceed viewport */
    object-fit: contain; /* CRITICAL: Fit without crop */
    display: block;
    margin: 0 auto; /* Center horizontally */
}

/**
 * Thumbnail images (if gallery is implemented)
 */
.thumbnail-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f9fafb;
    border-radius: 8px;
}

.thumbnail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ========================================
   COLLECTION/EVENT PAGE IMAGE CONSTRAINTS
   ======================================== */

/**
 * Event/Collection banner images
 */
.event-banner-wrapper {
    position: relative;
    width: 100%;
    max-height: 400px;
    overflow: hidden;
    border-radius: 12px;
}

.event-banner-image {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: cover;
    display: block;
}

/* ========================================
   CAROUSEL IMAGE CONSTRAINTS
   ======================================== */

/**
 * Carousel images on homepage
 */
.carousel-image-wrapper {
    position: relative;
    width: 100%;
    height: 500px; /* Fixed height */
    overflow: hidden;
}

.carousel-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ========================================
   BRAND LOGO CONSTRAINTS
   ======================================== */

/**
 * Brand logo containers
 */
.brand-logo-wrapper {
    position: relative;
    width: 100%;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    border-radius: 8px;
    padding: 1rem;
}

.brand-logo-image {
    max-width: 100%;
    max-height: 200px;
    height: auto;
    object-fit: contain;
    display: block;
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */

/**
 * Tablet adjustments
 */
@media (max-width: 1024px) {
    .gallery-main-container,
    .main-image {
        max-height: 60vh;
    }

    .carousel-image-wrapper {
        height: 400px;
    }
}

/**
 * Mobile adjustments
 */
@media (max-width: 768px) {
    .gallery-main-container,
    .main-image {
        max-height: 50vh;
    }

    .carousel-image-wrapper {
        height: 300px;
    }

    .event-banner-wrapper {
        max-height: 250px;
    }

    .event-banner-image {
        max-height: 250px;
    }
}

/**
 * Small mobile adjustments
 */
@media (max-width: 480px) {
    .gallery-main-container,
    .main-image {
        max-height: 40vh;
    }

    .carousel-image-wrapper {
        height: 250px;
    }

    .product-card-image-wrapper {
        /* Maintain square aspect on mobile */
        aspect-ratio: 1 / 1;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/**
 * Force image constraints (utility class)
 */
.img-constrained {
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/**
 * Force square aspect ratio (utility class)
 */
.img-square {
    aspect-ratio: 1 / 1 !important;
    object-fit: cover !important;
}

/**
 * Prevent any image overflow globally
 */
img {
    max-width: 100%; /* Never exceed container width */
    height: auto; /* Maintain aspect ratio */
}

/* ========================================
   LOADING STATES
   ======================================== */

/**
 * Placeholder for loading images
 */
.image-loading {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* ========================================
   PRINT STYLES
   ======================================== */

/**
 * Optimize images for printing
 */
@media print {
    .product-card-image-wrapper,
    .gallery-main-container {
        max-height: none !important;
        overflow: visible !important;
    }

    img {
        max-height: none !important;
        page-break-inside: avoid;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/**
 * Ensure images have proper focus states
 */
a:focus .product-card-image,
button:focus .product-card-image {
    outline: 2px solid var(--color-primary, #FF6B9D);
    outline-offset: 2px;
}

/**
 * Reduce motion for users who prefer it
 */
@media (prefers-reduced-motion: reduce) {
    .product-card-image,
    .image-loading {
        transition: none !important;
        animation: none !important;
    }
}
