/* Performance Optimizations for Images and Loading */

/* Fix line-clamp compatibility warnings */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 1;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 2;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-clamp: 3;
}

/* Image Loading Optimizations */
.product-image, .blog-image {
    /* Prevent layout shift during loading */
    min-height: 192px; /* h-48 equivalent */
    background-color: #f3f4f6;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23d1d5db'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='1' d='M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 48px 48px;
    transition: opacity 0.3s ease;
}

.product-image:not([src]), .blog-image:not([src]) {
    opacity: 0.5;
}

.product-image[src], .blog-image[src] {
    background-image: none;
}

/* Loading skeleton for product cards */
.product-card.loading {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.product-card.loading .product-image {
    background-color: #e5e7eb;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: .5;
    }
}

/* Lazy loading fade-in effect */
.product-image[loading="lazy"], .blog-image[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.product-image[loading="lazy"].loaded, .blog-image[loading="lazy"].loaded {
    opacity: 1;
}

/* Optimize image rendering */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Reduce paint and composite layers */
.product-card {
    will-change: transform;
    transform: translateZ(0);
}

.product-image {
    will-change: transform;
    transform: translateZ(0);
}

/* Optimize hover effects */
.group:hover .product-image {
    transform: scale(1.05) translateZ(0);
}

/* Preload critical images - attributes handled in HTML */
.hero-banner img {
    /* Critical images should load immediately */
    opacity: 1;
}

/* Optimize thumbnail grid */
.product-thumbnail {
    min-height: 80px;
    background-color: #f3f4f6;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.product-thumbnail:hover {
    transform: scale(1.02) translateZ(0);
}

/* Responsive image optimizations */
@media (max-width: 640px) {
    .product-image, .blog-image {
        min-height: 160px; /* Smaller on mobile */
    }
}

/* Critical CSS for above-the-fold content */
.hero-banner {
    contain: layout style paint;
}

.product-grid {
    contain: layout style;
}

/* Intersection Observer loading states */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Optimize grid layouts */
.grid-responsive-products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    contain: layout;
}

.grid-responsive-blogs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    contain: layout;
}

@media (max-width: 640px) {
    .grid-responsive-products {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1rem;
    }
    
    .grid-responsive-blogs {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}
