/* ============================================================
   public/css/layout/header-nav.css
   BEM + accesible + dropdown desktop + panel móvil
   Consolidado: desktop usa hover/focus-within, móvil usa [hidden]
   ============================================================ */

/* =========================
   Skip link (a11y)
========================= */
.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateY(-120%);
  background: #fff;
  color: var(--grey-900);
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 10px 26px rgba(0,0,0,.14);
  z-index: calc(var(--z-header, 1000) + 5);
}
.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(12px);
  outline: 3px solid var(--primary-400);
  outline-offset: 2px;
}

/* =========================
   HEADER
========================= */
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: var(--z-header, 1000);
  background: #f7f9fb;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}

.header__inner {
  max-width: var(--container-width, 1200px);
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* =========================
   BRAND
========================= */
.header__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 360px;
}

.header__brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex: 0 0 auto;
}

.header__brand-text {
  height: 32px;
  width: auto;
  max-width: 100%;
  display: block;
}

/* =========================
   TOGGLE
========================= */
.header__toggle {
  display: none;
  font-size: 2rem;
  line-height: 1;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--grey-900);
  border-radius: 10px;
}
.header__toggle:focus-visible {
  outline: 3px solid var(--primary-400);
  outline-offset: 2px;
}

/* Desktop CTA container */
.header__actions {
  display: flex;
  align-items: center;
}

/* =========================
   NAV (desktop base)
========================= */
.nav {
  display: flex;
  align-items: center;
}

.nav__list {
  display: flex;
  align-items: center;
  gap: 22px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__item { position: relative; }

.nav__link,
.dropdown-link,
.submenu-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--grey-700);
  text-decoration: none;
  padding: 10px 0;
  transition: color .2s ease, opacity .2s ease, background .2s ease;
  white-space: nowrap;
}

.nav__link:hover,
.dropdown-link:hover,
.submenu-link:hover {
  color: var(--primary-700);
}

/* Active underline */
.nav__link.is-active,
.dropdown-link.is-active,
.submenu-link.is-active {
  position: relative;
}
.nav__link.is-active::after,
.dropdown-link.is-active::after,
.submenu-link.is-active::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -3px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary-400);
}

/* Caret visual en links (desktop) */
.has-caret::after,
.has-caret-2::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-top: -2px;
  opacity: 0.85;
}

/* =========================
   Dropdown / Submenu structure
========================= */
.dropdown-head,
.submenu-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Caret buttons (visible in mobile only) */
.submenu-caret,
.submenu-caret-2 {
  display: none;
  border: 0;
  background: transparent;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: var(--grey-800);
  position: relative;
}

.submenu-caret:focus-visible,
.submenu-caret-2:focus-visible {
  outline: 3px solid var(--primary-400);
  outline-offset: 2px;
}

.submenu-caret::before,
.submenu-caret-2::before {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  position: absolute;
  inset: 0;
  margin: auto;
}

/* =========================
   Menús (desktop base)
========================= */
.dropdown-menu,
.submenu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;

  min-width: 230px;
  margin: 0;
  list-style: none;
  padding: 12px 0;

  background: #f7f9fb;
  border-radius: 14px;

  box-shadow:
    0 18px 40px rgba(15, 23, 42, 0.12),
    0 2px 6px rgba(15, 23, 42, 0.04);

  border: 1px solid rgba(15, 23, 42, 0.06);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transform: translateY(10px);
  transition:
    opacity .18s ease-out,
    transform .22s ease-out,
    visibility 0s linear .22s;

  z-index: 40;
}

/* Submenu (nivel 2) aparece a la derecha */
.has-sub { position: relative; }
.has-sub > .submenu {
  top: -6px;
  left: calc(100% + 14px);
  transform: translateY(8px);
}

/* Items */
.dropdown-menu a,
.submenu a {
  display: block;
  padding: 10px 18px;
  font-size: 0.95rem;
  border-radius: 8px;
  margin: 2px 8px;
  font-weight: 500;
  color: var(--grey-800);
  text-decoration: none;
  transition: background .18s ease, color .18s ease;
}
.dropdown-menu a:hover,
.submenu a:hover {
  background: rgba(38, 199, 213, 0.08);
  color: var(--primary-700);
}

/* =========================
   Desktop open (hover + focus-within)
========================= */
@media (min-width: 769px) {
  .dropdown-head:hover + .dropdown-menu,
  .dropdown-head:focus-within + .dropdown-menu,
  .dropdown-menu:hover,
  .dropdown-menu:focus-within {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition-delay: 0s;
  }

  .submenu-head:hover + .submenu,
  .submenu-head:focus-within + .submenu,
  .submenu:hover,
  .submenu:focus-within {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition-delay: 0s;
  }

  /* Hover bridges */
  .dropdown-menu::before {
    content: "";
    position: absolute;
    left: 0;
    top: -10px;
    height: 10px;
    width: 100%;
    background: transparent;
  }

  .submenu::before {
    content: "";
    position: absolute;
    top: 0;
    left: -14px;
    width: 14px;
    height: 100%;
    background: transparent;
  }
}

