/* ==========================================
   Documentation Specific Styles
   ========================================== */

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.back-to-top:active {
    transform: translateY(0);
}

.back-to-top svg {
    width: 20px;
    height: 20px;
}

@media (max-width: 768px) {
    .back-to-top {
        bottom: 24px;
        right: 24px;
        width: 44px;
        height: 44px;
    }
    
    .back-to-top svg {
        width: 18px;
        height: 18px;
    }
}

/* Docs Layout */
.docs-page {
    padding-top: 80px;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.docs-container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    padding-left: 240px;
}

/* Sidebar */
.docs-sidebar {
    position: fixed;
    left: 0;
    top: 80px;
    width: 240px;
    height: calc(100vh - 80px);
    overflow-y: auto;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 32px 0;
    z-index: 100;
}

@media (min-width: 1400px) {
    .docs-sidebar {
        left: calc((100vw - 1200px) / 2);
    }
}

/* Sidebar Toggle Button (Mobile) */
.sidebar-toggle {
    display: none;
    width: 100%;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 16px;
    align-items: center;
    justify-content: space-between;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle svg {
    transition: transform 0.3s ease;
}

.sidebar-toggle.active svg {
    transform: rotate(180deg);
}

.sidebar-content {
    padding: 0 20px;
}

.sidebar-section {
    margin-bottom: 32px;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding: 0 12px;
}

.sidebar-link {
    display: block;
    padding: 8px 12px;
    margin-bottom: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.sidebar-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: var(--primary);
    color: white;
}

/* Main Content */
.docs-main {
    padding: 40px 32px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

.doc-section {
    margin-bottom: 80px;
}

.doc-section h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.doc-section h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
    color: var(--text-primary);
}

.doc-section h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 32px 0 16px;
    color: var(--text-primary);
}

.doc-section h4 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 24px 0 16px;
    color: var(--text-primary);
}

.lead {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.7;
}

/* Info Boxes */
.info-box,
.warning-box {
    padding: 24px;
    border-radius: 12px;
    margin: 24px 0;
    border-left: 4px solid;
}

.info-box {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--primary);
}

.info-box h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.warning-box {
    background: rgba(251, 191, 36, 0.05);
    border-color: #fbbf24;
}

.warning-box strong {
    color: #f59e0b;
}

.info-box ul,
.warning-box ul {
    margin: 12px 0;
    padding-left: 24px;
}

.info-box li,
.warning-box li {
    margin: 8px 0;
    line-height: 1.6;
}

/* Tables */
.table-wrapper {
    position: relative;
    margin: 24px 0;
}

.table-wrapper::after {
    content: '→';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(to left, var(--bg-secondary) 0%, transparent 100%);
    padding: 8px 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .table-wrapper::after {
        opacity: 1;
    }
    
    .table-wrapper.scrolled::after {
        opacity: 0;
    }
}

.docs-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.docs-table thead {
    background: var(--bg-tertiary);
}

.docs-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.docs-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.docs-table tbody tr:last-child td {
    border-bottom: none;
}

.docs-table tbody tr:hover {
    background: var(--bg-hover);
}

.params-wrapper {
    position: relative;
    margin: 16px 0 32px;
}

.params-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.params-table thead {
    background: var(--bg-tertiary);
}

.params-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.params-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.params-table tbody tr:last-child td {
    border-bottom: none;
}

.params-table code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--primary);
}

/* Endpoints */
.endpoint {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    margin: 32px 0;
}

