/* ===== Sidebar & Submenu Styles ===== */
/* Extraido de base.html inline <style> para mantener el template limpio. */
/* Estos estilos controlan la barra lateral fija con hover-expand y submenus. */

/* --- Sidebar principal --- */
.sidebar {
  position: fixed;
  top: 64px;
  left: 0;
  bottom: 0;
  width: 70px;
  background: linear-gradient(180deg, #0f1520 0%, #131a27 100%);
  transition: width 0.3s ease;
  z-index: 30;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.sidebar nav {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.sidebar:hover {
  width: 260px;
}

.sidebar ul {
  list-style: none;
  padding: 15px 0;
  margin: 0;
  width: 260px;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

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

.sidebar ul::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar ul::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.sidebar ul::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.sidebar li {
  margin-bottom: 5px;
  width: 100%;
}

/* --- Menu items --- */
.menu-item {
  display: flex;
  align-items: center;
  padding: 12px;
  margin: 0 8px;
  border-radius: 8px;
  color: #e2e8f0;
  text-decoration: none;
  transition: background-color 0.2s;
  position: relative;
  width: calc(100% - 16px);
}

.menu-item:hover {
  background-color: rgba(249, 115, 22, 0.08);
}

.menu-item.active {
  background-color: rgba(249, 115, 22, 0.12);
}

.menu-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  height: 100%;
  width: 3px;
  background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
  border-radius: 0 4px 4px 0;
}

/* --- Icon containers en sidebar --- */
.sidebar .icon-container {
  min-width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-item i {
  font-size: 20px;
  color: #e2e8f0;
}

.menu-item.active i {
  color: #f97316;
}

/* --- Text items (animacion de slide al hover) --- */
.text-item {
  white-space: nowrap;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  transform: translateX(10px);
  width: 0;
  overflow: hidden;
  /* Sin `text-overflow` el nombre se cortaba a media palabra y desaparecia el
     sustantivo ("Estados nuevos sin clasi"). Con elipsis se ve que hay mas texto.
     `min-width: 0` es obligatorio: sin el, un hijo flex no baja de su ancho de
     contenido y la elipsis nunca aparece. */
  text-overflow: ellipsis;
  min-width: 0;
}

.sidebar:hover .text-item,
.sidebar:focus-within .text-item {
  opacity: 1;
  transform: translateX(0);
  width: auto;
}

/* La barra tambien se abre con el teclado: sin esto, quien navega con Tab llega a
   los enlaces de un menu de 70 px y no puede leer ningun nombre. */
.sidebar:focus-within {
  width: 260px;
}

/* --- Globo con el nombre completo cuando no cabe --- */
/* Sin `title=` nativo: tarda ~1 s en aparecer, no lo abre el teclado y no queda en
   una grabacion. El globo solo existe en los items cuyo nombre se recorta de verdad;
   el JS de layouts/base.html los marca con `data-nombre-completo` midiendo el ancho
   real, asi que funciona igual en cualquier idioma. El texto completo SIEMPRE esta en
   el DOM: el lector de pantalla nunca lee la version recortada. */
.menu-item[data-nombre-completo]::after {
  content: attr(data-nombre-completo);
  position: absolute;
  top: calc(100% + 4px);
  left: 8px;
  right: 8px;
  z-index: 60;
  padding: 6px 10px;
  border-radius: 8px;
  background: #1f2937;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.menu-item[data-nombre-completo]:hover::after,
.menu-item[data-nombre-completo]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
  .menu-item[data-nombre-completo]::after {
    transition: none;
  }
}

/* --- Main content offset --- */
.main-content {
  margin-left: 70px;
  padding-top: 64px;
  transition: margin-left 0.3s ease;
}

/* --- User profile en sidebar --- */
.user-profile {
  display: flex;
  align-items: center;
  padding: 12px;
  margin: 0 8px;
  border-radius: 8px;
  background-color: rgba(249, 115, 22, 0.06);
  transition: background-color 0.2s;
}

.user-profile:hover {
  background-color: rgba(249, 115, 22, 0.12);
}

.user-avatar {
  min-width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.2);
  transition: transform 0.2s;
}

.user-profile:hover .user-avatar {
  transform: scale(1.05);
}

.user-avatar i {
  color: white;
  font-size: 16px;
}

/* --- User container (bottom of sidebar) --- */
.user-container {
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 0;
  width: 100%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.25) 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.user-container .secondary-links {
  display: flex;
  gap: 12px;
  padding: 2px 14px 4px;
  overflow: hidden;
}

/* Sidebar minimizada */
.sidebar:not(:hover) .user-profile {
  justify-content: center;
  padding: 8px;
  margin: 0;
  border-radius: 0;
  background-color: transparent;
}

.sidebar:not(:hover) .user-avatar {
  min-width: 42px;
  height: 42px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@keyframes avatar-glow {
  0% { box-shadow: 0 0 5px rgba(249, 115, 22, 0.25); }
  50% { box-shadow: 0 0 12px rgba(249, 115, 22, 0.4); }
  100% { box-shadow: 0 0 5px rgba(249, 115, 22, 0.25); }
}

.sidebar:not(:hover) .user-avatar {
  animation: avatar-glow 2s infinite;
}

/* --- Header --- */
.header-shadow {
  background: linear-gradient(90deg, #1a2236 0%, #1e293b 50%, #1a2236 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

/* --- Submenu --- */
.submenu {
  display: none;
  max-height: 0;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  overflow: hidden;
  opacity: 0;
  padding-left: 0;
  margin: 4px 8px 4px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.submenu.visible {
  display: block;
  max-height: 400px;
  opacity: 1;
  transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
  padding: 6px 0;
}

.submenu li {
  margin-bottom: 0;
}

/* Menu item con submenu */
.menu-item-with-submenu {
  position: relative;
}

.menu-item-with-submenu > .menu-item::after {
  content: '';
  display: none;
}

.menu-item-with-submenu:hover > .menu-item::after {
  transform: translateY(-50%) rotate(90deg);
}

.submenu .menu-item.active {
  background-color: rgba(249, 115, 22, 0.12);
  border-left-color: #f97316;
  color: #f97316;
}

.menu-item-with-submenu.active-parent > .menu-item {
  background-color: rgba(249, 115, 22, 0.08);
}

.submenu li .menu-item {
  padding: 9px 12px 9px 20px;
  margin-left: 8px;
  margin-right: 4px;
  font-size: 0.875em;
  border-left: 2px solid rgba(249, 115, 22, 0.15);
  border-radius: 0 8px 8px 0;
  background-color: transparent;
  color: #94a3b8;
}

.submenu li .menu-item:hover {
  background-color: rgba(249, 115, 22, 0.08);
  border-left-color: rgba(249, 115, 22, 0.4);
  color: #e2e8f0;
}

.submenu li .menu-item .icon-container {
  min-width: 30px;
  height: 30px;
}

.submenu li .menu-item i {
  font-size: 15px;
  color: #94a3b8;
}

.submenu li .menu-item:hover i,
.submenu .menu-item.active i {
  color: #fb923c;
}

/* --- Submenu toggle button --- */
.submenu-toggle {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s;
  opacity: 0.7;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.1);
}

.submenu-toggle:hover {
  opacity: 1;
  background-color: rgba(255, 255, 255, 0.2);
}

.submenu-toggle i {
  font-size: 12px;
  color: #e2e8f0;
}

.menu-item-with-submenu.submenu-open .submenu-toggle {
  transform: translateY(-50%) rotate(90deg);
  opacity: 1;
}

/* Toggle en modo minimizado */
.sidebar:not(:hover) .submenu-toggle {
  display: none;
}

/* Submenu en sidebar minimizada (popup lateral) */
.sidebar:not(:hover) .submenu {
  position: absolute;
  left: 70px;
  top: 0;
  background: linear-gradient(135deg, #131a27 0%, #0f1520 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: none;
  border-radius: 0 12px 12px 0;
  box-shadow: 8px 4px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  min-width: 200px;
  margin: 0;
  padding: 8px 4px;
}

.sidebar:not(:hover) .submenu.visible {
  display: block;
}

.sidebar:not(:hover) .submenu li .menu-item {
  padding: 10px 16px;
  margin-left: 0;
  border-left: 2px solid transparent;
  border-radius: 0 8px 8px 0;
}

.sidebar:not(:hover) .submenu li .menu-item:hover {
  border-left-color: rgba(249, 115, 22, 0.4);
}
