/* assets/css/header.css */

:root {
  --header-top-h: 58px;
  --header-total-h: 58px;
  --header-bg: #ffffff;
  --header-border: var(--color-borde-suave);
  --header-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  --header-shadow-compact: 0 1px 8px rgba(0, 0, 0, 0.05);
  --header-pad-x: 16px;
  --header-transition: 180ms ease;
}

html {
  scroll-padding-top: var(--header-total-h);
}

/* contenedor inyectado */
#headerContainer {
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  z-index: 1000;
}

/* header global */
.encabezado-app {
  width: 100%;
  background: var(--header-bg);
  border: 1px solid var(--header-border);
  box-shadow: var(--header-shadow);
  transition: box-shadow var(--header-transition), opacity 0.2s ease;
  opacity: 0;
}

.encabezado-app.is-loaded {
  opacity: 1;
}

/* barra principal */
.topbar-sistema {
  min-height: var(--header-top-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 30px;
  padding: 10px var(--header-pad-x);
  background: #fff;
  transition: min-height var(--header-transition), padding var(--header-transition);
}

/* áreas */
.topbar-izquierda,
.topbar-derecha {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-centro {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-centro::-webkit-scrollbar {
  display: none;
}

/* marca */
.marca-sistema {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo-img {
  height: 30px;
  width: auto;
  max-width: 100px;
  object-fit: contain;
  display: none;
  flex-shrink: 0;
}

.logo-sistema {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--color-primario);
  color: #fff;
  flex: 0 0 auto;
}

.texto-marca {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.nombre-sistema {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--color-texto);
}

.area-sistema {
  font-size: 0.75rem;
  color: var(--color-texto-claro);
}

/* navegación */
.topbar-centro a.btn-nav-sistema {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-nav-sistema {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--color-texto);
  font-size: 0.88rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--color-borde-suave);
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
  white-space: nowrap;
}

.btn-nav-sistema:hover {
  background: #f2f7f7;
}

.btn-nav-sistema.activo {
  background: rgba(0, 170, 170, 0.12);
  color: var(--color-primario);
  border-color: rgba(0, 170, 170, 0.25);
}

/* ════════════════════════════════════════
   BADGE DE CORREO
════════════════════════════════════════ */
.correo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--color-error, #e74c3c);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

/* usuario */
.menu-usuario-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1200;
}

.usuario-nombre {
  font-size: 0.86rem;
  color: var(--color-texto);
  white-space: nowrap;
  font-weight: 600;
}

.btn-usuario-menu {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f5f7f8;
  border: 1px solid var(--color-borde-suave);
}

.menu-usuario-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 240px;
  background: #fff;
  border: 1px solid var(--color-borde-suave);
  border-radius: 12px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.10);
  overflow: hidden;
  z-index: 1100;
}

.menu-usuario-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--color-borde-suave);
}

.foto-usuario {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef7f7;
  color: var(--color-primario);
}

.menu-usuario-info strong {
  display: block;
  color: #2c3e50;
  font-size: 0.95rem;
}

.menu-usuario-acciones {
  display: flex;
  flex-direction: column;
}

.item-menu-usuario {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: #fff;
  color: var(--color-texto);
  text-decoration: none;
  border: 0;
  border-bottom: 1px solid var(--color-borde-suave);
  border-radius: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.item-menu-usuario:hover {
  background: #f7f7f7;
  transform: none;
}

.item-menu-usuario:last-child {
  border-bottom: 0;
}

.item-menu-usuario.cerrar {
  color: var(--color-error);
}

/* estado compacto */
.encabezado-app.is-compact {
  box-shadow: var(--header-shadow-compact);
}

.encabezado-app.is-compact .topbar-sistema {
  min-height: 52px;
  padding-top: 8px;
  padding-bottom: 8px;
}

/* páginas con header fijo */
body.has-fixed-header {
  padding-top: calc(var(--header-total-h) + 10px);
}


/* responsive */
@media (max-width: 900px) {
  .topbar-sistema {
    grid-template-columns: 1fr auto;
    min-height: auto;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .topbar-centro {
    grid-column: 1 / -1;
    justify-content: flex-start;
    padding-bottom: 4px;
  }

  .usuario-nombre {
    display: none;
  }

  .viewport-layout {
    height: auto;
  }
}

/* ════════════════════════════════════════
   SUB-NAV ADMINISTRACIÓN
════════════════════════════════════════ */
.subnav-admin {
  background: #f5fafc;
  border-bottom: 1px solid var(--color-borde-suave);
  padding: 6px var(--header-pad-x);
  display: flex;
  justify-content: center;
}

.subnav-inner {
  display: flex;
  gap: 4px;
}

.subnav-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--color-texto);
  font-size: 0.82rem;
  font-weight: 600;
  transition: background-color .15s ease, color .15s ease;
}

.subnav-item:hover {
  background: #e8f0f2;
}

.subnav-item.activo {
  background: rgba(0, 170, 170, 0.12);
  color: var(--color-primario);
}

@media (max-width: 768px) {
  #headerContainer {
    left: 10px;
    right: 10px;
    top: 10px;
  }

  .menu-usuario-dropdown {
    right: 0;
    left: auto;
    width: min(240px, calc(100vw - 20px));
  }
}