/* Auto TOC - Frontend Styles */

/* ═══════════════════════════════════════════
   Base Structure
   ═══════════════════════════════════════════ */

.auto-toc {
    margin: 1.5em 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

.auto-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
}

.auto-toc-title {
    font-weight: 600;
    font-size: 15px;
}

.auto-toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 8px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.auto-toc-toggle:hover {
    opacity: 1;
}

/* Body */
.auto-toc-body {
    transition: max-height 0.3s ease-out;
}

/* Hide collapsed body */
.auto-toc.collapsed .auto-toc-body {
    display: none;
}

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

.auto-toc-sub {
    padding-left: 20px;
    padding-top: 4px;
}

.auto-toc-item {
    margin: 4px 0;
}

.auto-toc-link {
    display: block;
    padding: 4px 8px;
    text-decoration: none;
    border-radius: 3px;
    transition: all 0.15s;
}

.auto-toc-text {
    word-break: break-word;
}

/* Expand/Collapse buttons */
.auto-toc-expand {
    display: inline-block;
    width: 16px;
    height: 16px;
    line-height: 14px;
    text-align: center;
    font-size: 12px;
    background: rgba(0,0,0,0.08);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    margin-right: 4px;
    vertical-align: middle;
}

.auto-toc-item.children-collapsed > .auto-toc-list {
    display: none;
}

.auto-toc-item.children-collapsed > .auto-toc-expand::before {
    content: '＋';
}

.auto-toc-item:not(.children-collapsed) > .auto-toc-expand::before {
    content: '－';
}

/* Current highlight */
.auto-toc-link.current {
    font-weight: 600;
}

/* ═══════════════════════════════════════════
   Theme 1: Minimal (简约默认)
   ═══════════════════════════════════════════ */

.auto-toc-theme-minimal {
    background: #f8f9fa;
    border-radius: 6px;
}

.auto-toc-theme-minimal .auto-toc-header {
    border-bottom: 1px solid #e9ecef;
}

.auto-toc-theme-minimal .auto-toc-title {
    color: #333;
}

.auto-toc-theme-minimal .auto-toc-toggle {
    color: #6c757d;
}

.auto-toc-theme-minimal .auto-toc-link {
    color: #495057;
}

.auto-toc-theme-minimal .auto-toc-link:hover {
    background: #e9ecef;
    color: #212529;
}

.auto-toc-theme-minimal .auto-toc-link.current {
    background: #e9ecef;
    color: #0d6efd;
}

.auto-toc-theme-minimal .auto-toc-expand {
    background: rgba(0,0,0,0.06);
    color: #6c757d;
}

/* ═══════════════════════════════════════════
   Theme 2: Academic (经典学术)
   ═══════════════════════════════════════════ */

.auto-toc-theme-academic {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.auto-toc-theme-academic .auto-toc-header {
    background: #f3f4f6;
    border-bottom: 1px solid #d1d5db;
    border-radius: 4px 4px 0 0;
}

.auto-toc-theme-academic .auto-toc-title {
    color: #1f2937;
}

.auto-toc-theme-academic .auto-toc-toggle {
    color: #6b7280;
}

.auto-toc-theme-academic .auto-toc-list {
    border-left: 2px solid #e5e7eb;
    margin-left: 12px;
}

.auto-toc-theme-academic .auto-toc-sub {
    border-left: 2px solid #d1d5db;
}

.auto-toc-theme-academic .auto-toc-link {
    color: #374151;
    border-left: 2px solid transparent;
    margin-left: -2px;
}

.auto-toc-theme-academic .auto-toc-link:hover {
    background: #f9fafb;
    border-left-color: #9ca3af;
}

.auto-toc-theme-academic .auto-toc-link.current {
    color: #1d4ed8;
    border-left-color: #3b82f6;
    background: #eff6ff;
}

.auto-toc-theme-academic .auto-toc-expand {
    background: #e5e7eb;
    color: #4b5563;
}

/* ═══════════════════════════════════════════
   Theme 3: Card (卡片浮雕)
   ═══════════════════════════════════════════ */

.auto-toc-theme-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
}

