/* ===== 前台样式 ===== */
:root {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-dark: #2563eb;
    --text: #1f2937;
    --text-light: #6b7280;
    --text-lighter: #9ca3af;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
    --transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
}

html[data-theme="dark"], html[data-theme="dark"] body {
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --text-lighter: #64748b;
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --shadow: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.container { max-width: 800px; margin: 0 auto; padding: 0 16px; }

/* 遮罩 */
.overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 200;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.overlay.show { display: block; opacity: 1; pointer-events: auto; }

/* 侧边栏 */
.sidebar {
    position: fixed; top: 0; left: 0; width: 260px; height: 100%;
    background: white; z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
}
html[data-theme="dark"] .sidebar { background: #1e293b; }
.sidebar.open { transform: translateX(0); }
.sidebar-head {
    padding: 20px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-head img { height: 32px; max-width: 160px; object-fit: contain; }
.sidebar-head .sidebar-brand { font-size: 18px; font-weight: 700; color: var(--text); }
.sidebar-head button { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg); color: var(--text-light); cursor: pointer; }
.sidebar-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 12px 20px;
    color: var(--text); text-decoration: none; font-size: 15px; font-weight: 500;
    border-left: 3px solid transparent; transition: all 0.2s;
}
.nav-link i { width: 20px; text-align: center; font-size: 15px; color: var(--primary); }
.nav-link:hover { background: var(--bg); color: var(--primary); }
.nav-link.active { background: rgba(59,130,246,0.08); color: var(--primary); border-left-color: var(--primary); }
.sidebar-foot { padding: 16px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }
.btn-apply {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; background: var(--primary); color: white;
    text-decoration: none; border-radius: 10px; font-size: 14px; font-weight: 600;
}
.btn-apply:hover { background: var(--primary-dark); }

/* 顶部栏 */
.topbar {
    position: sticky; top: 0; z-index: 100; display: flex; align-items: center;
    justify-content: center; padding: 0 16px; height: 56px;
    background: rgba(255,255,255,0.95); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 1200px; flex-wrap: nowrap; }
html[data-theme="dark"] .topbar { background: rgba(30,41,59,0.95); border-color: #334155; }
.btn-menu, .btn-theme {
    width: 40px; height: 40px; border-radius: 10px; border: none;
    background: transparent; color: var(--text-light); font-size: 18px;
    cursor: pointer; transition: all 0.2s;
}
.btn-menu:hover, .btn-theme:hover { background: var(--bg); color: var(--primary); }
.topbar-center { display: flex; align-items: center; justify-content: center; flex: 1; min-width: 0; text-decoration: none; }
.topbar-logo { height: 28px; max-width: 140px; object-fit: contain; }
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; max-width: 100%; }

/* 搜索 */
.search-wrap { padding: 16px 16px 0; max-width: 800px; margin: 0 auto; }
.search-box-new {
    display: flex; align-items: center; background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; padding: 4px; margin: 0 0 16px; box-shadow: var(--shadow); position: relative;
}
.engine-dropdown { position: relative; flex-shrink: 0; }
.engine-toggle { display: flex; align-items: center; gap: 6px; padding: 10px 14px; background: transparent; border: none; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; white-space: nowrap; }
.engine-toggle i { font-size: 10px; color: var(--text-light); }
.engine-list { display: none; position: absolute; top: calc(100% + 8px); left: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md); padding: 8px; min-width: 160px; z-index: 50; }
.engine-list.show { display: block; }
.engine-opt { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text); }
.engine-opt:hover { background: var(--bg); }
.engine-opt.active { background: rgba(59,130,246,0.08); color: var(--primary); font-weight: 600; }
.engine-opt img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }
.search-form { display: flex; align-items: center; flex: 1; gap: 8px; }
.search-form input { flex: 1; border: none; background: transparent; padding: 10px 8px; font-size: 15px; color: var(--text); outline: none; }
.search-form input::placeholder { color: var(--text-lighter); }
.search-icon-btn { width: 40px; height: 40px; border-radius: 10px; border: none; background: var(--primary); color: white; cursor: pointer; transition: all 0.2s; flex-shrink: 0; }
.search-icon-btn:hover { background: var(--primary-dark); }

/* 内容 */
.content { padding: 16px 0; }
.sec-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 16px; padding: 0 4px; }

/* 分类块 */
.block { background: var(--card); border-radius: 16px; padding: 20px; margin-bottom: 16px; border: 1px solid var(--border); box-shadow: var(--shadow); }
html[data-theme="dark"] .block { background: #1e293b; border-color: #334155; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.block-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.block-title i { font-size: 16px; color: var(--primary); }
.block-more, .block-count { display: flex; align-items: center; gap: 4px; color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 500; }
.fl-apply-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; border: none; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s; box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25); }
.fl-apply-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35); }
.fl-apply-btn i { font-size: 10px; }

