/* Article Table of Contents */

/* Layout: 文章+目录上下结构，目录在上方 */
.toc-layout {
    display: block;
}
.toc-layout > .article-content,
.toc-layout > #main-content {
    width: 100%;
}

/* Top position: 目录放文章上方，横向折叠条 */
.toc-pos-top .toc-sidebar {
    position: relative;
    top: auto;
    max-width: 980px;
    width: calc(100% - 2rem);
    margin: 0 auto 1.25rem;
    max-height: none;
    grid-column: auto;
    grid-row: auto;
    float: none;
    width: 100%;
}

/* 旧 right/left/bottom 兼容（不再使用） */
.toc-pos-right .toc-sidebar,
.toc-pos-left .toc-sidebar {
    position: sticky;
    top: 80px;
    align-self: start;
    max-height: calc(100vh - 100px);
}
.toc-pos-right .toc-sidebar { float: right; width: 240px; margin-left: 1.5rem; margin-bottom: 1rem; }
.toc-pos-left  .toc-sidebar { float: left;  width: 240px; margin-right: 1.5rem; margin-bottom: 1rem; }

.toc-sidebar {
    background: var(--gt-card-bg, #fff);
    border-radius: var(--gt-main-radius, 0.5rem);
    box-shadow: var(--gt-box-shadow, 0 3px 8px 6px rgba(7,17,27,0.05));
    padding: 0;
    font-size: 0.85rem;
    overflow: hidden;
    display: block;
}
.toc-mobile-fab { display: none !important; }

.toc-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gt-font-color);
    border-bottom: 1px solid var(--gt-border-color, rgba(0,0,0,0.08));
    cursor: pointer;
    user-select: none;
}
.toc-pos-top .toc-header {
    border-bottom: none;
}
.toc-header i {
    color: var(--gt-main-color, #007fff);
    font-size: 1.1rem;
}
.toc-toggle-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gt-font-56, rgba(52,73,94,0.56));
    padding: 0;
    font-size: 1rem;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
}
.toc-sidebar.collapsed .toc-toggle-btn {
    transform: rotate(-90deg);
}
.toc-sidebar.collapsed .toc-body {
    display: none;
}

/* Top: 横向滚动 */
.toc-pos-top .toc-body {
    padding: 0.5rem 0.75rem 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
}
.toc-pos-top .toc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.4rem;
}
.toc-pos-top .toc-sublist {
    padding-left: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.4rem;
}
.toc-pos-top .toc-item {
    display: inline-flex;
}
.toc-pos-top .toc-item a {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--gt-border-color, rgba(0,0,0,0.08));
    background: var(--gt-bg-fa, #fafafa);
    white-space: nowrap;
    font-size: 0.82rem;
    border-left: none;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}
.toc-pos-top .toc-item a:hover {
    background: var(--gt-main-color-6, rgba(0,127,255,0.06));
    border-color: var(--gt-main-color, #007fff);
}
.toc-pos-top .toc-item.active a {
    background: var(--gt-main-color, #007fff);
    color: #fff;
    border-color: var(--gt-main-color, #007fff);
    font-weight: 500;
}
.toc-pos-top .toc-sublist .toc-item a {
    font-size: 0.78rem;
    padding: 0.25rem 0.6rem;
    background: transparent;
    color: var(--gt-font-66, rgba(52,73,94,0.66));
}
.toc-pos-top .toc-sublist .toc-item a:hover {
    color: var(--gt-main-color, #007fff);
    background: var(--gt-main-color-6, rgba(0,127,255,0.06));
}

/* Side (right/left) - 旧竖向样式保留 */
.toc-body {
    padding: 0.5rem 0;
    overflow-y: auto;
    max-height: calc(100vh - 160px);
}
.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.toc-sublist {
    padding-left: 1rem;
}
.toc-item {
    margin: 0;
}
.toc-item a {
    display: block;
    padding: 0.35rem 1rem;
    color: var(--gt-font-66, rgba(52,73,94,0.66));
    text-decoration: none;
    font-size: 0.82rem;
    line-height: 1.5;
    border-left: 2px solid transparent;
    transition: all 0.15s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.toc-item a:hover {
    color: var(--gt-main-color, #007fff);
    background: var(--gt-main-color-6, rgba(0,127,255,0.06));
}
.toc-item.active a {
    color: var(--gt-main-color, #007fff);
    border-left-color: var(--gt-main-color, #007fff);
    font-weight: 500;
    background: var(--gt-main-color-6, rgba(0,127,255,0.06));
}

/* Mobile: top 模式下变回折叠 */
@media (max-width: 1023px) {
    .toc-mobile-fab { display: none !important; }
    .toc-pos-top .toc-sidebar {
        width: calc(100% - 1.5rem);
        margin: 0 0.75rem 1rem;
    }
    .toc-pos-top .toc-body {
        max-height: 0;
        padding: 0 0.75rem;
        overflow: hidden;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }
    .toc-pos-top .toc-sidebar.collapsed .toc-body {
        max-height: 0;
        padding: 0 0.75rem;
    }
    .toc-pos-top .toc-sidebar:not(.collapsed) .toc-body {
        max-height: 60vh;
        padding: 0.5rem 0.75rem 0.75rem;
        overflow-y: auto;
    }
    .toc-pos-top .toc-list,
    .toc-pos-top .toc-sublist {
        flex-direction: column;
        align-items: stretch;
    }
    .toc-pos-top .toc-item a {
        max-width: none;
        border-radius: 6px;
    }
}
