/* Table of Contents */
#toc {
  position: fixed;
  left: 15px;
  top: 200px; /* Align with article content top */
  width: 200px;
  max-height: calc(100vh - 250px); /* Dynamic height based on viewport */
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #d2d2d2;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  font-size: 12px;
  line-height: 1.4;
  backdrop-filter: blur(10px);
}

.toc-title {
  font-weight: bold;
  margin-bottom: 15px;
  color: #333;
  border-bottom: 2px solid #0065b3;
  padding-bottom: 8px;
  font-size: 14px;
  text-align: center;
}

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

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

.toc-item {
  margin: 0;
  padding: 0;
}

.toc-level-2 {
  margin-bottom: 8px;
}

.toc-level-3 {
  margin-bottom: 4px;
}

.toc-link {
  display: block;
  color: #505050;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.toc-level-2 > .toc-link {
  font-weight: 500;
  padding-left: 8px;
}

.toc-level-3 .toc-link {
  padding-left: 16px;
  font-size: 12px;
  color: #737373;
}

.toc-link:hover {
  background-color: #f5f5f5;
  color: #0065b3;
  text-decoration: none;
  border-left-color: #0065b3;
}

.toc-link.active {
  background-color: #e8f4fd;
  color: #0065b3;
  border-left-color: #0065b3;
  font-weight: 600;
}

.toc-level-3 .toc-link.active {
  font-weight: 500;
}

/* Scrollbar styling */
#toc::-webkit-scrollbar {
  width: 6px;
}

#toc::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#toc::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#toc::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Responsive design */
@media screen and (max-width: 1200px) {
  #toc {
    display: none;
  }
}

@media screen and (min-width: 1201px) and (max-width: 1399px) {
  #toc {
    left: 10px;
    width: 180px;
    top: 180px;
  }
}

/* Large screen adjustments */
@media screen and (min-width: 1400px) {
  #toc {
    left: 20px;
    width: 220px;
    top: 200px;
  }
}

@media screen and (min-width: 1600px) {
  #toc {
    left: 30px;
    width: 240px;
    top: 220px;
  }
}

/* Animation */
@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#toc {
  animation: fadeInLeft 0.3s ease-out;
}

/* Main content area adjustment when TOC is displayed */
@media screen and (min-width: 1201px) {
  body.has-toc .outer {
    margin-left: 240px;
  }
}

@media screen and (min-width: 1400px) {
  body.has-toc .outer {
    margin-left: 270px;
  }
}

@media screen and (min-width: 1600px) {
  body.has-toc .outer {
    margin-left: 300px;
  }
}