/**
 * Table of Contents
 * Clean sidebar navigation with active state tracking
 * 
 * Desktop: Sticky sidebar on the right
 * Mobile: Horizontal bar inline with content
 */

/**
 * @section Table of Contents
 */

/** @public Table of contents container */
.toc {
  padding: var(--spacing-3) 0;

  /** @public TOC title */
  &-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: hsl(var(--foreground));
    margin-bottom: var(--spacing-4);
    padding: 0 var(--spacing-3);
  }

  /** @public TOC list container */
  &-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-1);
    list-style: none;
    padding: 0;
    margin: 0;
  }

  /** @public TOC link */
  &-link {
    display: block;
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--text-sm);
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
    line-height: 1.5;
    position: relative;

    &:hover {
      color: hsl(var(--foreground));
      background: hsl(var(--accent) / 0.1);
    }

    &.active {
      color: hsl(var(--foreground));
      background: hsl(var(--accent) / 0.15);
      font-weight: var(--font-medium);
    }

    /** @public Nested TOC link (h3) */
    &--nested {
      padding-left: var(--spacing-6);
      font-size: var(--text-sm);
      color: hsl(var(--muted-foreground) / 0.8);
    }
  }
}

// Desktop: Sidebar layout
@media (min-width: 1025px) {
  .toc {
    position: sticky;
    top: 100px; // Account for sticky header
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    width: 240px;
    flex-shrink: 0;
    align-self: flex-start; // Critical for sticky to work in flex container
  }
}

// Mobile: Inline horizontal layout
@media (max-width: 1024px) {
  .toc {
    position: static;
    width: 100%;
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    margin: var(--spacing-6) 0;
    padding: var(--spacing-4);
    background: hsl(var(--muted) / 0.2);
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius-lg);

    &-title {
      margin-bottom: var(--spacing-3);
    }

    &-list {
      flex-direction: row;
      flex-wrap: wrap;
      gap: var(--spacing-2);

      li {
        border: none;
        margin: 0;
      }

      .row;
      .row-nowrap;
      .gap-2;
    }

    &-link {
      padding: var(--spacing-2) var(--spacing-3);
      white-space: nowrap;
      background: hsl(var(--background));
      border: 1px solid hsl(var(--border));

      &:hover {
        background: hsl(var(--accent) / 0.1);
      }

      // No active state on mobile - TOC is inline, not visible while scrolling
      &.active {
        background: hsl(var(--background));
      }

      &--nested {
        padding-left: var(--spacing-3);
        padding-right: var(--spacing-3);
        font-size: var(--text-sm);
        opacity: 0.9;
      }
    }
  }
}

/** @public TOC mobile anchor - hidden on desktop */
.toc-mobile-anchor {
  @media (min-width: 1025px) {
    display: none;
  }
}

/** @public TOC sidebar container - hidden on mobile */
.toc-sidebar {
  div[data-toc] {
    position: sticky;
    top: 80px;
  }
  @media (max-width: 1024px) {
    display: none;
  }
}
