/* ===== Variables ===== */
:root {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-header: rgba(255,255,255,0.92);
    --text: #1a1a2e;
    --text-secondary: #666;
    --text-muted: #999;
    --border: #e8e8e8;
    --primary: #1890ff;
    --primary-bg: #e6f7ff;
    --accent: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --sidebar-width: 200px;
    --header-height: 56px;
}

[data-theme="dark"] {
    --bg: #141414;
    --bg-card: #1f1f1f;
    --bg-sidebar: #1a1a1a;
    --bg-header: rgba(26,26,26,0.95);
    --text: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --border: #303030;
    --primary: #1890ff;
    --primary-bg: #111d2c;
    --shadow: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.4);
}

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background 0.3s, color 0.3s;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 100%;
    padding: 0 20px;
}

.sidebar-toggle {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.sidebar-toggle:hover { background: var(--border); }

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.logo-icon { font-size: 1.3rem; }

.search-box {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.search-box input {
    width: 100%;
    height: 36px;
    padding: 0 36px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24,144,255,0.15);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-shortcut {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--border);
    color: var(--text-muted);
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 3px;
    pointer-events: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-stat {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-stat strong { color: var(--primary); font-weight: 600; }

.theme-toggle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-toggle:hover { background: var(--border); }
.theme-toggle svg { width: 16px; height: 16px; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ===== Layout ===== */
.layout {
    display: flex;
    padding-top: var(--header-height);
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 90;
    transition: transform 0.3s;
}

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

.sidebar-inner { padding: 12px 0; }

.sidebar-header {
    padding: 8px 20px 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-item:hover {
    background: var(--bg);
    color: var(--text);
}

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

.sidebar-item .icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item .count {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 10px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 85;
}

/* ===== Main ===== */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px 24px 48px;
    min-width: 0;
}

/* ===== Sub Category Bar ===== */
.sub-category-bar {
    margin-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.sub-category-bar::-webkit-scrollbar { display: none; }

.sub-category-list {
    display: flex;
    gap: 8px;
}

.sub-cat-btn {
    padding: 5px 14px;
    border-radius: 16px;
    font-size: 0.8rem;
    white-space: nowrap;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.sub-cat-btn:hover { border-color: var(--primary); color: var(--primary); }

.sub-cat-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== Section Header ===== */
.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title .icon { font-size: 1.1rem; }

/* ===== Sites Grid ===== */
.sites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.site-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    cursor: pointer;
}

.site-card:hover {
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.site-favicon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    background: var(--bg);
    padding: 2px;
    flex-shrink: 0;
}

.site-info { flex: 1; min-width: 0; }

.site-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-name .badge {
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 500;
    flex-shrink: 0;
}

.badge-hot { background: #fff1f0; color: #ff4d4f; }
.badge-new { background: #f6ffed; color: #52c41a; }
.badge-rec { background: #e6f7ff; color: #1890ff; }

[data-theme="dark"] .badge-hot { background: #2a1215; color: #ff7875; }
[data-theme="dark"] .badge-new { background: #162312; color: #95de64; }
[data-theme="dark"] .badge-rec { background: #111d2c; color: #69c0ff; }

.site-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 64px 0;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 28px;
    max-width: 460px;
    width: 90%;
    transform: translateY(16px) scale(0.97);
    transition: transform 0.25s;
    position: relative;
}

.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-close {
    position: absolute;
    top: 10px;
    right: 14px;
    font-size: 1.4rem;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover { background: var(--border); }

.modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.modal-favicon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: contain;
    background: var(--bg);
    padding: 4px;
}

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-url {
    font-size: 0.78rem;
    color: var(--primary);
    word-break: break-all;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.7;
    margin-bottom: 14px;
}

.modal-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.modal-tag {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-muted);
}

.modal-visit {
    display: block;
    text-align: center;
    padding: 10px 0;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    transition: opacity 0.2s;
}

.modal-visit:hover { opacity: 0.85; }

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    margin-top: 32px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar-toggle { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        z-index: 95;
    }

    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.active { display: block; }

    .main { margin-left: 0; padding: 16px; }

    .search-box { max-width: none; }
    .header-stat { display: none; }
    .logo-text { display: none; }

    .sites-grid { grid-template-columns: 1fr; }
}
