/* ============================================================
   SIDEBAR
   ============================================================ */

/* BASE — top y height se calculan en JS dinámicamente */
#sidebar {
  position: fixed;
  left: 0;
  top: 4rem;
  height: calc(100vh - 4rem);
  width: 4rem;
  background: #fff;
  box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease;
  z-index: 40;
}

/* PINNED o HOVER → expandido */
#sidebar.pinned,
#sidebar:hover {
  width: 16rem;
}

/* TEXTO — solo visible cuando expandido */
#sidebar:not(.pinned):not(:hover) .sidebar-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  display: inline-block;
  transition: opacity 0.15s ease;
}
#sidebar.pinned .sidebar-text,
#sidebar:hover .sidebar-text {
  opacity: 1;
  width: auto;
  display: inline-block;
  transition: opacity 0.2s ease 0.05s;
}

/* FLECHAS DE SUBMENÚ — ocultas cuando sidebar cerrado */
#sidebar:not(.pinned):not(:hover) #flecha-inventario,
#sidebar:not(.pinned):not(:hover) #flecha-sucursales,
#sidebar:not(.pinned):not(:hover) .sucursal-flecha {
  opacity: 0;
  pointer-events: none;
}
#sidebar.pinned #flecha-inventario,
#sidebar:hover  #flecha-inventario,
#sidebar.pinned #flecha-sucursales,
#sidebar:hover  #flecha-sucursales,
#sidebar.pinned .sucursal-flecha,
#sidebar:hover  .sucursal-flecha {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}

/* LINKS */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--color-base, #dc2626);
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
}
.sidebar-link:hover {
  background-color: var(--color-hover, #fee2e2);
}
.sidebar-link i {
  flex-shrink: 0;
  width: 1.2rem;
  text-align: center;
}

/* SUBMENÚ */
.submenu-transition {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.submenu-open {
  max-height: 600px;
}

/* PESTAÑA DE ANCLAJE — position fixed, JS mueve el left */
#sidebar-tab {
  position: fixed;
  top: 4.75rem;
  left: 4rem;
  width: 1rem;
  height: 2.5rem;
  background: #dc2626;
  color: white;
  border-radius: 0 6px 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  transition: background 0.2s ease, width 0.2s ease, left 0.25s ease;
}
#sidebar-tab:hover {
  background: #b91c1c;
  width: 1.4rem;
}
#sidebar.pinned ~ * #sidebar-tab,
#sidebar.pinned #sidebar-tab {
  left: 16rem;
}
#tab-icon {
  transition: transform 0.3s ease;
  font-size: 0.65rem;
}
#sidebar.pinned #tab-icon {
  transform: rotate(180deg);
}

/* ROTATE HELPER */
.rotate-180 {
  transform: rotate(180deg);
}

/* ============================================================
   MÓVIL
   ============================================================ */
@media (max-width: 767px) {
  #sidebar {
    width: 16rem;
    top: 4rem;
    height: calc(100vh - 4rem);
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
  }
  #sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
  #sidebar .sidebar-text {
    opacity: 1 !important;
    width: auto !important;
    display: inline-block !important;
  }
  #sidebar #flecha-inventario,
  #sidebar #flecha-sucursales,
  #sidebar .sucursal-flecha {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  #sidebar-tab {
    display: none !important;
  }
}

/* ============================================================
   BOTÓN HAMBURGUESA
   ============================================================ */
#sidebar-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1rem;
  z-index: 60;
  background: #dc2626;
  color: white;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 3px solid black;
  box-shadow: 4px 4px 0 0 black;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
#sidebar-toggle:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 0 black;
}
#sidebar-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 0 black;
}

/* ============================================================
   ANIMACIÓN SVG HAMBURGUESA → X
   ============================================================ */
.sb-line {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity   0.2s ease;
  transform-box:    fill-box;
  transform-origin: center;
}
.sb-top-open    { transform: translateY(5px) rotate(45deg); }
.sb-mid-open    { opacity: 0; transform: scaleX(0); }
.sb-bottom-open { transform: translateY(-5px) rotate(-45deg); }

/* En desktop el botón y el backdrop no existen */
@media (min-width: 768px) {
  #sidebar-toggle,
  #sidebar-backdrop {
    display: none !important;
  }
}

/* ============================================================
   BACKDROP MÓVIL
   ============================================================ */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 35;
  animation: backdropIn 0.2s ease;
}
#sidebar-backdrop.visible {
  display: block;
}
@keyframes backdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}