/**
 * Main Menu Interactive Effects
 * Efectos interactivos para el menú principal
 * Compatible con estructura Bootstrap/Navbar
 */

/* Variables CSS para el menú principal */
:root {
  --menu-primary-color: #1d4577;
  --menu-hover-color: #ffffff;
  --menu-text-color: #333333;
  --menu-transition-duration: 0.4s;
  --menu-transition-easing: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --menu-line-height: 4px; /* Línea más gruesa */
}

/* ========================================
   EFECTOS INTERACTIVOS DEL LOGO - SUTIL
   ======================================== */

/* Logo - Efecto hover sutil y elegante */
.navbar .container > a {
  display: inline-block;
  transition: all 0.3s ease;
  position: relative;
}

.navbar .container > a img {
  transition: all 0.3s ease;
  transform-origin: center center;
}

/* Hover - Solo agrandamiento y elevación sutil */
.navbar .container > a:hover img {
  transform: scale(1.05) translateY(-2px);
  filter: brightness(1.1);
}

/* Focus para accesibilidad */
.navbar .container > a:focus,
.navbar .container > a:focus-visible {
  outline-offset: 4px;
  border-radius: 4px;
}

/* ========================================
   FIN EFECTOS DEL LOGO
   ======================================== */

/* Contenedor principal del navbar */
.navbar-nav {
  position: relative;
}

/* Items del menú principal */
.navbar-nav .nav-item {
  position: relative;
}

/* Enlaces del menú */
.navbar-nav .nav-item a {
  position: relative;
  display: inline-block;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--menu-text-color);
  font-weight: 500;
  font-size: 1rem;
  transition: all var(--menu-transition-duration) var(--menu-transition-easing);
  overflow: hidden;
  border-radius: 6px;
}

/* Efecto de línea animada debajo del enlace (izquierda a derecha) */
.navbar-nav .nav-item a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 1rem; /* Más cerca del inicio del texto */
  width: 0;
  height: var(--menu-line-height);
  background-color: var(--menu-primary-color);
  transition: width var(--menu-transition-duration) var(--menu-transition-easing);
  border-radius: 2px;
}

/* Hover effect - línea se extiende de izquierda a derecha con ancho más preciso */
.navbar-nav .nav-item a:hover::after,
.navbar-nav .nav-item a:focus::after {
  width: calc(100% - 2rem); /* Ancho más preciso para coincidir con el texto */
}

/* Hover effect - solo cambio de color y tamaño del texto */
.navbar-nav .nav-item a:hover,
.navbar-nav .nav-item a:focus {
  color: var(--menu-primary-color);
  transform: scale(1.05); /* Solo agrandar un poco la letra */
}

/* Estado activo (página actual) */
.navbar-nav .nav-item.active > a,
.navbar-nav .nav-item a.active,
.navbar-nav .nav-item a[aria-current="page"] {
  color: var(--menu-primary-color);
  font-weight: 600;
}

.navbar-nav .nav-item.active > a::after,
.navbar-nav .nav-item a.active::after,
.navbar-nav .nav-item a[aria-current="page"]::after {
  width: calc(100% - 2rem);
}

/* Efecto especial: cuando un item activo recibe hover, reiniciar la animación */
.navbar-nav .nav-item.active > a:hover::after,
.navbar-nav .nav-item a.active:hover::after,
.navbar-nav .nav-item a[aria-current="page"]:hover::after {
  width: 0;
  animation: lineReappear var(--menu-transition-duration) var(--menu-transition-easing) forwards;
}

@keyframes lineReappear {
  0% { width: 0; }
  100% { width: calc(100% - 2rem); }
}

/* ========================================
   REGLAS ESPECÍFICAS PARA EL ÚLTIMO ITEM
   ======================================== */

/* El último item NUNCA debe tener estado activo */
.navbar-nav .last-menu-item a,
.navbar-nav .last-menu-item.active > a,
.navbar-nav .last-menu-item a.active,
.navbar-nav .last-menu-item a[aria-current="page"] {
  color: var(--menu-text-color) !important;
  font-weight: 500 !important;
}

/* El último item no debe mostrar línea activa */
.navbar-nav .last-menu-item a::after,
.navbar-nav .last-menu-item.active > a::after,
.navbar-nav .last-menu-item a.active::after,
.navbar-nav .last-menu-item a[aria-current="page"]::after {
  width: 0 !important;
}

