html {
    scroll-behavior: smooth;
}

/* Layout: TOC sidebar + content */
#mainsection.toc-active {
    display: flex;
    flex-direction: row;
    max-width: var(--container-width) !important;
}

.glesys-toc-content {
    max-width: 776px;
}

.glesys-toc-content h1,
.glesys-toc-content h2,
.glesys-toc-content h3,
.glesys-toc-content h4,
.glesys-toc-content h5,
.glesys-toc-content h6 {
    scroll-margin-top: 172px !important;
}

.glesys-toc {
    margin-bottom: 32px;
    padding-left: var(--padding-m) !important;
    font-family: var(--font-family-primary, 'Aeonik', sans-serif);
    position: sticky;
    top: 172px;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 310px;
}

/* TOC items start hidden, animate in with stagger */
.glesys-toc--visible .glesys-toc__title,
.glesys-toc--visible .glesys-toc__item {
    opacity: 0;
    animation: tocFadeIn 0.35s ease forwards;
}

@keyframes tocFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.glesys-toc__nav {
    padding: 0;
}

/* Reset all lists in TOC */
.glesys-toc ul,
.glesys-toc li {
    margin: 0;
    padding: 0;
    list-style: none !important;
    list-style-type: none !important;
    max-width: 20ch;
}

.glesys-toc__list {
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.glesys-toc__item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.glesys-toc__list > li > .glesys-toc__sublist {
    padding-left: 14px !important;
}

.glesys-toc__sublist .glesys-toc__sublist {
    padding-left: 0 !important;
}

/* All TOC links */
.root-toc-link {
    color: var(--glesys-gray-900);
    font-size: var(--text-xs);
    font-style: normal;
    font-weight: 400;
    line-height: 120%;
    text-decoration: none;
    transition: color 0.15s ease;
}

.glesys-toc__item > a,
a.glesys-toc__title {
    color: rgba(0, 0, 0, 0.40);
}

.glesys-toc__item > a:hover,
a.glesys-toc__title:hover {
    color: var(--glesys-gray-900);
}

.glesys-toc__item > a.glesys-toc__link--active,
a.glesys-toc__title.glesys-toc__link--active {
    color: var(--glesys-gray-900);
}

/* Hide TOC on smaller screens */
@media (max-width: 980px) {
    .glesys-toc {
        display: none !important;
    }
}

/* Nested sublists */
.glesys-toc__sublist {
    margin: 0;
    padding: 0 0 0 14px !important;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
