/* ===== AI Collection Page ===== */
/* 大分类 & 小分类平级展示布局 */

/* Anchor scroll offset to prevent header overlap */
.ai-content [id] {
    scroll-margin-top: 80px;
}

.ai-main {
    padding: 16px 0 30px;
    min-height: 100vh;
    overflow-x: hidden;
}

/* 两列布局: 侧边栏(fixed) + 主内容 */
.ai-layout {
    position: relative;
}

/* ===== 左侧分类侧边栏 ===== */
.ai-sidebar {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    left: 12px;
    width: 280px;
    z-index: 10;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    border: none;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-sidebar.sidebar-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-section {
    padding-bottom: 16px;
}

.sidebar-section:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
}

.sidebar-item:hover {
    color: var(--text-primary);
    background-color: var(--sidebar-active-bg, rgba(0,0,0,0.04));
}

.sidebar-item svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.sidebar-item:hover svg {
    color: var(--text-secondary);
}

.sidebar-count {
    margin-left: auto;
    font-size: 14px;
    color: var(--text-muted);
    background: var(--badge-bg, rgba(0,0,0,0.05));
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* ===== 右侧内容区 ===== */
.ai-content {
    max-width: 1100px;
    margin: 0 auto;
    min-width: 0;
}

/* Collision avoidance: when viewport ≤1708px, push content right of sidebar */
/* 1708 = 1100 (content) + 2×(12+280+12) → content left edge clears sidebar right edge + 12px gap */
@media (max-width: 1708px) {
    .ai-content {
        margin-left: 304px;
        margin-right: auto;
    }
}

/* 分类组标题 */
.ai-category-group {
    margin-bottom: 24px;
}

.ai-category-group:last-child {
    margin-bottom: 0;
}

.group-heading {
    font-size: 23px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

/* 分类区段 */
.category-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px;
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.category-section:last-child {
    margin-bottom: 0;
}

/* 分类区段头 */
.category-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.category-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.category-badge {
    display: inline-flex;
    align-items: center;
}

.category-count {
    background-color: var(--badge-bg, rgba(0,0,0,0.05));
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 600;
}

.section-more {
    margin-left: auto;
    font-size: 16px;
    color: var(--text-tertiary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.section-more svg {
    width: 16px;
    height: 16px;
}

.section-more:hover {
    color: var(--text-primary);
}

/* 工具卡片网格 - 5列 */
.tools-grid-compact {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

/* 工具卡片 */
.tool-card {
    border-radius: var(--radius-sm);
    padding: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--card-bg);
    border: 1px solid transparent;
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tool-card:hover {
    background: var(--card-hover-bg, rgba(0,0,0,0.02));
    border-color: var(--border-color);
}

.tool-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
    overflow: hidden;
    background: var(--bg-tertiary, #f5f5f5);
    object-fit: cover;
}

.tool-card-info {
    flex: 1;
    min-width: 0;
}

.tool-card-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.tool-card-desc {
    font-size: 14px;
    color: var(--text-tertiary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: var(--radius-xs);
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    text-decoration: none;
}

.pagination a:hover {
    background: var(--card-hover-bg);
    color: var(--text-primary);
}

.pagination .current {
    background: var(--text-primary);
    color: var(--bg-primary);
    font-weight: 600;
}

.pagination .disabled {
    color: var(--text-muted);
    pointer-events: none;
}

/* ===== Responsive ===== */
@media (max-width: 1400px) {
    .tools-grid-compact {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1200px) {
    .tools-grid-compact {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .ai-content {
        margin-left: 0;
    }

    /* Sidebar: inline flat layout */
    .ai-sidebar {
        position: static;
        transform: none;
        width: 100%;
        max-height: none;
        margin-bottom: 12px;
    }

    /* Override sidebar-hidden — inline sidebar always visible */
    .ai-sidebar.sidebar-hidden {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Sidebar nav: 3-column grid for tablets */
    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 3px;
    }

    /* Sidebar item: grid layout, count below title */
    .sidebar-item {
        display: grid;
        grid-template-columns: 18px 1fr;
        gap: 2px 10px;
        min-width: 0;
    }

    .sidebar-item > svg {
        grid-row: 1 / 3;
        align-self: center;
    }

    .sidebar-item > span:not(.sidebar-count) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }

    .sidebar-count {
        margin-left: 0;
        grid-column: 2;
        justify-self: start;
    }

    .tools-grid-compact {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    /* Sidebar nav: 3-col → 2-col for phones */
    .sidebar-nav {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Wider columns: allow text wrapping */
    .sidebar-item > span:not(.sidebar-count) {
        white-space: normal;
        overflow: visible;
    }

    /* Headers: allow wrapping on narrow screens */
    .category-header {
        flex-wrap: wrap;
    }

    /* Grid: use minmax(0,1fr) to prevent content overflow */
    .tools-grid-compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Clip overflow inside section containers */
    .category-section {
        overflow: hidden;
    }
}
