/* =========================
  MENÚ PRINCIPAL MAXIMENU
  ========================= */

/* Base y reseteo */
.maximenu,
.maximenu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Items de primer nivel */
.maximenu > li {
  display: inline-block;
  position: relative;
  vertical-align: middle;
}

/* Enlaces y spans */
.maximenu li a,
.maximenu li span {
  display: block;
  text-decoration: none;
  color: #fff;
  background-color: #009a57;
  padding: 0 20px;
  line-height: 60px;
  font-size: 1.1em;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease-out, color 0.2s ease-out;
  white-space: nowrap;
}

/* Estados hover y activo (excepto flecha) */
.maximenu li a:hover:not(.arrow),
.maximenu li span:hover:not(.arrow),
.maximenu li.active > a:not(.arrow),
.maximenu li.active > span:not(.arrow),
.maximenu li.Nivel1:hover > a:not(.arrow) {
  background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
  color: #fff;
}

/* Submenús generales */
.maximenu li ul {
  background-color: #4499cb;
  border-bottom: 1px solid #000;
  position: absolute;
  display: none;
  z-index: 1000;
  min-width: 180px;
}

/* Hover para mostrar submenús */
.maximenu li:hover > ul {
  display: block;
}

/* Nivel 1 desplegable */
.maximenu li.Nivel1 > ul {
  top: 100%;
  left: 0;
  min-width: 200px;
}

/* Nivel 2 desplegable */
.maximenu li.Nivel2 > ul {
  top: 0;
  left: 100%;
}

/* Enlaces en submenús */
.maximenu li ul li a {
  background-color: #4499cb;
  border-bottom: 1px solid #000;
  color: #fff;
  font-size: 14px;
  font-weight: 400;
  padding: 0 15px;
  line-height: 32px;
}

.maximenu li ul li a:hover:not(.arrow),
.maximenu li ul li.active > a:not(.arrow) {
  background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
}

/* =========================
  PROPAGAR ACTIVO AL PADRE (excepto flecha)
  ========================= */
.maximenu li.active > a:not(.arrow),
.maximenu li.active > span:not(.arrow) {
  background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
  color: #fff;
}

.maximenu li li.active {
  background: none;
}

.maximenu li li.active a:not(.arrow),
.maximenu li li.active span:not(.arrow) {
  background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
  color: #fff;
}

/* =========================
  PROPAGACIÓN AUTOMÁTICA CON :has()
  ========================= */
@supports selector(:has(*)) {
  .maximenu li:has(ul li.active) > a:not(.arrow),
  .maximenu li:has(ul li.active) > span:not(.arrow),
  .maximenu li:has(ul a[aria-current="page"]) > a:not(.arrow),
  .maximenu li:has(ul a[aria-current="page"]) > span:not(.arrow) {
    background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
    color: #fff;
  }
}

/* =========================
  FLECHAS DE INDICADOR
  ========================= */
.maximenu li {
  position: relative;
}

