.mobile-nav-header {
  display: none;
}

.nav-dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  z-index: 30;
  width: min(440px, calc(100vw - 48px));
  padding-top: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px) scale(.98);
  transform-origin: top center;
  transition: opacity .2s ease, transform .2s ease;
}

.nav-item:hover .nav-dropdown,
.nav-item:focus-within .nav-dropdown,
.nav-item.open .nav-dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
}

.nav-dropdown-grid {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 28px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.nav-dropdown-grid > * {
  position: relative;
  z-index: 1;
  animation: navItemEnter .24s ease both;
}

.nav-dropdown-grid > *:nth-child(2) {
  animation-delay: .04s;
}

.nav-dropdown-grid > *:nth-child(3) {
  animation-delay: .08s;
}

.nav-dropdown-grid strong {
  display: block;
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 15px;
}

.nav-dropdown-grid a:not(.btn) {
  display: block;
  padding: 7px 0;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 700;
  transition: color .16s ease, transform .16s ease;
}

.nav-dropdown-grid a:not(.btn):hover {
  transform: translateX(4px);
  color: var(--blue);
}

.nav-dropdown-grid a[aria-disabled="true"] {
  color: var(--muted);
  cursor: default;
}

.nav-dropdown-grid a[aria-disabled="true"]:hover {
  transform: none;
  color: var(--muted);
}

.nav-dropdown--tree {
  left: 0;
  width: 300px;
  transform: translate(0, 12px) scale(.98);
}

.nav-item:hover .nav-dropdown--tree,
.nav-item:focus-within .nav-dropdown--tree,
.nav-item.open .nav-dropdown--tree {
  transform: translate(0, 0) scale(1);
}

.module-tree {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.module-tree-item {
  position: relative;
}

.module-tree-row {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  transition: background-color .14s ease;
}

.module-tree-row:hover,
.module-tree-item:focus-within > .module-tree-row {
  background: var(--sage);
}

.module-tree-link {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 10px;
  color: var(--green-dark);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: color .14s ease;
}

.module-tree-row:hover .module-tree-link,
.module-tree-item:focus-within > .module-tree-row .module-tree-link {
  color: var(--blue);
}

.module-tree-link--inert {
  color: var(--muted);
  cursor: default;
}

/* Módulo con submódulos: se ve activo y despliega al tocarlo, pero no navega. */
.module-tree-link--parent {
  cursor: pointer;
  user-select: none;
}

.module-tree-row:hover .module-tree-link--inert,
.module-tree-item:focus-within > .module-tree-row .module-tree-link--inert {
  color: var(--muted);
}

.module-tree-toggle {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.module-tree-caret {
  font-size: 14px;
  line-height: 1;
  transition: transform .18s ease;
}

.module-tree-toggle[aria-expanded="true"] .module-tree-caret {
  transform: rotate(90deg);
}

.module-tree-sub {
  position: absolute;
  top: -10px;
  left: 100%;
  z-index: 1;
  list-style: none;
  margin: 0;
  padding: 10px;
  width: 300px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateX(6px);
  transition: opacity .15s ease, transform .15s ease;
}

.module-tree-item.open > .module-tree-sub,
.module-tree-item:focus-within > .module-tree-sub {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.module-tree-sub.flip-left {
  left: auto;
  right: 100%;
  transform: translateX(-6px);
}

.module-tree-item.open > .module-tree-sub.flip-left,
.module-tree-item:focus-within > .module-tree-sub.flip-left {
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .nav-dropdown--tree,
  .module-tree-sub {
    transition: none;
  }
}

@keyframes navItemEnter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

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

@media (prefers-reduced-motion: reduce) {
  .nav-dropdown,
  .nav-dropdown-grid > * {
    animation: none;
    transition: none;
  }
}

@media (max-width: 980px) {
  .nav-dropdown {
    left: 0;
    width: min(440px, calc(100vw - 32px));
    transform: translate(0, 8px) scale(.98);
  }

  .nav-item:hover .nav-dropdown,
  .nav-item:focus-within .nav-dropdown,
  .nav-item.open .nav-dropdown {
    transform: translate(0, 0) scale(1);
  }
}

@media (max-width: 680px) {
  .menu-btn {
    display: grid;
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(5, 7, 12, .5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.mobile-nav-open .mobile-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .nav-links {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    z-index: 70;
    width: min(320px, 86vw);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 18px 16px 24px;
    background: var(--paper);
    box-shadow: var(--shadow);
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform .25s ease;
  }

  .mobile-nav-header {
    display: flex;
    align-items: center;
    padding-bottom: 16px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }

  body.mobile-nav-open .nav-links {
    transform: translateX(0);
  }

  .nav-item {
    width: 100%;
  }

  .nav-link {
    width: 100%;
    justify-content: space-between;
  }

  .nav-dropdown,
  .nav-dropdown--tree {
    position: static;
    width: 100%;
    padding-top: 0;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
  }

  .nav-item.open > .nav-dropdown {
    max-height: 3000px;
  }

  .nav-dropdown-grid,
  .module-tree {
    border: none;
    box-shadow: none;
    background: none;
    padding: 4px 0 4px 10px;
  }

  .nav-dropdown-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .module-tree-sub {
    position: static;
    width: 100%;
    border: none;
    box-shadow: none;
    background: none;
    padding: 0 0 0 14px;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
  }

  .module-tree-item.open > .module-tree-sub {
    max-height: 3000px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-links,
  .mobile-nav-backdrop,
  .nav-dropdown,
  .nav-dropdown--tree,
  .module-tree-sub {
    transition: none;
  }
}
