/* ================================================================
   MAIN HEADER — Velonet ERP Intranet
   Usa --surface-nav (nunca --corp-purple-deep) para evitar el
   bug de dark mode donde ese alias se reasigna a tono claro.
================================================================ */

/* ── HEADER BASE ─────────────────────────────────────────────── */
.main-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10002;
  height: 60px;
  background-color: var(--surface-nav);
  border-bottom: 1px solid var(--nav-border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-base);
}

.main-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 var(--space-6);
  gap: var(--space-3);
}

/* ── LEFT SECTION ─────────────────────────────────────────────── */
.nav-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 100%;
  flex: 1;
  min-width: 0;
}

/* ── HAMBURGER BUTTON ─────────────────────────────────────────── */
.nav-hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--nav-text);
  transition: background-color var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}

.nav-hamburger:hover {
  background-color: var(--nav-hover-bg);
}

.nav-hamburger .material-symbols-outlined {
  font-size: 24px;
  line-height: 1;
}

/* ── LOGO ─────────────────────────────────────────────────────── */
.nav-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo img {
  height: 42px;
  width: auto;
}

/* ── BACK BUTTON ──────────────────────────────────────────────── */
.nav-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--nav-text);
  opacity: 0.8;
  padding: 0;
  flex-shrink: 0;
  transition: background-color var(--transition-fast), opacity var(--transition-fast), transform var(--transition-fast);
}

.nav-back-btn:hover {
  background-color: var(--nav-hover-bg);
  opacity: 1;
}

.nav-back-btn:active {
  transform: translateX(-2px);
}

.nav-back-btn .material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}

/* ── DESKTOP NAV LINKS ────────────────────────────────────────── */
.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 100%;
  margin-left: var(--space-3);
}

/* ── NAV DROPDOWN ────────────────────────────────────────────── */
.nav-dropdown-container {
  position: relative;
  height: 100%;
}

.nav-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: 100%;
  padding: 0 var(--space-3);
  background: transparent;
  border: none;
  color: var(--nav-text);
  font-size: 0.75rem;
  font-weight: var(--weight-semibold);
  cursor: pointer;
  opacity: 0.85;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.nav-dropdown-trigger:hover,
.nav-dropdown-trigger--open {
  background-color: var(--nav-hover-bg);
  opacity: 1;
}

.nav-dropdown-trigger--active {
  color: var(--color-secondary-500);
  opacity: 1;
}

.nav-dropdown-trigger .material-symbols-outlined {
  font-size: 16px;
  transition: transform var(--transition-fast);
}

.nav-dropdown-trigger--open .material-symbols-outlined {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background-color: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-2);
  z-index: 10002;
  animation: dropdownIn 0.2s var(--ease-standard);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.nav-dropdown-item:hover {
  background-color: var(--surface-sunken);
  color: var(--color-secondary-500);
  text-decoration: none;
}

.nav-dropdown-item.active {
  background-color: var(--surface-sunken);
  color: var(--color-secondary-500);
  font-weight: var(--weight-bold);
}

.nav-dropdown-item .material-symbols-outlined {
  font-size: 20px;
  opacity: 0.7;
}

/* ── NAV LINKS (desktop bar) ─────────────────────────────────── */
.nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  /* Blanco fijo: el header siempre tiene fondo oscuro en ambos modos */
  color: rgba(255, 255, 255, 0.92) !important;
  text-decoration: none;
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: color var(--transition-fast), background-color var(--transition-fast), opacity var(--transition-fast);
}

.nav-link:hover {
  color: #ffffff !important;
  background-color: var(--nav-hover-bg);
  text-decoration: none;
  opacity: 1;
}

.nav-link--active {
  color: var(--nav-active-text) !important;
  background-color: var(--nav-active-bg);
}

/* Dark mode: garantizar blanco */
.dark-mode-active .nav-link {
  color: rgba(255, 255, 255, 0.92) !important;
}
.dark-mode-active .nav-link:hover {
  color: #ffffff !important;
}
.dark-mode-active .nav-link--active {
  color: var(--nav-active-text) !important;
}

/* ── HOME ICON dentro de nav-link ────────────────────────────── */
.nav-link .material-symbols-outlined {
  font-size: 16px;
  line-height: 1;
}

/* ── RIGHT SECTION ────────────────────────────────────────────── */
.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ── ICON BUTTONS ─────────────────────────────────────────────── */
.nav-icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--nav-text);
  opacity: 0.8;
  padding: 0;
  transition: background-color var(--transition-fast), opacity var(--transition-fast);
}

.nav-icon-btn:hover {
  background-color: var(--nav-hover-bg);
  opacity: 1;
}

.nav-icon-btn .material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}

