/* Performance Optimization CSS - Perfect Score Optimizations
   Improves Core Web Vitals and reduces layout shifts */

/* Font optimizations */
@font-face {
  font-family: 'Inter';
  font-display: swap;
  src: local('Inter');
}

/* Prevent font loading layout shifts */
.font-loading {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Aspect ratio boxes to prevent layout shift */
.aspect-ratio-16-9 {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
}

.aspect-ratio-16-9 > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.aspect-ratio-4-3 {
  position: relative;
  padding-bottom: 75%;
  height: 0;
  overflow: hidden;
}

.aspect-ratio-4-3 > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Optimized image loading with explicit dimensions */
img {
  content-visibility: auto;
  contain-intrinsic-size: 400px 300px;
  max-width: 100%;
  height: auto;
}

img[loading="lazy"] {
  background: #f3f4f6;
  transition: background 0.3s ease;
}

img[loading="lazy"].loaded {
  background: transparent;
}

/* Blur-up technique for images */
.blur-load {
  filter: blur(5px);
  transition: filter 0.3s ease;
}

.blur-load.loaded {
  filter: blur(0);
}

/* Skeleton screens for better perceived performance */
.skeleton {
  animation: skeleton-loading 1.5s ease-in-out infinite;
  background: linear-gradient(
    90deg,
    #f3f4f6 0%,
    #e5e7eb 50%,
    #f3f4f6 100%
  );
  background-size: 200% 100%;
}

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

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

/* Critical CSS for above-the-fold content */
.hero-critical {
  min-height: 100vh;
  display: flex;
  align-items: center;
  background-color: #1e40af;
}

/* Optimize mobile menu for performance */
#mobile-menu {
  will-change: transform;
  transform: translateX(-100%);
  transition: transform 0.3s ease-out;
}

#mobile-menu.active {
  transform: translateX(0);
}

/* Font loading optimization */
.font-loaded .hero-heading {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Image blur-up technique */
.blur-load {
  filter: blur(5px);
  transition: filter 0.3s;
}

.blur-load.loaded {
  filter: blur(0);
}

/* Container queries for responsive components */
@container (min-width: 768px) {
  .service-card {
    grid-template-columns: 1fr 2fr;
  }
}

/* Hardware acceleration for smooth animations */
.smooth-scroll {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
}

/* Optimize form inputs */
input, textarea, select {
  font-size: 16px; /* Prevents zoom on iOS */
}

/* Preload critical background images */
.hero-bg::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(135deg, rgba(30, 64, 175, 0.9) 0%, rgba(37, 99, 235, 0.8) 100%),
    url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IiMxZTQwYWYiLz48L3N2Zz4=');
  z-index: -1;
}

/* Optimize hover states */
@media (hover: hover) {
  .hover-optimize {
    transition: transform 0.2s ease-out;
  }
  
  .hover-optimize:hover {
    transform: translateY(-4px);
  }
}

/* Content visibility for better rendering performance */
.below-fold {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* Optimize animations */
.animate-in {
  animation: fadeInUp 0.6s ease-out forwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Critical path CSS */
.critical-text {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Optimize table layouts */
table {
  table-layout: fixed;
}

/* Reduce repaints */
.no-repaint {
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Optimize scroll performance */
.scroll-container {
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}