/* ==================== 文档解析器增强样式 ==================== */

/* ========== 1. 阅读进度指示器 ========== */
.docs-progress-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    z-index: 20;
    border-radius: 0 0 2px 2px;
}

.docs-progress-bar-inner {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), #a855f7, #ec4899);
    border-radius: 0 2px 2px 0;
    transition: width 0.15s ease-out;
}

/* ========== 2. 文档内搜索栏 ========== */
.docs-search-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--primary-color);
    border-radius: 10px;
    margin-bottom: 12px;
    animation: docs-slide-down 0.2s ease;
    box-shadow: 0 2px 12px rgba(102, 126, 234, 0.15);
}

.docs-search-bar.active {
    display: flex;
}

.docs-search-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    padding: 4px 0;
}

.docs-search-input::placeholder {
    color: var(--text-muted);
}

.docs-search-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.docs-search-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 56px;
    text-align: center;
}

.docs-search-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.docs-search-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* 搜索高亮 */
.docs-search-highlight {
    background: rgba(255, 235, 59, 0.5);
    border-radius: 2px;
    padding: 0 1px;
    scroll-margin-top: 80px;
}

.docs-search-highlight.current {
    background: rgba(255, 152, 0, 0.7);
    color: #000;
    box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.3);
}

[data-theme="dark"] .docs-search-highlight {
    background: rgba(255, 235, 59, 0.3);
}

[data-theme="dark"] .docs-search-highlight.current {
    background: rgba(255, 152, 0, 0.5);
}

/* ========== 3. TOC 目录增强 ========== */
.docs-toc {
    position: relative;
}

.docs-toc-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.docs-toc-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.docs-toc.collapsed .docs-toc-list {
    display: none;
}

.docs-toc.collapsed .docs-toc-toggle {
    transform: rotate(-90deg);
}

/* TOC 激活状态 */
.docs-toc-list a.toc-active {
    color: var(--primary-color) !important;
    font-weight: 600;
    position: relative;
}

.docs-toc-list a.toc-active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 2px;
}

/* ========== 4. 树形目录（侧边栏增强） ========== */
.docs-folder-toggle {
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
    border-radius: 6px;
}

.docs-folder-toggle:hover {
    background: rgba(102, 126, 234, 0.08);
}

