/* ============================================
   PERFORMANCE OPTIMIZATION STYLES
   Core Web Vitals & Loading Optimization
   ============================================ */

/* Lazy Loading Image Styles */
img[data-src] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img.lazy-loading {
  opacity: 0;
  filter: blur(5px);
}

img.lazy-loaded {
  opacity: 1;
  filter: blur(0);
}

img.lazy-error {
  opacity: 1;
  background-color: var(--light-gray);
}

/* Placeholder for lazy images */
.lazy-placeholder {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
}

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

/* Content Visibility for Off-screen Content */
.content-visibility-auto {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* 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;
    scroll-behavior: auto !important;
  }
  
  img[data-src] {
    transition: none;
  }
}

/* Critical CSS - Above the Fold Optimizations */
.critical-above-fold {
  content-visibility: visible;
}

/* Font Loading Optimization */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfAZ9hjp-Ek-_EeA.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuBKfAZ9hjp-Ek-_EeA.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYAZ9hjp-Ek-_EeA.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Image Optimization */
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

/* Responsive Images */
.responsive-img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* Aspect Ratio Boxes to Prevent CLS */
.aspect-ratio-box {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
  overflow: hidden;
}

.aspect-ratio-box img,
.aspect-ratio-box iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Common Aspect Ratios */
.aspect-16-9 { padding-bottom: 56.25%; }
.aspect-4-3 { padding-bottom: 75%; }
.aspect-3-2 { padding-bottom: 66.66%; }
.aspect-1-1 { padding-bottom: 100%; }
.aspect-21-9 { padding-bottom: 42.86%; }

/* Preload Critical Resources Hint */
.link-preload {
  display: none;
}

/* Print Styles - Optimize for Printing */
@media print {
  .no-print,
  .header,
  .footer,
  .sidebar-nav,
  .sidebar-toggle,
  .mobile-menu-toggle {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 10pt;
    color: #666;
  }
  
  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }
  
  .page-break {
    page-break-before: always;
  }
}

/* Connection-Aware Loading */
@media (prefers-reduced-data: reduce) {
  img[data-src] {
    display: none;
  }
  
  .lazy-load-optional {
    display: none;
  }
}

/* Hardware Acceleration for Animations */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
}

/* Contain Layout for Complex Components */
.layout-contained {
  contain: layout style paint;
}

/* Optimize Paint Operations */
.paint-optimized {
  transform: translateZ(0);
}

/* Smooth Scrolling with Reduced Motion Support */
html {
  scroll-behavior: smooth;
}

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

/* Focus Visible for Accessibility */
:focus-visible {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
}

/* Remove Default Focus Outline for Mouse Users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Loading States */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--light-gray);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Skeleton Loading Screens */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

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

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 1.5em;
  width: 60%;
  margin-bottom: 0.75em;
}

.skeleton-image {
  height: 200px;
  width: 100%;
}

/* Intersection Observer Polyfill Styles */
.intersection-observed {
  min-height: 1px;
}

/* Container Queries Support */
@supports (container-type: inline-size) {
  .container-query-card {
    container-type: inline-size;
  }
  
  @container (min-width: 400px) {
    .container-query-card .card-content {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 1rem;
    }
  }
}
