/* ================= 1. 全局变量与基础设置 ================= */

/* 默认隐藏 QuantumultX 标签按钮 */
#tab-qx {
    display: none !important;
}
/* 显示状态的类 */
#tab-qx.show {
    display: flex !important;
}

:root {
    --sidebar-w: 240px;
    --primary: #3b82f6;
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --text-main: #333333;
    --text-sub: #666666;
    --border: #e5e7eb;
    --grid-line: rgba(0, 0, 0, 0.04);
    --header-h-mobile: 60px;
}

[data-theme="dark"] {
    --bg-body: #111827;
    --bg-card: #1f2937;
    --text-main: #f3f4f6;
    --text-sub: #9ca3af;
    --border: #374151;
    --grid-line: rgba(255, 255, 255, 0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-body);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

a { text-decoration: none; color: inherit; }
.clickable { color: blue; cursor: pointer; text-decoration: none; }
.clickable:hover { text-decoration: underline; }

/* ================= 2. 布局：侧边栏 (Sidebar) ================= */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1100;
    transition: transform 0.3s ease;
    height: 100%;
    flex-shrink: 0;
}

.logo {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
}
.logo i { margin-right: 8px; font-size: 1.4rem; }

.nav-menu { flex: 1; overflow-y: auto; padding: 10px 0; }

.nav-item {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-sub);
    display: flex;
    align-items: center;
    transition: 0.2s;
    border-left: 3px solid transparent;
}
.nav-item i { margin-right: 10px; font-size: 1.1rem; width: 20px; text-align: center; }
.nav-item:hover { background: var(--bg-body); color: var(--primary); }
.nav-item.active {
    background: var(--bg-body);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-sub);
    background: var(--bg-card);
}
.run-time { display: block; margin-bottom: 5px; opacity: 0.8; }
.app-version {
    display: inline-block;
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.dev-tools { padding: 15px; border-top: 1px solid var(--border); background: var(--bg-card); }
.btn-tool {
    width: 100%; padding: 8px; border: 1px solid var(--border);
    background: transparent; color: var(--text-sub); border-radius: 6px;
    margin-top: 8px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 5px; font-size: 0.85rem; transition: 0.2s;
}
.btn-tool:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: white; border: none; }

.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1050;
    display: none; opacity: 0; transition: opacity 0.3s; backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* ================= 3. 布局：主区域 (Main) ================= */
.main-viewport {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    scroll-behavior: smooth;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 20px 20px;
    position: relative;
}

/* 顶部 Banner 与 搜索 */
.banner {
    height: 220px;
    background-image: url('../bg.jpg');
    background-color: #3b82f6;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 20px; color: white; background-size: cover; background-position: center;
    background-repeat: no-repeat; transition: height 0.3s;
}
.banner h1 { font-size: 1.6rem; margin-bottom: 15px; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,0.3); text-align: center;}

.search-container { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 10px; }
.search-bar { position: relative; width: 100%; }
.search-bar input {
    width: 100%; padding: 12px 20px 12px 45px;
    border-radius: 50px; border: none;
    background: rgba(255,255,255,0.95);
    font-size: 0.95rem; box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    transition: all 0.3s;
}
.search-bar i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #666; }

/* 滚动公告 */
.notice-bar {
    height: 24px; background: rgba(0, 0, 0, 0.2); backdrop-filter: blur(4px);
    border-radius: 12px; display: flex; align-items: center; padding: 0 10px;
    font-size: 12px; color: rgba(255,255,255, 0.9); overflow: hidden;
    border: 1px solid rgba(255,255,255,0.15); margin-top: 5px;
}
.notice-icon { margin-right: 6px; font-size: 12px; animation: bellShake 3s infinite; }
.notice-content { flex: 1; height: 100%; position: relative; overflow: hidden; }
.notice-list {
    list-style: none; position: absolute; top: 0; left: 0; width: 100%;
    animation: scrollUp 12s infinite cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
.notice-item { height: 24px; line-height: 25px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notice-item a { color: inherit; display: block; width: 100%; }

/* 内容网格 */
.content-area { padding: 30px; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 400px); }
.section-header {
    font-size: 1.05rem; color: var(--text-sub); margin: 30px 0 15px 0;
    display: flex; align-items: center; font-weight: 600; opacity: 0.9;
}
.section-header::before {
    content: "#"; margin-right: 6px; font-weight: 400; font-size: 1.1rem; color: #cbd5e1;
}
.grid-box { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }

/* 底部 */
.footer {
    text-align: center; padding: 30px 20px 80px 20px; color: var(--text-sub);
    font-size: 0.75rem; line-height: 1.6; opacity: 0.8;
    border-top: 1px dashed var(--border); margin-top: 40px;
}

/* ================= 4. 组件：卡片 (整合优化版) ================= */
.card {
    background: var(--bg-card); border-radius: 8px; padding: 14px;
    display: flex; align-items: center; text-decoration: none;
    color: inherit; transition: all 0.2s; position: relative;
    overflow: hidden; border: 1px solid transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03); cursor: pointer;
}

