/* ============================================
   Table of Contents Component
   ============================================ */

.table-of-contents {
  position: fixed;
  top: 120px;
  right: 2rem;
  min-width: 250px;
  max-width: 400px;
  width: max-content;
  height: auto;
  max-height: 80vh;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  padding: 1.5rem;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  z-index: 100;
  transition: var(--transition-normal);
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--color-border-light);
}

.toc-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
}

.toc-toggle {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: var(--transition-normal);
}

.toc-toggle:hover {
  background: var(--color-bg-primary);
  color: var(--color-primary);
}

.toc-toggle-icon {
  display: block;
  line-height: 1;
}

.toc-nav {
  display: block;
}

.toc-nav.collapsed {
  display: none;
}

.toc-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-nav li {
  margin: 0;
}

.toc-nav a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--color-text-primary);
  text-decoration: none;
  border-radius: 8px;
  transition: var(--transition-normal);
  font-size: 0.95rem;
  line-height: 1.6;
  font-weight: 400;
  white-space: nowrap;
}

.toc-nav a:hover {
  background: var(--color-bg-primary);
  color: var(--color-primary);
  transform: translateX(4px);
  font-weight: 500;
}

.toc-nav a.active {
  background: var(--color-text-primary);
  color: var(--color-bg-secondary);
  font-weight: 500;
}

/* Mobile trigger button (hidden on desktop) */
.toc-mobile-trigger {
  display: none;
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--hero-gradient);
  color: var(--hero-text-color);
  border: none;
  border-radius: 50px;
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 99;
  transition: var(--transition-normal);
  gap: 0.5rem;
  align-items: center;
}

.toc-mobile-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.toc-icon {
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

/* Mobile and Tablet styles */
@media (max-width: 1366px) {
  .toc-mobile-trigger {
    display: flex;
    bottom: 2rem;
    right: 2rem;
    left: auto;
  }

  .table-of-contents {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    padding: 2rem;
    z-index: 1000;
  }

  .table-of-contents.mobile-open {
    transform: translateX(0);
  }

  .toc-toggle {
    font-size: 2rem;
    width: 40px;
    height: 40px;
  }

  .toc-header {
    margin-bottom: 1.5rem;
  }

  .toc-title {
    font-size: 1.5rem;
  }

  .toc-nav a {
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }
}

/* Hide TOC on very small screens when not explicitly opened */
@media (max-width: 480px) {
  .table-of-contents:not(.mobile-open) {
    display: none;
  }
}

/* Overlay for mobile */
.toc-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.toc-overlay.active {
  display: block;
  opacity: 1;
}

/* Scrollbar styling for TOC */
.table-of-contents::-webkit-scrollbar {
  width: 6px;
}

.table-of-contents::-webkit-scrollbar-track {
  background: var(--color-bg-primary);
  border-radius: 3px;
}

.table-of-contents::-webkit-scrollbar-thumb {
  background: var(--color-border-light);
  border-radius: 3px;
}

.table-of-contents::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}
