/* ============================================================
   API 文档页样式
   ============================================================ */

/* ========== 整体布局 ========== */
.api-layout {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

/* ========== 左侧目录 ========== */
.api-sidebar {
    width: 200px;
    flex-shrink: 0;
    position: sticky;
    top: 84px;
    max-height: calc(100vh - 104px);
    overflow-y: auto;
}

.api-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.api-nav a {
    display: block;
    padding: 8px 12px;
    font-size: 14px;
    color: #4b5563;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.api-nav a:hover {
    background: #f3f4f6;
    color: #2563eb;
    text-decoration: none;
}

.api-nav a.active {
    background: #eff6ff;
    color: #2563eb;
    border-left-color: #2563eb;
    font-weight: 500;
}

/* ========== 右侧内容区 ========== */
.api-content {
    flex: 1;
    /* 防止内部超长代码或表格撑破 Flex 容器导致页面横向滚动 */
    min-width: 0; 
    background: #fff;
    border-radius: 8px;
    padding: 32px 40px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.api-content section {
    margin-bottom: 48px;
    scroll-margin-top: 84px;
}

.api-content section:last-child {
    margin-bottom: 0;
}

.api-content h1 {
    font-size: 28px;
    color: #111827;
    margin-bottom: 16px;
}

.api-content h2 {
    font-size: 22px;
    color: #111827;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f3f4f6;
}

.api-content h3 {
    font-size: 16px;
    color: #111827;
    margin-top: 24px;
    margin-bottom: 12px;
}

.api-content p {
    font-size: 14px;
    color: #374151;
    line-height: 1.8;
    margin-bottom: 12px;
}

.api-content a {
    color: #2563eb;
}

.api-content strong {
    color: #111827;
    font-weight: 600;
}

/* 行内代码 */
.api-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
    color: #dc2626;
}

/* ========== 代码块 ========== */
/* 新增外层容器，限制宽度并作为绝对定位的参考系 */
.code-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
    border-radius: 6px;
    overflow: hidden; /* 防止圆角被内部滚动条破坏 */
}

.code-block {
    background: #1f2937;
    color: #e5e7eb;
    padding: 16px 20px;
    overflow-x: auto;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.6;
    margin: 0; /* 清除默认外边距 */
    white-space: pre;
}

.code-block code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 12px;
    color: #9ca3af;
    background: rgba(31, 41, 55, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    z-index: 10;
    font-family: inherit;
}

.copy-code-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* ========== 列表 ========== */
.step-list {
    padding-left: 24px;
    margin-bottom: 16px;
}

.step-list li {
    font-size: 14px;
    color: #374151;
    line-height: 1.8;
    margin-bottom: 6px;
}

.constraint-list {
    padding-left: 24px;
    margin-bottom: 16px;
}

.constraint-list li {
    font-size: 14px;
    color: #374151;
    line-height: 1.8;
    margin-bottom: 4px;
}

/* ========== 表格 ========== */
.api-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 14px;
}

.api-table th,
.api-table td {
    border: 1px solid #e5e7eb;
    padding: 10px 14px;
    text-align: left;
}

.api-table th {
    background: #f9fafb;
    font-weight: 600;
    color: #111827;
}

.api-table td {
    color: #374151;
}

/* 表格里的行内代码 */
.api-table code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 12px;
    color: #dc2626;
}

/* 元素样式表特殊处理 */
.style-table .col-structure {
    font-weight: 600;
    color: #2563eb;
    white-space: nowrap;
    background: #fafbff;
    vertical-align: middle;
}

.style-table td code {
    display: inline-block;
    white-space: nowrap;
}

.style-table td[rowspan] {
    vertical-align: middle;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
}

/* ========== 代码块展示 ========== */
.mathml-code {
    white-space: pre;
    overflow-x: auto;
    background: #f3f4f6; 
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 12px 0;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.6;
}

.mathml-code code {
    color: #d6336c;
    background: transparent;
    padding: 0;
}

/* ========== 提示框 ========== */
.tip {
    background: #eff6ff;
    border-left: 3px solid #2563eb;
    padding: 10px 16px;
    border-radius: 0 4px 4px 0;
    font-size: 13px;
    color: #1e40af;
}

/* ========== 语言切换 ========== */
.lang-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.lang-tab {
    padding: 10px 20px;
    font-size: 14px;
    color: #6b7280;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.lang-tab:hover {
    color: #2563eb;
}

.lang-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 500;
}

.lang-panel {
    display: none;
}

.lang-panel.active {
    display: block;
}

/* ========== 代码弹窗 ========== */
#code-modal .code-modal-body {
    margin-top: 16px;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 6px;
    background: #1f2937;
}

#code-modal .code-wrapper {
    margin-bottom: 0;
}

#code-modal .code-block {
    border-radius: 6px;
    padding: 16px 20px;
    white-space: pre;
    overflow-x: auto; 
}

/* ========== 响应式（移动端适配） ========== */
@media (max-width: 768px) {
    .api-layout {
        flex-direction: column;
        gap: 16px;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden; 
    }

    .api-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        overflow-x: auto;
    }

    .api-nav {
        flex-direction: row;
        overflow-x: auto;
        gap: 8px;
        padding-bottom: 8px;
    }

    .api-nav a {
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
    }

    .api-nav a.active {
        border-left: none;
        border-bottom-color: #2563eb;
    }

    .api-content {
        padding: 20px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box; 
    }

    .api-content h1 {
        font-size: 22px;
    }

    .api-content h2 {
        font-size: 18px;
    }

    /* 表格在移动端改为独立横向滚动，避免撑破页面 */
    .api-table {
        font-size: 13px;
        display: block;
        overflow-x: auto;
        white-space: nowrap; 
    }

    .api-table th,
    .api-table td {
        padding: 6px 8px;
    }

    /* 代码块在移动端保留原始格式并独立横向滚动 */
    .code-block {
        white-space: pre !important; 
        overflow-x: auto;            
        width: 100%;
        box-sizing: border-box;
    }
}