/* ============================================
   Layout Styles - Header, Sidebar, Content
   ============================================ */

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--space-6);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all var(--transition-base);
    gap: var(--space-4);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-6);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
}

.header-logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    box-shadow: var(--accent-glow);
}

.header-logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    list-style: none;
    padding: 0;
    margin: 0;
}

.header-nav a {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.header-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

/* Search Bar */
.search-container {
    position: relative;
}

.search-input {
    width: 280px;
    padding: var(--space-2) var(--space-3) var(--space-2) 36px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
    outline: none;
}

.search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-light);
    width: 320px;
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
    font-size: 0.875rem;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: var(--space-2);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: var(--z-modal);
}

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

.search-result-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition-fast);
}

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

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

.search-result-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.search-result-path {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* App Layout */
.app-layout {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    height: calc(100vh - var(--header-height));  /* 固定高度 */
    overflow: hidden;  /* 防止整体滚动 */
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    overflow-y: auto;  /* 侧边栏独立滚动 */
    overflow-x: hidden;
    height: 100%;  /* 填充父容器高度 */
    position: relative;  /* 改为 relative */
    top: 0;  /* 移除 sticky */
    padding: var(--space-4) 0;
}

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

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

.sidebar-section {
    padding: 0 var(--space-3);
}

.sidebar-heading {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    padding: var(--space-3) var(--space-3) var(--space-2);
    margin-top: var(--space-2);
}

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

.sidebar-nav li {
    margin: 1px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    gap: var(--space-2);
}

.sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-nav a.active {
    background: var(--bg-active);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.sidebar-nav a .nav-icon {
    font-size: 0.9rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Nested nav levels */
.sidebar-nav .nav-level-2 {
    padding-left: var(--space-6);
    font-size: 0.8rem;
}

.sidebar-nav .nav-level-3 {
    padding-left: calc(var(--space-6) + var(--space-4));
    font-size: 0.78rem;
    color: var(--text-tertiary);
}

.sidebar-nav .nav-level-3:hover {
    color: var(--text-primary);
}

/* Collapsible sidebar sections */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-collapse-btn:hover {
    background: var(--bg-hover);
}

.sidebar-collapse-btn .arrow {
    transition: transform var(--transition-fast);
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.sidebar-collapse-btn.collapsed .arrow {
    transform: rotate(-90deg);
}

.sidebar-collapse-content {
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.sidebar-collapse-content.collapsed {
    max-height: 0 !important;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: var(--space-8) var(--space-10);
    max-width: var(--content-max-width);
    min-width: 0;
    overflow-y: auto;  /* 主内容独立滚动 */
    height: 100%;  /* 填充父容器高度 */
    scroll-behavior: smooth;  /* 平滑滚动 */
}

/* Content Loader */
.content-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    gap: var(--space-4);
}

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

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

/* Table of Contents Panel */
.toc-panel {
    width: var(--toc-width);
    min-width: var(--toc-width);
    padding: var(--space-6) var(--space-4);
    height: 100%;  /* 填充父容器高度 */
    overflow-y: auto;  /* TOC独立滚动 */
    border-left: 1px solid var(--border-light);
    background: var(--bg-surface);
    position: relative;  /* 改为 relative */
    top: 0;  /* 移除 sticky */
}

.toc-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: var(--space-3);
}

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

.toc-list a {
    display: block;
    padding: var(--space-1) var(--space-2);
    color: var(--text-tertiary);
    font-size: 0.78rem;
    text-decoration: none;
    border-radius: var(--radius-xs);
    transition: all var(--transition-fast);
    border-left: 2px solid transparent;
}

.toc-list a:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    text-decoration: none;
}

.toc-list a.active {
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 500;
}

.toc-list .toc-h3 {
    padding-left: var(--space-4);
}

.toc-list .toc-h4 {
    padding-left: var(--space-8);
    font-size: 0.75rem;
}

/* 分类锚点 - 偏移以补偿 fixed header */
.category-anchor {
    display: block;
    height: 1px;
    scroll-margin-top: 80px;  /* 现代浏览器的简单方案 */
    margin-top: calc(-1 * var(--header-height) - 10px);
    padding-top: calc(var(--header-height) + 10px);
    visibility: hidden;
}

/* 分类大标题 */
.category-title {
    margin-bottom: var(--space-8);
}

.category-title h1 {
    font-size: 2.5rem;
    margin: 0;
    padding-bottom: var(--space-3);
    border-bottom: 3px solid var(--accent-primary);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Footer */
.footer {
    text-align: center;
    padding: var(--space-6);
    border-top: 1px solid var(--border-light);
    color: var(--text-tertiary);
    font-size: 0.8rem;
    background: var(--bg-surface);
}

/* ============================================
   Responsive Design - 响应式设计
   ============================================ */

/* 平板和小屏幕设备 */
@media (max-width: 1200px) {
    .toc-panel {
        display: none;  /* 隐藏右侧目录 */
    }
    
    .main-content {
        padding: var(--space-6) var(--space-6);
    }
}

/* 移动端设备 */
@media (max-width: 900px) {
    /* 恢复整体布局的滚动 */
    .app-layout {
        height: auto;
        overflow: visible;
    }
    
    /* 侧边栏改为固定定位的抽屉式 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: var(--z-sidebar);
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        box-shadow: var(--shadow-xl);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* 主内容区恢复自动高度 */
    .main-content {
        height: auto;
        overflow: visible;
        padding: var(--space-4) var(--space-4);
    }
    
    /* 显示移动端菜单按钮 */
    .mobile-menu-toggle {
        display: block;
    }
    
    /* 侧边栏遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-sidebar) - 1);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    /* 搜索框调整 */
    .search-input {
        width: 200px;
    }
    
    .search-input:focus {
        width: 240px;
    }
    
    /* 标题字体调整 */
    .category-title h1 {
        font-size: 1.8rem;
    }
    
    /* API卡片调整 */
    .api-card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .params-table {
        font-size: 0.8rem;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .header {
        padding: 0 var(--space-3);
    }
    
    .header-logo-text {
        display: none;  /* 隐藏logo文字，只留图标 */
    }
    
    .search-input {
        width: 160px;
    }
    
    .search-input:focus {
        width: 180px;
    }
    
    .main-content {
        padding: var(--space-3);
    }
    
    /* API卡片全宽显示 */
    .property-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .property-description {
        margin-left: 0;
        text-align: left;
    }
}