/* Performance Optimizations CSS */

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

/* Lazy loading fade-in effect */
img[data-src] {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

img.loaded {
  opacity: 1;
}

/* Aspect ratio boxes to prevent CLS */
.img-wrapper {
  position: relative;
  overflow: hidden;
  background-color: #f0f0f0;
}

.img-wrapper::before {
  content: '';
  display: block;
  padding-top: 66.67%; /* 3:2 aspect ratio */
}

.img-wrapper img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Modern image formats fallback */
.no-webp .webp-only {
  display: none;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print optimizations */
@media print {
  /* Hide non-essential elements */
  nav,
  .sidebar,
  .social-share,
  .comments {
    display: none !important;
  }
  
  /* Optimize for print */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
  
  /* Show URLs after links */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
  
  /* Prevent page breaks in important elements */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  
  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }
  
  pre, blockquote {
    page-break-inside: avoid;
    border: 1px solid #999;
    padding: 10px;
  }
}

/* Loading skeleton for better perceived performance */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Focus visible for better accessibility */
*:focus-visible {
  outline: 2px solid #4A90E2;
  outline-offset: 2px;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Optimize font loading */
@font-face {
  font-family: 'System Font';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('system-ui'), local('-apple-system'), local('BlinkMacSystemFont');
}

/* Critical CSS - Above the fold */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  margin: 0;
  padding: 0;
  line-height: 1.6;
  color: #333;
  background: #fff;
}

/* Container optimization */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Responsive images with srcset */
img[srcset] {
  width: 100%;
  height: auto;
}

/* Modern grid layout */
@supports (display: grid) {
  .grid {
    display: grid;
    gap: 20px;
  }
  
  @media (min-width: 768px) {
    .grid {
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }
  }
}

/* Fallback for older browsers */
@supports not (display: grid) {
  .grid {
    display: flex;
    flex-wrap: wrap;
    margin: -10px;
  }
  
  .grid > * {
    flex: 1 1 300px;
    margin: 10px;
  }
}
