.toc-toggle-btn {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background-color: var(--secondary-background-color);
  border-right: 2px solid var(--light-color-alt);
  border-top: 2px solid var(--light-color-alt);
  border-bottom: 2px solid var(--light-color-alt);
  border-radius: 0;
  color: var(--light-color-alt);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toc-toggle-btn:hover {
  background-color: var(--main-theme-color);
  border-color: var(--main-theme-color);
  color: var(--primary-background-color);
  transform: translateY(-50%) scale(1.05);
}

.toc-toggle-btn.toc-active {
  display: none;
}

.toc-toggle-btn i {
  font-size: 2.4rem;
}

.toc-panel {
  position: fixed;
  left: -350px;
  top: 50%;
  transform: translateY(-50%);
  width: 320px;
  max-height: 70vh;
  background-color: var(--secondary-background-color);
  border-right: 2px solid var(--light-color-alt);
  border-top: 2px solid var(--light-color-alt);
  border-bottom: 2px solid var(--light-color-alt);
  border-radius: 0;
  z-index: 999;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.toc-panel.toc-active {
  left: 0;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem;
  border-bottom: 2px solid var(--light-color-alt);
  background-color: var(--primary-background-color);
}

.toc-title {
  font-size: 1.8rem;
  color: var(--main-theme-color);
  margin: 0;
  font-weight: 600;
}

.toc-close-btn {
  background: none;
  border: none;
  color: var(--light-color-alt);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.toc-close-btn:hover {
  color: var(--main-theme-color);
}

.toc-close-btn i {
  font-size: 2.4rem;
}

.toc-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
}

/* Custom scrollbar for webkit browsers - matches code snippet scrollbar style */
.toc-content::-webkit-scrollbar {
  display: none !important;
  width: 1rem;
}

.toc-content:hover::-webkit-scrollbar,
.toc-panel:hover .toc-content::-webkit-scrollbar {
  display: block !important;
}

.toc-content:hover,
.toc-panel:hover .toc-content {
  -ms-overflow-style: scrollbar !important;
  scrollbar-width: inherit !important;
}

.toc-content::-webkit-scrollbar-track {
  background-color: #f1f1f1;
  border-radius: 0;
}

.toc-content::-webkit-scrollbar-thumb {
  background-color: #3f4254;
  border-radius: 0;
}

.toc-content::-webkit-scrollbar-thumb:hover {
  background-color: #2e303b;
}

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

.toc-section-item {
  margin-bottom: 1rem;
}

.toc-section-item:last-child {
  margin-bottom: 0;
}

.toc-sublist {
  list-style: none;
  padding-left: 1.5rem;
  margin-top: 0.5rem;
}

.toc-subsection-item {
  margin-bottom: 0.5rem;
}

.toc-subsection-item:last-child {
  margin-bottom: 0;
}

.toc-link {
  display: block;
  color: var(--light-color-alt);
  text-decoration: none;
  padding: 0.6rem 1rem;
  border-radius: 0;
  transition: all 0.2s ease;
  font-size: 1.4rem;
  line-height: 1.4;
  position: relative;
}

.toc-link:hover {
  background-color: var(--transparent-light-color);
  color: var(--main-theme-color);
  padding-left: 1.5rem;
}

.toc-link.active {
  background-color: var(--transparent-light-color);
  color: var(--main-theme-color);
  font-weight: 600;
}

/* Section links */
.toc-section-link {
  font-weight: 600;
  font-size: 1.5rem;
}

/* Subsection links */
.toc-subsection-link {
  font-weight: 400;
  font-size: 1.3rem;
  opacity: 0.9;
}

.toc-subsection-link:hover {
  opacity: 1;
}

/* Tablet */
@media screen and (max-width: 1024px) {
  .toc-toggle-btn {
    left: 0;
    width: 45px;
    height: 45px;
  }

  .toc-toggle-btn i {
    font-size: 2.2rem;
  }

  .toc-panel {
    width: 300px;
    left: -330px;
  }

  .toc-panel.toc-active {
    left: 0;
  }
}

/* Mobile */
@media screen and (max-width: 768px) {
  .toc-toggle-btn {
    left: auto;
    right: 20px;
    bottom: 10px;
    top: auto;
    transform: none;
    width: 50px;
    height: 50px;
    border: 2px solid var(--light-color-alt);
    animation: none;
  }

  .toc-toggle-btn:hover {
    transform: scale(1.05);
  }

  .toc-toggle-btn i {
    font-size: 2.4rem;
  }

  .toc-panel {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    left: -100vw;
    top: 0;
    transform: none;
    border: none;
  }

  .toc-panel.toc-active {
    left: 0;
  }

  .toc-header {
    padding: 1.2rem 1.5rem;
  }

  .toc-title {
    font-size: 1.8rem;
  }

  .toc-content {
    padding: 1.2rem 1.5rem;
  }

  .toc-link {
    font-size: 1.4rem;
    padding: 0.5rem 0.8rem;
  }

  .toc-section-link {
    font-size: 1.5rem;
  }

  .toc-subsection-link {
    font-size: 1.3rem;
  }
}

/* Very small mobile devices */
@media screen and (max-width: 480px) {
  .toc-sublist {
    padding-left: 1rem;
  }
}

/* Focus styles for keyboard navigation */
.toc-toggle-btn:focus,
.toc-close-btn:focus,
.toc-link:focus {
  outline: 2px solid var(--main-theme-color);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .toc-toggle-btn,
  .toc-panel,
  .toc-link {
    transition: none;
  }
}

@media print {
  .toc-toggle-btn,
  .toc-panel {
    display: none;
  }
}

body.light-theme .toc-toggle-btn {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body.light-theme .toc-panel {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-20px) translateY(-50%);
  }
  to {
    opacity: 1;
    transform: translateX(0) translateY(-50%);
  }
}

.toc-toggle-btn {
  animation: slideInFromLeft 0.5s ease-out 0.5s both;
}

@media screen and (max-width: 768px) {
  .toc-panel.toc-active::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: -1;
    animation: fadeIn 0.3s ease;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.toc-empty {
  text-align: center;
  padding: 2rem;
  color: var(--light-color-alt);
  font-style: italic;
}

.toc-link {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-link:hover {
  white-space: normal;
  word-wrap: break-word;
}
