/* ========= NAV (Header / Navbar) ========= */
:root {
  /* Capas globales */
  --z-mega: 1400;
  --z-header: 1200;
  --z-quickbar: 900;
  --z-drawer: 2000;

  /* Altura del header para posicionar el mega */
  --header-h: 60px;

  /* Ajuste fino (negativo = panel más arriba) */
  --mega-nudge: -8px;
}

/* -------- Header -------- */
header.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  backdrop-filter: blur(8px);
  background: color-mix(in oklab, var(--bg) 80%, black 20%);
  border-bottom: 1px solid var(--border);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.logo .mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 0 0 2px #000 inset;
}

.util {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* -------- Buscador -------- */
.search {
  position: relative;
}
.search input {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px 8px 36px;
  width: 260px;
}
.search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.7;
}

/* -------- Botón hamburguesa -------- */
.hamb {
  display: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
}

/* -------- Menú principal -------- */
nav.main {
  position: static;
}
.nav-list {
  display: flex;
  gap: 18px;
  padding: 8px 0 14px;
}
.nav-list > li {
  list-style: none;
  position: static;
}

.nav-list > li > button,
.nav-list > li > a {
  background: transparent;
  color: var(--text);
  border: 0;
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.nav-list > li > button:hover,
.nav-list > li > a:hover {
  background: color-mix(in oklab, var(--card) 70%, black);
}
.nav-list > li > a.cta {
  border: 1px solid var(--border);
  padding: 8px 12px;
}
.nav-list > li > button:focus-visible {
  outline: 3px solid var(--focus);
}

/* -------- Mega–menú (anclado al header) -------- */
.mega {
  position: fixed;
  top: calc(var(--header-h) + var(--mega-nudge));
  left: 0;
  right: 0;
  display: none;
  z-index: var(--z-mega);
  padding: 0 0 24px;
}
.mega .panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.mega .col h4 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.mega .col ul {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.mega .col li {
  list-style: none;
}

/* enlaces dentro del mega */
.header .mega .panel a {
  display: block;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--text);
  text-decoration: none;
}
/* hover/activo con contraste – tema CLARO */
html[data-theme="light"] .header .mega .panel a:hover,
html[data-theme="light"] .header .mega .panel a:focus,
html[data-theme="light"] .header .mega .panel a[aria-current="true"],
html[data-theme="light"] .header .mega .panel li:focus-within > a {
  background: #0f1a28;
  border-color: var(--border);
  color: #f4f8ff;
}
/* hover/activo con contraste – tema OSCURO */
html[data-theme="dark"] .header .mega .panel a:hover,
html[data-theme="dark"] .header .mega .panel a:focus,
html[data-theme="dark"] .header .mega .panel a[aria-current="true"],
html[data-theme="dark"] .header .mega .panel li:focus-within > a {
  background: #0e1622;
  border-color: var(--border);
  color: #eaf1ff;
}

/* Mostrar mega SOLO por hover (sin focus-within para evitar “fijo” por click) */
.nav-list > li:hover > .mega {
  display: block;
}

/* “Puente” para no perder hover entre botón y panel (el panel es fixed) */
.nav-list > li:hover::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  top: calc(var(--header-h) + var(--mega-nudge) - 2px);
  height: 14px; /* si ves parpadeo al bajar, sube a 18px */
  z-index: var(--z-mega);
  pointer-events: auto;
}

/* Mientras un mega está abierto (hover), la quickbar no captura el mouse */
.header:has(.nav-list > li:hover) ~ .quickbar {
  pointer-events: none;
}

/* -------- Cuenta (dropdown) -------- */
.account {
  position: relative;
}
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.account-btn .avatar {
  font-size: 16px;
}
.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  max-width: 76vw;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  padding: 8px;
  display: none;
  z-index: calc(var(--z-drawer) + 1);
}
.account.open .account-menu {
  display: block;
}
.account-menu .menu-block {
  display: none;
}
.account[data-auth-state="guest"] .menu-block[data-auth="guest"] {
  display: block;
}
.account[data-auth-state="auth"] .menu-block[data-auth="auth"] {
  display: block;
}

.account-menu a,
.account-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.account-menu a:hover,
.account-menu button:hover {
  background: color-mix(in oklab, var(--card) 70%, black);
}

.account-menu hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}
.account-menu .userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 10px;
}
.account-menu .avatar.sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.account-menu .who small {
  color: var(--muted);
}
.account-menu .danger {
  color: #ffb4b4;
}
.theme-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* -------- Drawer móvil -------- */
.mobile-drawer {
  display: none;
}
.drawer-account .row {
  display: none;
  gap: 10px;
}
.drawer-account .row a,
.drawer-account .row button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  margin-bottom: 8px;
}
.drawer-account .row button.danger {
  border-color: #5c2626;
  color: #ffb4b4;
}
.drawer-account .row button.theme-inline {
  border-style: dashed;
}

