/* Layout — shell de la app (sidebar con grupos, barra superior,
   pestañas de módulos, pantalla de acceso). Fase 2 del rediseño visual. */

/* ---------- Pantalla de acceso ---------- */
#pantalla-acceso {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--navy3);
  position: relative;
  overflow: hidden;
}
#pantalla-acceso::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 15% 30%, rgba(1, 75, 67, 0.1) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 70%, rgba(1, 75, 67, 0.12) 0%, transparent 50%);
  pointer-events: none;
}

.tarjeta-acceso {
  background: #fff;
  border-radius: var(--r2);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(1, 75, 67, 0.1);
  padding: 36px 36px 30px;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}
.tarjeta-acceso h1 { font-size: 21px; font-weight: 800; margin: 0 0 4px; color: var(--text); }
.tarjeta-acceso .subtitulo { color: var(--text3); font-size: 12.5px; margin-bottom: 22px; }

/* ---------- Layout principal ---------- */
#app-shell {
  min-height: 100vh;
  background: var(--navy3);
}

/* Riel angosto por defecto (72px, solo iconos); un botón "fijar" lo deja
   expandido (264px, con etiquetas) de forma persistente — ya NO se expande
   al pasar el mouse, para no "saltar" sobre el contenido sin que el
   usuario lo haya pedido. */
#barra-lateral {
  position: fixed;
  top: 0;
  left: 0;
  width: 72px;
  height: 100vh;
  background: linear-gradient(180deg, #01352f, #014b43);
  color: white;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
#barra-lateral:hover,
#barra-lateral.expandido {
  width: 264px;
  /* Sombra lateral a propósito (no --shadow-lg): esa es una sombra
     omnidireccional pensada para paneles que "flotan" arriba de la
     página (modal, dropdown) — con desplazamiento vertical, no se nota
     en un panel fijo a la izquierda que se expande sobre el contenido.
     Acá se necesita una sombra horizontal, hacia la derecha, para que
     se note que es un overlay flotando sobre #contenido y no un error
     de layout. */
  box-shadow: 6px 0 24px rgba(15, 23, 42, 0.25);
  overflow-y: auto;
}

/* Colapsado: se esconde el texto (marca/submarca/etiquetas/encabezados de
   grupo), queda el ícono centrado + tooltip al pasar el mouse/enfocar con
   teclado. El botón de fijar y la marca corta ("AC") NUNCA se ocultan —
   son lo único que permite volver a expandir. Al pasar el mouse (:hover)
   se ve igual que fijado, pero es solo visual — nunca mueve el contenido
   (eso lo hace únicamente .expandido/body.sidebar-expandido, cuando el
   usuario lo fija a propósito con el botón). */
#barra-lateral .sb-top-texto,
#barra-lateral .sb-item-label,
.sb-grupo-header {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.15s ease, max-width 0.15s ease;
}
#barra-lateral:hover .sb-top-texto,
#barra-lateral.expandido .sb-top-texto {
  opacity: 1;
  max-width: 220px;
}
#barra-lateral:hover .sb-item-label,
#barra-lateral.expandido .sb-item-label {
  opacity: 1;
  max-width: 180px;
}
#barra-lateral:hover .sb-grupo-header,
#barra-lateral.expandido .sb-grupo-header {
  opacity: 1;
  max-width: none;
  display: flex;
}
#barra-lateral:not(:hover):not(.expandido) .sb-grupo-header { display: none; }

.sb-top {
  padding: 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-marca-corta {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.sb-top-texto { min-width: 0; flex: 1; }
#barra-lateral .marca {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 6px;
  white-space: nowrap;
}
#barra-lateral .submarca { font-size: 14px; font-weight: 800; color: #fff; line-height: 1.3; white-space: nowrap; }

.sb-nav { flex: 1; padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; overflow-x: hidden; }

/* Grupos colapsables del menú */
.sb-grupo-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  box-shadow: none;
  padding: 8px 12px 6px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.sb-grupo-flecha { display: inline-flex; transition: transform 0.15s ease; color: rgba(255, 255, 255, 0.55); }
.sb-grupo.cerrado .sb-grupo-flecha { transform: rotate(-90deg); }
.sb-grupo-items { display: flex; flex-direction: column; gap: 2px; }
#barra-lateral:hover .sb-grupo.cerrado .sb-grupo-items,
#barra-lateral.expandido .sb-grupo.cerrado .sb-grupo-items { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.8);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.14); }
.nav-item.activo { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.28); color: #fff; }
.nav-item.activo::before {
  content: '';
  position: absolute;
  left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  border-radius: 0 3px 3px 0;
  background: #fff;
}

.sb-item-icon { flex-shrink: 0; width: 20px; display: inline-flex; align-items: center; justify-content: center; }
.sb-item-label { flex: 1; }

/* Tooltip en modo colapsado (icon-only): la etiqueta real está oculta, así
   que se repite vía data-tooltip y se muestra al pasar el mouse/enfocar. */
#barra-lateral:not(.expandido) [data-tooltip]:hover::after,
#barra-lateral:not(.expandido) [data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  background: var(--text);
  color: #fff;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 300;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

#barra-lateral .btn-fijar-sidebar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.85);
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
#barra-lateral .btn-fijar-sidebar:hover { background: rgba(255, 255, 255, 0.12); }
#barra-lateral.expandido .btn-fijar-sidebar { background: rgba(255, 255, 255, 0.14); }

/* ---------- Barra superior ---------- */
#barra-superior {
  position: fixed;
  top: 0;
  left: 72px;
  right: 0;
  height: 56px;
  z-index: 150;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--borde);
  transition: left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
body.sidebar-expandido #barra-superior { left: 264px; }