/* Pero sí debe responder al hover normalmente */
.navbar-nav .last-menu-item a:hover,
.navbar-nav .last-menu-item a:focus {
  color: var(--menu-primary-color) !important;
  transform: scale(1.05) !important;
}

.navbar-nav .last-menu-item a:hover::after,
.navbar-nav .last-menu-item a:focus::after {
  width: calc(100% - 2rem) !important;
}

/* Efecto de background eliminado - solo línea y texto */

/* Efecto de brillo eliminado - simplicidad en el hover */

/* Efectos para dropdown menus */
.navbar-nav .dropdown {
  position: relative;
}

.navbar-nav .dropdown > a {
  position: relative;
  padding-right: 2rem;
}

/* Flecha para dropdown */
.navbar-nav .dropdown > a::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid currentColor;
  transform: translateY(-50%);
  transition: transform var(--menu-transition-duration) var(--menu-transition-easing);
  z-index: 2;
}

/* Línea para items con dropdown - sin ajustes de before ya que se eliminó */

.navbar-nav .dropdown:hover > a::after,
.navbar-nav .dropdown.show > a::after {
  transform: translateY(-50%) rotate(180deg);
}

/* Menu dropdown */
.navbar-nav .dropdown .dropdown-menu {
  background: white;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 0.75rem 0;
  min-width: 220px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(15px);
  transition: all var(--menu-transition-duration) var(--menu-transition-easing);
  border: 1px solid rgba(29, 69, 119, 0.1);
  margin-top: 0.5rem;
}

.navbar-nav .dropdown:hover .dropdown-menu,
.navbar-nav .dropdown.show .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.navbar-nav .dropdown .dropdown-item {
  padding: 0.75rem 1.5rem;
  color: var(--menu-text-color);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.navbar-nav .dropdown .dropdown-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--menu-primary-color), rgba(29, 69, 119, 0.8));
  transition: width 0.3s ease;
}

.navbar-nav .dropdown .dropdown-item:hover::before {
  width: 4px;
}

.navbar-nav .dropdown .dropdown-item:hover {
  background-color: rgba(29, 69, 119, 0.05);
  color: var(--menu-primary-color);
  transform: translateX(8px);
}

/* Efectos de entrada escalonados */
.navbar-nav .nav-item {
  animation: navItemFadeIn 0.6s ease-out forwards;
  animation-delay: calc(var(--nav-index, 0) * 0.1s);
  opacity: 0;
  transform: translateY(-20px);
}

@keyframes navItemFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Aplicar delays escalonados */
.navbar-nav .nav-item:nth-child(1) { --nav-index: 0; }
.navbar-nav .nav-item:nth-child(2) { --nav-index: 1; }
.navbar-nav .nav-item:nth-child(3) { --nav-index: 2; }
.navbar-nav .nav-item:nth-child(4) { --nav-index: 3; }
.navbar-nav .nav-item:nth-child(5) { --nav-index: 4; }
.navbar-nav .nav-item:nth-child(6) { --nav-index: 5; }
.navbar-nav .nav-item:nth-child(7) { --nav-index: 6; }
.navbar-nav .nav-item:nth-child(8) { --nav-index: 7; }

/* ========================================
   ESTILOS MÓVILES INTERACTIVOS
   ======================================== */

