/* Core Web Vitals Optimizations */

/* 1. Prevent Layout Shift (CLS) */

/* Reserve space for images */
img {
    height: auto;
    max-width: 100%;
}

/* Define aspect ratios for common image containers */
.product-image-container {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
}

.product-image-container::before {
    content: "";
    display: block;
    padding-top: 100%; /* 1:1 aspect ratio */
}

.product-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Reserve space for sliders */
.swiper-container {
    min-height: 300px;
}

/* Reserve space for fonts to prevent FOUT */
.font-loaded body {
    font-family: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* 2. Optimize First Input Delay (FID) */

/* Use CSS containment for better performance */
.product-card,
.category-card {
    contain: layout style paint;
}

/* Optimize animations */
.lazy-loaded {
    animation: fadeIn 0.3s ease-in-out;
    will-change: auto;
}

@keyframes fadeIn {
    from { 
        opacity: 0;
        transform: translateY(10px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

/* 3. Optimize Largest Contentful Paint (LCP) */

/* Priority loading for hero images */
.hero-image,
.banner-image {
    will-change: auto;
    transform: translateZ(0);
}

/* Optimize text rendering */
body {
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 4. Reduce reflow/repaint */

/* Use transform instead of position changes */
.hover-lift {
    transition: transform 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-5px);
}

/* 5. Optimize scrolling performance */
.scrollable-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 6. Skeleton screens for loading states */
.skeleton {
    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; }
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    border-radius: 8px;
}

/* 7. Optimize for mobile */
@media (max-width: 768px) {
    /* Disable hover effects on mobile */
    .hover-lift:hover {
        transform: none;
    }
    
    /* Optimize touch targets */
    button,
    a,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Reduce animations on mobile */
    * {
        animation-duration: 0.2s !important;
    }
}

/* 8. Critical CSS for above-the-fold content */
.critical-content {
    /* Inline critical styles in HTML head for faster rendering */
}

/* 9. Reduce paint areas */
.fixed-header {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 10. Optimize form inputs */
input,
textarea,
select {
    font-size: 16px; /* Prevent zoom on iOS */
}

/* RTL Support for Arabic */
[dir="rtl"] .hover-lift:hover {
    transform: translateY(-5px);
}

[dir="rtl"] @keyframes fadeIn {
    from { 
        opacity: 0;
        transform: translateY(10px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}