/* 仅在支持悬停的设备上启用上浮效果，防止手机端闪烁 */
@media (hover: hover) {
    .card:hover {
        transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0,0,0,0.06);
        border-color: rgba(59, 130, 246, 0.3);
    }
}

.card-img {
    width: 36px; height: 36px; border-radius: 6px;
    background: var(--bg-body); margin-right: 12px; object-fit: cover; flex-shrink: 0;
}

/* 图标加载失败时的文字兜底 */
.card-fallback-icon {
    width: 36px; height: 36px; border-radius: 6px;
    background: var(--primary); margin-right: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 16px; font-weight: 700; line-height: 1;
}

/* 卡片信息容器 - Flex 布局控制紧凑间距 */
.card-info {
    flex: 1;
    overflow: hidden;
    padding-right: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px; /* 核心：行间距 */
}

.card-title {
    font-size: 0.9rem; font-weight: 700; color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin: 0; line-height: 1.4;
}

.card-desc {
    font-size: 0.75rem; color: var(--text-sub);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin: 0; line-height: 1.5;
}

/* 作者/标签 - 紧凑样式 */
.card-tag {
    display: inline-block;
    font-size: 11px;
    padding: 0px 6px;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    font-weight: 500;
    line-height: 1.5;
    width: fit-content;
    margin: 0;
}

/* 热度/按钮标识 */
.card-views {
    position: absolute; top: 6px; right: 8px; font-size: 10px;
    color: #f59e0b; background: rgba(245, 158, 11, 0.1);
    padding: 1px 4px; border-radius: 4px; display: flex; align-items: center; gap: 2px;
}
.view-count { font-weight: 600; }

/* 编辑/删除按钮 (DEV模式) */
.card-actions { position: absolute; top: 0; right: 0; display: none; z-index: 10; }
.card:hover .card-actions { display: flex; }
.action-btn {
    width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: white; font-size: 12px;
}
.btn-edit { background-color: #3b82f6; }
.btn-del { background-color: #ef4444; border-bottom-left-radius: 6px; }

/* ================= 5. 组件：Tab 切换器 ================= */
.tab-container {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    padding: 4px;
    margin-top: 15px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
    position: relative;
    z-index: 10;
}

.tab-btn {
    padding: 6px 24px;
    border-radius: 16px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
    border: none;
    background: transparent;
}

.tab-btn.active {
    background: white;
    color: var(--primary);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ================= 6. 组件：浮动按钮 & 弹窗 ================= */
.fab-container {
    position: fixed; bottom: 30px; right: 30px;
    display: flex; flex-direction: column; gap: 12px; z-index: 100;
}
.fab-btn {
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--bg-card); color: var(--text-sub);
    border: 1px solid var(--border); cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
    transition: 0.2s;
}
.fab-btn:hover { transform: scale(1.1); color: var(--primary); border-color: var(--primary); }

/* 通用 Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; justify-content: center; align-items: center;
    z-index: 2000; backdrop-filter: blur(3px);
}
.modal-box {
    background: var(--bg-card); width: 90%; max-width: 400px;
    padding: 24px; border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
}
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 0.85rem; margin-bottom: 4px; color: var(--text-sub); }
.form-row input, .form-row select {
    width: 100%; padding: 8px 10px;
    background: var(--bg-body); border: 1px solid var(--border);
    color: var(--text-main); border-radius: 6px; font-size: 0.9rem;
}
.modal-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.textarea-export { width: 100%; height: 150px; padding: 10px; background: #1e293b; color: #86efac; border-radius: 6px; font-family: monospace; font-size: 12px; border:none; }

/* 更新日志 Modal */
.log-scroll-box {
    max-height: 300px; overflow-y: auto; margin: 10px 0; padding-right: 5px;
}
.log-scroll-box::-webkit-scrollbar { width: 4px; }
.log-scroll-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 20px; padding-top: 5px; }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item:last-child { margin-bottom: 0; }
.timeline-item::before {
    content: ''; position: absolute; left: -27px; top: 5px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--bg-card); border: 2px solid var(--primary); z-index: 1;
}
.timeline-date {
    font-size: 0.75rem; color: var(--primary); font-weight: 600;
    margin-bottom: 4px; display: inline-block;
    background: rgba(59, 130, 246, 0.1); padding: 1px 6px; border-radius: 4px;
}
.timeline-content { font-size: 0.9rem; color: var(--text-main); line-height: 1.5; }