/* ── NOTIFICATION BADGE ───────────────────────────────────────── */
.nav-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 16px;
  height: 16px;
  background-color: var(--color-secondary-500);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-nav);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: var(--weight-bold);
  color: var(--color-neutral-900);
  padding: 0 3px;
  line-height: 1;
  font-family: var(--font-sans);
  pointer-events: none;
}

/* ── PROFILE SECTION ──────────────────────────────────────────── */
.nav-profile {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  transition: background-color var(--transition-fast);
  user-select: none;
}

.nav-profile:hover {
  background: rgba(255, 255, 255, 0.10);
}

.nav-profile-info {
  text-align: right;
  line-height: 1.2;
}

.nav-profile-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--nav-text);
  font-family: var(--font-sans);
}

.nav-profile-role {
  display: block;
  font-size: var(--text-xs);
  color: var(--nav-text-muted);
  font-family: var(--font-sans);
}

.nav-profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.nav-profile-chevron {
  color: var(--nav-text-muted);
  display: flex;
  align-items: center;
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.nav-profile-chevron .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
}

.nav-profile--open .nav-profile-chevron {
  transform: rotate(180deg);
}

/* ── CARNET DROPDOWN ──────────────────────────────────────────── */
.nav-carnet-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 230px;
  background-color: var(--surface-overlay);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-4);
  z-index: 1001;
  border: 1px solid var(--border-default);
  animation: dropdownIn 0.2s var(--ease-standard);
}

.nav-carnet-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-extrabold);
  color: var(--text-tertiary);
  text-align: center;
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  margin: 0 0 var(--space-3);
  font-family: var(--font-sans);
}

.nav-carnet-img {
  width: 100%;
  border-radius: var(--radius-md);
  display: block;
}

.nav-carnet-empty {
  padding: var(--space-6) var(--space-2);
  text-align: center;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-default);
}

.nav-carnet-empty p {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-style: italic;
  font-family: var(--font-sans);
}

.nav-carnet-close {
  display: block;
  width: 100%;
  margin-top: var(--space-3);
  background: none;
  border: none;
  color: var(--color-secondary-500);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  cursor: pointer;
  text-align: center;
  letter-spacing: var(--tracking-wide);
  font-family: var(--font-sans);
  padding: var(--space-1) 0;
}

.nav-carnet-close:hover {
  color: var(--color-secondary-400);
}

/* ── LOGOUT BUTTON ────────────────────────────────────────────── */
.nav-logout-btn {
  background-color: var(--color-secondary-500);
  border: none;
  color: var(--color-neutral-900);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}

.nav-logout-btn:hover {
  background-color: var(--color-secondary-600);
  transform: translateY(-1px);
}

/* ── SIDEBAR OVERLAY ──────────────────────────────────────────── */
.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s var(--ease-standard), visibility 0.3s var(--ease-standard);
}

.nav-overlay--visible {
  opacity: 1;
  visibility: visible;
}

/* ── SIDEBAR PANEL ────────────────────────────────────────────── */
.nav-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 288px;
  z-index: 10001;
  background-color: var(--surface-sidebar);
  transform: translateX(-100%);
  transition: transform 0.3s var(--ease-standard);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  border-right: 1px solid var(--nav-border);
}

.nav-sidebar--open {
  transform: translateX(0);
}

/* ── SIDEBAR HEADER ───────────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-3);
  height: 60px;
  border-bottom: 1px solid var(--nav-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: opacity 0.2s;
}

.sidebar-logo img {
  height: 28px;
  width: auto;
}


.sidebar-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--nav-text-muted);
  padding: 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-close-btn:hover {
  background-color: var(--nav-hover-bg);
  color: var(--nav-text);
}

.sidebar-close-btn .material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}

/* ── SIDEBAR BODY ─────────────────────────────────────────────── */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.sidebar-body::-webkit-scrollbar {
  width: 4px;
}

.sidebar-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-full);
}

/* ── SIDEBAR CATEGORIES ───────────────────────────────────────── */
.sidebar-category {
  margin-bottom: var(--space-5);
}

.sidebar-category-title {
  font-size: 0.625rem;
  font-weight: var(--weight-extrabold);
  color: var(--nav-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  padding: 0 var(--space-2) var(--space-2);
  margin: 0;
  font-family: var(--font-sans);
  white-space: nowrap;
  transition: opacity 0.2s;
}


.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--nav-text);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  opacity: 0.78;
  transition: all var(--transition-fast);
  justify-content: flex-start;
  width: 100%;
  line-height: 1;
  min-height: 44px;
  white-space: nowrap;
}

