/* ========================================
   WorldTool - Sidebar Styles
   Responsive & Collapsible
   ======================================== */

/* ========== SIDEBAR CONTAINER ========== */
#sidebar {
  position: fixed;
  left: 0;
  top: var(--app-shell-offset);
  height: calc(100dvh - var(--app-shell-offset));
  width: var(--sidebar-width);
  background: var(--bg-primary);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  padding: 12px 6px 0;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  z-index: 900;
  transition: width 0.3s ease, transform 0.3s ease;
}

/* ========== SIDEBAR COLLAPSED (Desktop) ========== */
@media (width > 1024px) {
  body.sidebar-collapsed #sidebar {
    width: var(--sidebar-collapsed-width);
  }

  body.sidebar-collapsed #sidebar :is(.sidebar-label, .sidebar-badge) {
    display: none;
  }

  body.sidebar-collapsed #sidebar .sidebar-item {
    justify-content: center;
  }

  body.sidebar-collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
  }
}

/* ========== SIDEBAR SECTIONS ========== */
.sidebar-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0 8px;
  overscroll-behavior: contain;
}

.sidebar-nav,
.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-group + .sidebar-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--card-border);
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 6px 0;
  border-top: 1px solid var(--card-border);
}

#sidebar,
.sidebar-section {
  scrollbar-width: thin;
  scrollbar-color: var(--card-border) transparent;
}

#sidebar::-webkit-scrollbar,
.sidebar-section::-webkit-scrollbar {
  width: 4px;
}

#sidebar::-webkit-scrollbar-track,
.sidebar-section::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar::-webkit-scrollbar-thumb,
.sidebar-section::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 4px;
}

/* ========== SIDEBAR ITEMS ========== */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 15px;
  line-height: 20px;
  min-height: 36px;
  flex-shrink: 0;
  text-decoration: none;
  background: none;
  border: none;
  width: 100%;
  transition: all 0.2s ease;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  text-align: left;
}

.sidebar-item:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.sidebar-item:focus-visible {
  outline-offset: -2px;
}

.sidebar-item-active {
  background: var(--accent-bg);
  color: var(--accent-fg);
  font-weight: 600;
}

.sidebar-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== SIDEBAR COLLAPSE BUTTON (Barre horizontale) ========== */
.sidebar-collapse-btn {
  flex-shrink: 0;
  width: calc(100% + 12px);
  margin: 0 -6px;
  height: 48px;
  border: none;
  border-top: 1px solid var(--sidebar-toggle-border);
  background: var(--sidebar-toggle-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--sidebar-toggle-icon);
  z-index: 10;
  pointer-events: auto;
}

.sidebar-collapse-btn:hover {
  background: var(--sidebar-toggle-hover-bg);
  color: var(--sidebar-toggle-hover-icon);
}

.sidebar-collapse-btn:active {
  background: var(--sidebar-toggle-active-bg);
}

.sidebar-collapse-btn svg {
  transition: transform 0.3s ease;
}

/* ========== MOBILE SIDEBAR ( 1024px) ========== */
@media (max-width: 1024px) {
  #sidebar {
    display: block;
    overflow-y: auto;
    transform: translateX(-100%);
    width: var(--sidebar-mobile-width);
    box-shadow: none;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .sidebar-section {
    overflow: visible;
  }
  
  .mobile-menu-open #sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
    z-index: 1370;
  }

  .sidebar-item {
    padding: 12px 8px;
    min-height: 44px;
  }
  
  .sidebar-collapse-btn {
    display: none;
  }
}

/* ========== SIDEBAR OVERLAY (Mobile) ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--navbar-height) 0 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1360;
  animation: sidebar-overlay-enter 0.2s ease;
}

@media (max-width: 1024px) {
  .mobile-menu-open .sidebar-overlay {
    display: block;
  }
}

/* ========== ANIMATIONS ========== */
@keyframes sidebar-overlay-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ========== SIDEBAR BADGE ========== */
.sidebar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--sidebar-badge-bg);
  color: var(--sidebar-badge-color);
  border: 1px solid var(--sidebar-badge-border);
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  margin-left: auto;
  transition: all 0.2s ease;
}
