/*
 * Performance Optimizations CSS
 * Advanced CSS for better performance and user experience
 */

/* ===== CRITICAL CSS OPTIMIZATIONS ===== */
.critical-render {
  contain: layout style paint;
}

/* ===== LOADING STATES ===== */
.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; }
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top: 4px solid var(--primary-600);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== LAZY LOADING OPTIMIZATIONS ===== */
img[data-src] {
  filter: blur(5px);
  transition: filter 0.3s;
}

img[data-src].loaded {
  filter: blur(0);
}

.lazy-load-placeholder {
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  font-size: var(--text-sm);
}

/* ===== INTERSECTION OBSERVER ANIMATIONS ===== */
.fade-in-up {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in-up.visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-in-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.fade-in-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.scale-in {
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.scale-in.visible {
  opacity: 1;
  transform: scale(1);
}

/* ===== PERFORMANCE OPTIMIZED COMPONENTS ===== */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
}

.smooth-scroll {
  scroll-behavior: smooth;
}

/* ===== REDUCED MOTION SUPPORT ===== */
@media (prefers-reduced-motion: reduce) {
  .fade-in-up,
  .fade-in-left,
  .fade-in-right,
  .scale-in {
    transition: none;
  }
  
  .loading-skeleton {
    animation: none;
    background: #f0f0f0;
  }
  
  .loading-spinner {
    animation: none;
    border-top-color: var(--primary-600);
  }
}

/* ===== FOCUS MANAGEMENT ===== */
.focus-trap {
  position: relative;
}

.focus-trap::before,
.focus-trap::after {
  content: '';
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ===== OPTIMIZED HOVER STATES ===== */
@media (hover: hover) {
  .hover-lift {
    transition: transform 0.2s ease;
  }
  
  .hover-lift:hover {
    transform: translateY(-2px);
  }
  
  .hover-scale {
    transition: transform 0.2s ease;
  }
  
  .hover-scale:hover {
    transform: scale(1.05);
  }
}

/* ===== CONTAINER QUERIES SUPPORT ===== */
@supports (container-type: inline-size) {
  .responsive-container {
    container-type: inline-size;
  }
  
  @container (min-width: 400px) {
    .container-responsive {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
    }
  }
  
  @container (min-width: 600px) {
    .container-responsive {
      grid-template-columns: repeat(3, 1fr);
    }
  }
}

/* ===== MODERN CSS FEATURES ===== */
@supports (backdrop-filter: blur(10px)) {
  .modern-blur {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.8);
  }
}

@supports (display: grid) {
  .modern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-6);
  }
}

/* ===== SCROLL SNAP ===== */
.scroll-snap-container {
  scroll-snap-type: x mandatory;
  overflow-x: auto;
  display: flex;
  gap: var(--space-4);
}

.scroll-snap-item {
  scroll-snap-align: start;
  flex-shrink: 0;
}

/* ===== OPTIMIZED TYPOGRAPHY ===== */
.optimized-text {
  font-display: swap;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== EFFICIENT ANIMATIONS ===== */
.efficient-fade {
  opacity: 0;
  animation: efficientFadeIn 0.3s ease forwards;
}

@keyframes efficientFadeIn {
  to { opacity: 1; }
}

.efficient-slide {
  transform: translateX(-100%);
  animation: efficientSlideIn 0.3s ease forwards;
}

@keyframes efficientSlideIn {
  to { transform: translateX(0); }
}

/* ===== CONTENT VISIBILITY ===== */
@supports (content-visibility: auto) {
  .content-visibility-auto {
    content-visibility: auto;
    contain-intrinsic-size: 300px;
  }
}

/* ===== ASPECT RATIO ===== */
@supports (aspect-ratio: 16/9) {
  .aspect-video {
    aspect-ratio: 16/9;
  }
  
  .aspect-square {
    aspect-ratio: 1/1;
  }
  
  .aspect-portrait {
    aspect-ratio: 3/4;
  }
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 16/9) {
  .aspect-video {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
  }
  
  .aspect-video > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

/* ===== OPTIMIZED SHADOWS ===== */
.efficient-shadow {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  transition: box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.efficient-shadow:hover {
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
}

/* ===== PERFORMANCE MONITORING ===== */
.performance-marker {
  position: relative;
}

.performance-marker::after {
  content: attr(data-performance);
  position: absolute;
  top: -20px;
  right: 0;
  font-size: 10px;
  color: var(--success-500);
  background: var(--success-50);
  padding: 2px 4px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.3s;
}

.performance-marker:hover::after {
  opacity: 1;
}

/* ===== CRITICAL RESOURCE HINTS ===== */
.preload-hint {
  position: relative;
}

.preload-hint::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary-500), transparent);
  animation: preloadProgress 2s ease-in-out;
}

@keyframes preloadProgress {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}