.auto-toc-theme-card .auto-toc-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-radius: 12px 12px 0 0;
}

.auto-toc-theme-card .auto-toc-title {
    color: #fff;
}

.auto-toc-theme-card .auto-toc-toggle {
    color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}

.auto-toc-theme-card .auto-toc-toggle:hover {
    background: rgba(255,255,255,0.25);
}

.auto-toc-theme-card .auto-toc-link {
    color: #4a5568;
}

.auto-toc-theme-card .auto-toc-link:hover {
    background: #f7fafc;
    color: #667eea;
}

.auto-toc-theme-card .auto-toc-link.current {
    background: linear-gradient(90deg, rgba(102,126,234,0.1) 0%, rgba(118,75,162,0.1) 100%);
    color: #667eea;
    font-weight: 600;
}

.auto-toc-theme-card .auto-toc-expand {
    background: #edf2f7;
    color: #667eea;
}

/* ═══════════════════════════════════════════
   Theme 4: Left Line (左侧竖线)
   ═══════════════════════════════════════════ */

.auto-toc-theme-leftline {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border-left: 4px solid #3b82f6;
}

.auto-toc-theme-leftline .auto-toc-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.auto-toc-theme-leftline .auto-toc-title {
    color: #1e293b;
}

.auto-toc-theme-leftline .auto-toc-toggle {
    color: #64748b;
}

.auto-toc-theme-leftline .auto-toc-link {
    color: #334155;
    position: relative;
    padding-left: 16px;
}

.auto-toc-theme-leftline .auto-toc-link::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: #cbd5e1;
    border-radius: 50%;
    transition: all 0.15s;
}

.auto-toc-theme-leftline .auto-toc-link:hover {
    background: #f1f5f9;
}

.auto-toc-theme-leftline .auto-toc-link:hover::after {
    background: #3b82f6;
}

.auto-toc-theme-leftline .auto-toc-link.current {
    color: #3b82f6;
    background: #eff6ff;
}