.topbar-boton-icono {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  color: var(--text2);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.topbar-boton-icono:hover { background: var(--navy4); color: var(--text); }

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  flex-shrink: 0;
  white-space: nowrap;
}
#breadcrumb svg { stroke: var(--text3); flex-shrink: 0; }
#breadcrumb .breadcrumb-actual { color: var(--text); font-weight: 700; }

.topbar-buscar {
  position: relative;
  flex: 1;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 36px;
  border: 1.5px solid var(--borde);
  border-radius: var(--radius-sm);
  background: var(--navy4);
  color: var(--text3);
  transition: border-color 0.15s, background-color 0.15s;
}
.topbar-buscar svg { flex-shrink: 0; }
.topbar-buscar input {
  border: none;
  background: none;
  outline: none;
  font-size: 13px;
  color: var(--text);
  flex: 1;
  padding: 0;
  min-height: 0;
}
.topbar-buscar:focus-within { border-color: var(--accent); background: #fff; }
.busqueda-global-resultados {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1.5px solid var(--borde);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 160;
  padding: 6px;
}
.busqueda-global-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.busqueda-global-item svg { color: var(--text3); flex-shrink: 0; }
.busqueda-global-item:hover, .busqueda-global-item.activo { background: var(--accent-soft); }
.busqueda-global-item .busqueda-global-grupo { color: var(--text3); font-size: 11px; margin-left: auto; }
.busqueda-global-sin-resultados { padding: 8px 9px; font-size: 12.5px; color: var(--text3); }

.topbar-usuario { position: relative; margin-left: auto; flex-shrink: 0; }
.topbar-usuario .user-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--navy4);
  border: 1px solid var(--borde);
  color: var(--text);
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  box-shadow: none;
  cursor: pointer;
}
.topbar-usuario .user-pill:hover { background: var(--navy3); }
.topbar-usuario .user-av {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.topbar-usuario .user-info-texto { min-width: 0; text-align: left; }
.topbar-usuario #info-sesion-email { font-size: 12.5px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.topbar-usuario #info-sesion-rol { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text3); }

.usuario-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 160;
}
.usuario-menu-panel #btn-salir {
  width: 100%;
  justify-content: flex-start;
  background: none;
  box-shadow: none;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 9px 10px;
}
.usuario-menu-panel #btn-salir:hover { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.usuario-menu-panel #btn-salir .sb-item-icon { opacity: 1; max-width: none; }
.usuario-menu-panel #btn-salir .sb-item-label { opacity: 1; max-width: none; }

.overlay-sidebar-movil {
  position: fixed;
  inset: 0;
  background: rgba(7, 13, 26, 0.45);
  z-index: 190;
}

#contenido {
  margin-left: 72px;
  padding: 84px 36px 28px;
  transition: margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
body.sidebar-expandido #contenido { margin-left: 264px; }

/* Barra de pestañas de módulos abiertos: varios módulos pueden quedar
   abiertos a la vez y se cambia entre ellos sin perder lo que se tenía
   filtrado/escrito en cada uno, porque las secciones nunca se destruyen
   (solo se muestran/ocultan). Fija debajo de la barra superior al hacer
   scroll. */
.barra-pestanas-modulos {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  margin: 0 -36px 32px;
  padding: 10px 36px 0;
  border-bottom: 1px solid var(--borde);
  background: var(--navy);
  position: sticky;
  top: 56px;
  z-index: 50;
  scrollbar-width: thin;
}
.barra-pestanas-modulos::-webkit-scrollbar { height: 6px; }
.barra-pestanas-modulos::-webkit-scrollbar-thumb { background: var(--borde); border-radius: 3px; }
.barra-pestanas-modulos::-webkit-scrollbar-track { background: transparent; }
.barra-pestanas-modulos:empty { display: none; margin-bottom: 0; border-bottom: none; }

.pestana-modulo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 8px 8px 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 6px 6px 0 0;
}
.pestana-modulo svg { flex-shrink: 0; }
.pestana-modulo:hover { background: var(--accent-soft); }
.pestana-modulo.activa {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
  background: var(--accent-soft);
}
.pestana-modulo .cerrar-pestana {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  color: var(--text2);
  opacity: 0;
  transition: opacity 0.1s ease;
}
.pestana-modulo:hover .cerrar-pestana,
.pestana-modulo.activa .cerrar-pestana { opacity: 1; }
.pestana-modulo .cerrar-pestana:hover { background: rgba(0, 0, 0, 0.1); color: var(--text); }

#contenido h2 {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  padding-bottom: 14px;
  padding-right: 4px;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  border-bottom: 2px solid var(--borde);
}
#contenido h2::before {
  content: '';
  width: 5px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 3px;
  background: var(--accent);
}

.seccion-vista { margin-bottom: 28px; }

/* ---------- Responsive: bajo cierto ancho, el sidebar pasa a overlay ---------- */
@media (max-width: 900px) {
  #barra-lateral {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  #barra-lateral.movil-abierto {
    transform: translateX(0);
    width: 264px;
    overflow-y: auto;
  }
  #barra-lateral.movil-abierto .sb-top-texto,
  #barra-lateral.movil-abierto .sb-item-label {
    opacity: 1;
    max-width: none;
  }
  #barra-lateral.movil-abierto .sb-grupo-header {
    opacity: 1;
    max-width: none;
    display: flex;
  }
  #barra-lateral .btn-fijar-sidebar { display: none; }

  #barra-superior, body.sidebar-expandido #barra-superior { left: 0; }
  #contenido, body.sidebar-expandido #contenido { margin-left: 0; }
  .topbar-boton-icono#btn-menu-movil { display: flex; }
  .topbar-buscar { max-width: none; }
  .topbar-usuario .user-info-texto { display: none; }
}
