/**
 * CLS (Cumulative Layout Shift) Prevention Styles
 * Prevents layout shifts by reserving space for dynamic content
 */

/* Ensure all images have aspect ratio preserved */
img {
  height: auto;
  max-width: 100%;
}

/* Images with explicit dimensions */
img[width][height] {
  aspect-ratio: attr(width) / attr(height);
}

/* Reserve space for ad containers */
.ad-container {
  display: block;
  position: relative;
  overflow: hidden;
}

.ad-container ins {
  display: block !important;
}

/* Prevent layout shift from lazy-loaded images */
img[loading="lazy"] {
  content-visibility: auto;
}

/* Reserve space for Font Awesome icons before they load */
.fa, .fas, .far, .fal, .fab {
  display: inline-block;
  min-width: 1em;
  text-align: center;
}

/* Tool icon containers - fixed dimensions */
.tool-ic {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
}

/* Prevent layout shift from navigation */
.header {
  min-height: 70px;
}

.nav {
  min-height: 40px;
}

/* Footer fixed height to prevent shift */
.footer {
  min-height: 100px;
}

/* Card containers maintain minimum height */
.card {
  min-height: 50px;
}

/* Button fixed heights */
.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Usage counter fixed dimensions */
.usage-counter {
  min-width: 120px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Mobile menu fixed width */
.mobile-menu {
  min-width: 250px;
}

/* Language switcher fixed dimensions */
.lang-switcher {
  min-width: 100px;
  height: 36px;
}

/* Prevent shift from dynamic content loading */
[data-i18n] {
  min-height: 1em;
}

/* Hero section minimum height */
.hero {
  min-height: 200px;
}

.hero-title {
  min-height: 1.2em;
}

.hero-sub {
  min-height: 1.2em;
}

/* Tool cards fixed aspect ratio */
.tool-card {
  min-height: 180px;
}

/* Prevent shift from form elements */
input, select, textarea {
  box-sizing: border-box;
}

/* Reserve space for loading states */
.loading-placeholder {
  min-height: 100px;
  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;
  }
}

/* Aspect ratio utilities */
.aspect-ratio-16-9 {
  aspect-ratio: 16 / 9;
}

.aspect-ratio-4-3 {
  aspect-ratio: 4 / 3;
}

.aspect-ratio-1-1 {
  aspect-ratio: 1 / 1;
}

/* Prevent shift from transforms */
.transform-gpu {
  transform: translateZ(0);
  will-change: transform;
}

/* Contain layout shifts within elements */
.contain-layout {
  contain: layout;
}

.contain-paint {
  contain: paint;
}

.contain-strict {
  contain: strict;
}

/* Responsive images with aspect ratio */
.responsive-img {
  width: 100%;
  height: auto;
  display: block;
}

/* Grid layouts with fixed gaps */
.tools-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

/* Prevent shift from absolute positioned elements */
.relative-container {
  position: relative;
  min-height: 1px;
}

/* Reserve space for dynamic badges/counters */
.badge, .counter {
  min-width: 20px;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Prevent shift from modal/popup overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  contain: strict;
}

/* Skeleton loading states */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 4px;
}

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 2em;
  width: 60%;
  margin-bottom: 1em;
}

.skeleton-button {
  height: 44px;
  width: 120px;
  border-radius: 8px;
}

/* Prevent shift from cookie consent banner */
.cookie-consent {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 80px;
  z-index: 9999;
}

/* Media queries for responsive CLS prevention */
@media (max-width: 768px) {
  .header {
    min-height: 60px;
  }
  
  .hero {
    min-height: 150px;
  }
  
  .tool-card {
    min-height: 160px;
  }
  
  .ad-container {
    min-height: 200px;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 1.8rem;
    min-height: 2.4em;
  }
  
  .tool-card {
    min-height: 140px;
  }
}
