/**
 * Critical CSS - Solo lo esencial para el primer render
 * Optimizado para trabajar con design-system.css
 * Sin duplicaciones, máximo rendimiento
 */

/* ===== VARIABLES DE COMPATIBILIDAD BOOTSTRAP ===== */
:root {
  /* Bootstrap compatibility bridge */
  --bs-primary: var(--color-primary-500);
  --bs-blue: var(--color-primary-500);
  --bs-body-font-family: var(
    --font-family-base,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif
  );
  --bs-body-font-size: var(--font-size-base, 1rem);
  --bs-body-font-weight: var(--font-weight-normal, 400);
  --bs-body-line-height: var(--line-height-normal, 1.5);
  --bs-body-color: var(--color-on-surface, #212529);
  --bs-body-bg: var(--color-surface, #fff);
  --bs-gradient: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0)
  );
}

/* ===== CAMPO DE BÚSQUEDA CRÍTICO ===== */
#filter-main {
  height: 48px;
  border: 1px solid var(--color-outline-variant, #ced4da);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, 12px);
  background-color: var(--color-surface, #fff);
  color: var(--color-on-surface, #212529);
  transform: translateZ(0);
  will-change: transform;
  transition:
    border-color var(--duration-fast, 150ms) var(--easing-standard, ease),
    outline var(--duration-fast, 150ms) var(--easing-standard, ease);
}

#filter-main:focus {
  border-color: var(--color-primary-500, #0d6efd);
  outline: 2px solid var(--color-primary-100, rgba(13, 110, 253, 0.25));
  outline-offset: 1px;
}

/* ===== ENLACES CRÍTICOS ===== */
a {
  color: var(--color-primary-500, #0d6efd);
  text-decoration: none;
  transition: color var(--duration-fast, 150ms) var(--easing-standard, ease);
}

a:hover {
  color: var(--color-primary-600, #0b5ed7);
  text-decoration: underline;
}

a:active {
  color: var(--color-primary-600, #0b5ed7);
}

/* ===== BOTONES CRÍTICOS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2, 8px) var(--space-4, 16px);
  border: none;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  font-weight: var(--font-weight-medium, 500);
  transition: all var(--duration-fast, 150ms) var(--easing-standard, ease);
  text-decoration: none;
}

.btn-primary {
  background-color: var(--color-primary-500, #0d6efd);
  color: var(--color-on-primary, #fff);
  transform: translateZ(0);
  will-change: transform;
}

.btn-primary:hover {
  background-color: var(--color-primary-600, #0b5ed7);
  color: var(--color-on-primary, #fff);
  transform: translateY(-1px);
}

.btn-primary:active {
  background-color: var(--color-primary-600, #0b5ed7);
  transform: translateY(0);
}

/* ===== FONT LOADING CRÍTICO ===== */
@font-face {
  font-family: "Main Font";
  src: url("/static/fonts/main-font.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ===== ESTILOS CRÍTICOS DEL DOCUMENTO ===== */
html,
body {
  overflow-x: hidden;
  height: 100%;
  width: 100%;
  margin: 0;
  scroll-behavior: auto; /* Prevenir CLS */
}

body {
  font-family: var(
    --font-family-base,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif
  );
  color: var(--color-on-surface);
  background-color: var(--color-surface);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  opacity: 1;
  overflow-anchor: none; /* Prevenir scroll anchoring automático */
}

/* ===== BARRA DE PROGRESO TURBO ===== */
.turbo-progress-bar {
  height: 3px;
  background-color: var(--color-primary-500);
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-max);
}

/* ===== ESTRUCTURA PRINCIPAL OPTIMIZADA ===== */
main.flex-shrink-0 {
  /* Estabilización de layout sin excesos */
  display: block;
  position: relative;
  width: 100%;
  min-height: 100vh;
  height: auto;

  /* Contención mínima necesaria */
  contain: layout style;

  /* Optimización de GPU */
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;

  /* Prevención de scroll horizontal */
  overflow-x: hidden;
  max-width: 100vw;

  /* Garantizar flujo normal */
  margin: 0;
  padding: 0;
  z-index: var(--z-base);
}

/* ===== NAVEGACIÓN CRÍTICA ===== */
.navbar {
  padding: var(--space-2) var(--space-4);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-outline-light);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(8px);
  background-color: var(--color-surface);
}

.navbar-brand img,
.navbar-brand-logo {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== HERO SECTION CRÍTICA ===== */
.hero-section,
.hero,
.position-relative.py-5.text-white,
.position-relative.py-3.text-white {
  position: relative;
  min-height: 320px;
  height: auto;
  background-color: var(--color-primary-500);
  color: var(--color-on-primary);
  contain: paint;
  content-visibility: auto;
  padding: var(--space-8) 0;
}

/* Fondo hero */
.hero-bg {
  background-color: var(--color-primary-500);
  opacity: 0.85;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ===== IMAGEN HERO OPTIMIZADA ===== */
.img-fluid {
  max-width: 100%;
  height: auto;
}

.hero-image-compact {
  width: 300px;
  max-width: 300px;
  height: auto;
  max-height: 240px;
  aspect-ratio: 5/4;
  display: block;
  margin: 0 auto;
  contain: strict;
}

/* ===== TÍTULO PRINCIPAL (LCP OPTIMIZADO) ===== */
.display-4 {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-on-primary);
  margin-bottom: var(--space-4);

  /* Optimización LCP */
  font-display: swap;
  content-visibility: auto;
  contain-intrinsic-size: 0 120px;
  transform: translateZ(0);
  will-change: transform;
  min-height: 70px;
  contain: layout style;
}

/* Preload del texto para LCP */
@media screen {
  .display-4::before {
    content: "Procesamiento Geoespacial En Línea";
    display: block;
    height: 0;
    overflow: hidden;
    visibility: hidden;
  }
}

/* ===== SECCIÓN DE HERRAMIENTAS CRÍTICA ===== */
.tools-section,
.container.py-5.tools-section {
  min-height: 500px;
  height: auto;
  contain: layout style;
  position: relative;
  z-index: var(--z-base);
  margin-bottom: var(--space-12);
  transform: translateZ(0);
}

/* Componentes internos */
.section-title {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-on-surface);
  margin-bottom: var(--space-4);
  min-height: 40px;
  display: block;
}

.section-description {
  font-size: var(--font-size-lg);
  color: var(--color-on-surface-variant);
  margin-bottom: var(--space-6);
  min-height: 30px;
  display: block;
}

/* ===== TARJETAS CRÍTICAS ===== */
.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-outline-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  contain: layout style;
  min-height: 200px;
  transition:
    box-shadow var(--duration-normal) var(--easing-standard),
    transform var(--duration-normal) var(--easing-standard);
}

.card:hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-2px);
}

.card-body {
  padding: var(--space-6);
}

/* ===== FOOTER CRÍTICO ===== */
footer.footer,
.page-footer {
  position: relative;
  z-index: var(--z-base);
  contain: layout;
  height: auto;
  clear: both;
  margin-top: var(--space-12);
  background-color: var(--color-surface-variant);
  border-top: 1px solid var(--color-outline-light);
}

/* ===== UTILIDADES CRÍTICAS ===== */
.position-relative {
  position: relative;
}

.position-absolute {
  position: absolute;
}

.z-index-2 {
  z-index: 2;
  position: relative;
}

/* Espaciado crítico */
.py-5 {
  padding-top: var(--space-12);
  padding-bottom: var(--space-12);
}

.py-3 {
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

.text-white {
  color: var(--color-on-primary);
}

/* ===== ELEMENTOS CRÍTICOS SIEMPRE VISIBLES ===== */
.section-divider [data-scroll-effect="fade"],
.use-case-icon-container,
.section-divider .card {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ===== ESTABILIZACIÓN AVANZADA ===== */
/* Estabilizar elementos de texto para prevenir CLS */
.lead,
p.lead,
.display-4,
h1.display-4,
h2.section-title {
  display: block;
  height: auto;
  min-height: 1.5em;
  contain: layout paint;
}

/* ===== OPTIMIZACIONES DE RENDIMIENTO ===== */
/* Optimizar elementos con animaciones */
.btn,
.card,
.navbar {
  will-change: transform;
  backface-visibility: hidden;
}

/* Optimización para reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== TEMA OSCURO CRÍTICO ===== */
[data-bs-theme="dark"] {
  .navbar {
    background-color: var(--color-surface);
    border-bottom-color: var(--color-outline-light);
  }

  .hero-section,
  .position-relative.py-5.text-white,
  .position-relative.py-3.text-white {
    background-color: var(--color-primary-600);
  }

  .card {
    background-color: var(--color-surface-container);
    border-color: var(--color-outline-variant);
  }

  footer.footer,
  .page-footer {
    background-color: var(--color-surface-container);
    border-top-color: var(--color-outline-variant);
  }
}

/* ===== RESPONSIVE CRÍTICO ===== */
@media (max-width: 991.98px) {
  #filter-main {
    height: 44px;
  }
}

@media (max-width: 768px) {
  .hero-section,
  .position-relative.py-5.text-white,
  .position-relative.py-3.text-white {
    min-height: 280px;
    padding: var(--space-6) 0;
  }

  .display-4 {
    font-size: var(--font-size-2xl);
  }

  .hero-image-compact {
    width: 250px;
    max-width: 250px;
    max-height: 200px;
  }

  .tools-section,
  .container.py-5.tools-section {
    min-height: 400px;
  }

  #filter-main {
    height: 42px;
  }
}

/* ===== PRELOAD HINTS ===== */
.navbar-brand img,
.hero-image-compact {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* ===== CONTENIDO CRÍTICO ===== */
/* Asegurar que el contenido crítico se vea inmediatamente */
.container:first-child,
.hero-section:first-child,
.tools-section:first-child {
  contain: none; /* Permitir que el contenido crítico se renderice sin restricciones */
}
