/* CLS (Cumulative Layout Shift) Optimizations */

/* Font Display Optimization - Using Google Fonts with font-display: swap */
/* Google Fonts Inter is already loaded in HTML with font-display: swap */

/* Global font fallback stack to minimize layout shifts */
body {
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    'Roboto',
    'Helvetica Neue',
    Arial,
    sans-serif;
}

/* Prevent layout shifts from images without dimensions */
img:not([width]):not([height]) {
  aspect-ratio: 16/9;
  min-height: 200px;
  object-fit: cover;
  content-visibility: auto;
  contain-intrinsic-size: 300px 200px;
}

/* Optimize image loading performance */
img[loading='lazy'] {
  content-visibility: auto;
  contain-intrinsic-size: 1px 200px;
}

/* Prevent layout shifts for hero images */
.hero-image {
  aspect-ratio: 16/9;
  min-height: 400px;
  object-fit: cover;
  content-visibility: auto;
}

/* Reserve space for common ad sizes */
.ad-banner {
  min-height: 90px;
  aspect-ratio: 728/90;
  content-visibility: auto;
  contain-intrinsic-size: 728px 90px;
}

.ad-rectangle {
  min-height: 250px;
  aspect-ratio: 300/250;
  content-visibility: auto;
  contain-intrinsic-size: 300px 250px;
}

.ad-mobile {
  min-height: 100px;
  aspect-ratio: 320/100;
  content-visibility: auto;
  contain-intrinsic-size: 320px 100px;
}

/* Optimize performance monitor */
.performance-monitor {
  content-visibility: auto;
  contain-intrinsic-size: 300px 400px;
  contain: layout style paint;
}

/* Prevent iframe layout shifts */
iframe {
  width: 100%;
  min-height: 400px;
}

iframe[src*='youtube'] {
  aspect-ratio: 16/9;
  min-height: 315px;
}

iframe[src*='vimeo'] {
  aspect-ratio: 16/9;
  min-height: 315px;
}

/* Prevent button and form element shifts */
button,
input,
select,
textarea {
  min-height: 40px;
  box-sizing: border-box;
}

/* Loading states that maintain layout */
.loading-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;
  }
}

/* Dark mode loading skeleton */
@media (prefers-color-scheme: dark) {
  .loading-skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
  }
}

/* Prevent text content shifts */
.text-content {
  line-height: 1.6;
  word-wrap: break-word;
  hyphens: auto;
}

/* Reserve space for navigation elements */
.nav-item {
  min-height: 48px;
  display: flex;
  align-items: center;
}

/* Prevent modal and overlay shifts */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
}

/* Prevent scroll bar layout shifts */
html {
  scrollbar-gutter: stable;
}

/* Container queries for responsive ads (when supported) */
@container (min-width: 728px) {
  .responsive-ad {
    aspect-ratio: 728/90;
    min-height: 90px;
  }
}

@container (max-width: 727px) {
  .responsive-ad {
    aspect-ratio: 320/100;
    min-height: 100px;
  }
}

/* Prevent table layout shifts */
table {
  table-layout: fixed;
  width: 100%;
}

/* Prevent video element shifts */
video {
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
  min-height: 200px;
}

/* Prevent SVG layout shifts */
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Utility classes for common aspect ratios */
.aspect-square {
  aspect-ratio: 1/1;
}

.aspect-video {
  aspect-ratio: 16/9;
}

.aspect-photo {
  aspect-ratio: 4/3;
}

.aspect-banner {
  aspect-ratio: 728/90;
}

/* Prevent content jumping during font loading */
.font-loading {
  visibility: hidden;
}

.font-loaded {
  visibility: visible;
}

/* Critical above-the-fold content optimization */
.above-fold {
  contain: layout style;
}

/* Prevent layout shifts from dynamic content */
.dynamic-content {
  min-height: 100px;
  transition: height 0.3s ease;
}

/* Optimize for Core Web Vitals */
.optimize-cls {
  contain: layout;
  content-visibility: auto;
  contain-intrinsic-size: 0 200px;
}
