/* ==========================================================================
   TOC NAVIGATION COMPONENT
   Template B Sidebar Table of Contents with Scroll-Spy
   Component ID: COMP-TOC-001
   Created: 2026-01-14
   ========================================================================== */

/* --------------------------------------
   Base Container
   -------------------------------------- */
.toc-nav {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

/* --------------------------------------
   Progress Bar
   -------------------------------------- */
.toc-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--bg-section);
  /* Progress bar is absolutely positioned, stays at top */
  order: -2;
}

.toc-progress__bar {
  height: 100%;
  background: var(--primary);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.1s ease-out;
  will-change: transform;
}

/* Disable transition for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .toc-progress__bar {
    transition: none;
  }
}

/* --------------------------------------
   Title - Always at top of TOC
   -------------------------------------- */
.toc-nav__title {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--space-md) 0;
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
  /* Ensure title stays at top and doesn't get reordered */
  order: -1;
}

/* --------------------------------------
   Links List
   -------------------------------------- */
.toc-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-nav__item {
  margin: 0;
  padding: 0;
}

.toc-nav__item + .toc-nav__item {
  margin-top: var(--space-xs);
}

/* --------------------------------------
   Link States
   -------------------------------------- */
.toc-nav__link {
  display: block;
  padding: var(--space-xs) var(--space-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  margin-left: -3px;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

/* Hover state */
.toc-nav__link:hover {
  color: var(--primary);
  background: var(--primary-light);
}

/* Focus state (keyboard navigation) */
.toc-nav__link:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  color: var(--primary);
}

/* Focus visible for keyboard users only (modern browsers) */
.toc-nav__link:focus:not(:focus-visible) {
  outline: none;
}

.toc-nav__link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  color: var(--primary);
}

/* Active state (current section) */
.toc-nav__link[aria-current="true"],
.toc-nav__link.is-active {
  color: var(--primary);
  background: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 500;
}

/* Visited state - keep same as default for consistency */
.toc-nav__link:visited {
  color: var(--text-secondary);
}

.toc-nav__link:visited:hover,
.toc-nav__link:visited.is-active,
.toc-nav__link:visited[aria-current="true"] {
  color: var(--primary);
}

/* --------------------------------------
   Reduced Motion
   -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .toc-nav__link {
    transition: none;
  }
}

/* --------------------------------------
   Print Styles
   -------------------------------------- */
@media print {
  .toc-nav {
    display: none;
  }
}

/* --------------------------------------
   Graceful Degradation (No JS)
   When JavaScript is disabled, the TOC
   still works as standard anchor links
   -------------------------------------- */
.no-js .toc-progress {
  display: none;
}

/* --------------------------------------
   High Contrast Mode Support
   -------------------------------------- */
@media (forced-colors: active) {
  .toc-nav__link.is-active,
  .toc-nav__link[aria-current="true"] {
    border-left: 3px solid CanvasText;
    forced-color-adjust: none;
  }

  .toc-progress__bar {
    background: Highlight;
  }
}
