/**
 * Sticky Floating Table of Contents Sidebar Styles
 *
 * Responsive design:
 * - Toggle button on screens < 1280px
 * - Always visible and sticky on screens >= 1280px
 */

/* Hide the original TOC in the content (we use the floating one) */
#table-of-contents {
  display: none;
}

/* Toggle Button (for mobile/tablet) */
.toc-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  cursor: pointer;
  z-index: 1001;
  transition: all 0.3s ease;
  color: #18181b;
}

.toc-toggle:hover {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transform: scale(1.05);
}

.toc-toggle:active {
  transform: scale(0.95);
}

.toc-toggle.active {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

@media (prefers-color-scheme: dark) {
  .toc-toggle {
    background: rgba(23, 23, 23, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    color: #fafafa;
  }

  .toc-toggle:hover {
    background: rgba(23, 23, 23, 1);
  }

  .toc-toggle.active {
    background: #60a5fa;
    border-color: #60a5fa;
  }
}

/* Sidebar container */
.toc-sidebar {
  position: fixed;
  top: 2rem;
  right: 2rem;
  width: 280px;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(10px);
  z-index: 1000;
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

/* Desktop: always visible */
.toc-sidebar.visible {
  opacity: 1;
  transform: translateX(0);
  visibility: visible;
}

/* Mobile: slide in from right, hidden by default */
.toc-sidebar.mobile {
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 320px;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  opacity: 0;
  transform: translateX(100%);
  visibility: hidden;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
}

.toc-sidebar.mobile.visible {
  opacity: 1;
  transform: translateX(0);
  visibility: visible;
}

/* Dark mode styles */
@media (prefers-color-scheme: dark) {
  .toc-sidebar {
    background: rgba(23, 23, 23, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .toc-sidebar.mobile {
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
  }
}

/* Overlay for mobile when sidebar is open */
.toc-sidebar.mobile.visible::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: -1;
  backdrop-filter: blur(2px);
}

/* Heading */
.toc-sidebar-heading {
  margin: 0 0 1rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: #18181b;
  border-bottom: 2px solid #e4e4e7;
  padding-bottom: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar-heading {
    color: #fafafa;
    border-bottom-color: #3f3f46;
  }
}

/* TOC list styles */
.toc-sidebar ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.toc-sidebar ul ul {
  padding-left: 1rem;
  margin-top: 0.25rem;
}

.toc-sidebar li {
  margin: 0.25rem 0;
}

/* TOC links */
.toc-sidebar a {
  display: block;
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #52525b;
  text-decoration: none;
  border-radius: 0.25rem;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar a {
    color: #a1a1aa;
  }
}

/* Hover state */
.toc-sidebar a:hover {
  color: #18181b;
  background-color: rgba(0, 0, 0, 0.05);
  border-left-color: #a1a1aa;
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar a:hover {
    color: #fafafa;
    background-color: rgba(255, 255, 255, 0.05);
    border-left-color: #71717a;
  }
}

/* Active state */
.toc-sidebar a.active {
  color: #3b82f6;
  background-color: rgba(59, 130, 246, 0.1);
  border-left-color: #3b82f6;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar a.active {
    color: #60a5fa;
    background-color: rgba(96, 165, 250, 0.1);
    border-left-color: #60a5fa;
  }
}

/* Nested links styling */
.toc-sidebar ul ul a {
  font-size: 0.8125rem;
  padding-left: 0.75rem;
}

.toc-sidebar ul ul ul a {
  font-size: 0.75rem;
  padding-left: 1rem;
}

/* Scrollbar styling for webkit browsers */
.toc-sidebar::-webkit-scrollbar {
  width: 6px;
}

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

.toc-sidebar::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
  }
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  .toc-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
  }
}

/* Adjust main content max-width when sidebar is visible */
@media (min-width: 1280px) {
  /* Add some right margin to prevent content from being hidden behind sidebar */
  main.content {
    margin-right: 320px;
  }
}

/* For very wide screens, increase sidebar size slightly */
@media (min-width: 1536px) {
  .toc-sidebar {
    width: 320px;
    right: 3rem;
  }

  main.content {
    margin-right: 380px;
  }
}