.sidebar-nav-item:hover {
  background-color: var(--nav-hover-bg);
  opacity: 1;
  color: var(--nav-text);
  text-decoration: none;
}

.sidebar-nav-item--active {
  background-color: var(--nav-active-bg);
  color: var(--nav-active-text);
  opacity: 1;
}

.sidebar-nav-item .material-symbols-outlined {
  font-size: 22px; 
  flex-shrink: 0;
  opacity: 0.85;
  line-height: 1;
  transition: transform var(--transition-fast);
}

.sidebar-nav-item--active .material-symbols-outlined {
  opacity: 1;
}

/* ── SUBMENU SPECIFIC ────────────────────────────────────────── */
.sidebar-submenu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: var(--space-4);
  margin-top: 4px;
  position: relative;
}

/* Línea vertical de guía para submenús */
.sidebar-submenu::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 12px;
  width: 1.5px;
  background-color: var(--nav-border);
  opacity: 0.5;
}

.sidebar-nav-item--sub {
  min-height: 38px;
  padding: var(--space-1) var(--space-4);
  font-size: 0.8125rem;
  opacity: 0.7;
  position: relative;
}

.sidebar-nav-item--sub::after {
  content: '';
  position: absolute;
  left: -22px; /* Ajuste para coincidir con la línea vertical */
  top: 50%;
  width: 8px;
  height: 1.5px;
  background-color: var(--nav-border);
  opacity: 0.5;
  transform: translateY(-50%);
}

.sidebar-nav-item--sub .material-symbols-outlined {
  font-size: 18px;
  opacity: 0.7;
}

.sidebar-nav-item--sub:hover,
.sidebar-nav-item--sub.sidebar-nav-item--active {
  opacity: 1;
  color: var(--nav-active-text);
}

/* ── CATEGORY TOGGLE ─────────────────────────────────────────── */
.sidebar-category-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background-color var(--transition-fast);
  border-radius: var(--radius-md);
}

.sidebar-category-toggle:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

.sidebar-toggle-icon {
  font-size: 18px;
  color: var(--nav-text-muted);
}
.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--nav-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-user-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  border: 2px solid var(--color-secondary-500);
}

.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--nav-text);
  font-family: var(--font-sans);
  line-height: 1.3;
}

.sidebar-user-role {
  font-size: var(--text-xs);
  color: var(--nav-text-muted);
  font-family: var(--font-sans);
}


.sidebar-logout-btn {
  width: 100%;
}

/* ── ANIMATIONS ───────────────────────────────────────────────── */
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── RESPONSIVE ───────────────────────────────────────────────── */

/* Ocultar dropdowns en mobile, mostrar solo home? */
@media (max-width: 1024px) {
  .nav-links {
    display: none;
  }
}

/* ================================================================
   HEADER EXCLUSIVO PARA MÓVIL (≤640px)
   El header de escritorio (.main-header-inner) se oculta y este lo
   reemplaza. Reutiliza exactamente los mismos botones/handlers que
   el header de escritorio (ver MainMenu.jsx) — solo cambia el layout.
================================================================ */
.mobile-header-inner {
  display: none;
}

@media (max-width: 640px) {
  .main-header-inner {
    display: none;
  }

  .mobile-header-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 100%;
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  /* ── Izquierda: solo hamburguesa ── */
  .mobile-header-left {
    display: flex;
    align-items: center;
    justify-self: start;
    min-width: 0;
  }

  .mobile-header-left .nav-hamburger {
    width: 36px;
    height: 36px;
  }

  .mobile-header-left .nav-hamburger .material-symbols-outlined {
    font-size: 22px;
  }

  /* ── Centro: logo + notificaciones + modo oscuro ── */
  .mobile-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-width: 0;
  }

  .mobile-nav-logo {
    flex-shrink: 0;
  }

  .mobile-nav-logo img {
    height: 26px;
    width: auto;
    display: block;
  }

  .mobile-header-center .nav-icon-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  .mobile-header-center .nav-icon-btn .material-symbols-outlined {
    font-size: 20px;
  }

  /* ── Derecha: solo avatar + flecha (sin nombre/cargo) ── */
  .mobile-header-right {
    display: flex;
    align-items: center;
    justify-self: end;
    min-width: 0;
  }

  .nav-profile--mobile {
    padding: 4px 6px 4px 4px;
    gap: 2px;
  }

  .nav-profile--mobile .nav-profile-avatar {
    width: 30px;
    height: 30px;
  }

  .nav-profile--mobile .nav-carnet-dropdown {
    /* En pantallas muy angostas, evita que el dropdown del carnet
       se salga por la izquierda: se limita al ancho disponible. */
    width: min(230px, calc(100vw - 2 * var(--space-4)));
  }
}
