/**
 * API文档浏览器 - 企业级样式
 */

/* 基础变量 */
:root {
    --primary-color: #1890ff;
    --primary-light: #e6f7ff;
    --primary-dark: #096dd9;
    --primary-gradient: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
    --secondary-color: #52c41a;
    --warning-color: #faad14;
    --error-color: #ff4d4f;
    --text-color: #333;
    --text-light: #666;
    --text-lighter: #999;
    --border-color: #e8e8e8;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --sidebar-bg: #001529;
    --sidebar-text: rgba(255, 255, 255, 0.65);
    --sidebar-active-text: #ffffff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
    --border-radius: 6px;
    --transition: all 0.3s ease;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --code-font: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Fira Mono', 'Droid Sans Mono', 'Source Code Pro', monospace;
}

/* 重置样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-color);
    background-color: var(--bg-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 主容器 */
.container {
    max-width: 100%;
    min-height: 100vh;
}

/* 头部 */
.header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 30px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
}

.header h1 {
    font-size: 22px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.search-container {
    position: relative;
    flex: 1;
    max-width: 600px;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    white-space: nowrap;
}

.header-nav a {
    color: #ffffff;
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
}

.header-nav a:hover {
    opacity: 0.8;
}

.search-input {
    width: 100%;
    padding: 10px 40px 10px 40px;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(4px);
    transition: var(--transition);
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.3);
}

.search-input:focus::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.search-container::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='white' opacity='0.8' d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
}

.search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-clear:hover {
    background: rgba(255, 255, 255, 0.4);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--primary-light);
}

.search-result-title {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 4px;
    font-size: 14px;
}

.search-result-category {
    font-size: 12px;
    color: var(--text-lighter);
    margin-bottom: 6px;
}

.search-result-preview {
    font-size: 12px;
    color: var(--text-light);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-result-highlight {
    background: #fff3cd;
    padding: 0 2px;
    border-radius: 2px;
}

.search-no-results {
    padding: 24px;
    text-align: center;
    color: var(--text-lighter);
    font-size: 14px;
}

.header h1::before {
    content: '';
    display: inline-block;
    width: 32px;
    height: 32px;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='white' d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2l5 5h-5V4zM6 20V4h6v6h6v10H6z'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
}

/* 主内容区 */
.main {
    display: flex;
    min-height: calc(100vh - 72px);
}

/* 侧边栏 */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    overflow-y: auto;
    flex-shrink: 0;
    position: sticky;
    top: 72px;
    height: calc(100vh - 72px);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 导航 */
.nav h2 {
    color: var(--sidebar-active-text);
    font-size: 16px;
    font-weight: 500;
    padding: 20px 20px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* 导航列表 */
#nav-list {
    list-style: none;
    padding: 10px 0;
}

/* 分类 */
.nav-category {
    margin-bottom: 0;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    border-left: 3px solid transparent;
}

.category-header:hover {
    color: var(--sidebar-active-text);
    background: rgba(255, 255, 255, 0.05);
}

.category-name {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.category-toggle {
    transition: transform 0.3s ease;
    opacity: 0.6;
}

.nav-category.collapsed .category-toggle {
    transform: rotate(-90deg);
}

/* 分类文件列表 */
.category-files {
    list-style: none;
    background: rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: max-height 0.3s ease;
}

/* 导航项 */
.nav-item {
    margin: 0;
}

.nav-item a {
    display: block;
    padding: 10px 20px 10px 30px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 13px;
    transition: var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.nav-item a::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.4;
}

.nav-item a:hover {
    color: var(--sidebar-active-text);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item a.active {
    color: var(--sidebar-active-text);
    background: var(--primary-color);
    border-left-color: var(--primary-color);
}

.nav-item a.active::before {
    opacity: 1;
    background: white;
}

/* 内容区包装器 */
.content-wrapper {
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: calc(100vh - 72px);
}

/* 主内容区 */
.content {
    flex: 1;
    padding: 30px 40px;
    background: var(--card-bg);
    margin: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    min-width: 0;
    position: relative;
}

/* 加载状态 */
#loading {
    display: none;
    justify-content: center;
    align-items: center;
    height: 400px;
    flex-direction: column;
    gap: 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-light);
    font-size: 14px;
}

/* Markdown 内容样式 */
#content {
    max-width: 100%;
}

#content h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-color);
    margin: 0 0 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

#content h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-color);
    margin: 32px 0 16px;
    padding-left: 12px;
    border-left: 4px solid var(--primary-color);
}

#content h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin: 24px 0 12px;
}

#content h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-light);
    margin: 20px 0 10px;
}

#content p {
    margin: 0 0 16px;
    color: var(--text-color);
    line-height: 1.8;
}

#content ul, #content ol {
    margin: 0 0 16px;
    padding-left: 24px;
}

#content li {
    margin-bottom: 8px;
    line-height: 1.8;
}

#content a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

#content a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* 表格样式 */
#content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13px;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

#content th {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    border-bottom: 2px solid var(--primary-color);
}

#content td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