/* -------- Site Search -------- */
.site-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
}
.site-search input {
  width: 240px;
  max-width: 38vw;
  height: 34px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--text);
}
.site-search-results {
  position: absolute;
  inset-inline-start: 0;
  top: calc(100% + 6px);
  width: min(520px, 92vw);
  max-height: 60vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 9999;
}
.site-search-results.show {
  display: block;
}
.site-search-results .item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.site-search-results .item:last-child {
  border-bottom: 0;
}
.site-search-results .item a {
  text-decoration: none;
  color: var(--text);
  display: flex;
  gap: 10px;
  width: 100%;
}
.site-search-results .t {
  font-weight: 600;
}
.site-search-results .d {
  color: var(--muted);
  font-size: 12px;
}

/* Hover/selección por tema */
html[data-theme="light"] .site-search-results .item:hover,
html[data-theme="light"] .site-search-results .item[aria-selected="true"] {
  background: #0f1a28;
}
html[data-theme="light"] .site-search-results .item:hover a,
html[data-theme="light"] .site-search-results .item[aria-selected="true"] a,
html[data-theme="light"] .site-search-results .item:hover .t,
html[data-theme="light"] .site-search-results .item[aria-selected="true"] .t,
html[data-theme="light"] .site-search-results .item:hover .d,
html[data-theme="light"] .site-search-results .item[aria-selected="true"] .d {
  color: #f4f8ff;
}

html[data-theme="dark"] .site-search-results .item:hover,
html[data-theme="dark"] .site-search-results .item[aria-selected="true"] {
  background: #0e1622;
}
html[data-theme="dark"] .site-search-results .item:hover a,
html[data-theme="dark"] .site-search-results .item[aria-selected="true"] a,
html[data-theme="dark"] .site-search-results .item:hover .t,
html[data-theme="dark"] .site-search-results .item[aria-selected="true"] .t,
html[data-theme="dark"] .site-search-results .item:hover .d,
html[data-theme="dark"] .site-search-results .item[aria-selected="true"] .d {
  color: #eaf1ff;
}

/* Resaltado <mark> */
.site-search-results mark {
  background: #ffdf5a;
  color: #000;
  padding: 0 0.5px;
  border-radius: 2px;
}
html[data-theme="dark"] .site-search-results .item:hover mark,
html[data-theme="dark"] .site-search-results .item[aria-selected="true"] mark {
  background: #ffd84a;
  color: #10161f;
}
html[data-theme="light"] .site-search-results .item:hover mark,
html[data-theme="light"] .site-search-results .item[aria-selected="true"] mark {
  background: #ffde4f;
  color: #0e1622;
}

@media (max-width: 860px) {
  .site-search input {
    width: 170px;
  }
}
.site-search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 0;
  width: 0;
}
.site-search input::-ms-clear {
  display: none;
  width: 0;
  height: 0;
}

/* Botón “limpiar” propio */
.site-search .clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  z-index: 1;
}
.site-search.has-value .clear {
  display: inline-flex;
}
.site-search .clear:hover {
  background: color-mix(in oklab, var(--brand-2) 10%, var(--card));
  color: var(--text);
}

/* -------- Botón de tema (switch) -------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover {
  background: color-mix(in oklab, var(--brand-2) 8%, var(--card));
}
.theme-toggle .sep {
  opacity: 0.55;
}
html[data-theme="light"] .theme-toggle .moon {
  opacity: 0.45;
}
html[data-theme="dark"] .theme-toggle .sun {
  opacity: 0.45;
}

/* accesibilidad para texto oculto */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* -------- Responsive -------- */
@media (max-width: 1200px) {
  .search input {
    width: 180px;
  }
  .nav-list {
    display: none;
  }
  .hamb {
    display: inline-flex;
  }

  .mobile-drawer {
    display: block;
    position: fixed;
    inset: 0 40% 0 0;
    translate: -100% 0;
    padding: 18px;
    background: var(--card);
    border-right: 1px solid var(--border);
    z-index: var(--z-drawer);
    transition: translate 0.25s ease;
    overflow: auto;
  }
  .mobile-drawer.open {
    translate: 0 0;
  }
  .mobile-drawer h4 {
    margin: 10px 0;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }
  .mobile-drawer details {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
  }
  .mobile-drawer summary {
    cursor: pointer;
    padding: 10px 12px;
  }
  .mobile-drawer ul {
    margin: 0;
    padding: 0 10px 10px;
  }
  .mobile-drawer li {
    list-style: none;
  }
  .mobile-drawer a {
    display: block;
    padding: 8px 10px;
    border-radius: 8px;
  }
  .mobile-drawer .close {
    margin-top: 8px;
    width: 100%;
  }
}

/* Mostrar filas de cuenta en drawer según estado */
@media (max-width: 980px) {
  #drawerAccount .auth[data-auth="auth"],
  #drawerAccount .guest[data-auth="guest"] {
    display: block;
  }
  #drawer[data-auth-state="auth"] .guest {
    display: none;
  }
  #drawer[data-auth-state="guest"] .auth {
    display: none;
  }
}
