/* Table of Contents Sidebar */
.toc-sidebar {
    position: fixed;
    top: 120px;
    right: 0;
    width: 320px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(25px);
    border-radius: 20px 0 0 20px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-right: none;
    z-index: 1000;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
    transform: translateX(0);
    opacity: 1;
    pointer-events: all;
    scroll-behavior: smooth; /* Enable smooth scrolling */
}

body.dark-mode .toc-sidebar {
    background: rgba(45, 55, 72, 0.4);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
}

.toc-title {
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

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

.toc-item {
    margin-bottom: 0.3rem;
}

.toc-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.6rem 1rem;
    display: block;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    border-radius: 8px;
    border-left: 3px solid transparent;
    position: relative; /* For scroll positioning */
}

.toc-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    border-left-color: #63b3ed;
    transform: translateX(5px);
}

.toc-link.active {
    color: #63b3ed;
    background: rgba(99, 179, 237, 0.15);
    border-left-color: #63b3ed;
    font-weight: 500;
    box-shadow: 0 0 10px rgba(99, 179, 237, 0.3);
}

.toc-subheader {
    padding-left: 2rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

.toc-subheader:hover {
    color: rgba(255, 255, 255, 0.9);
    border-left-color: rgba(255, 255, 255, 0.4);
}

.toc-subheader.active {
    color: #63b3ed;
    background: rgba(99, 179, 237, 0.1);
    border-left-color: #63b3ed;
    font-weight: 500;
}

/* TOC Toggle Button */
.toc-toggle {
    display: none;
}

/* Hide TOC on mobile */
@media (max-width: 1200px) {
    .toc-sidebar {
        display: none;
    }
}

@media (min-width: 1200px) {
    main {
        margin-right: 0;
    }
}

/* Scroll margin for headers */
.section-header {
    scroll-margin-top: 100px;
}

/* Scrollbar styling for TOC indicator */
.toc-indicator::-webkit-scrollbar {
    width: 3px;
}

.toc-indicator::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.toc-indicator::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

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

/* Scrollbar styling for TOC */
.toc-sidebar::-webkit-scrollbar {
    width: 6px;
}

.toc-sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.toc-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

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

/* ToC Indicator */
.toc-indicator {
    position: fixed;
    top: 120px;
    right: 8px;
    width: 12px;
    max-height: calc(100vh - 180px);
    z-index: 998;
    pointer-events: none;
    transition: all 0.3s ease;
    overflow-y: auto;
    overflow-x: visible;
    padding-right: 10px;
    margin-right: -10px;
}

.toc-indicator.hidden {
    opacity: 0.6;
}

.toc-indicator.visible {
    opacity: 0;
}

.toc-indicator-item {
    width: 100%;
    margin-bottom: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    transition: all 0.3s ease;
    cursor: pointer;
    pointer-events: all;
    transform-origin: right;
}

.toc-indicator-item.header {
    height: 20px;
    background: rgba(255, 255, 255, 0.5);
}

.toc-indicator-item.subheader {
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    margin-left: 4px;
    width: 8px;
}

.toc-indicator-item.active {
    background: #63b3ed;
    box-shadow: 0 0 12px #63b3ed, 0 0 5px rgba(99, 179, 237, 0.7);
}

.toc-indicator-item:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: scaleX(1.75);
}

body.dark-mode .toc-indicator-item {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .toc-indicator-item.header {
    background: rgba(255, 255, 255, 0.4);
}

body.dark-mode .toc-indicator-item:hover {
    background: rgba(255, 255, 255, 0.7);
}

/* Hide indicator on mobile */
@media (max-width: 1200px) {
    .toc-indicator {
        display: none;
    }
}