@media (max-width: 991px) {
  /* Contenedor del collapse en móvil */
  .navbar-collapse {
    text-align: center;
    width: 100%;
  }
  /* Reset para móvil */
  .navbar-nav {
    flex-direction: column;
    width: 100%;
    background: white;
    padding: 1rem 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    /* Centrar el menú en móvil */
    text-align: center;
    align-items: center;
    gap: 1rem;
  }

  .navbar-nav .nav-item {
    margin: 0;
    width: 100%;
    /* Centrar cada item individualmente */
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /* Enlaces en móvil */
  .navbar-nav .nav-item a {
    display: block;
    padding: 1.25rem 2rem;
    margin: 0;
    font-size: 1.1rem;
    border-radius: 0;
    text-align: center;
    width: 100%;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(29, 69, 119, 0.05) 0%,
      rgba(29, 69, 119, 0.05) 100%,
      transparent 100%
    );
    background-size: 0% 100%;
    background-repeat: no-repeat;
    transition: all var(--menu-transition-duration) var(--menu-transition-easing);
  }

  /* Línea lateral izquierda en móvil */
  .navbar-nav .nav-item a::after {
    left: 0;
    top: 0;
    width: 0;
    height: 100%;
    border-radius: 0 3px 3px 0;
    bottom: auto;
  }

  /* Efecto de slide en móvil - línea de izquierda a derecha completa */
  .navbar-nav .nav-item a:hover,
  .navbar-nav .nav-item a:focus,
  .navbar-nav .nav-item a:active {
    background-size: 100% 100%;
    color: var(--menu-primary-color);
  }

  .navbar-nav .nav-item a:hover::after,
  .navbar-nav .nav-item a:focus::after,
  .navbar-nav .nav-item.active > a::after,
  .navbar-nav .nav-item a.active::after {
    width: 5px;
  }

  /* Efecto táctil en móvil */
  .navbar-nav .nav-item a:active {
    background-color: rgba(29, 69, 119, 0.1);
    transform: scale(0.98);
  }

  /* Estados activos en móvil */
  .navbar-nav .nav-item.active > a,
  .navbar-nav .nav-item a.active {
    background-size: 100% 100%;
    color: var(--menu-primary-color);
    font-weight: 600;
  }

  /* Reglas específicas para el último item en móvil */
  .navbar-nav .last-menu-item a,
  .navbar-nav .last-menu-item.active > a,
  .navbar-nav .last-menu-item a.active,
  .navbar-nav .last-menu-item a[aria-current="page"] {
    color: var(--menu-text-color) !important;
    font-weight: 500 !important;
    background-size: 0% 100% !important;
  }

  .navbar-nav .last-menu-item a::after,
  .navbar-nav .last-menu-item.active > a::after,
  .navbar-nav .last-menu-item a.active::after,
  .navbar-nav .last-menu-item a[aria-current="page"]::after {
    width: 0 !important;
  }

  /* Pero sí debe responder al hover en móvil */
  .navbar-nav .last-menu-item a:hover,
  .navbar-nav .last-menu-item a:focus {
    background-size: 100% 100% !important;
    color: var(--menu-primary-color) !important;
  }

  .navbar-nav .last-menu-item a:hover::after,
  .navbar-nav .last-menu-item a:focus::after {
    width: 5px !important;
  }

  /* Dropdown en móvil */
  .navbar-nav .dropdown .dropdown-menu {
    position: static;
    box-shadow: inset 0 0 10px rgba(29, 69, 119, 0.1);
    background: rgba(29, 69, 119, 0.02);
    border-radius: 0;
    margin: 0;
    padding: 0;
    transform: scaleY(0);
    transform-origin: top;
    height: 0;
    overflow: hidden;
  }

  .navbar-nav .dropdown.show .dropdown-menu {
    transform: scaleY(1);
    height: auto;
    animation: mobileDropdownSlide 0.3s ease;
  }

  @keyframes mobileDropdownSlide {
    from {
      opacity: 0;
      transform: scaleY(0);
    }
    to {
      opacity: 1;
      transform: scaleY(1);
    }
  }

  .navbar-nav .dropdown .dropdown-item {
    padding: 1rem 3rem;
    font-size: 1rem;
    border-left: 2px solid transparent;
  }

  .navbar-nav .dropdown .dropdown-item:hover {
    border-left-color: var(--menu-primary-color);
    background-color: rgba(29, 69, 119, 0.05);
    transform: translateX(10px);
  }
}

/* ========================================
   MEJORAS DE ACCESIBILIDAD
   ======================================== */

/* Focus visible mejorado */
.navbar-nav .nav-item a:focus-visible {
  outline-offset: 3px;
  border-radius: 4px;
}

/* Reducir animaciones para usuarios con preferencias de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  .navbar-nav .nav-item a,
  .navbar-nav .nav-item a::after,
  .navbar-nav .nav-item a::before,
  .navbar-nav .nav-item {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Mejoras para pantallas de alto contraste */
@media (prefers-contrast: high) {
  .navbar-nav .nav-item a {
    border: 2px solid transparent;
  }
  
  .navbar-nav .nav-item a:hover,
  .navbar-nav .nav-item a:focus {
    border-color: var(--menu-primary-color);
    background-color: rgba(29, 69, 119, 0.1);
  }
}

/* ========================================
   EFECTOS ADICIONALES DE INTERACTIVIDAD
   ======================================== */

@keyframes activePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Efecto de loading para items que están cargando */
.navbar-nav .nav-item.loading a::after {
  background: linear-gradient(
    90deg,
    var(--menu-primary-color) 25%,
    rgba(29, 69, 119, 0.3) 50%,
    var(--menu-primary-color) 75%
  );
  background-size: 200% 100%;
  animation: loadingBar 1.5s infinite;
  width: calc(100% - 2.5rem);
}

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