/* Layout Shift Prevention - CLS Optimization */

/* Image aspect ratio containers to prevent layout shifts */
.problem-image img,
.features-landscaped__image img,
.portfolio-card .portfolio-image img,
.founders-image img,
.founders-image-mobile img {
  width: 100%;
  height: auto;
}

/* Specific aspect ratios for known images */
.problem-image img {
  aspect-ratio: 800 / 533; /* problem-frustrated-business-owner image */
}

.features-landscaped__image img {
  aspect-ratio: 800 / 450; /* team-collaboration.jpg */
}

.founders-image img,
.founders-image-mobile img {
  aspect-ratio: 400 / 600; /* riley-family-optimized.jpg */
}

/* Portfolio images with explicit aspect ratios */
.portfolio-image img[src*="brightview"] {
  aspect-ratio: 600 / 303;
}

.portfolio-image img[src*="detail-handyman"] {
  aspect-ratio: 600 / 241;
}

/* Lawndale Inc. portfolio image - fixed text cutoff positioning */
.portfolio-image img[src*="lawndale"] {
  aspect-ratio: 3 / 2;
  object-fit: cover;
  object-position: center top;
  width: 100%;
  height: auto;
  max-width: 600px;
  border-radius: 8px;
  image-rendering: auto;
}

/* Mobile-specific optimizations for Lawndale */
@media (max-width: 768px) {
  .portfolio-image img[src*="lawndale"] {
    max-width: 100%;
    aspect-ratio: 3 / 2;
    border-radius: 6px;
  }
}

/* Netlify deployment compatibility */
@supports not (aspect-ratio: 3 / 2) {
  .portfolio-image img[src*="lawndale"] {
    height: calc(66.67vw); /* 3:2 fallback for older browsers */
    max-height: 400px;
  }
}

/* Iframe container to prevent layout shifts */
.form-container iframe,
iframe[data-tally-src] {
  min-height: 600px;
  border: none;
  background: #f9f9f9;
}

/* Reserve space for dynamic content */
.fade-up-element {
  min-height: 1px; /* Ensures space is always reserved */
}

/* Prevent layout shifts from loading states */
.hero {
  min-height: 85vh;
  display: flex;
  align-items: center;
}

/* Font loading optimization - prevent FOIT/FOUT */
.hero-headline,
.hero-subheadline,
h1, h2, h3, h4, h5, h6 {
  font-display: swap;
}

/* Skeleton loading for images */
img[loading="lazy"] {
  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; }
}

img[loading="lazy"]:not([src*="data:"]) {
  min-height: 200px; /* Fallback height */
}

/* Hide skeleton once image loads */
img[loading="lazy"][src]:not([src=""]) {
  background: none;
  animation: none;
}

/* Prevent layout shifts from hover effects */
.btn,
.feature-card,
.benefit-item {
  transform-origin: center;
  will-change: transform;
}

/* Reserve space for transformed elements */
.btn:hover,
.feature-card:hover,
.benefit-item:hover {
  transform-style: preserve-3d;
}

/* Sticky header height reservation */
body {
  padding-top: 0;
}

.site-header {
  height: auto;
  min-height: 80px;
}

/* Ensure consistent mobile navigation height */
@media (max-width: 768px) {
  .site-header {
    min-height: 70px;
  }
  
  .main-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 1001;
  }
  
  .main-nav.active {
    transform: translateY(0);
  }
}