/**
 * TOC目录样式 - 增强版
 * 右侧文章目录、树形折叠、拖拽调整宽度
 */

/* 右侧TOC侧边栏 */
.toc-sidebar {
    width: var(--toc-width, 260px);
    min-width: var(--toc-width, 260px);
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-right 0.3s ease;
    position: relative;
}

.toc-sidebar.collapsed {
    margin-right: var(--toc-collapsed-margin, -260px);
}

.toc-sidebar.resizing {
    transition: none;
}

.toc-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toc-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
}

.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.toc-empty {
    padding: 20px 16px;
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
}

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

/* TOC项目基础样式 */
.toc-item {
    margin: 0;
}

.toc-item > a {
    display: block;
    padding: 6px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
    transition: all 0.2s;
    border-left: 2px solid transparent;
}

.toc-item > a:hover {
    color: var(--primary-color);
    background-color: var(--hover-bg);
}

.toc-item > a.active {
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    background-color: var(--hover-bg);
}

/* TOC文件夹样式（有子节点的项） */
.toc-folder {
    margin: 0;
}

.toc-item-header {
    display: flex;
    align-items: center;
    padding: 6px 12px 6px 8px;
    cursor: pointer;
}

.toc-toggle-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.toc-toggle-icon:hover {
    color: var(--primary-color);
}

.toc-item-header a {
    flex: 1;
    padding: 2px 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
    transition: all 0.2s;
    border-radius: 4px;
}

.toc-item-header a:hover {
    color: var(--primary-color);
    background-color: var(--hover-bg);
}

.toc-item-header a.active {
    color: var(--primary-color);
    background-color: var(--hover-bg);
}

/* TOC子节点容器 */
.toc-children {
    display: none;
    list-style: none;
    padding: 0;
    margin: 0;
    padding-left: 16px;
}

.toc-folder.open > .toc-children {
    display: block;
}

/* TOC层级缩进 */
.toc-level-1 > a,
.toc-level-1 > .toc-item-header a { font-weight: 600; font-size: 14px; }
.toc-level-2 > a,
.toc-level-2 > .toc-item-header a { padding-left: 8px; }
.toc-level-3 > a,
.toc-level-3 > .toc-item-header a { font-size: 12px; }
.toc-level-4 > a,
.toc-level-4 > .toc-item-header a { font-size: 12px; }
.toc-level-5 > a,
.toc-level-5 > .toc-item-header a { font-size: 12px; }
.toc-level-6 > a,
.toc-level-6 > .toc-item-header a { font-size: 12px; }

/* 右侧TOC收缩按钮 */
.toc-toggle {
    position: absolute;
    right: var(--toc-width, 260px);
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    border: 1px solid var(--border-color);
    border-right: none;
    background: var(--sidebar-bg);
    border-radius: 6px 0 0 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-secondary);
    transition: right 0.3s ease, background 0.2s;
    z-index: 20;
}

.toc-toggle:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

.toc-sidebar.collapsed + .toc-toggle {
    right: 0 !important; /* 使用 !important 覆盖 js 设置的内联 right 样式 */
}

/* 拖拽调整手柄 */
.toc-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background-color 0.2s;
    z-index: 21;
}

.toc-resize-handle:hover {
    background-color: var(--primary-color);
}

.toc-resize-handle::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 0;
    bottom: 0;
    width: 8px;
    background: transparent;
}

.toc-sidebar.resizing .toc-resize-handle {
    background-color: var(--primary-color);
}

/* 拖拽时的视觉反馈 */
.toc-sidebar.resizing {
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .toc-sidebar {
        width: 100%;
        min-width: 100%;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    /* 移动端通过 mobile-open 类控制显示 */
    .toc-sidebar.mobile-open {
        transform: translateX(0);
    }

    .toc-toggle {
        right: 0;
        border-radius: 6px 0 0 6px;
    }

    .toc-resize-handle {
        display: none;
    }
}

/* 暗色主题适配 */
[data-theme="dark"] .toc-resize-handle:hover {
    background-color: var(--primary-color);
}

[data-theme="dark"] .toc-sidebar.resizing {
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
}

/* 高对比度主题适配 */
[data-theme="high-contrast"] .toc-resize-handle {
    width: 6px;
}

[data-theme="high-contrast"] .toc-resize-handle:hover {
    background-color: var(--primary-color);
    border: 1px solid var(--text-color);
}

/* 打印样式 */
@media print {
    .toc-sidebar {
        display: none;
    }

    .toc-toggle {
        display: none;
    }
}
