/* 
 * Product Images Optimization CSS - Version 3.1
 * Full Box Image Coverage with Easy Thumbnails
 */

/* Product Grid Layout */
.product {
    margin-bottom: 2rem;
    position: relative;
    z-index: 1;
}

.product .grid-inner {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    position: relative;
    z-index: 2;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.product .grid-inner:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* Product Image Container - Full Coverage */
.product-image {
    position: relative;
    width: 100%;
    height: 280px; /* Increased height for better coverage */
    overflow: hidden;
    border-radius: 0.5rem 0.5rem 0 0;
    background: #f8f9fa;
    z-index: 3;
    flex: 1; /* Take available space */
}

/* Main Product Image - Full Coverage */
.product-image .product-link {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
}

.product-image .lazy-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 5;
    display: block;
    border: none;
    border-radius: 0;
}

/* Hover Image Effect - Full Coverage */
.product-image .product-link-hover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 6;
}

.product-image .hover-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    opacity: 0;
    z-index: 7;
    transition: opacity 0.3s ease;
    border: none;
    border-radius: 0;
}

.product-image:hover .hover-image {
    opacity: 1;
}

.product-image:hover .lazy-image {
    transform: scale(1.05);
}

/* Lazy Loading States */
.lazy-image {
    opacity: 0;
    transition: opacity 0.4s ease-in-out, transform 0.3s ease;
}

.lazy-image.lazy-loaded {
    opacity: 1;
}

/* Loading placeholder animation */
.lazy-image:not(.lazy-loaded) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

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

/* No Image Placeholder - Full Coverage */
.no-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    z-index: 4;
}

.placeholder-content {
    text-align: center;
    color: #6c757d;
}

/* Background Overlay Z-Index Management */
.bg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 8;
    pointer-events: none;
}

.bg-overlay-content {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 10;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.product-image:hover .bg-overlay-content {
    opacity: 1;
}

.bg-overlay-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.3) 100%);
    z-index: 9;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.product-image:hover .bg-overlay-bg {
    opacity: 1;
}

/* Product Description - Fixed Height */
.product-desc {
    padding: 1rem;
    text-align: center;
    position: relative;
    z-index: 3;
    background: #fff;
    flex-shrink: 0; /* Don't shrink */
    min-height: 120px; /* Fixed minimum height */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.product-title {
    margin-bottom: 0.5rem;
    min-height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.product-title h3 {
    font-size: 0.95rem;
    line-height: 1.3;
    margin: 0;
    font-weight: 600;
    text-align: center;
}

.product-price {
    font-size: 1rem;
    font-weight: 600;
    color: #e74c3c;
    margin-bottom: 0.5rem;
}

.product-rating {
    font-size: 0.85rem;
    color: #f39c12;
}

/* Responsive Design - Optimized Heights */
@media (max-width: 575.98px) {
    .product {
        margin-bottom: 1.5rem;
    }
    
    .product-image {
        height: 220px; /* Smaller on mobile but still full coverage */
    }
    
    .product-title h3 {
        font-size: 0.85rem;
    }
    
    .product-desc {
        padding: 0.75rem;
        min-height: 100px;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .product {
        margin-bottom: 1.75rem;
    }
    
    .product-image {
        height: 250px; /* Medium size for tablets */
    }
    
    .product-title h3 {
        font-size: 0.9rem;
    }
    
    .product-desc {
        min-height: 110px;
    }
}

@media (min-width: 992px) {
    .product {
        margin-bottom: 2rem;
    }
    
    .product-image {
        height: 280px; /* Larger for desktop */
    }
    
    .product-title h3 {
        font-size: 0.95rem;
    }
    
    .product-desc {
        min-height: 120px;
    }
}

/* Ensure consistent grid heights */
.shop .product {
    height: 100%;
}

.shop .product .grid-inner {
    height: 100%;
}

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

/* Performance Optimizations */
.product-image {
    contain: layout style paint;
    will-change: transform;
}

.lazy-image {
    content-visibility: auto;
    contain-intrinsic-size: 400px 300px;
}

/* Error Handling for Failed Images */
.lazy-image[src=""], 
.lazy-image:not([src]) {
    background: #f8f9fa url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300"><rect width="100%" height="100%" fill="%23f8f9fa"/><text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" fill="%23dee2e6" font-family="Arial, sans-serif" font-size="18">No Image</text></svg>') center/cover no-repeat;
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .hover-image,
    .product .grid-inner,
    .bg-overlay-content,
    .bg-overlay-bg {
        transition: none;
        animation: none;
        transform: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .product .grid-inner {
        background: #2c2c2c;
        box-shadow: 0 2px 8px rgba(255,255,255,0.1);
    }
    
    .product .grid-inner:hover {
        box-shadow: 0 4px 16px rgba(255,255,255,0.15);
    }
    
    .product-image,
    .no-image-placeholder {
        background: #2c2c2c;
    }
    
    .product-title h3 a {
        color: #fff;
    }
    
    .product-desc {
        color: #e0e0e0;
        background: #2c2c2c;
    }
}

/* Force Image Visibility - Override any conflicting styles */
.product img {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: absolute !important;
}

/* Ensure images are not hidden by any parent elements */
.product .product-image,
.product .product-link,
.product .product-link-hover {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Remove any Bootstrap img-fluid restrictions that might interfere */
.product-image .img-fluid {
    max-width: none !important;
    height: 100% !important;
    width: 100% !important;
}

/* Force proper object-fit coverage */
.product-image img {
    object-fit: cover !important;
    object-position: center center !important;
    width: 100% !important;
    height: 100% !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* Version 3.1 - Full Box Coverage Implementation */
/* Cache busting comment - Update timestamp on deployment */ 