.maximenu .arrow {
  position: absolute;
  background-color: transparent;
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.maximenu .arrow > div {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #fff;
}

/* Flecha hacia la derecha en niveles secundarios */
.maximenu li.Nivel2 .arrow > div {
  border-top: none;
  border-left: 6px solid #fff;
  border-bottom: 5px solid transparent;
  border-top: 5px solid transparent;
}

/* =========================
  RESPONSIVE
  ========================= */
@media (max-width: 768px) {
  .maximenu > li {
    display: block;
  }
  .maximenu li ul {
    position: static;
    min-width: 100%;
  }
  .maximenu .arrow {
    right: 15px;
  }
}

/* =========================
  VARIABLES DE ANIMACIÓN
  ========================= */
:root {
  --animate-duration: 1s;
  --animate-delay: 1s;
  --animate-repeat: 1;
}

/* =========================
  Fallback JS para navegadores sin :has()
  ========================= */
.maximenu li.active-trail > a:not(.arrow),
.maximenu li.active-trail > span:not(.arrow) {
  background: linear-gradient(to bottom, rgba(56, 172, 231, 1) 0%, rgba(22, 129, 209, 1) 100%);
  color: #fff;
}
.maximenu li {
  position: relative;
}

/* Icono "hamburger" para .icon-menu (CSS puro) */
.icon-menu {
  display: inline-block;
  width: 22px;
  height: 2px;
  background: #fff;
  position: relative;
  vertical-align: middle;
  transition: transform 0.2s ease;
}
.icon-menu::before,
.icon-menu::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.icon-menu::before {
  top: -6px;
}
.icon-menu::after {
  bottom: -6px;
}

/* estado focus/active del botón (pequeña animación, opcional) */
.navbar-toggler:focus .icon-menu,
.navbar-toggler:active .icon-menu {
  transform: scale(0.98);
}

/* Si quieres animar a "X" al abrir (requiere toggle de clase .open en el botón desde JS/PHP) */
.navbar-toggler.open .icon-menu {
  background: transparent;
}
.navbar-toggler.open .icon-menu::before {
  transform: translateY(6px) rotate(45deg);
}
.navbar-toggler.open .icon-menu::after {
  transform: translateY(-6px) rotate(-45deg);
}

/* Ajustes visuales para botón hamburguesa */
.maximenu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem .5rem;
  color: #fff;
  align-items: center;
}

/* icon-menu (líneas) */
.icon-menu {
  display: inline-block;
  width: 22px;
  height: 2px;
  background: #fff;
  position: relative;
  vertical-align: middle;
  transition: transform 0.2s ease;
}
.icon-menu::before,
.icon-menu::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.icon-menu::before { top: -6px; }
.icon-menu::after { bottom: -6px; }

/* estado abierto del toggler */
.navbar-toggler.open .icon-menu {
  background: transparent;
}
.navbar-toggler.open .icon-menu::before {
  transform: translateY(6px) rotate(45deg);
}
.navbar-toggler.open .icon-menu::after {
  transform: translateY(-6px) rotate(-45deg);
}

/* Submenu-toggle (botón flecha) */
.submenu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0 .5rem;
  margin: 0;
  cursor: pointer;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 100%;
  color: inherit;
}
.submenu-toggle .arrow {
  right: auto;
  top: auto;
  transform: none;
  pointer-events: none;
}
.submenu-toggle:focus {
  outline: 2px solid rgba(255,255,255,.25);
  outline-offset: 2px;
}

/* Móvil: layout vertical y control de submenús */
@media (max-width: 768px) {
  .maximenu-toggle {
    display: inline-flex;
  }

  .maximenu {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    width: 90%;
    margin: 0.5rem auto;
    transition: max-height .25s ease;
    overflow: visible;
  }
  .maximenu.open {
    display: flex;
  }

  .maximenu > li {
    display: block;
    position: relative;
  }

  .maximenu li a,
  .maximenu li span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #008f4c;
    border-radius: 6px;
    line-height: 1;
  }

  /* Esconder las sublistas por defecto en móvil */
  .maximenu li ul {
    display: none;
    flex-direction: column;
    padding-left: 1rem;
    background: transparent;
    position: static;
    border: none;
    min-width: auto;
  }
  .maximenu li.open > ul {
    display: flex;
  }

  /* Ajuste del botón de flecha dentro del item */
  .maximenu li .submenu-toggle {
    right: .75rem;
  }

  /* Cuando el item está abierto, rotar flecha */
  .maximenu li.open .submenu-toggle .arrow > div {
    transform: rotate(180deg);
  }

  /* Pequeña transición para submenús */
  .maximenu li ul,
  .maximenu li a {
    transition: all .18s ease;
  }
}

/* ===== ADICIONES / CORRECCIONES ===== */

