/* ==========================================================================
   Sidebar — Document table of contents panel
   ========================================================================== */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 200;
  border: none;
}

.sidebar-overlay--visible {
  display: block;
}

/* Sidebar */
.document-sidebar {
  position: sticky;
  top: calc(var(--menu-height) + 16px);
  width: var(--sidebar-width);
  height: fit-content;
  max-height: calc(100vh - var(--menu-height) - 32px);
  flex-shrink: 0;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-color);
  box-shadow: var(--shadow-sm);
}

/* Custom scrollbar */
.document-sidebar::-webkit-scrollbar {
  width: 8px;
}

.document-sidebar::-webkit-scrollbar-track {
  background: transparent;
  margin: 12px 0;
}

.document-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--neutral-60);
  border-radius: 10px;
  border: 2px solid var(--bg-color);
}

.document-sidebar::-webkit-scrollbar-thumb:hover {
  background-color: var(--neutral-300);
}

.sidebar-header {
  display: none;
}

.sidebar-close {
  padding: 8px;
  color: var(--text-secondary);
}

.sidebar-close:hover {
  color: var(--text-color);
}

.sidebar-content {
  padding: 20px;
  padding-bottom: 40px;
}

.sidebar-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--primary-color);
  margin-bottom: 16px;
}

.sidebar-back-link:hover {
  text-decoration: underline;
}

/* Floating TOC button (mobile only) */
.document-toc-button {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsive: Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 1023px) {
  .document-toc-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 199;
    padding: 10px 18px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--white);
    border: 1px solid var(--neutral-40);
    border-radius: 100px;
    box-shadow: 0 2px 12px rgba(18, 27, 44, 0.12), 0 1px 3px rgba(18, 27, 44, 0.08);
    cursor: pointer;
    transition: all var(--transition-fast);
  }

  .document-toc-button:active {
    transform: scale(0.96);
  }

  .document-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    z-index: 300;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    border: none;
    border-radius: 0;
    box-shadow: none;
    opacity: 0;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
                opacity 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .document-sidebar--open {
    opacity: 1;
    transform: translateY(0);
  }

  .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    z-index: 1;
  }

  .sidebar-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
  }

  .sidebar-content {
    padding: 20px;
    padding-bottom: 80px;
  }
}
