/* Table of Contents styling for markdown-generated content */
/* Uses design system theme variables */

/* TOC Container */
.toc {
  background: linear-gradient(
    to bottom,
    var(--color-base-50),
    var(--color-base-100)
  );
  border: 1px solid var(--color-border);
  border-radius: var(--radius-box);
  padding: 1.75rem;
  margin: 2.5rem 0;
  font-size: 0.9375rem;
  line-height: 1.7;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05),
    0 1px 2px -1px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
}

.toc::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--color-primary-500),
    var(--color-primary-400),
    var(--color-primary-500)
  );
}

/* TOC Header */
.toc-header {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--color-heading);
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--color-base-200);
}

.toc-header::before {
  content: "📑";
  font-size: 1.25rem;
  line-height: 1;
}

/* Reset prose list styling for TOC */
.prose .toc ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.prose .toc li {
  margin: 0;
  padding: 0;
}

/* TOC List Item */
.toc li {
  position: relative;
  margin: 0.125rem 0;
}

/* TOC Links */
.toc a {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  color: var(--color-body);
  text-decoration: none;
  border-radius: var(--radius-input);
  transition: all 0.2s var(--ease-out-cubic);
  position: relative;
  font-weight: 450;
  border-left: 2px solid transparent;
  margin-left: 0.25rem;
}

.toc a::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--color-light);
  margin-right: 0.625rem;
  flex-shrink: 0;
  transition: all 0.2s var(--ease-out-cubic);
}

.toc a:hover {
  color: var(--color-primary-600);
  background-color: var(--color-primary-50);
  border-left-color: var(--color-primary-500);
  padding-left: 1rem;
}

.toc a:hover::before {
  background-color: var(--color-primary-500);
  transform: scale(1.5);
}

.toc a:active,
.toc a.active {
  color: var(--color-primary-700);
  background-color: var(--color-primary-100);
  border-left-color: var(--color-primary-600);
  font-weight: 600;
  padding-left: 1rem;
}

.toc a.active::before {
  background-color: var(--color-primary-600);
  transform: scale(1.5);
  box-shadow: 0 0 0 3px var(--color-primary-100);
}

/* Level 1 (H2) - Main sections */
.toc > ul > li > a {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--color-heading);
  margin-bottom: 0.125rem;
}

/* Level 2 (H3) - Subsections */
.toc ul ul {
  margin-top: 0.25rem;
  margin-bottom: 0.375rem;
  padding-left: 1.25rem;
  border-left: 1px solid var(--color-base-200);
  margin-left: 0.875rem;
}

.toc ul ul a {
  font-size: 0.875rem;
  padding: 0.375rem 0.625rem;
  font-weight: 400;
  color: var(--color-body);
}

.toc ul ul a::before {
  width: 3px;
  height: 3px;
}

/* Level 3+ - Deep subsections */
.toc ul ul ul {
  padding-left: 1rem;
  margin-top: 0.125rem;
  margin-left: 0.625rem;
}

.toc ul ul ul a {
  font-size: 0.8125rem;
  color: var(--color-subtle);
  padding: 0.25rem 0.5rem;
}

.toc ul ul ul a::before {
  width: 2px;
  height: 2px;
  opacity: 0.7;
}

/* Section divider between main items */
.toc > ul > li:not(:last-child) {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--color-base-200);
}

/* Permalink styling (if enabled) */
.headerlink {
  opacity: 0;
  margin-left: 0.5rem;
  font-size: 0.875em;
  text-decoration: none;
  color: var(--color-light);
  transition: all 0.2s var(--ease-out-cubic);
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius-input);
}

h1:hover .headerlink,
h2:hover .headerlink,
h3:hover .headerlink,
h4:hover .headerlink,
h5:hover .headerlink,
h6:hover .headerlink {
  opacity: 1;
}

.headerlink:hover {
  color: var(--color-primary-600);
  background-color: var(--color-primary-50);
}

.headerlink::before {
  content: "#";
  font-weight: 600;
}

/* Sticky TOC variant */
.toc.sticky {
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom scrollbar for sticky TOC */
.toc.sticky {
  scrollbar-width: thin;
  scrollbar-color: var(--color-base-300) transparent;
}

.toc.sticky::-webkit-scrollbar {
  width: 0.375rem;
}

.toc.sticky::-webkit-scrollbar-track {
  background: transparent;
  border-radius: var(--radius-input);
}

.toc.sticky::-webkit-scrollbar-thumb {
  background: var(--color-base-300);
  border-radius: var(--radius-input);
  transition: background 0.2s var(--ease-out-cubic);
}

.toc.sticky::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary-400);
}