/* 网站网格（旧版兼容：搜索/标签页） */
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.item { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 8px; border-radius: 12px; text-decoration: none; color: var(--text); transition: all 0.2s; text-align: center; min-width: 0; }
.item:hover { background: var(--bg); transform: translateY(-2px); }
.icon { width: 48px; height: 48px; border-radius: 12px; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,0.06); position: relative; }
html[data-theme="dark"] .icon { background: #0f172a; }
.icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.icon .fallback { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: var(--primary); font-size: 18px; font-weight: 700; background: var(--bg); }
.name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; color: var(--text); }

/* ===== 子分类标签栏 ===== */
.subcat-tabs { display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 14px; padding-bottom: 4px; scrollbar-width: none; }
.subcat-tabs::-webkit-scrollbar { display: none; }
.subcat-tab { display: inline-flex; align-items: center; gap: 4px; padding: 7px 16px; border-radius: 20px; background: var(--bg); border: 1.5px solid var(--border); color: var(--text-light); font-size: 13px; font-weight: 500; text-decoration: none; transition: all 0.2s; white-space: nowrap; flex-shrink: 0; cursor: pointer; }
.subcat-tab:hover { border-color: var(--primary); color: var(--primary); }
.subcat-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 站点卡片（2列：favicon+标题+描述） ===== */
.site-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.site-card { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; text-decoration: none; color: var(--text); transition: all 0.2s; overflow: hidden; }
.site-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(59,130,246,0.1); transform: translateY(-1px); }
.site-card .sc-icon { width: 44px; height: 44px; border-radius: 12px; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,0.06); flex-shrink: 0; position: relative; }
.site-card .sc-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* .sc-fb removed - no letter fallback */
.site-card .sc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.site-card .sc-title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.site-card .sc-desc { font-size: 12px; color: var(--text-light); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.site-card .sc-count { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-lighter); margin-top: 2px; }
.site-card .sc-count i { font-size: 11px; }

/* ===== 面包屑 ===== */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-light); margin-bottom: 12px; flex-wrap: wrap; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb .bc-sep { color: var(--text-lighter); }

/* ===== 分页 ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 20px; padding: 12px 0; }
.pagination a, .pagination span { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 10px; border-radius: 10px; font-size: 14px; font-weight: 500; text-decoration: none; transition: all 0.2s; }
.pagination a { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.dots { border: none; background: none; color: var(--text-lighter); }
.pagination .prev-next { padding: 0 14px; white-space: nowrap; }

/* 空状态 */
.empty { text-align: center; padding: 40px 20px; color: var(--text-lighter); }
.empty i { font-size: 36px; margin-bottom: 8px; opacity: 0.5; }

/* ===== 流量统计 ===== */
.stats-block .stats-grid-inline { display: flex; flex-wrap: wrap; gap: 12px 20px; font-size: 13px; }
.stats-item { display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; white-space: nowrap; }
.stats-item .stats-label { color: var(--text-light); font-size: 12px; }
.stats-item .stats-num { color: var(--primary); font-weight: 700; font-size: 15px; }
@media (max-width: 480px) {
    .stats-block .stats-grid-inline { gap: 8px 14px; }
    .stats-item .stats-label { font-size: 11px; }
    .stats-item .stats-num { font-size: 13px; }
}

/* ===== 排名角标 ===== */
.sc-rank { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #64748b, #475569); box-shadow: 0 2px 4px rgba(0,0,0,0.15); vertical-align: middle; flex-shrink: 0; }
.sc-rank.rank-1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); width: 22px; height: 22px; font-size: 11px; }
.sc-rank.rank-2 { background: linear-gradient(135deg, #cbd5e1, #94a3b8); width: 20px; height: 20px; }
.sc-rank.rank-3 { background: linear-gradient(135deg, #fdba74, #f97316); width: 20px; height: 20px; }

/* ===== 每日推荐 ===== */
.recommend-bar { display: flex; gap: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 4px 12px; scrollbar-width: none; }
.recommend-bar::-webkit-scrollbar { display: none; }
.rec-card { flex: 0 0 100px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; text-decoration: none; color: var(--text); transition: all 0.2s; text-align: center; }
.rec-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary); }
.rec-card .rec-icon { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; background: var(--bg); }
.rec-card .rec-title { font-size: 12px; font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; width: 100%; }

/* ===== 搜索历史和热门搜索 ===== */
.search-hint { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; margin-top: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); z-index: 50; display: none; overflow: hidden; }
.search-hint.show { display: block; }
.sh-section { padding: 10px 14px; }
.sh-section + .sh-section { border-top: 1px solid var(--border); }
.sh-title { font-size: 11px; color: var(--text-lighter); margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; }
.sh-title button { background: none; border: none; color: var(--text-lighter); font-size: 11px; cursor: pointer; }
.sh-title button:hover { color: var(--danger); }
.sh-tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg); border-radius: 16px; font-size: 13px; color: var(--text); margin: 3px; cursor: pointer; border: 1px solid var(--border); transition: all 0.15s; }
.sh-tag:hover { border-color: var(--primary); color: var(--primary); }
.sh-tag.hot { color: var(--danger); }
.sh-tag.hot i { font-size: 10px; }