.docs-folder-arrow {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.docs-folder-toggle.collapsed .docs-folder-arrow {
    transform: rotate(-90deg);
}

.docs-folder-children {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.docs-folder-toggle.collapsed+.docs-folder-children {
    max-height: 0 !important;
    padding: 0;
}

/* ========== 5. 代码块语法高亮（基础主题） ========== */
.docs-markdown pre code .keyword {
    color: #c678dd;
}

.docs-markdown pre code .string {
    color: #98c379;
}

.docs-markdown pre code .comment {
    color: #5c6370;
    font-style: italic;
}

.docs-markdown pre code .number {
    color: #d19a66;
}

.docs-markdown pre code .function {
    color: #61afef;
}

.docs-markdown pre code .operator {
    color: #56b6c2;
}

.docs-markdown pre code .tag {
    color: #e06c75;
}

.docs-markdown pre code .attr-name {
    color: #d19a66;
}

.docs-markdown pre code .attr-value {
    color: #98c379;
}

/* 代码块语言标签 */
.docs-code-lang {
    position: absolute;
    top: 0;
    left: 0;
    padding: 2px 10px;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: 0 0 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ========== 6. 文档切换过渡动画 ========== */
@keyframes docs-slide-down {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes docs-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.docs-content-transition {
    animation: docs-fade-in 0.3s ease;
}

/* 骨架屏加载 */
.docs-skeleton {
    padding: 20px;
}

.docs-skeleton-line {
    height: 14px;
    background: linear-gradient(90deg,
            var(--bg-tertiary) 25%,
            rgba(102, 126, 234, 0.08) 50%,
            var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: docs-skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 6px;
    margin-bottom: 12px;
}

.docs-skeleton-line:nth-child(1) {
    width: 60%;
    height: 24px;
    margin-bottom: 20px;
}

.docs-skeleton-line:nth-child(2) {
    width: 100%;
}

.docs-skeleton-line:nth-child(3) {
    width: 90%;
}

.docs-skeleton-line:nth-child(4) {
    width: 80%;
}

.docs-skeleton-line:nth-child(5) {
    width: 95%;
}

.docs-skeleton-line:nth-child(6) {
    width: 70%;
}

.docs-skeleton-line:nth-child(7) {
    width: 85%;
}

.docs-skeleton-line:nth-child(8) {
    width: 60%;
}

@keyframes docs-skeleton-pulse {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* ========== 7. Lightbox 图片查看器 ========== */
.docs-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.docs-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.docs-lightbox img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    cursor: default;
}

.docs-lightbox.active img {
    transform: scale(1);
}

.docs-lightbox-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.docs-lightbox-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.docs-lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.docs-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.docs-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* 文档内图片可点击样式 */
.docs-markdown img {
    cursor: zoom-in;
    transition: all 0.3s ease;
}

.docs-markdown img:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

/* ========== 8. Markdown 原文/渲染切换 ========== */
.docs-view-toggle {
    display: flex;
    gap: 4px;
    padding: 2px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.docs-view-toggle-btn {
    padding: 4px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.docs-view-toggle-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.docs-view-toggle-btn:hover:not(.active) {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* 原文视图 */
.docs-raw-view {
    display: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow-y: auto;
}

.docs-raw-view.active {
    display: block;
}

/* ========== 9. 工具栏增强 ========== */
.docs-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    margin-bottom: 8px;
    gap: 8px;
    flex-wrap: wrap;
}

.docs-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.docs-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.docs-toolbar-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.docs-toolbar-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.docs-toolbar-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ========== 10. 打印优化增强 ========== */
@media print {
    .docs-parser-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
    }

    .docs-header,
    .docs-sidebar,
    .docs-footer,
    .docs-toolbar,
    .docs-search-bar,
    .docs-progress-bar,
    .docs-toc-toggle,
    .docs-code-copy-btn,
    .docs-lightbox {
        display: none !important;
    }

    .docs-body {
        display: block !important;
    }

    .docs-content {
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
        padding: 0 !important;
    }

    .docs-markdown {
        font-size: 11pt;
        line-height: 1.6;
        color: #000 !important;
    }

    .docs-markdown pre {
        border: 1px solid #ddd !important;
        background: #f8f8f8 !important;
        page-break-inside: avoid;
    }

    .docs-markdown img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }

    .docs-markdown h1,
    .docs-markdown h2,
    .docs-markdown h3 {
        page-break-after: avoid;
        color: #000 !important;
    }

    .docs-toc {
        page-break-after: always;
    }
}

/* ========== 响应式适配 ========== */
@media (max-width: 768px) {
    .docs-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .docs-toolbar-right {
        justify-content: flex-end;
    }

    .docs-search-bar {
        flex-wrap: wrap;
    }

    .docs-search-nav {
        width: 100%;
        justify-content: flex-end;
    }

    .docs-lightbox img {
        max-width: 95vw;
        max-height: 80vh;
    }

    .docs-lightbox-toolbar {
        bottom: 12px;
    }
}

/* ========== 11. GFM 增强样式 ========== */

/* 任务列表 */
.docs-task-item {
    list-style: none;
    position: relative;
    padding-left: 4px;
}

.docs-task-checkbox {
    margin-right: 8px;
    width: 15px;
    height: 15px;
    accent-color: var(--primary-color);
    vertical-align: middle;
    cursor: default;
    border-radius: 3px;
}

.docs-task-item:has(.docs-task-checkbox:checked) {
    color: var(--text-muted);
    text-decoration: line-through;
    text-decoration-color: var(--text-muted);
}

/* details/summary 折叠块 */
.docs-details {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0;
    margin: 12px 0;
    overflow: hidden;
    transition: background 0.2s;
}

.docs-details[open] {
    background: var(--bg-secondary);
}

.docs-summary {
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    transition: background 0.2s;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.docs-summary::before {
    content: '▶';
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.docs-details[open] .docs-summary::before {
    transform: rotate(90deg);
}

.docs-summary::-webkit-details-marker {
    display: none;
}

.docs-summary:hover {
    background: rgba(102, 126, 234, 0.08);
}

.docs-details> :not(summary) {
    padding: 12px 14px;
}