.endpoint-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.method-badge {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.method-badge.get {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.method-badge.post {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.method-badge.put {
    background: rgba(251, 191, 36, 0.1);
    color: #fbbf24;
}

.method-badge.delete {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.endpoint-path {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.endpoint-desc {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 32px;
}

/* Code Blocks */
.code-block {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 16px 0;
    overflow: hidden;
    display: none;
}

.code-block.active {
    display: block;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
}

.code-header span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.copy-btn {
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.copy-btn.copied {
    background: #10b981;
}

.code-block pre {
    margin: 0;
    padding: 20px;
    overflow-x: auto;
}

.code-block code {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
}

/* Code Tabs */
.code-tabs {
    display: flex;
    gap: 8px;
    margin: 24px 0 0;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Scrollbar Styling */
.docs-sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.docs-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.docs-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .docs-container {
        max-width: 100%;
        margin: 0;
        padding: 0;
        padding-left: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .docs-sidebar {
        position: static;
        left: 0;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 50vh;
        overflow-y: auto;
        width: 100%;
    }
    
    .docs-main {
        padding: 32px 24px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .endpoint {
        padding: 24px 20px;
        box-sizing: border-box;
    }

    .code-block pre {
        font-size: 0.85rem;
    }
}

@media (max-width: 768px) {
    .docs-page {
        padding-top: 80px;
        overflow-x: hidden;
    }

    body.docs-page {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }

    .docs-container {
        padding: 0;
        max-width: 100%;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* 侧边栏优化 - 可折叠设计 */
    .docs-sidebar {
        position: relative;
        height: auto;
        max-height: none;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 16px;
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .sidebar-content.active {
        max-height: 80vh;
        overflow-y: auto;
        margin-top: 16px;
    }

    .sidebar-section {
        margin-bottom: 20px;
    }

    .sidebar-title {
        font-size: 0.85rem;
        margin-bottom: 10px;
        padding: 0 8px;
    }

    .sidebar-link {
        font-size: 0.85rem;
        padding: 10px 12px;
        margin-bottom: 4px;
        min-height: 40px;
        display: flex;
        align-items: center;
    }

    /* 主内容区优化 */
    .docs-sidebar {
        position: static;
        width: 100%;
    }
    
    .docs-main {
        padding: 20px 16px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .doc-section {
        margin-bottom: 50px;
    }

    .doc-section h1 {
        font-size: 1.6rem;
        line-height: 1.3;
        margin-bottom: 12px;
        word-break: keep-all;
    }

    .doc-section h2 {
        font-size: 1.3rem;
        margin-top: 32px;
        margin-bottom: 16px;
        padding-bottom: 10px;
        line-height: 1.4;
    }

    .doc-section h3 {
        font-size: 1.1rem;
        margin: 24px 0 12px;
    }

    .doc-section h4 {
        font-size: 1rem;
        margin: 20px 0 12px;
    }

    .lead {
        font-size: 1rem;
        line-height: 1.6;
        margin-bottom: 24px;
    }

    /* 端点卡片优化 */
    .endpoint {
        padding: 16px 14px;
        margin: 20px 0;
        border-radius: 10px;
        box-sizing: border-box;
        max-width: 100%;
        overflow-x: hidden;
    }

    .endpoint-header {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        margin-bottom: 12px;
    }

    .method-badge {
        padding: 5px 10px;
        font-size: 0.7rem;
    }

    .endpoint-path {
        font-size: 0.8rem;
        word-break: break-all;
        flex: 1 1 100%;
    }

    .endpoint-desc {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    /* 代码块优化 - 关键改进 */
    .code-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 20px -16px 0;
        padding: 0 16px;
        scrollbar-width: thin;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
        white-space: nowrap;
        min-height: 40px;
    }

    .code-block {
        margin: 16px -16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .code-header {
        padding: 10px 16px;
    }

    .code-header span {
        font-size: 0.75rem;
    }

    .copy-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
        min-height: 32px;
    }

    .code-block pre {
        padding: 16px;
        font-size: 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .code-block code {
        font-size: 0.75rem;
        line-height: 1.5;
    }

    /* 表格优化 - 横向滚动 */
    .docs-table,
    .params-table {
        font-size: 0.75rem;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 16px -16px;
        border-radius: 0;
        scrollbar-width: thin;
    }

    .docs-table thead,
    .params-table thead {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .docs-table th,
    .docs-table td,
    .params-table th,
    .params-table td {
        padding: 10px 12px;
        white-space: nowrap;
        min-width: 100px;
    }

    .params-table code {
        font-size: 0.75rem;
        padding: 2px 5px;
        white-space: nowrap;
    }

    /* 信息框优化 */
    .info-box,
    .warning-box,
    .success-box {
        padding: 16px 14px;
        margin: 16px 0;
        border-radius: 10px;
        box-sizing: border-box;
        max-width: 100%;
        overflow-x: hidden;
        word-wrap: break-word;
    }

    .info-box h3,
    .warning-box h3,
    .success-box h3 {
        font-size: 0.95rem;
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        line-height: 1.4;
    }

    .info-box h3 svg,
    .warning-box h3 svg,
    .success-box h3 svg {
        width: 18px;
        height: 18px;
        margin-right: 6px;
        flex-shrink: 0;
    }

    .info-box ul,
    .info-box ol,
    .warning-box ul {
        padding-left: 20px;
        margin: 8px 0;
    }

    .info-box li,
    .warning-box li {
        margin-bottom: 6px;
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .info-box code,
    .warning-box code {
        font-size: 0.8rem;
        padding: 2px 5px;
        word-break: break-all;
    }

    /* 滚动条样式 */
    .docs-table::-webkit-scrollbar,
    .params-table::-webkit-scrollbar,
    .code-block pre::-webkit-scrollbar,
    .code-tabs::-webkit-scrollbar {
        height: 6px;
    }

    .docs-table::-webkit-scrollbar-track,
    .params-table::-webkit-scrollbar-track,
    .code-block pre::-webkit-scrollbar-track,
    .code-tabs::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.05);
        border-radius: 3px;
    }

    .docs-table::-webkit-scrollbar-thumb,
    .params-table::-webkit-scrollbar-thumb,
    .code-block pre::-webkit-scrollbar-thumb,
    .code-tabs::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 3px;
    }

    /* 触摸优化 */
    .sidebar-link,
    .tab-btn,
    .copy-btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* 改进代码块的可读性 */
    pre code {
        display: block;
        line-height: 1.6;
    }

    /* 表格文字大小优化 */
    .docs-table code,
    .params-table code {
        word-break: break-word;
    }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
    .docs-main {
        padding: 16px 12px;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .doc-section h1 {
        font-size: 1.4rem;
    }

    .doc-section h2 {
        font-size: 1.2rem;
    }

    .doc-section h3 {
        font-size: 1rem;
    }

    .lead {
        font-size: 0.9rem;
    }

    .endpoint {
        padding: 14px 12px;
    }

    .code-block pre {
        padding: 12px;
        font-size: 0.7rem;
    }

    .docs-table th,
    .docs-table td,
    .params-table th,
    .params-table td {
        padding: 8px 10px;
        font-size: 0.7rem;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .docs-sidebar,
    .copy-btn,
    footer {
        display: none;
    }

    .docs-container {
        grid-template-columns: 1fr;
    }

    .docs-main {
        max-width: 100%;
        padding: 0;
    }

    .code-block {
        page-break-inside: avoid;
    }
}
