/* Ali Blog TOC - Ali Software Development
 * Cormak styled sticky table of contents
 */

:root {
    --ali-toc-accent: #e30613;
    --ali-toc-accent-dark: #b9000a;
    --ali-toc-text: #202124;
    --ali-toc-muted: #666b72;
    --ali-toc-border: #e6e6e6;
    --ali-toc-bg: #ffffff;
    --ali-toc-soft: #f7f7f7;
    --ali-toc-scroll-offset: 132px;
    --ali-toc-sticky-top: 132px;
}

.ali-blog-layout {
    display: grid;
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    gap: 44px;
    align-items: start;
    width: 100%;
}

/* The whole sidebar is sticky. This is more reliable than making only
   the inner panel sticky and makes it stop naturally at article end. */
.ali-blog-layout__sidebar {
    position: -webkit-sticky;
    position: sticky;
    top: var(--ali-toc-sticky-top, 132px);
    align-self: start;
    min-width: 0;
    height: fit-content;
    z-index: 20;
}

.ali-blog-layout__content {
    min-width: 0;
}

.ali-blog-toc {
    position: relative;
    width: 100%;
    max-height: calc(100vh - 138px);
    overflow: hidden;
    border: 1px solid var(--ali-toc-border);
    border-radius: 8px;
    background: var(--ali-toc-bg);
    box-shadow: 0 6px 22px rgba(0, 0, 0, .055);
}

.ali-blog-toc::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--ali-toc-accent);
    z-index: 2;
}

.ali-blog-toc__panel {
    max-height: calc(100vh - 138px);
    overflow-y: auto;
    padding: 0 0 12px;
    scrollbar-width: thin;
    scrollbar-color: #bfc2c6 transparent;
}

.ali-blog-toc__panel::-webkit-scrollbar {
    width: 5px;
}

.ali-blog-toc__panel::-webkit-scrollbar-track {
    background: transparent;
}

.ali-blog-toc__panel::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: #c8c8c8;
}

.ali-blog-toc__title {
    position: relative;
    margin: 0 0 7px;
    padding: 20px 20px 15px;
    border-bottom: 1px solid #ededed;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.3;
    letter-spacing: .015em;
    text-transform: uppercase;
    color: #151515;
    background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
}

.ali-blog-toc__title::after {
    content: '';
    display: block;
    width: 38px;
    height: 3px;
    margin-top: 9px;
    border-radius: 4px;
    background: var(--ali-toc-accent);
}

.ali-blog-toc__nav {
    padding: 3px 10px 0;
}

.ali-blog-toc__list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ali-blog-toc__item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ali-blog-toc__link {
    position: relative;
    display: block;
    margin: 2px 0;
    padding: 9px 10px 9px 14px;
    border: 0 !important;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.42;
    text-decoration: none !important;
    color: var(--ali-toc-text);
    transition: color .18s ease, background-color .18s ease, transform .18s ease;
}

/* H2 = strong section headings */
.ali-blog-toc__item--h2 .ali-blog-toc__link {
    font-weight: 800;
    color: #1b1b1b;
}

/* H3/H4 keep the hierarchy visibly clear. */
.ali-blog-toc__item--h3 .ali-blog-toc__link {
    padding-left: 26px;
    font-size: 13.5px;
    font-weight: 650;
    color: #4d5156;
}

.ali-blog-toc__item--h4 .ali-blog-toc__link {
    padding-left: 39px;
    font-size: 13px;
    font-weight: 600;
    color: #757980;
}

.ali-blog-toc__item--h3 .ali-blog-toc__link::after,
.ali-blog-toc__item--h4 .ali-blog-toc__link::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #c7c7c7;
    transform: translateY(-50%);
}

.ali-blog-toc__item--h3 .ali-blog-toc__link::after {
    left: 15px;
}

.ali-blog-toc__item--h4 .ali-blog-toc__link::after {
    left: 28px;
}

.ali-blog-toc__link:hover {
    color: #111111;
    background: #f3f3f3;
    transform: translateX(2px);
}

.ali-blog-toc__link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: transparent;
    transition: background-color .18s ease;
}

.ali-blog-toc__link.is-active {
    color: var(--ali-toc-accent-dark);
    font-weight: 800;
    background: rgba(227, 6, 19, .085);
    box-shadow: inset 0 0 0 1px rgba(227, 6, 19, .045);
}

.ali-blog-toc__link.is-active::before {
    background: var(--ali-toc-accent);
}

.ali-blog-toc__link.is-active::after {
    background: var(--ali-toc-accent);
}

.ali-blog-toc__mobile-toggle {
    display: none;
}

.ali-blog-anchor-heading {
    scroll-margin-top: var(--ali-toc-scroll-offset, 132px);
}

@media (max-width: 1199.98px) and (min-width: 992px) {
    .ali-blog-layout {
        grid-template-columns: 225px minmax(0, 1fr);
        gap: 28px;
    }

    .ali-blog-toc__link {
        font-size: 13px;
    }

    .ali-blog-layout__sidebar {
        top: var(--ali-toc-sticky-top, 132px);
    }
}

@media (max-width: 991.98px) {
    .ali-blog-layout {
        display: flex;
        flex-direction: column;
        gap: 18px;
    }

    .ali-blog-layout__sidebar,
    .ali-blog-layout__content {
        position: static;
        width: 100%;
        height: auto;
    }

    .ali-blog-toc {
        max-height: none;
        overflow: visible;
        border-radius: 7px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, .045);
    }

    .ali-blog-toc__mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 17px 18px 15px;
        border: 0;
        background: transparent;
        font: inherit;
        font-size: 14px;
        font-weight: 800;
        text-align: left;
        text-transform: uppercase;
        color: #171717;
        cursor: pointer;
    }

    .ali-blog-toc__mobile-toggle > span:first-child::after {
        content: '';
        display: block;
        width: 32px;
        height: 3px;
        margin-top: 7px;
        border-radius: 3px;
        background: var(--ali-toc-accent);
    }

    .ali-blog-toc__chevron {
        width: 9px;
        height: 9px;
        margin-right: 3px;
        border-right: 2px solid var(--ali-toc-accent);
        border-bottom: 2px solid var(--ali-toc-accent);
        transform: rotate(45deg) translateY(-2px);
        transition: transform .2s ease;
    }

    .ali-blog-toc--open .ali-blog-toc__chevron {
        transform: rotate(225deg) translate(-2px, -2px);
    }

    .ali-blog-toc__panel {
        display: none;
        max-height: 60vh;
        overflow-y: auto;
        padding: 6px 10px 12px;
        border-top: 1px solid #eeeeee;
    }

    .ali-blog-toc--open .ali-blog-toc__panel {
        display: block;
    }

    .ali-blog-toc__title {
        display: none;
    }

    .ali-blog-toc__nav {
        padding: 0;
    }

    .ali-blog-toc__link {
        padding-top: 9px;
        padding-bottom: 9px;
    }
}
