/**
 * MSiR Table of Contents - November 2025
 * Sticky sidebar TOC with scroll spy and progress tracking
 */

/* ========================================
   TABLE OF CONTENTS SIDEBAR
   ======================================== */
.article-toc {
  position: sticky;
  top: 140px; /* Below header + progress bar */
  height: fit-content;
  background: white;
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--scientific-cyan);
}

.toc-header h3 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--laboratory-dark);
  margin: 0;
}

.toc-toggle {
  display: none; /* Show only on mobile */
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-sm);
  color: var(--scientific-cyan);
}

/* ========================================
   TOC LIST
   ======================================== */
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: var(--space-sm);
}

.toc-link {
  display: block;
  padding: var(--space-sm) var(--space-md);
  color: #6c757d;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition-base);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.toc-link:hover {
  color: var(--scientific-cyan);
  border-left-color: var(--scientific-cyan);
  padding-left: var(--space-lg);
}

.toc-link.active {
  color: var(--mad-magenta);
  border-left-color: var(--mad-magenta);
  font-weight: 600;
  padding-left: var(--space-lg);
}

/* ========================================
   TOC METADATA
   ======================================== */
.toc-metadata {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid #e9ecef;
}

.toc-meta-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  font-size: 0.875rem;
  color: #6c757d;
}

/* ========================================
   READING PROGRESS
   ======================================== */
.toc-progress {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid #e9ecef;
}

.progress-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--laboratory-dark);
  margin-bottom: var(--space-sm);
}

.progress-bar-container {
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--space-sm);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--mad-magenta), var(--scientific-cyan));
  width: 0%;
  transition: width 0.3s ease;
}

.progress-percentage {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--scientific-cyan);
  text-align: right;
}

/* ========================================
   TOC TAGS
   ======================================== */
.toc-tags {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid #e9ecef;
}

.tags-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--laboratory-dark);
  margin-bottom: var(--space-sm);
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.toc-tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: rgba(0, 169, 224, 0.1);
  border: 1px solid rgba(0, 169, 224, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--scientific-cyan);
  font-weight: 600;
}

/* ========================================
   SCROLLBAR STYLING (for webkit browsers)
   ======================================== */
.article-toc::-webkit-scrollbar {
  width: 6px;
}

.article-toc::-webkit-scrollbar-track {
  background: #f8f9fa;
  border-radius: 3px;
}

.article-toc::-webkit-scrollbar-thumb {
  background: var(--scientific-cyan);
  border-radius: 3px;
}

.article-toc::-webkit-scrollbar-thumb:hover {
  background: var(--mad-magenta);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 1024px) {
  .article-toc {
    position: static;
    margin-bottom: var(--space-2xl);
    max-height: none;
  }

  .toc-toggle {
    display: block;
  }

  .toc-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .article-toc.expanded .toc-content {
    max-height: 1000px; /* Large enough for most TOCs */
  }

  .toc-progress {
    display: none; /* Hide on mobile, use top bar instead */
  }
}

@media (max-width: 768px) {
  .article-toc {
    padding: var(--space-lg);
  }

  .toc-header h3 {
    font-size: 1rem;
  }

  .toc-link {
    font-size: 0.875rem;
  }
}