/* ================= 7. 动画与提示 (Toast) ================= */
#toast-container {
    position: fixed; top: 30px; left: 50%; transform: translateX(-50%);
    z-index: 10000; display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast-msg {
    background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px); color: #fff;
    padding: 10px 24px; border-radius: 50px; font-size: 0.9rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2); display: flex; align-items: center; gap: 8px;
    white-space: nowrap;
    opacity: 0; animation: toastIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}
.toast-success i { color: #4ade80; }
.toast-warn i { color: #facc15; }

@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-20px); } }
@keyframes scrollUp { 0%, 20% { top: 0; } 25%, 45% { top: -24px; } 50%, 70% { top: -48px; } 75%, 95% { top: -72px; } 100% { top: 0; } }
@keyframes bellShake { 0%, 100% { transform: rotate(0); } 10%, 30%, 50% { transform: rotate(-15deg); } 20%, 40% { transform: rotate(15deg); } 60% { transform: rotate(0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin-slow { animation: spin 4s linear infinite; display: inline-block; margin-right: 4px; }

/* ================= 8. 移动端适配 (优化版) ================= */
.mobile-header {
    display: none; position: fixed; top: 0; left: 0; right: 0; height: var(--header-h-mobile);
    z-index: 1000; padding: 0 20px; align-items: center; justify-content: space-between;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); color: white;
}
.mobile-header.scrolled {
    background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px); border-bottom: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 4px 20px rgba(0,0,0,0.06); color: var(--text-main);
}
[data-theme="dark"] .mobile-header.scrolled {
    background: rgba(31, 41, 55, 0.9); border-bottom: 1px solid rgba(255,255,255,0.08); color: var(--text-main);
}
.m-logo-icon { font-size: 1.5rem; display: flex; align-items: center; }
.m-menu-btn { font-size: 1.5rem; cursor: pointer; }

/* ★★★ 修改重点在这里 ★★★ */
@media (max-width: 768px) {
    body { display: block; height: auto; overflow-y: auto; }
    .mobile-header { display: flex; }

    .sidebar {
        position: fixed; left: -100%; height: 100%; top: 0;
        transform: translateX(0); left: -100%;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
    }
    .sidebar.show { left: 0; }
    .main-viewport { height: auto; overflow: visible; }

    .banner {
        /* 顶部避让导航栏 (60px) */
        padding-top: var(--header-h-mobile);
        height: auto;

        /* 1. 减小最小高度 (原240px -> 180px)，防止强制撑开导致上下空隙过大 */
        min-height: 180px;

        /* 2. 减小底部留白 (原30px -> 15px)，解决Tab离底部太宽的问题 */
        padding-bottom: 15px;
    }

    .banner h1 {
        font-size: 1.25rem;

        /* 3. 减小标题上边距 (原20px -> 5px)，解决文字离顶部太宽的问题 */
        margin-top: 5px;
        margin-bottom: 10px; /* 微调标题与搜索框的间距 */
    }

    .search-bar input { padding: 8px 15px 8px 40px; font-size: 0.85rem; height: 38px; }
    .search-bar i { font-size: 0.9rem; left: 12px; }
    .content-area { padding: 15px; }
    .grid-box { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card { padding: 10px; flex-direction: column; align-items: flex-start; text-align: left; }
    .card-img { margin-bottom: 8px; width: 32px; height: 32px; }
    .card-fallback-icon { margin-bottom: 8px; width: 32px; height: 32px; font-size: 14px; }
    #mobileMenuBtn { display: none !important; }
}

/* ================= 环形进度条新增样式 ================= */
/* 调整置顶按钮，使其支持绝对定位的 SVG */
#toTopBtn {
    position: relative;
    border: none; /* 去除原有边框，改用 SVG 圆环作为边框视觉 */
    background: var(--bg-card); /* 保持背景色 */
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); /* 保持阴影 */
    padding: 0; /* 清除内边距 */
    overflow: visible; /* 允许SVG稍微溢出一点（如果有需要） */
}

/* 进度条 SVG 容器，旋转 -90度 是为了让进度从正上方开始 */
.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none; /* 让点击事件穿透 SVG 作用于按钮 */
}

/* 圆环的背景轨道（灰色/浅色圆圈） */
.progress-ring__bg {
    stroke: var(--border); /* 使用你定义的边框颜色变量 */
    transition: stroke 0.3s;
}

/* 蓝色的进度条圆圈 */
.progress-ring__circle {
    stroke: var(--primary); /* 使用你定义的主题蓝色 */
    transition: stroke-dashoffset 0.1s linear; /* 丝滑动画 */
    transform-origin: 50% 50%;
    stroke-linecap: round; /* 圆头看起来更精致 */
}

/* 调整原来的图标层级，确保在圆环上面 */
#toTopBtn i {
    position: relative;
    z-index: 2;
}
