/* --- SIDEBAR BASE --- */
.sidebar {
  width: var(--sidebar-width-expanded);
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition-speed) ease, width var(--transition-speed) ease;
  z-index: 1000;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 25px 20px;
  margin-bottom: 10px;
  position: relative;
}

.logo-icon {
  color: var(--cr-red, #dc2626);
  font-size: 1.8rem;
  min-width: 40px;
  text-align: center;
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-dark, #1e293b);
  margin-left: 10px;
  white-space: nowrap;
}

/* Botón de cierre interno (Oculto por defecto en escritorio) */
.sidebar-close-btn {
  display: none;
  background: rgba(226, 29, 72, 0.1);
  color: var(--sidebar-active-text);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition-speed) ease;
  margin-left: auto; /* Lo empuja a la derecha */
}

.sidebar-close-btn:hover {
  background: rgba(226, 29, 72, 0.2);
  transform: scale(1.05);
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-title {
  color: var(--sidebar-title);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 25px;
  margin-bottom: 10px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* --- ESTADO POR DEFECTO (ABIERTO) --- */
.sidebar .logo-small {
  display: none;
}

.sidebar .logo-full {
  display: block;
}

/* NAV LINKS */
.sidebar-nav {
  list-style: none;
  padding: 0 15px;
  margin: 0;
}

.nav-item {
  margin-bottom: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all var(--transition-speed) ease;
  cursor: pointer;
}

.nav-link:hover {
  background-color: var(--sidebar-hover);
  color: var(--text-dark, #334155);
}

.nav-link.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-link i.icon {
  font-size: 1.1rem;
  min-width: 24px;
  margin-right: 12px;
  text-align: center;
}

.nav-link i.arrow {
  margin-left: auto;
  font-size: 0.8rem;
  transition: transform var(--transition-speed);
}

/* SUBMENU */
.submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-speed) ease-in-out;
}

.nav-item.open .submenu {
  max-height: 200px;
}

.nav-item.open > .nav-link i.arrow {
  transform: rotate(180deg);
}

.submenu-item {
  padding: 10px 15px 10px 50px;
  color: var(--sidebar-text);
  text-decoration: none;
  display: block;
  font-size: 0.9rem;
  transition: all var(--transition-speed) ease;
}

.submenu-item:hover, .submenu-item.active {
  color: var(--sidebar-active-text);
  font-weight: 600;
}

/* --- ESTADO COMPACTO (SOLO ESCRITORIO) --- */
@media (min-width: 769px) {
  .sidebar.compact {
    width: var(--sidebar-width-compact);
  }

  .sidebar.compact .logo-full {
    display: none;
  }

  .sidebar.compact .logo-small {
    display: block;
    margin: 0 auto;
  }

  .sidebar.compact .sidebar-header {
    padding: 25px 0;
    justify-content: center;
  }

  .sidebar.compact .logo-text,
  .sidebar.compact .text-link,
  .sidebar.compact i.arrow {
    display: none;
  }

  .sidebar.compact .sidebar-title {
    color: transparent;
    position: relative;
  }

  .sidebar.compact .sidebar-title::after {
    content: '';
    color: var(--sidebar-title);
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 1.2rem;
  }

  .sidebar.compact .nav-link {
    justify-content: center;
    padding: 12px 0;
  }

  .sidebar.compact .nav-link i.icon {
    margin-right: 0;
    font-size: 1.3rem;
  }

  .sidebar.compact .submenu {
    display: none !important;
  }
}

/* --- ESTILO RESPONSIVE (MÓVIL) --- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.15); /* Sombra más pronunciada para resaltar sobre el fondo */
    transform: translateX(0);
  }

  .sidebar.compact {
    transform: translateX(-100%);
    width: var(--sidebar-width-expanded);
  }

  /* Mostramos el botón de cerrar en móvil */
  .sidebar-close-btn {
    display: flex;
  }
}