/* Table of Contents Styles
   ––––––––––––––––––––––––––––––––––––––––––––––––––– */

.toc-container {
  --toc-background: #ffffff;
  --toc-border: rgba(0, 0, 0, 0.1);
  --toc-text: #151618;
  --toc-link: #333333;
  --toc-active: var(--ghost-accent-color, #0094da);
  --toc-hover: var(--ghost-accent-color, #0094da);
  --toc-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --toc-overlay: rgba(0, 0, 0, 0.5);
  --toc-button-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  
  font-size: 1.5rem !important;
  line-height: 1.5;
  z-index: 2002;
  position: relative;
}

/* Dark mode support - using the theme's dark mode class */
.dark-mode .toc-container {
  --toc-background: #1a1b1e;
  --toc-border: rgba(255, 255, 255, 0.1);
  --toc-text: #f7f7f5;
  --toc-link: rgba(255, 255, 255, 0.8);
  --toc-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  --toc-overlay: rgba(0, 0, 0, 0.7);
}

/* Toggle Button */
.toc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: 40px;
  padding: 0.75rem 1rem;
  background-color: var(--toc-active);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.8rem !important;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: var(--toc-button-shadow);
  outline: none;
}

.toc-toggle:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  background-color: var(--toc-active);
  color: #ffffff;
}

.toc-toggle:focus,
.toc-toggle:focus-visible {
  background-color: var(--toc-active);
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 148, 218, 0.3);
  outline: none;
}

.toc-toggle:active {
  background-color: var(--toc-active);
  color: #ffffff;
  opacity: 0.8;
  transform: translateY(0);
}

.toc-icon {
  flex-shrink: 0;
}

/* TOC Wrapper */
.toc-wrapper {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--toc-background);
  border: 1px solid var(--toc-border);
  border-radius: 8px;
  margin-top: 1rem;
  box-shadow: var(--toc-shadow);
  z-index: 2001;
}

.toc-header {
  display: none;
  padding: 1.5rem;
  border-bottom: 1px solid var(--toc-border);
  position: sticky;
  top: 0;
  background: var(--toc-background);
  z-index: 2;
}

.toc-header h2 {
  margin: 0;
  font-size: 1.8rem !important;
  color: var(--toc-text);
}

.toc-close {
  display: none;
  padding: 1rem;
  background: #ff4444;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: white;
  position: absolute;
  right: 1.5rem;
  top: 0.5rem;
  width: 4rem;
  height: 4rem;
  transition: all 0.2s ease;
}

.toc-close:hover {
  background: #ff6666;
  transform: scale(1.1);
}

.toc-wrapper.expanded {
  max-height: 80vh;
  overflow-y: auto;
  transform: translateX(0);
  pointer-events: auto;
  opacity: 1;
}

/* TOC Navigation */
.toc {
  padding: 1.5rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list .toc-list {
  padding-left: 2rem;
  margin-top: 0.5rem;
  margin-left: 0.5rem;
  border-left: 2px solid var(--toc-border);
}

.toc-list-item {
  margin: 0.75rem 0;
}

.toc-link {
  color: var(--toc-link);
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-weight: 400;
  width: 100%;
  border-radius: 4px;
  font-size: 1.5rem !important;
}

.toc-link:hover,
.toc-link:focus {
  color: var(--toc-hover);
  padding-left: 1rem;
  background-color: rgba(0, 148, 218, 0.1);
}

.dark-mode .toc-link:hover,
.dark-mode .toc-link:focus {
  background-color: rgba(0, 148, 218, 0.2);
}

.is-active-link {
  color: var(--toc-active) !important;
  font-weight: 600;
  background-color: rgba(0, 148, 218, 0.05);
}

.dark-mode .is-active-link {
  background-color: rgba(0, 148, 218, 0.15);
}

/* Overlay */
.toc-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: transparent; /* Transparent on desktop for click-to-close */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 2000;
}

.toc-overlay.active {
  opacity: 1;
  display: block;
  pointer-events: auto;
}

/* Mobile overlay with background */
@media (max-width: 767px) {
  .toc-overlay {
    background-color: var(--toc-overlay);
  }
}

/* Mobile Styles */
@media (max-width: 767px) {
  .toc-container.is-mobile {
    position: fixed;
    bottom: 2.5rem;
    left: 2.5rem;
    margin: 0;
    width: auto;
    z-index: 2002;
  }

  .toc-container.is-mobile .toc-toggle {
    width: auto;
    height: 6rem;
    border-radius: 999px;
    padding: 0 2rem;
    background-color: var(--toc-active);
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(0, 148, 218, 0.4);
    animation: pulse 2s infinite;
  }
  
  .toc-container.is-mobile .toc-toggle:focus,
  .toc-container.is-mobile .toc-toggle:active {
    background-color: var(--toc-active);
    color: #ffffff !important;
  }

  @keyframes pulse {
    0% {
      box-shadow: 0 0 0 0 rgba(0, 148, 218, 0.4);
    }
    70% {
      box-shadow: 0 0 0 10px rgba(0, 148, 218, 0);
    }
    100% {
      box-shadow: 0 0 0 0 rgba(0, 148, 218, 0);
    }
  }

  .toc-container.is-mobile .toc-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    max-height: 100vh;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 2001;
  }

  .toc-container.is-mobile .toc-wrapper.expanded {
    transform: translateX(0);
  }

  .toc-container.is-mobile .toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .toc-container.is-mobile .toc-close {
    display: block;
  }

  .toc-container.is-mobile .toc {
    height: calc(100vh - 8rem);
    overflow-y: auto;
    padding-bottom: 2rem;
  }

  .toc-container.is-mobile .toc-overlay {
    display: block;
  }
}

/* Desktop Styles */
@media (min-width: 768px) {
  .toc-container {
    position: fixed;
    top: 50%;
    right: 2rem;
    transform: translateY(-50%);
    width: auto;
    z-index: 2002;
  }
  
  /* Show toggle button on desktop as a floating button */
  .toc-container .toc-toggle {
    display: flex;
    width: auto;
    height: auto;
    padding: 1rem 1.5rem;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    background-color: var(--toc-active);
    color: #ffffff !important;
  }
  
  .toc-container .toc-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    background-color: var(--toc-active);
    color: #ffffff !important;
  }
  
  .toc-container .toc-toggle:focus,
  .toc-container .toc-toggle:focus-visible {
    background-color: var(--toc-active);
    color: #ffffff !important;
    box-shadow: 0 0 0 3px rgba(0, 148, 218, 0.3);
  }
  
  .toc-container .toc-toggle:active {
    background-color: var(--toc-active);
    color: #ffffff !important;
    transform: scale(0.98);
  }
  
  /* TOC wrapper hidden by default on desktop */
  .toc-container .toc-wrapper {
    position: fixed;
    top: 50%;
    right: 100px;
    transform: translateY(-50%);
    width: 350px;
    max-height: 0;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    margin-top: 0;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  /* Show TOC when expanded */
  .toc-container .toc-wrapper.expanded {
    max-height: 70vh;
    overflow-y: auto;
    opacity: 1;
  }
}

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

/* Tocbot overrides */
.toc-list-container {
  padding: 0;
}

.toc-list-container > .toc-list {
  padding-left: 0;
}

.node-name--H2 {
  font-weight: 500;
}

.node-name--H3 {
  font-size: 1.4rem !important;
}

/* Smooth scrolling for anchor links */
html {
  scroll-behavior: smooth;
}

/* Scroll padding to account for fixed header */
html {
  scroll-padding-top: 100px;
}