/* CLS (Cumulative Layout Shift) Optimizations */

/* Image Dimension Fixes to Prevent Layout Shifts */
.video-placeholder img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    aspect-ratio: 16/9;
}

.gallery-image img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    aspect-ratio: 4/3;
}

/* Service Images */
.service-image img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    aspect-ratio: 16/9;
}

/* YouTube Thumbnail Optimization */
img[src*="youtube.com"],
img[src*="ytimg.com"] {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    object-fit: cover;
}

/* Gallery Images with Lazy Loading */
img[data-src] {
    width: 100%;
    min-height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    aspect-ratio: 4/3;
}

/* Hero Background Images - Prevent Layout Shift */
.hero-bg {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    min-height: 100vh;
    width: 100%;
}

/* Font Loading Optimization to Prevent FOIT/FOUT */
body {
    font-display: swap;
}

/* Prevent Icon Font Layout Shifts */
.fab, .fas, .far {
    display: inline-block;
    width: 1em;
    text-align: center;
    font-variant: normal;
    text-rendering: auto;
    line-height: 1;
}

/* Carousel Controls Positioning Fix */
.carousel-control-prev,
.carousel-control-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    z-index: 5;
}

/* Video Card Stabilization */
.video-card {
    min-height: 350px;
    contain: layout style paint;
}

.video-placeholder {
    height: 250px;
    overflow: hidden;
    position: relative;
}

/* Gallery Card Stabilization */
.gallery-card {
    min-height: 400px;
    contain: layout style paint;
}

/* Service Card Stabilization */
.service-card {
    min-height: 450px;
    contain: layout style paint;
}

/* Loading Skeleton Improvements */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-skeleton 1.5s infinite;
    min-height: inherit;
}

@keyframes loading-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Button Dimensions Fixed */
.btn-cta-whatsapp,
.btn-cta-call {
    width: 160px;
    height: 120px;
    flex-shrink: 0;
}

/* Responsive Button Dimensions */
@media (max-width: 768px) {
    .btn-cta-whatsapp,
    .btn-cta-call {
        width: 140px;
        height: 100px;
    }
}

@media (max-width: 480px) {
    .btn-cta-whatsapp,
    .btn-cta-call {
        width: 130px;
        height: 90px;
    }
}

/* Modal Stabilization */
.modal-dialog {
    max-width: 90vw;
    margin: 1.75rem auto;
}

.modal-xl {
    max-width: 1140px;
}

/* Navbar Height Stabilization */
.navbar {
    min-height: 76px;
    contain: layout;
}

/* Footer Stabilization */
.footer {
    contain: layout style;
}

/* Section Spacing Stabilization */
.hero-section,
.services-section,
.video-section,
.gallery-section,
.about-section,
.contact-section {
    contain: layout style paint;
}

/* Image Containers with Fixed Aspect Ratios */
.img-container {
    position: relative;
    overflow: hidden;
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Aspect Ratio Containers */
.aspect-ratio-16-9 {
    aspect-ratio: 16/9;
}

.aspect-ratio-4-3 {
    aspect-ratio: 4/3;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1/1;
}

/* Floating Button Stabilization */
.floating-buttons {
    position: fixed !important;
    left: 20px !important;
    bottom: 90px !important;
    z-index: 1001 !important;
    contain: layout;
}

.floating-btn {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Back to Top Button */
.back-to-top {
    width: 50px;
    height: 50px;
    position: fixed;
    bottom: 80px;
    right: 20px;
    contain: layout;
}

/* Slider/Carousel Stabilization */
.slick-slide {
    min-height: 1px;
    contain: layout;
}

.slick-track {
    contain: layout;
}

/* Performance Hints */
.performance-hint {
    will-change: auto;
    contain: layout style paint;
}

/* Prevent Text Reflow During Font Loading */
.font-loading {
    font-display: swap;
    text-rendering: optimizeSpeed;
}

/* Container Queries for Better Responsive Behavior */
@container (min-width: 768px) {
    .video-card,
    .gallery-card,
    .service-card {
        min-height: 0;
    }
}

/* Optimize Animation Performance */
.animated-element {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Remove will-change after animation */
.animation-complete {
    will-change: auto;
}

/* Critical Layout Stabilization */
.layout-stable {
    contain: layout style;
    min-height: 0;
}

/* Specific fixes for identified layout shift culprits */
#gallery img[data-src] {
    width: 100%;
    height: 250px;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: #f0f0f0;
}

/* Video Section YouTube Images */
.video-section img[src*="youtube.com"] {
    width: 100%;
    height: 250px;
    aspect-ratio: 16/9;
    object-fit: cover;
}