/* 页脚 */

.site-footer { padding: 16px; text-align: center; border-top: 1px solid var(--border); margin-top: 16px; background: var(--card); }
html[data-theme="dark"] .site-footer { background: #1e293b; border-color: #334155; }
.footer-content p { font-size: 13px; color: var(--text-light); margin: 4px 0; }
.footer-icp { font-size: 12px; color: var(--text-lighter); }
.footer-copyright { font-size: 12px; color: var(--text-lighter); margin-top: 8px; }

/* 广告位 */
.ad-bar { padding: 0 16px; margin: 12px auto; max-width: 800px; }
.ad-list {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}
.ad-item {
    display: flex; align-items: center; justify-content: center;
    padding: 10px 12px; border-radius: 12px; background: var(--card);
    border: 1px solid var(--border); font-size: 13px;
    text-decoration: none; font-weight: 600; transition: all 0.25s ease;
    box-shadow: var(--shadow); position: relative; overflow: hidden;
    border-left: 4px solid var(--primary); color: var(--text);
}
.ad-item::before {
    content: '\f641'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    font-size: 12px; margin-right: 6px; color: var(--primary); flex-shrink: 0;
}
.ad-item span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: block;
}
.ad-item:hover {
    transform: translateY(-2px); box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, rgba(59,130,246,0.05), rgba(99,102,241,0.05));
}

@media (max-width: 768px) {
    .ad-list { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
@media (max-width: 480px) {
    .ad-list { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .ad-item { padding: 8px 10px; font-size: 12px; border-radius: 10px; }
}

/* ===== 右侧工具栏 ===== */
.rightbar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 250;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.rightbar-overlay.show { display: block; opacity: 1; pointer-events: auto; }
.rightbar {
    position: fixed; top: 0; right: 0; width: 260px; height: 100%;
    background: var(--card); z-index: 300;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}
.rightbar.open { transform: translateX(0); }
.rightbar-head {
    padding: 20px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.rightbar-head span { font-size: 16px; font-weight: 700; color: var(--text); }
.rightbar-head button { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg); color: var(--text-light); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rightbar-body { flex: 1; overflow-y: auto; padding: 12px 0; }
.rb-item {
    display: flex; align-items: center; gap: 12px; padding: 14px 20px;
    color: var(--text); text-decoration: none; font-size: 15px; font-weight: 500;
    transition: all 0.2s; cursor: pointer; border: none; background: none; width: 100%; font-family: inherit;
}
.rb-item i { width: 20px; text-align: center; font-size: 16px; color: var(--primary); }
.rb-item:hover { background: var(--bg); color: var(--primary); }
.rb-divider { height: 1px; background: var(--border); margin: 8px 16px; }
.rb-theme-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; }
.rb-theme-row span { font-size: 15px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 12px; }
.rb-theme-row span i { width: 20px; text-align: center; font-size: 16px; color: var(--primary); }
/* 暗色切换开关 */
.theme-switch { position: relative; width: 46px; height: 26px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.theme-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--border); border-radius: 26px;
    transition: all 0.3s;
}
.theme-slider::before {
    content: ''; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background: white; border-radius: 50%; transition: all 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.theme-switch input:checked + .theme-slider { background: var(--primary); }
.theme-switch input:checked + .theme-slider::before { transform: translateX(20px); }

/* 响应式 */

body { padding-bottom: 0; }

@media (max-width: 768px) {
    .grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
    .site-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
@media (max-width: 480px) {
    .grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .search-box-new { margin: 0 8px 12px; }
    .site-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .site-card { padding: 10px; border-radius: 12px; }
    .site-card .sc-icon { width: 40px; height: 40px; border-radius: 10px; }
    .site-card .sc-title { font-size: 13px; }
    .site-card .sc-desc { -webkit-line-clamp: 1; font-size: 11px; }
    .subcat-tab { padding: 6px 12px; font-size: 12px; }
}

/* ===== 搜索引擎选择面板（弹窗式） ===== */
.engine-select-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 90; backdrop-filter: blur(2px); }
.engine-select-overlay.show { display: block; }
.engine-select-panel { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90%; max-width: 420px; max-height: 80vh; background: var(--card); border-radius: 20px; box-shadow: var(--shadow-lg); z-index: 100; overflow: hidden; border: 1px solid var(--border); }
.engine-select-panel.show { display: block; }
.engine-select-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.engine-select-header h3 { font-size: 16px; font-weight: 600; color: var(--text); margin: 0; }
.engine-select-header .btn-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg); color: var(--text-light); display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; }
.engine-select-header .btn-close:hover { background: var(--danger); color: #fff; }
.engine-select-categories { padding: 12px; overflow-y: auto; max-height: calc(80vh - 60px); }