.auto-toc-theme-leftline .auto-toc-link.current::after {
    background: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

.auto-toc-theme-leftline .auto-toc-expand {
    background: #e2e8f0;
    color: #64748b;
}

/* ═══════════════════════════════════════════
   Theme 5: Dark (暗色主题)
   ═══════════════════════════════════════════ */

.auto-toc-theme-dark {
    background: #1e293b;
    border-radius: 8px;
}

.auto-toc-theme-dark .auto-toc-header {
    background: #0f172a;
    border-bottom: 1px solid #334155;
    border-radius: 8px 8px 0 0;
}

.auto-toc-theme-dark .auto-toc-title {
    color: #f1f5f9;
}

.auto-toc-theme-dark .auto-toc-toggle {
    color: #94a3b8;
    background: #334155;
    border-radius: 4px;
}

.auto-toc-theme-dark .auto-toc-toggle:hover {
    background: #475569;
}

.auto-toc-theme-dark .auto-toc-link {
    color: #cbd5e1;
}

.auto-toc-theme-dark .auto-toc-link:hover {
    background: #334155;
    color: #f1f5f9;
}

.auto-toc-theme-dark .auto-toc-link.current {
    background: rgba(59,130,246,0.2);
    color: #60a5fa;
    font-weight: 600;
}

.auto-toc-theme-dark .auto-toc-expand {
    background: #334155;
    color: #94a3b8;
}

/* ═══════════════════════════════════════════
   Theme 6: Gradient (渐变标签)
   ═══════════════════════════════════════════ */

.auto-toc-theme-gradient {
    background: linear-gradient(135deg, #fef3c7 0%, #fce7f3 50%, #ddd6fe 100%);
    border-radius: 10px;
}

.auto-toc-theme-gradient .auto-toc-header {
    background: linear-gradient(90deg, rgba(251,191,36,0.3) 0%, rgba(236,72,153,0.3) 50%, rgba(139,92,246,0.3) 100%);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    border-radius: 10px 10px 0 0;
}

.auto-toc-theme-gradient .auto-toc-title {
    color: #1f2937;
}

.auto-toc-theme-gradient .auto-toc-toggle {
    color: #6b7280;
    background: rgba(255,255,255,0.6);
    border-radius: 12px;
}

.auto-toc-theme-gradient .auto-toc-link {
    color: #374151;
}

.auto-toc-theme-gradient .auto-toc-link:hover {
    background: rgba(255,255,255,0.6);
}

.auto-toc-theme-gradient .auto-toc-link.current {
    background: rgba(255,255,255,0.8);
    color: #7c3aed;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(139,92,246,0.15);
}

.auto-toc-theme-gradient .auto-toc-expand {
    background: rgba(255,255,255,0.5);
    color: #7c3aed;
}

/* ═══════════════════════════════════════════
   Theme 7: Transparent (全局透明)
   ═══════════════════════════════════════════ */

.auto-toc-theme-transparent {
    background: transparent;
    border: none;
    box-shadow: none;
}

.auto-toc-theme-transparent .auto-toc-header {
    background: transparent;
    border-bottom: 1px solid currentColor;
    opacity: 0.6;
}

.auto-toc-theme-transparent .auto-toc-title {
    color: inherit;
}

.auto-toc-theme-transparent .auto-toc-toggle {
    color: inherit;
}

.auto-toc-theme-transparent .auto-toc-link {
    color: inherit;
    opacity: 0.8;
}

.auto-toc-theme-transparent .auto-toc-link:hover {
    opacity: 1;
    background: rgba(128,128,128,0.1);
}

.auto-toc-theme-transparent .auto-toc-link.current {
    opacity: 1;
    font-weight: 600;
}

.auto-toc-theme-transparent .auto-toc-expand {
    background: rgba(128,128,128,0.15);
    color: inherit;
}

/* ═══════════════════════════════════════════
   Theme 8: Flat (扁平风格)
   ═══════════════════════════════════════════ */

.auto-toc-theme-flat {
    background: #3b82f6;
    border-radius: 0;
}

.auto-toc-theme-flat .auto-toc-header {
    background: #2563eb;
    border-bottom: none;
}

.auto-toc-theme-flat .auto-toc-title {
    color: #fff;
}

.auto-toc-theme-flat .auto-toc-toggle {
    color: rgba(255,255,255,0.8);
}

.auto-toc-theme-flat .auto-toc-link {
    color: rgba(255,255,255,0.9);
}

.auto-toc-theme-flat .auto-toc-link:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.auto-toc-theme-flat .auto-toc-link.current {
    background: rgba(255,255,255,0.25);
    color: #fff;
    font-weight: 600;
}

.auto-toc-theme-flat .auto-toc-expand {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* ═══════════════════════════════════════════
   Theme 9: Glass (玻璃拟态)
   ═══════════════════════════════════════════ */

.auto-toc-theme-glass {
    background: rgba(255,255,255,0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.auto-toc-theme-glass .auto-toc-header {
    background: rgba(255,255,255,0.3);
    border-bottom: 1px solid rgba(255,255,255,0.2);
    border-radius: 16px 16px 0 0;
}

.auto-toc-theme-glass .auto-toc-title {
    color: #1f2937;
}

.auto-toc-theme-glass .auto-toc-toggle {
    color: #6b7280;
    background: rgba(255,255,255,0.5);
    border-radius: 8px;
}

.auto-toc-theme-glass .auto-toc-link {
    color: #374151;
}

.auto-toc-theme-glass .auto-toc-link:hover {
    background: rgba(255,255,255,0.5);
}

.auto-toc-theme-glass .auto-toc-link.current {
    background: rgba(99,102,241,0.2);
    color: #4f46e5;
    font-weight: 600;
}

.auto-toc-theme-glass .auto-toc-expand {
    background: rgba(255,255,255,0.5);
    color: #6366f1;
}

/* ═══════════════════════════════════════════
   Theme 10: Dashed (虚线边框)
   ═══════════════════════════════════════════ */

.auto-toc-theme-dashed {
    background: #fff;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
}

.auto-toc-theme-dashed .auto-toc-header {
    background: transparent;
    border-bottom: 2px dashed #d1d5db;
}

.auto-toc-theme-dashed .auto-toc-title {
    color: #374151;
}

.auto-toc-theme-dashed .auto-toc-toggle {
    color: #6b7280;
    border: 1px dashed #d1d5db;
    border-radius: 4px;
}

.auto-toc-theme-dashed .auto-toc-toggle:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.auto-toc-theme-dashed .auto-toc-link {
    color: #4b5563;
    border: 1px dashed transparent;
    margin: 2px 0;
}

.auto-toc-theme-dashed .auto-toc-link:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.auto-toc-theme-dashed .auto-toc-link.current {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
    font-weight: 600;
}

.auto-toc-theme-dashed .auto-toc-expand {
    background: #f3f4f6;
    color: #6b7280;
}

/* ═══════════════════════════════════════════
   Theme 11: Capsule (圆角胶囊)
   ═══════════════════════════════════════════ */

.auto-toc-theme-capsule {
    background: #f8fafc;
    border-radius: 16px;
}

.auto-toc-theme-capsule .auto-toc-header {
    background: transparent;
    border-bottom: none;
    padding-bottom: 8px;
}

.auto-toc-theme-capsule .auto-toc-title {
    color: #1e293b;
    font-size: 14px;
}

.auto-toc-theme-capsule .auto-toc-toggle {
    color: #64748b;
    background: #e2e8f0;
    border-radius: 20px;
    padding: 4px 12px;
}

.auto-toc-theme-capsule .auto-toc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 12px;
}

.auto-toc-theme-capsule .auto-toc-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 0 0;
    margin-left: 0;
    width: 100%;
}

.auto-toc-theme-capsule .auto-toc-item {
    margin: 0;
}

.auto-toc-theme-capsule .auto-toc-link {
    display: inline-block;
    padding: 6px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 13px;
    color: #475569;
}

.auto-toc-theme-capsule .auto-toc-link:hover {
    background: #fff;
    border-color: #3b82f6;
    color: #3b82f6;
}

.auto-toc-theme-capsule .auto-toc-link.current {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
    font-weight: 500;
}

.auto-toc-theme-capsule .auto-toc-expand {
    display: none;
}

/* ═══════════════════════════════════════════
   Theme 12: Custom (自定义配色)
   ═══════════════════════════════════════════ */

.auto-toc-theme-custom {
    background: var(--auto-toc-bg, #ffffff);
    border: 1px solid var(--auto-toc-border, #e9ecef);
    border-radius: 8px;
}

.auto-toc-theme-custom .auto-toc-header {
    background: transparent;
    border-bottom: 1px solid var(--auto-toc-border, #e9ecef);
}

.auto-toc-theme-custom .auto-toc-title {
    color: var(--auto-toc-title, #333333);
}

.auto-toc-theme-custom .auto-toc-toggle {
    color: var(--auto-toc-link, #495057);
}

.auto-toc-theme-custom .auto-toc-link {
    color: var(--auto-toc-link, #495057);
}

.auto-toc-theme-custom .auto-toc-link:hover {
    background: var(--auto-toc-hover, #0d6efd);
    color: #fff;
}

.auto-toc-theme-custom .auto-toc-link.current {
    background: var(--auto-toc-active, #0d6efd);
    color: #fff;
    font-weight: 600;
}

.auto-toc-theme-custom .auto-toc-expand {
    background: var(--auto-toc-border, #e9ecef);
    color: var(--auto-toc-link, #495057);
}

/* ═══════════════════════════════════════════
   Float Mode (浮动模式)
   ═══════════════════════════════════════════ */

.auto-toc-float-wrapper {
    position: fixed;
    top: 100px;
    width: 280px;
    max-height: calc(100vh - 140px);
    z-index: 9999;
    transition: transform 0.3s, opacity 0.3s;
}

.auto-toc-float-wrapper.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.auto-toc-float-left {
    left: 20px;
}

.auto-toc-float-right {
    right: 20px;
}

.auto-toc-float-wrapper .auto-toc {
    margin: 0;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}

.auto-toc-float-wrapper .auto-toc-body {
    overflow-y: auto;
    max-height: calc(100vh - 220px) !important;
}

/* Responsive: hide float on small screens */
@media (max-width: 1200px) {
    .auto-toc-float-wrapper {
        display: none;
    }
}

/* ═══════════════════════════════════════════
   Widget (侧边栏小工具)
   ═══════════════════════════════════════════ */

.auto-toc-sidebar-wrap {
    background: #fff;
    border: 1px solid #e2e4e7;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.auto-toc-sidebar-wrap .auto-toc {
    margin: 0;
    border: none;
    background: transparent;
}

.auto-toc-sidebar-wrap .auto-toc-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #f1f3f5 100%);
    border-bottom: 1px solid #e2e4e7;
    padding: 14px 16px;
    border-radius: 0;
}

.auto-toc-sidebar-wrap .auto-toc-title {
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
}

.auto-toc-sidebar-wrap .auto-toc-toggle {
    font-size: 12px;
    padding: 4px 10px;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    color: #50575e;
}

.auto-toc-sidebar-wrap .auto-toc-toggle:hover {
    background: #f0f0f1;
    border-color: #8c8f94;
}

.auto-toc-sidebar-wrap .auto-toc-body {
    max-height: 450px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #dcdcde transparent;
}

.auto-toc-sidebar-wrap .auto-toc-body::-webkit-scrollbar {
    width: 6px;
}

.auto-toc-sidebar-wrap .auto-toc-body::-webkit-scrollbar-track {
    background: transparent;
}

.auto-toc-sidebar-wrap .auto-toc-body::-webkit-scrollbar-thumb {
    background: #dcdcde;
    border-radius: 3px;
}

.auto-toc-sidebar-wrap .auto-toc-body::-webkit-scrollbar-thumb:hover {
    background: #8c8f94;
}

.auto-toc-sidebar-wrap .auto-toc-list {
    padding: 10px 12px 12px;
}

.auto-toc-sidebar-wrap .auto-toc-sub {
    padding-left: 12px;
}

.auto-toc-sidebar-wrap .auto-toc-item {
    margin: 2px 0;
}

.auto-toc-sidebar-wrap .auto-toc-link {
    display: block;
    padding: 8px 12px;
    color: #2c3338;
    font-size: 13px;
    border-radius: 6px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.auto-toc-sidebar-wrap .auto-toc-link:hover {
    background: #f6f7f7;
    color: #2271b1;
    border-left-color: #2271b1;
}

.auto-toc-sidebar-wrap .auto-toc-link.current {
    background: #2271b1;
    color: #fff;
    font-weight: 500;
    border-left-color: #2271b1;
}

.auto-toc-sidebar-wrap .auto-toc-expand {
    background: #f0f0f1;
    color: #50575e;
    width: 18px;
    height: 18px;
    line-height: 16px;
    border-radius: 4px;
}

.auto-toc-sidebar-wrap .auto-toc-expand:hover {
    background: #dcdcde;
}

/* Collapsed state */
.auto-toc-sidebar-wrap.collapsed .auto-toc-body {
    max-height: 0;
    overflow: hidden;
}

/* Widget Sticky */
.auto-toc-widget-sticky {
    position: sticky;
    top: 20px;
    transition: box-shadow 0.3s;
}

.auto-toc-widget-sticky.is-stuck {
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

/* ═══════════════════════════════════════════
   Numbering (层级编号)
   ═══════════════════════════════════════════ */

.auto-toc.has-numbering .auto-toc-link::before {
    font-variant-numeric: tabular-nums;
    margin-right: 6px;
    opacity: 0.6;
}

/* ═══════════════════════════════════════════
   Smooth Scroll Base
   ═══════════════════════════════════════════ */

html.auto-toc-smooth-scroll {
    scroll-behavior: smooth;
}