/* =========================
   OVERLAY (created by JS)
========================= */
.menu-overlay { display: none; }

/* Panel head exists only in mobile */
.nav__panel-head { display: none; }

/* =========================
   MOBILE
========================= */
@media (max-width: 768px) {
  .header__toggle { display: inline-flex; }
  .header__actions { display: none; }

  /* In móvil: ocultar caret del link (dejamos solo botón caret) */
  .has-caret::after,
  .has-caret-2::after {
    display: none;
  }

  /* Panel */
  .nav {
    position: fixed;
    top: var(--header-height, 70px);
    right: 0;

    width: min(84vw, 380px);
    height: calc(100dvh - var(--header-height, 70px));

    /* ⭐ Look premium: suave, con transparencia */
    background: rgba(230, 248, 250, 0.72);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    /* ⭐ Bordes y radio */
    border-left: 1px solid rgba(38, 199, 213, 0.25);
    border-top-left-radius: 22px;
    border-bottom-left-radius: 22px;

    /* ⭐ Sombra más “pro” */
    box-shadow:
      -18px 0 50px rgba(0,0,0,.18),
      -2px 0 0 rgba(255,255,255,.35) inset;

    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;

    min-height: 0;

    transform: translate3d(100%, 0, 0);
    opacity: 0;
    pointer-events: none;

    will-change: transform, opacity;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;

    transition: transform .28s ease, opacity .28s ease;
    z-index: calc(var(--z-overlay, 1100) + 2);
  }

  .nav.active {
    transform: translate3d(0, 0, 0);
    opacity: 1;
    pointer-events: auto;
  }

  /* Panel head: CTA + Cerrar (solo móvil) */
  .nav__panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    padding-bottom: 12px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  }

  .nav__cta {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }

  .nav__close {
    width: 44px;
    height: 44px;
    border-radius: 14px;

    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.06);
    color: var(--grey-900);

    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
  }

  .nav__close:hover {
    background: rgba(15, 23, 42, 0.10);
  }

  .nav__close:focus-visible {
    outline: 3px solid var(--primary-400);
    outline-offset: 2px;
  }

  /* Lista con scroll interno */
  .nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;

    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;

    /* ⭐ Un poco más de “aire” interno */
    padding: 10px 4px 18px;
  }

  /* Items principales (premium) */
  .nav__link,
  .dropdown-link,
  .submenu-link {
    width: 100%;
    padding: 14px 12px;
    border-radius: 14px;

    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--grey-900);

    /* ⭐ Más “card”, menos plano */
    background: rgba(15, 23, 42, 0.035);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 1px 0 rgba(255,255,255,.6) inset;
  }

  .nav__link:hover,
  .dropdown-link:hover,
  .submenu-link:hover {
    background: rgba(38, 199, 213, 0.10);
  }

  /* Head layout: link + caret */
  .dropdown-head,
  .submenu-head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  /* Caret buttons visible */
  .submenu-caret,
  .submenu-caret-2 {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 44px;
    height: 44px;
    border-radius: 14px;

    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.05);
  }

  /* Overlay */
  .menu-overlay.active {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: var(--z-overlay, 1100);
  }

  /* =========================
     FIX DEFINITIVO:
     En móvil NO usamos opacity/visibility del desktop.
     Solo control con [hidden]
  ========================= */
  .nav .dropdown-menu,
  .nav .submenu {
    position: static !important;
    min-width: 0;
    padding: 6px 0 0;

    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: auto !important;

    display: block !important;

    box-shadow: none !important;
    border: 0 !important;
    background: transparent !important;
    border-radius: 0 !important;
  }

  .nav .dropdown-menu[hidden],
  .nav .submenu[hidden] {
    display: none !important;
  }

  /* Indents */
  .dropdown.open > .dropdown-menu { margin-top: 6px; }
  .has-sub.open > .submenu { padding-left: 12px; }

  
  
  /* =========================
     MÓVIL: desactivar 2º nivel (desktop mantiene 2 niveles)
  ========================= */
  .nav .has-sub > .submenu {
    display: none !important;
  }

  .nav .submenu-caret-2 {
    display: none !important;
  }

  /* =====================================================
     MÓVIL: unificar estilo de TODOS los links del dropdown
     (convencional, deportiva, avanzada, etc.)
  ===================================================== */

  .nav .dropdown-menu > li > a,
  .nav .dropdown-menu > li > .submenu-head > a {
    width: 100%;
    padding: 14px 12px;
    border-radius: 14px;

    font-weight: 600;
    letter-spacing: 0.02em;
    font-size: 0.95rem;
    color: var(--grey-900);

    background: rgba(235, 235, 235, 0.55);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 1px 0 rgba(255,255,255,.6) inset;

    display: block;
    margin: 6px 0;
  }

  .nav .dropdown-menu {
    margin-left: 12px;
    padding-left: 10px;
    border-left: 1px solid rgba(15, 23, 42, 0.08);
  }

  .nav__list {
    overscroll-behavior: contain;
  }
}
/* Body lock (JS añade .menu-open) */
body.menu-open { overflow: hidden; }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .dropdown-menu,
  .submenu,
  .nav {
    transition: none !important;
  }
}
