/**
 * AdZeta Lazy Loading CSS
 * Prevents layout shifts (CLS) and provides smooth loading transitions
 * Optimized for Core Web Vitals
 */

/* Lazy loading images - prevent layout shift */
img[loading="lazy"] {
  /* Reserve minimum space to prevent layout shift */
  min-height: 1px;
  /* Smooth transition when image loads */
  transition: opacity 0.3s ease-in;
}

/* Loading state */
img.lazy-loading {
  opacity: 0;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Loaded state */
img.lazy-loaded {
  opacity: 1;
}

/* Error state */
img.lazy-error {
  opacity: 0.5;
  filter: grayscale(100%);
}

/* Shimmer animation for loading placeholder */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Background images with lazy loading */
[data-bg-image] {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity 0.3s ease-in;
}

[data-bg-image].lazy-loading {
  opacity: 0;
  background-color: #f0f0f0;
}

[data-bg-image].lazy-loaded {
  opacity: 1;
}

/* Prevent layout shift for images without explicit dimensions */
/* Only apply to specific containers to avoid breaking existing layouts */
.content-area img:not([width]):not([height])[loading="lazy"],
.blog-content img:not([width]):not([height])[loading="lazy"] {
  /* Default aspect ratio to prevent shift */
  aspect-ratio: 16 / 9;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* Hero images - load immediately, no lazy loading effects */
.hero-section img[loading="eager"],
[class*="hero"] img[loading="eager"] {
  opacity: 1 !important;
  transition: none !important;
}

/* Chip image container - preserve existing layout */
.chip-image-container img[loading="lazy"] {
  /* Don't apply any width/height/aspect-ratio overrides */
  width: auto !important;
  height: auto !important;
  aspect-ratio: unset !important;
}

/* Responsive images - maintain aspect ratio */
img[loading="lazy"].responsive-img {
  width: 100%;
  height: auto;
}

/* Logo images - prevent layout shift */
img[loading="lazy"][class*="logo"] {
  max-width: 100%;
  height: auto;
}

/* Case study images - maintain aspect ratio */
.case-study-image img[loading="lazy"] {
  aspect-ratio: 16 / 9;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* Testimonial images - circular avatars */
.client-photo[loading="lazy"] {
  /* Don't override width/height - let existing CSS handle sizing */
  object-fit: cover;
  border-radius: 50% !important; /* Ensure border-radius is applied */
}

/* Performance optimization - reduce repaints */
img[loading="lazy"] {
  will-change: opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Mobile optimization */
@media (max-width: 767px) {
  /* Faster transitions on mobile */
  img[loading="lazy"] {
    transition: opacity 0.2s ease-in;
  }
  
  /* Disable shimmer animation on mobile for better performance */
  img.lazy-loading {
    animation: none;
    background: #f0f0f0;
  }
}

/* Print styles - ensure all images are visible */
@media print {
  img[loading="lazy"],
  img.lazy-loading,
  img.lazy-loaded {
    opacity: 1 !important;
    transition: none !important;
  }
}

/* Accessibility - respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  img[loading="lazy"],
  [data-bg-image] {
    transition: none !important;
    animation: none !important;
  }
}