#content tr:last-child td {
    border-bottom: none;
}

#content tr:hover td {
    background: #fafafa;
}

/* 代码块样式 */
#content pre {
    background: #0d1117;
    border-radius: var(--border-radius);
    padding: 20px;
    margin: 16px 0;
    overflow-x: auto;
    position: relative;
    border: 1px solid #30363d;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    max-height: none;
    transition: max-height 0.3s ease;
    border-bottom: none;
    background-clip: padding-box;
}

#content pre::-webkit-scrollbar-track {
    background: #0d1117;
}

#content pre::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 4px;
}

#content pre::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#content pre code {
    display: block;
    padding-right: 60px;
    white-space: pre;
    word-wrap: normal;
    tab-size: 4;
    border-bottom: none;
    background: transparent;
    outline: none;
    box-shadow: none;
}

#content pre.collapsed {
    max-height: 150px;
}

.collapse-btn {
    position: absolute;
    top: 8px;
    right: 70px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #c9d1d9;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.collapse-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: translateY(-1px);
}

#content code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
}

#content pre code {
    display: block;
    padding-right: 60px;
    white-space: pre;
    word-wrap: normal;
    tab-size: 4;
}

#content p code, #content li code {
    background: #ffffff00;
    padding: 2px 6px;
    border-radius: 4px;
    color: #d73a49;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.code-language {
    position: absolute;
    top: 8px;
    left: 12px;
    font-size: 11px;
    color: #8b949e;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #c9d1d9;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: translateY(-1px);
}

.copy-btn.copied {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: #fff;
}

/* 引用块 */
#content blockquote {
    margin: 16px 0;
    padding: 12px 20px;
    border-left: 4px solid var(--primary-color);
    background: var(--primary-light);
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.8;
}

#content blockquote p {
    margin: 0 0 8px;
}

#content blockquote p:last-child {
    margin-bottom: 0;
}

#content blockquote > p:first-child > strong:first-child,
#content blockquote > p:first-child > b:first-child {
    display: inline-block;
    margin-right: 6px;
}

/* 嵌套引用 */
#content blockquote blockquote {
    margin: 8px 0;
    padding: 8px 16px;
    border-left-color: var(--warning-color);
    background: #fffbe6;
    color: var(--text-light);
}

#content blockquote blockquote blockquote {
    border-left-color: #722ed1;
    background: #f9f0ff;
}

/* 引用块内代码 */
#content blockquote code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
    color: var(--error-color);
}

/* 分割线 */
#content hr {
    border: none;
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* 目录侧边栏 */
.toc {
    width: 240px;
    background: var(--card-bg);
    margin: 20px 20px 20px 0;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: sticky;
    top: 92px;
    height: calc(100vh - 112px);
    overflow-y: auto;
    flex-shrink: 0;
    align-self: flex-start;
}

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

.toc-toggle {
    display: none;
}

#toc-nav {
    padding: 8px 0;
}

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

.toc-item {
    margin: 0;
}

.toc-item a {
    display: block;
    padding: 6px 16px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 13px;
    transition: var(--transition);
    border-left: 2px solid transparent;
}

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

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

.toc-h3 a { padding-left: 28px; font-size: 12px; }
.toc-h4 a { padding-left: 40px; font-size: 12px; }
.toc-h5 a { padding-left: 52px; font-size: 12px; }
.toc-h6 a { padding-left: 64px; font-size: 12px; }

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

/* 返回顶部按钮 */
.back-to-top {
    position: fixed;
    right: 30px;
    bottom: 30px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-hover);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--primary-dark);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(24, 144, 255, 0.4);
}

/* 错误容器 */
.error-container {
    text-align: center;
    padding: 60px 20px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 20px;
}

.error-message {
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.8;
    margin-bottom: 20px;
}

.retry-btn {
    padding: 8px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.retry-btn:hover {
    background: var(--primary-dark);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-lighter);
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--text-light);
}

.empty-state p {
    font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 1400px) {
    .toc {
        width: 200px;
    }

    .content {
        max-width: calc(100% - 240px);
    }
}

@media (max-width: 1200px) {
    .toc {
        display: none;
    }

    .content {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 15px 20px;
    }

    .header h1 {
        font-size: 18px;
    }

    .main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 300px;
        position: relative;
        top: 0;
    }

    .content {
        margin: 10px;
        padding: 20px;
        max-width: 100%;
    }

    #content h1 {
        font-size: 22px;
    }

    #content h2 {
        font-size: 18px;
    }

    #content table {
        font-size: 12px;
    }

    #content th, #content td {
        padding: 8px 12px;
    }

    .back-to-top {
        right: 20px;
        bottom: 20px;
        width: 40px;
        height: 40px;
    }
}

/* 打印样式 */
@media print {
    .sidebar, .toc, .back-to-top, .header {
        display: none !important;
    }

    .content {
        margin: 0;
        padding: 0;
        box-shadow: none;
        max-width: 100%;
    }

    #content pre {
        white-space: pre-wrap;
        word-wrap: break-word;
    }
}