/* Compact variant */
.toc.compact {
  padding: 1.25rem;
  font-size: 0.875rem;
}

.toc.compact .toc-header {
  font-size: 0.9375rem;
  margin-bottom: 1rem;
}

.toc.compact a {
  padding: 0.375rem 0.625rem;
}

.toc.compact ul ul {
  padding-left: 1rem;
}

.toc.compact > ul > li:not(:last-child) {
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
}

/* Minimal variant - no background, cleaner look */
.toc.minimal {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 1.25rem 0;
}

.toc.minimal::before {
  display: none;
}

.toc.minimal .toc-header {
  border-bottom-color: var(--color-border);
}

/* Progress indicator variant - shows reading progress */
.toc.with-progress a.active::after {
  content: "";
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-success);
  box-shadow: 0 0 0 2px var(--color-success-content);
  animation: pulse-dot 2s var(--ease-out-cubic) infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
    transform: translateY(-50%) scale(1.2);
  }
}

/* Collapsible sections (if you add JS) */
.toc li.has-children > a::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-light);
  margin-left: auto;
  transition: transform 0.2s var(--ease-out-cubic);
}

.toc li.has-children.collapsed > a::after {
  transform: rotate(-90deg);
}

.toc li.has-children.collapsed > ul {
  display: none;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .toc {
    background: linear-gradient(
      to bottom,
      oklch(0.2 0.01 264),
      oklch(0.18 0.01 264)
    );
    border-color: oklch(0.3 0.02 264);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3),
      0 2px 4px -2px rgba(0, 0, 0, 0.3);
  }

  .toc::before {
    background: linear-gradient(
      90deg,
      var(--color-primary-400),
      var(--color-primary-300),
      var(--color-primary-400)
    );
  }

  .toc-header {
    color: var(--color-primary-content-50);
    border-bottom-color: oklch(0.3 0.02 264);
  }

  .toc a {
    color: var(--color-primary-content-200);
  }

  .toc a::before {
    background-color: oklch(0.5 0.02 264);
  }

  .toc > ul > li > a {
    color: var(--color-primary-content-100);
  }

  .toc ul ul {
    border-left-color: oklch(0.3 0.02 264);
  }

  .toc ul ul a {
    color: var(--color-primary-content-300);
  }

  .toc ul ul ul a {
    color: var(--color-primary-content-400);
  }

  .toc a:hover {
    color: var(--color-primary-300);
    background-color: oklch(0.25 0.08 277);
    border-left-color: var(--color-primary-400);
  }

  .toc a:hover::before {
    background-color: var(--color-primary-400);
  }

  .toc a:active,
  .toc a.active {
    color: var(--color-primary-200);
    background-color: oklch(0.3 0.1 277);
    border-left-color: var(--color-primary-300);
  }

  .toc a.active::before {
    background-color: var(--color-primary-300);
    box-shadow: 0 0 0 3px oklch(0.3 0.1 277);
  }

  .toc > ul > li:not(:last-child) {
    border-bottom-color: oklch(0.3 0.02 264);
  }

  .headerlink {
    color: oklch(0.5 0.02 264);
  }

  .headerlink:hover {
    color: var(--color-primary-300);
    background-color: oklch(0.25 0.08 277);
  }

  .toc.sticky::-webkit-scrollbar-thumb {
    background: oklch(0.4 0.02 264);
  }

  .toc.sticky::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-500);
  }

  .toc.minimal .toc-header {
    border-bottom-color: oklch(0.3 0.02 264);
  }
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .toc {
    margin: 2rem 0;
  }
}

@media (max-width: 768px) {
  .toc {
    padding: 1.25rem;
    margin: 1.5rem 0;
    font-size: 0.875rem;
  }

  .toc-header {
    font-size: 0.9375rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .toc a {
    padding: 0.375rem 0.625rem;
  }

  .toc ul ul {
    padding-left: 1rem;
    margin-left: 0.5rem;
  }

  .toc > ul > li:not(:last-child) {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
  }

  /* Disable sticky on mobile */
  .toc.sticky {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

/* Print styles */
@media print {
  .toc {
    background: white;
    border: 1px solid #e5e7eb;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .toc::before {
    display: none;
  }

  .toc a {
    color: black;
  }

  .headerlink {
    display: none;
  }
}
