/* Modern Table of Contents (Right Sidebar) Styling */

/* Main TOC Container - Default Theme (Purple Gradient) */
.book-toc {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.book-toc nav {
  background: transparent;
  padding: 1.5rem 1.25rem !important;
}

/* TOC Header/Title Styling */
.book-toc nav > ul:first-child::before {
  content: 'On This Page';
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

/* TOC List Styling */
.book-toc nav ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.book-toc nav ul li {
  margin: 0.5rem 0;
  position: relative;
}

/* TOC Links */
.book-toc nav ul a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.5;
  border-left: 3px solid transparent;
  transition: all 0.3s ease;
  border-radius: 0 4px 4px 0;
  position: relative;
}

/* Hover Effect */
.book-toc nav ul a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-left-color: rgba(255, 255, 255, 0.5);
  transform: translateX(3px);
}

/* Active/Current Section */
.book-toc nav ul a.active,
.book-toc nav ul a[aria-current="true"] {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  border-left-color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Nested List Items (H3, H4, etc.) */
.book-toc nav ul ul {
  padding-left: 0.75rem;
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.book-toc nav ul ul li {
  margin: 0.375rem 0;
}

.book-toc nav ul ul a {
  font-size: 0.8125rem;
  padding: 0.375rem 0.625rem;
  color: rgba(255, 255, 255, 0.8);
}

.book-toc nav ul ul a:hover {
  color: #fff;
  border-left-color: rgba(255, 255, 255, 0.6);
}

/* Third Level Nesting */
.book-toc nav ul ul ul {
  padding-left: 0.625rem;
  border-left-color: rgba(255, 255, 255, 0.15);
}

.book-toc nav ul ul ul a {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Scroll Progress Indicator */
.book-toc::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: rgba(255, 255, 255, 0.3);
  opacity: 0.5;
}

/* Smooth Scrolling for TOC Navigation */
.book-toc a {
  scroll-behavior: smooth;
}

/* Custom Scrollbar for TOC */
.book-toc nav::-webkit-scrollbar {
  width: 5px;
}

.book-toc nav::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

.book-toc nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  transition: background 0.3s ease;
}

.book-toc nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Sticky Positioning Enhancement */
.book-toc nav {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

/* Empty State (No TOC) */
.book-toc:empty::after {
  content: 'No headings in this page';
  display: block;
  padding: 1rem;
  text-align: center;
  color: #999;
  font-size: 0.875rem;
  font-style: italic;
}

/* Reading Progress Dots */
.book-toc nav ul li::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.book-toc nav ul a:hover + li::before,
.book-toc nav ul a.active ~ li::before {
  background: rgba(255, 255, 255, 0.8);
  transform: translateY(-50%) scale(1.3);
}

/* Mobile Responsiveness */
@media screen and (max-width: 1200px) {
  .book-toc {
    display: none;
  }
}

/* Tablet - Show TOC but make it collapsible */
@media screen and (min-width: 1201px) and (max-width: 1400px) {
  .book-toc {
    flex: 0 0 14rem;
  }
  
  .book-toc nav {
    width: 14rem;
    padding: 1rem !important;
  }
  
  .book-toc nav ul a {
    font-size: 0.8125rem;
    padding: 0.375rem 0.625rem;
  }
}

/* Large Screens - Full Width */
@media screen and (min-width: 1920px) {
  .book-toc {
    flex: 0 0 18rem;
  }
  
  .book-toc nav {
    width: 18rem;
    padding: 2rem 1.5rem !important;
  }
}

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

/* Accessibility - Focus Styles */
.book-toc nav ul a:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
  background: rgba(102, 126, 234, 0.08);
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .book-toc nav ul a {
    border-left-width: 4px;
  }
  
  .book-toc nav ul a:hover,
  .book-toc nav ul a.active {
    background: #667eea;
    color: #fff;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .book-toc nav ul a,
  .book-toc nav ul li::before {
    transition: none;
  }
}

/* Dark Mode Support (if enabled) */
@media (prefers-color-scheme: dark) {
  .book-toc {
    background: #1a1a1a;
    border-left-color: #333;
  }
  
  .book-toc nav ul a {
    color: #ccc;
  }
  
  .book-toc nav ul a:hover {
    color: #8ba3ff;
    background: rgba(139, 163, 255, 0.1);
  }
  
  .book-toc nav ul a.active {
    color: #8ba3ff;
    background: rgba(139, 163, 255, 0.15);
  }
}

/* =================================================================
   THEME VARIATIONS - Match Left Sidebar Themes
   ================================================================= */

/* Theme 2: Light Professional */
.sidebar-theme-light .book-toc {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  border-left: 1px solid #e0e0e0;
  box-shadow: -2px 0 15px rgba(0, 0, 0, 0.08);
}

.sidebar-theme-light .book-toc nav > ul:first-child::before {
  color: #333;
  border-bottom-color: #667eea;
}

.sidebar-theme-light .book-toc nav ul a {
  color: #555;
}

.sidebar-theme-light .book-toc nav ul a:hover {
  color: #667eea;
  background: rgba(102, 126, 234, 0.08);
  border-left-color: #667eea;
}

.sidebar-theme-light .book-toc nav ul a.active {
  color: #667eea;
  background: rgba(102, 126, 234, 0.15);
  border-left-color: #764ba2;
}

.sidebar-theme-light .book-toc nav ul ul a {
  color: #666;
}

.sidebar-theme-light .book-toc nav::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.sidebar-theme-light .book-toc nav::-webkit-scrollbar-thumb {
  background: #d0d0d0;
}

.sidebar-theme-light .book-toc nav::-webkit-scrollbar-thumb:hover {
  background: #667eea;
}

.sidebar-theme-light .book-toc::before {
  background: linear-gradient(to bottom, #667eea 0%, #764ba2 100%);
  opacity: 0.2;
}

.sidebar-theme-light .book-toc nav ul li::before {
  background: #e0e0e0;
}

.sidebar-theme-light .book-toc nav ul a:hover + li::before,
.sidebar-theme-light .book-toc nav ul a.active ~ li::before {
  background: #667eea;
}

/* Theme 3: Ocean Blue */
.sidebar-theme-ocean .book-toc {
  background: linear-gradient(135deg, #0093E9 0%, #80D0C7 100%);
}

.sidebar-theme-ocean .book-toc nav ul a:hover {
  background: rgba(255, 255, 255, 0.2);
  border-left-color: rgba(255, 255, 255, 0.6);
}

.sidebar-theme-ocean .book-toc nav ul a.active {
  background: rgba(255, 255, 255, 0.25);
  border-left-color: #fff;
}

/* Theme 4: Sunset Orange */
.sidebar-theme-sunset .book-toc {
  background: linear-gradient(135deg, #FA8BFF 0%, #2BD2FF 50%, #2BFF88 100%);
}

.sidebar-theme-sunset .book-toc nav ul a:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-theme-sunset .book-toc nav ul a.active {
  background: rgba(255, 255, 255, 0.25);
}

/* Theme 5: Dark Mode (True Black) */
.sidebar-theme-dark .book-toc {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  box-shadow: -2px 0 20px rgba(0, 0, 0, 0.5);
  border-left-color: rgba(100, 255, 218, 0.2);
}

.sidebar-theme-dark .book-toc nav > ul:first-child::before {
  color: rgba(255, 255, 255, 0.9);
  border-bottom-color: #64ffda;
}

.sidebar-theme-dark .book-toc nav ul a {
  color: rgba(255, 255, 255, 0.85);
}

.sidebar-theme-dark .book-toc nav ul a:hover {
  color: #64ffda;
  background: rgba(100, 255, 218, 0.1);
  border-left-color: #64ffda;
}

.sidebar-theme-dark .book-toc nav ul a.active {
  color: #64ffda;
  background: rgba(100, 255, 218, 0.15);
  border-left-color: #64ffda;
}

.sidebar-theme-dark .book-toc::before {
  background: #64ffda;
  opacity: 0.3;
}

.sidebar-theme-dark .book-toc nav::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-theme-dark .book-toc nav::-webkit-scrollbar-thumb {
  background: rgba(100, 255, 218, 0.3);
}

.sidebar-theme-dark .book-toc nav::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 255, 218, 0.5);
}

/* Theme 6: Minimal Gray */
.sidebar-theme-minimal .book-toc {
  background: #f8f9fa;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.05);
  border-left: 1px solid #e0e0e0;
}

.sidebar-theme-minimal .book-toc nav > ul:first-child::before {
  color: #212529;
  border-bottom-color: #212529;
}

.sidebar-theme-minimal .book-toc nav ul a {
  color: #495057;
}

.sidebar-theme-minimal .book-toc nav ul a:hover {
  color: #212529;
  background: #e9ecef;
  border-left-color: #212529;
}

.sidebar-theme-minimal .book-toc nav ul a.active {
  color: #fff;
  background: #212529;
  border-left-color: #212529;
}

.sidebar-theme-minimal .book-toc nav ul ul a {
  color: #6c757d;
}

.sidebar-theme-minimal .book-toc::before {
  background: #212529;
  opacity: 0.2;
}

.sidebar-theme-minimal .book-toc nav::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.sidebar-theme-minimal .book-toc nav::-webkit-scrollbar-thumb {
  background: #ced4da;
}

.sidebar-theme-minimal .book-toc nav::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

.sidebar-theme-minimal .book-toc nav ul li::before {
  background: #dee2e6;
}

.sidebar-theme-minimal .book-toc nav ul a:hover + li::before,
.sidebar-theme-minimal .book-toc nav ul a.active ~ li::before {
  background: #212529;
}

/* Smooth transitions between themes */
.book-toc,
.book-toc nav ul a,
.book-toc::before {
  transition: background 0.5s ease, color 0.5s ease, border-color 0.5s ease;
}

/* Section Dividers */
.book-toc nav > ul > li {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.book-toc nav > ul > li:last-child {
  border-bottom: none;
}

/* Light themes need darker dividers */
.sidebar-theme-light .book-toc nav > ul > li,
.sidebar-theme-minimal .book-toc nav > ul > li {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

/* Heading Level Indicators */
.book-toc nav ul a[href*="#"]:not([href="#"])::after {
  content: '→';
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

.sidebar-theme-light .book-toc nav ul a::after,
.sidebar-theme-minimal .book-toc nav ul a::after {
  color: #667eea;
}

.sidebar-theme-dark .book-toc nav ul a::after {
  color: #64ffda;
}

.book-toc nav ul a:hover::after {
  opacity: 1;
}

/* Compact Mode (Optional) */
.book-toc.compact nav ul li {
  margin: 0.25rem 0;
}

.book-toc.compact nav ul a {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

/* Expanded Mode (Optional) */
.book-toc.expanded nav ul li {
  margin: 0.75rem 0;
}

.book-toc.expanded nav ul a {
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
}