/* Contenedor y comportamiento por defecto (escritorio) */
.maximenu-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between; /* ajustar según diseño */
  gap: .5rem;
}

/* Forzar layout de escritorio por defecto */
.maximenu {
  display: flex;
  flex-direction: row;
  align-items: center;
}

/* Hamburguesa más grande y centrada */
.maximenu-toggle {
  display: none; /* seguirá mostrándose en la media query móvil */
  width: 60px;
  height: 60px;
  min-width: 60px;
  min-height: 60px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  padding: 6px;
  margin: 0;
  background: transparent;
  border: none;
  cursor: pointer;
}

/* Icono ligeramente mayor */
.icon-menu {
  width: 28px;
  height: 3px;
}
.icon-menu::before,
.icon-menu::after { height: 3px; }

/* Ampliar zona de toque del toggle de submenú */
.submenu-toggle {
  position: absolute;
  right: 0.5rem;
  top: 0;
  bottom: 0;
  width: 56px;    /* zona amplia para tocar */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  z-index: 5;
}

/* Asegurar que el propio <li> tenga padding a la derecha para la zona de botón */
.maximenu li > a,
.maximenu li > span {
  padding-right: 3.5rem; /* deja espacio para el botón sin afectar el texto */
}

/* Ocultar menú en móvil por defecto (mejor especificidad) */
@media (max-width: 768px) {
  /* Contenedor y menú ocupando 100% */
  .maximenu-wrapper {
    width: 100%;
    padding: 0 0.5rem;
    box-sizing: border-box;
  }

  .maximenu {
    width: 100% !important;
    margin: 0;
    display: none !important;
    flex-direction: column;
    gap: 0.5rem;
  }
  .maximenu.open {
    display: flex !important;
  }

  /* Cada item ocupa todo el ancho */
  .maximenu > li,
  .maximenu li {
    display: block;
    width: 100%;
    box-sizing: border-box;
    position: relative;
  }

  /* Enlace ocupa todo el ancho; dejar espacio a la derecha para la flecha/botón */
  .maximenu li > a,
  .maximenu li > span {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.75rem 3.5rem 0.75rem 1rem; /* derecha para botón */
    box-sizing: border-box;
    border-radius: 6px;
  }

  /* Submenús también a ancho completo, con sangría interior */
  .maximenu li ul {
    display: none !important;
    width: 100%;
    box-sizing: border-box;
    padding-left: 0; /* controlamos sangría en enlaces */
    margin: 0;
    background: transparent;
    position: static;
  }
  .maximenu li.open > ul {
    display: flex !important;
    flex-direction: column;
  }

  /* Subitems con sangría visual sin reducir ancho */
  .maximenu li ul li > a {
    padding-left: 1.5rem;
    padding-right: 3.5rem;
    width: 100%;
    box-sizing: border-box;
  }

  /* Flecha/botón posicionado a la derecha dentro del ancho completo */
  .maximenu li .submenu-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
  }

  .maximenu li.open > .submenu-toggle {
    top: 0;
    transform: translateY(-20%);
  }
  /* Centrar hamburguesa y separarla del contenido */
  .maximenu-wrapper .maximenu-toggle {
    display: inline-flex;
    margin: 0.5rem auto;
  }
}

/* ===== Ajuste: evitar que el menú sobrepase la pantalla en móvil ===== */
:root {
  /* distancia reservada (header, margen, toggler). Ajusta en px o rem según necesites */
  --maximenu-offset: 120px;
}

/* Solo para móvil */
@media (max-width: 768px) {
  /* Limitar la altura del menú abierto y habilitar scroll interno */
  .maximenu.open {
    max-height: calc(100vh - var(--maximenu-offset)) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Si quieres que el menú ocupe toda la pantalla (opcional):
  .maximenu.open {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
    z-index: 9999;
  }
  */
}

/* =========================
  FIN DEL CSS DEL MENÚ
  ========================= */