/* ========== 全局样式 ========== */
:root {
    --primary: #7c3aed;
    --primary-light: #8b5cf6;
    --primary-dark: #6d28d9;
    --primary-bg: #f5f3ff;
    --sidebar-width: 260px;
    --sidebar-tablet: 220px;
    --header-height: 56px;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --card-hover-shadow: 0 10px 25px rgba(124, 58, 237, 0.12), 0 4px 10px rgba(0, 0, 0, 0.06);
    --radius: 10px;
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #f8fafc;
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ========== 头部 ========== */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}

header .logo {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

header .search-box {
    display: flex;
    align-items: center;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 24px;
    padding: 6px 16px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    gap: 8px;
}

header .search-box select {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    padding-right: 6px;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
}

header .search-box select option {
    color: var(--text);
    background: #fff;
}

header .search-box input {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 14px;
    outline: none;
    width: 220px;
    padding: 4px 0;
}

header .search-box input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

header .search-box button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

header .search-box button:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ========== 汉堡菜单按钮 ========== */
#menuToggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    margin-right: 12px;
    padding: 4px 8px;
    line-height: 1;
}

/* ========== 主体布局 ========== */
.main-wrapper {
    display: flex;
    margin-top: var(--header-height);
    flex: 1;
}

/* ========== 侧边栏 ========== */
#sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: #fff;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 90;
    padding: 16px 0 80px;
    transition: transform var(--transition);
}

#sidebar .cat-group {
    margin-bottom: 4px;
}

#sidebar .cat-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition);
    user-select: none;
}

#sidebar .cat-title:hover {
    background: var(--primary-bg);
}

#sidebar .cat-title .arrow {
    font-size: 10px;
    transition: transform var(--transition);
}

#sidebar .cat-title.collapsed .arrow {
    transform: rotate(-90deg);
}

#sidebar .cat-children {
    overflow: hidden;
    max-height: 2000px;
    transition: max-height 0.3s ease;
}

#sidebar .cat-children.collapsed {
    max-height: 0;
}

#sidebar .child-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 8px 32px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

#sidebar .child-item:hover {
    background: var(--primary-bg);
    color: var(--primary);
}

#sidebar .child-item.active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 600;
    border-left-color: var(--primary);
}

#sidebar .child-item .badge {
    background: #f1f5f9;
    color: var(--text-secondary);
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 500;
}

#sidebar .child-item.active .badge {
    background: #ede9fe;
    color: var(--primary);
}

#sidebar .all-item {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

#sidebar .all-item:hover {
    background: var(--primary-bg);
}

/* 侧边栏遮罩 */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#sidebarOverlay.show {
    display: block;
    opacity: 1;
}

/* ========== 内容区 ========== */
#content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px;
    min-height: calc(100vh - var(--header-height) - 60px);
}

#content .section-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

#content .section-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

#content .category-search {
    margin-bottom: 20px;
}

#content .category-search input {
    width: 100%;
    max-width: 400px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}

#content .category-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

/* ========== 工具网格 ========== */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.tool-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: all var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.tool-card:hover {
    box-shadow: var(--card-hover-shadow);
    border-color: #ddd6fe;
    transform: translateY(-2px);
}

.tool-card .tc-logo {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-card .tc-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 2px;
}

.tool-card .tc-logo .placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.tool-card .tc-info {
    flex: 1;
    min-width: 0;
}

.tool-card .tc-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-card .tc-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tool-card .tc-url {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ========== 概览页分类统计卡片 ========== */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}

.overview-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    text-align: center;
}

.overview-card:hover {
    box-shadow: var(--card-hover-shadow);
    border-color: #ddd6fe;
    transform: translateY(-2px);
}

.overview-card .oc-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.overview-card .oc-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.overview-card .oc-count {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========== 页脚 ========== */
footer {
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: var(--sidebar-width);
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ========== 一键置顶 ========== */
#backToTop {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.4);
    display: none;
    z-index: 80;
    transition: all var(--transition);
}

#backToTop:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.5);
}

#backToTop.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: var(--sidebar-tablet);
    }
    #content {
        margin-left: var(--sidebar-tablet);
    }
    footer {
        margin-left: var(--sidebar-tablet);
    }
    .tool-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (max-width: 768px) {
    #menuToggle {
        display: block;
    }
    #sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #content {
        margin-left: 0;
        padding: 20px 16px;
    }
    footer {
        margin-left: 0;
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 16px;
    }
    header .search-box input {
        width: 140px;
    }
    .tool-grid {
        grid-template-columns: repeat(auto-fill, minmax(100%, 1fr));
    }
    .overview-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    header {
        padding: 0 12px;
    }
    header .logo {
        font-size: 16px;
    }
    header .search-box {
        padding: 4px 10px;
        gap: 4px;
    }
    header .search-box select {
        font-size: 12px;
    }
    header .search-box input {
        width: 100px;
        font-size: 13px;
    }
}
