/* ========================================
   Performance Optimization - CLS & Loading
   ======================================== */

/* ========================================
   1. Layout Shift Prevention (CLS)
   ======================================== */

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

/* Hero section - prevent layout shift */
.hero-modern {
    position: relative;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.hero-content {
    position: relative;
    z-index: 1;
}

/* Aspect ratio boxes for consistent spacing */
.aspect-ratio-box {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.aspect-ratio-16-9 {
    padding-top: 56.25%;
}

.aspect-ratio-4-3 {
    padding-top: 75%;
}

.aspect-ratio-1-1 {
    padding-top: 100%;
}

.aspect-ratio-box img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========================================
   2. Lazy Loading Optimizations
   ======================================== */

/* Lazy load image placeholders */
.lazy-load {
    background: var(--bg-gray);
    min-height: 200px;
}

/* Low quality image placeholders */
.lqip {
    filter: blur(10px);
    transition: filter 0.3s ease;
}

.lqip.loaded {
    filter: blur(0);
}

/* ========================================
   3. Vehicle Cards - CLS Prevention
   ======================================== */

.vehicle-card,
.model-card {
    contain: layout style paint;
    will-change: transform;
}

.vehicle-card-image,
.model-image {
    aspect-ratio: 16 / 9;
    background: var(--bg-gray);
    overflow: hidden;
}

.vehicle-card-image img,
.model-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========================================
   4. Font Loading Optimization
   ======================================== */

/* Font display swap for better CLS */
@font-face {
    font-display: swap;
}

/* ========================================
   5. Animation Performance
   ======================================== */

/* Use transform and opacity for smooth animations */
.animate-transform {
    will-change: transform;
    backface-visibility: hidden;
}

.animate-opacity {
    will-change: opacity;
}

/* Hardware acceleration */
.hw-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ========================================
   6. Scroll Performance
   ======================================== */

/* Prevent scroll chaining */
.scroll-container {
    overscroll-behavior: contain;
}

/* Smooth scrolling but performant */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   7. Header Scroll Performance
   ======================================== */

.site-header {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ========================================
   8. Floating Elements Performance
   ======================================== */

.whatsapp-float,
.back-to-top,
.mobile-quick-actions,
.mobile-sticky-cta {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ========================================
   9. Content Visibility
   ======================================== */

/* Offscreen content optimization */
.offscreen-section {
    content-visibility: auto;
}

/* ========================================
   10. Image Gallery Performance
   ======================================== */

.thumbnail-gallery {
    content-visibility: auto;
}

.thumbnail-item {
    contain: layout style;
}

/* ========================================
   11. Form Performance
   ======================================== */

.form-control,
input,
select,
textarea {
    contain: layout style;
}

/* ========================================
   12. Reduce Paint Areas
   ======================================== */

/* Contain paint areas */
.contain-paint {
    contain: paint;
}

.contain-layout {
    contain: layout;
}

.contain-strict {
    contain: strict;
}

/* ========================================
   13. Specific Hero CLS Fixes
   ======================================== */

.hero-scroll {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

/* Reserve space for hero content */
.hero-modern::before {
    content: '';
    display: block;
    padding-top: 62.5%;
}

@media (max-width: 768px) {
    .hero-modern::before {
        padding-top: 75%;
    }
}

/* ========================================
   14. Third-Party Script Containment
   ======================================== */

.third-party-container {
    contain: strict;
    visibility: hidden;
}

.third-party-container.visible {
    visibility: visible;
}

/* ========================================
   15. Critical CSS - Above the Fold
   ======================================== */

/* Ensure above-the-fold content renders fast */
.site-header,
.hero-modern,
.mobile-quick-actions {
    contain: layout style;
}
