/* ELIMED - Performance Optimization Styles */

/* =============== LAZY LOADING STYLES =============== */

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

.lazy-loaded {
  animation: fade-in 0.5s ease;
}

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* =============== CORE WEB VITALS OPTIMIZATION =============== */

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

/* Aspect ratio containers to prevent CLS */
.aspect-ratio-16-9 {
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.aspect-ratio-4-3 {
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.aspect-ratio-1-1 {
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.aspect-ratio-3-2 {
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

/* Image containers with fixed aspect ratios */
.hero__image,
.about-hero__image,
.doctor-intro__image {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
}

.hero__image {
  aspect-ratio: 4 / 5;
}

.about-hero__image {
  aspect-ratio: 3 / 4;
}

.doctor-intro__image {
  aspect-ratio: 3 / 4;
}

/* Ensure images fill their containers */
.hero__img,
.about-hero__img,
.doctor-intro__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* =============== PERFORMANCE CRITICAL STYLES =============== */

/* Critical above-the-fold styles */
.header {
  contain: layout style;
  will-change: transform;
}

.hero {
  contain: layout;
}

/* Optimize animations for performance */
.service-card,
.btn,
.nav__link {
  will-change: transform;
  backface-visibility: hidden;
  perspective: 1000px;
}

/* GPU acceleration for smooth animations */
.service-card:hover {
  transform: translateZ(0) translateY(-5px);
}

.btn:hover {
  transform: translateZ(0) translateY(-2px);
}

/* =============== LOADING STATES =============== */

/* Section loading states */
.lazy-section {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 0.6s ease,
    transform 0.6s ease;
}

.section-loaded {
  opacity: 1;
  transform: translateY(0);
}

/* Content loading skeleton */
.content-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

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

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-title {
  height: 2em;
  margin-bottom: 1em;
}

.skeleton-image {
  width: 100%;
  height: 200px;
  margin-bottom: 1em;
}

/* =============== FONT LOADING OPTIMIZATION =============== */

/* Font display optimization */
@font-face {
  font-family: "Inter";
  font-display: swap;
  src: url("https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfAZ9hiA.woff2")
    format("woff2");
}

/* Removed duplicate @font-face for Playfair Display - using Google Fonts API instead */

/* Fallback fonts to prevent FOIT */
.hero__title,
.section__title,
.doctor-intro__subtitle {
  font-family: var(--font-heading), Georgia, "Times New Roman", serif;
}

body,
.nav__link,
.btn {
  font-family:
    var(--font-primary),
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
}

/* =============== CRITICAL CSS INLINING =============== */

/* Critical styles that should be inlined */
.critical-above-fold {
  /* Header styles */
  --header-height: 70px;

  /* Hero section styles */
  --hero-min-height: 100vh;

  /* Primary colors */
  --primary-green: #2d5a27;
  --white: #ffffff;
  --text-dark: #2c3e50;
}

/* =============== RESPONSIVE PERFORMANCE =============== */

/* Optimize for mobile performance */
@media (max-width: 768px) {
  /* Reduce animation complexity on mobile */
  .service-card:hover {
    transform: none;
  }

  /* Simplify shadows on mobile */
  .service-card,
  .btn {
    box-shadow: var(--shadow-sm);
  }

  /* Optimize images for mobile */
  .hero__image,
  .about-hero__image {
    aspect-ratio: 1 / 1;
  }
}

/* Reduce motion for users who prefer it */
@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;
  }

  .lazy-section {
    transition: none;
  }

  .service-card:hover,
  .btn:hover {
    transform: none;
  }
}

/* =============== PRINT OPTIMIZATION =============== */

@media print {
  /* Hide non-essential elements when printing */
  .header,
  .footer,
  .whatsapp-widget,
  .nav__toggle {
    display: none !important;
  }

  /* Optimize colors for print */
  .hero,
  .cta {
    background: white !important;
    color: black !important;
  }

  /* Ensure good contrast for print */
  .service-card {
    border: 1px solid #000 !important;
    box-shadow: none !important;
  }
}

/* =============== HIGH CONTRAST MODE =============== */

@media (prefers-contrast: high) {
  :root {
    --primary-green: #1a4a15;
    --secondary-green: #2d5a27;
    --text-light: #333333;
    --gray: #666666;
  }

  .service-card {
    border: 2px solid var(--primary-green);
  }

  .btn--outline {
    border-width: 3px;
  }
}

/* =============== DARK MODE SUPPORT =============== */
/* Note: Dark mode disabled for medical website - keeping light, clean appearance */

@media (prefers-color-scheme: dark) {
  /* Override system dark mode preference for medical website */
  /* Keeping light, professional appearance for better readability */
  :root {
    --white: #ffffff;
    --off-white: #fafafa;
    --light-gray: #f5f5f5;
    --text-dark: #2c3e50;
    --text-light: #7f8c8d;
  }

  body {
    background-color: var(--white);
    color: var(--text-dark);
  }

  .service-card {
    background-color: var(--white);
    border-color: var(--gray);
  }

  .lazy-loading {
    background-color: #f0f0f0;
    background-image: linear-gradient(
      90deg,
      #f0f0f0 25%,
      #e0e0e0 50%,
      #f0f0f0 75%
    );
  }
}

/* =============== CONTAINER QUERIES (Future Enhancement) =============== */

/* When container queries are supported, use them for better responsive design */
@supports (container-type: inline-size) {
  .services__grid {
    container-type: inline-size;
  }

  @container (max-width: 600px) {
    .service-card {
      padding: var(--space-md);
    }
  }
}

/* =============== PERFORMANCE MONITORING STYLES =============== */

/* Visual indicators for performance debugging */
.perf-debug .lazy-loading {
  border: 2px dashed red;
}

.perf-debug .lazy-loaded {
  border: 2px solid green;
}

.perf-debug .above-fold {
  outline: 2px solid blue;
}

/* Hide performance debug styles by default */
.perf-debug {
  display: none;
}

/* Show when debug mode is enabled */
body.debug-performance .perf-debug {
  display: block;
}

/* =============== ACCESSIBILITY PERFORMANCE =============== */

/* Ensure focus indicators are performant */
.btn:focus,
.nav__link:focus {
  outline: 2px solid var(--primary-green);
  outline-offset: 2px;
  transition: none; /* Remove transition for immediate feedback */
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary-green);
  color: var(--white);
  padding: 8px;
  text-decoration: none;
  border-radius: var(--radius-sm);
  z-index: 10000;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 6px;
}

/* =============== CRITICAL RESOURCE HINTS =============== */

/* These should be added to HTML head, documented here for reference */
/*
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="dns-prefetch" href="//www.google-analytics.com">
<link rel="preload" href="/css/styles.css" as="style">
<link rel="preload" href="/js/main.js" as="script">
<link rel="preload" href="/images/hero-doctor.jpeg" as="image">
*/
