/* ================================================================
 *  FAFAlink Analytics v2.0 — Design System (3-tier token model)
 *
 *  :root                        → 结构 token (主题无关)
 *  :root, body[data-theme=dark] → 深色语义 token
 *  body[data-theme=light]       → 浅色 overrides
 *
 *  历史：这里曾有 token 作用域 bug —— 全局 token 被误放在
 *  body[data-theme=light] 里，导致深色下所有 var(--sp-*)/var(--r-*)/
 *  var(--ease)/var(--sidebar-w) 都 fallback 到 initial。已修复。
 * ================================================================ */

:root {
    /* ----- 结构 token (与主题无关) ----- */
    /* Spacing (8px 节奏) */
    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 12px;
    --sp-lg: 16px;
    --sp-xl: 24px;
    --sp-2xl: 32px;
    --sp-3xl: 48px;

    /* Radius */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-pill: 999px;

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --fast: 0.15s var(--ease);
    --mid: 0.25s var(--ease);
    --slow: 0.4s var(--ease);

    /* Layout */
    --sidebar-w: 220px;
    --sidebar-w-collapsed: 64px;
    --topbar-h: 64px;
    --content-max: 1600px;

    /* Typography scale */
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 14px;
    --fs-md: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 28px;
    --fs-3xl: 36px;

    /* Z-index scale */
    --z-topbar: 10;
    --z-dropdown: 50;
    --z-modal: 100;
    --z-toast: 200;

    /* Micro-detail primitives (可复用交互变量) */
    --fx-hover-lift-y: -1px;
    --fx-active-press-y: 0.5px;
    --fx-active-scale: 0.992;
    --fx-focus-outline-size: 2px;
    --fx-kpi-sheen-angle: 112deg;
    --fx-stripe-step: 11px;
    --fx-track-size: 24px;
}

:root,
body[data-theme="dark"] {
    /* ----- DARK THEME (默认) ----- */
    color-scheme: dark;

    /* Primary/accent 的 RGB 三元数 —— 用于 rgba() 合成 */
    --primary-rgb: 102, 126, 234;
    --accent-rgb: 118, 75, 162;

    --bg: #0b1020;
    --surface: #131a30;
    --surface-2: #1e2744;
    --surface-3: #0f162b;
    --border: rgba(var(--primary-rgb), 0.12);
    --border-strong: rgba(var(--primary-rgb), 0.32);
    --text: #e5e9f5;
    --muted: #8e9bb3;
    --subtle: #5b6478;

    --primary: #8b9eff;          /* 深色背景下用更亮的紫蓝保证对比 */
    --primary-strong: #667eea;
    --primary-soft: rgba(var(--primary-rgb), 0.25);
    --chip-bg: rgba(139, 158, 255, 0.14);
    --chip-bg-strong: rgba(139, 158, 255, 0.22);
    --chip-text: #dbe4ff;
    --chip-text-muted: #c7d2fe;
    --chip-border: rgba(139, 158, 255, 0.38);
    --accent: #b794f4;
    --gradient: linear-gradient(135deg, #667eea, #764ba2);
    --gradient-soft: linear-gradient(135deg, rgba(var(--primary-rgb), 0.22), rgba(var(--accent-rgb), 0.10));

    --green: #10b981;
    --orange: #f59e0b;
    --red: #ef4444;
    --cyan: #06b6d4;
    --pink: #ec4899;

    /* Shadows — 深色下阴影用冷色，强度适中 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 0 3px rgba(var(--primary-rgb), 0.35);

    /* State feedback tokens */
    --feedback-hover-bg: rgba(var(--primary-rgb), 0.08);
    --feedback-active-bg: rgba(var(--primary-rgb), 0.16);
    --feedback-focus-outline: rgba(var(--primary-rgb), 0.72);
    --feedback-focus-glow: rgba(var(--primary-rgb), 0.24);
    --feedback-press-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);

    /* Heat / contribution visibility tokens */
    --heat-empty-map-visible: #1a2340;
    --contrib-empty-cell: #202c4d;
    --contrib-empty-border: rgba(175, 194, 255, 0.20);
    --contrib-l1-core: rgba(208, 220, 255, 0.76);
    --contrib-low-dot: rgba(226, 235, 255, 0.82);

    /* Timezone / language single-series compensation tokens */
    --dist-track-bg: rgba(var(--primary-rgb), 0.08);
    --dist-track-border: rgba(var(--primary-rgb), 0.22);
    --dist-track-stripe: rgba(var(--primary-rgb), 0.12);
    --dist-meta-bg: rgba(var(--primary-rgb), 0.10);
    --dist-meta-border: rgba(var(--primary-rgb), 0.24);
    --dist-meta-text: #afbddc;

    /* ECharts sync */
    --chart-bg: #131a30;
    --chart-axis: #3b4869;
    --chart-split: rgba(var(--primary-rgb), 0.08);
    --chart-empty-map: var(--heat-empty-map-visible);
}

body[data-theme="light"] {
    /* ----- LIGHT THEME overrides ----- */
    color-scheme: light;

    /* Primary/accent 的 RGB 三元数 —— 浅色下使用更深的紫蓝 #4f46e5 / 紫 #7c3aed */
    --primary-rgb: 79, 70, 229;
    --accent-rgb: 124, 58, 237;

    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #eef1f8;
    --surface-3: #fafbfd;
    --border: rgba(71, 85, 105, 0.14);
    --border-strong: rgba(71, 85, 105, 0.28);
    --text: #0f172a;
    --muted: #475569;
    --subtle: #94a3b8;

    --primary: #4f46e5;          /* 浅色下用更深的紫蓝，WCAG AA+ */
    --primary-strong: #4338ca;
    --primary-soft: rgba(var(--primary-rgb), 0.10);
    --chip-bg: #eef2ff;
    --chip-bg-strong: #e0e7ff;
    --chip-text: #3730a3;
    --chip-text-muted: #475569;
    --chip-border: #c7d2fe;
    --accent: #7c3aed;
    --gradient: linear-gradient(135deg, #4f46e5, #7c3aed);
    --gradient-soft: linear-gradient(135deg, rgba(var(--primary-rgb), 0.10), rgba(var(--accent-rgb), 0.04));

    --green: #059669;
    --orange: #d97706;
    --red: #dc2626;
    --cyan: #0891b2;
    --pink: #db2777;

    /* Shadows — 浅色下阴影用冷色极淡，避免脏感 */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10), 0 4px 8px rgba(15, 23, 42, 0.04);
    --shadow-glow: 0 0 0 3px rgba(79, 70, 229, 0.18);

    /* State feedback tokens */
    --feedback-hover-bg: rgba(var(--primary-rgb), 0.08);
    --feedback-active-bg: rgba(var(--primary-rgb), 0.16);
    --feedback-focus-outline: rgba(var(--primary-rgb), 0.64);
    --feedback-focus-glow: rgba(var(--primary-rgb), 0.16);
    --feedback-press-shadow: 0 1px 6px rgba(15, 23, 42, 0.16);

    /* Heat / contribution visibility tokens */
    --heat-empty-map-visible: #e3e9f5;
    --contrib-empty-cell: #e8edf7;
    --contrib-empty-border: rgba(79, 70, 229, 0.18);
    --contrib-l1-core: rgba(79, 70, 229, 0.56);
    --contrib-low-dot: rgba(67, 56, 202, 0.5);

    /* Timezone / language single-series compensation tokens */
    --dist-track-bg: rgba(var(--primary-rgb), 0.07);
    --dist-track-border: rgba(var(--primary-rgb), 0.16);
    --dist-track-stripe: rgba(var(--primary-rgb), 0.10);
    --dist-meta-bg: rgba(var(--primary-rgb), 0.08);
    --dist-meta-border: rgba(var(--primary-rgb), 0.2);
    --dist-meta-text: #58657f;

    /* ECharts sync */
    --chart-bg: #ffffff;
    --chart-axis: #cbd5e1;
    --chart-split: rgba(148, 163, 184, 0.18);
    --chart-empty-map: var(--heat-empty-map-visible);
}
body[data-theme="light"] .kpi:hover,
body[data-theme="light"] .card:hover,
body[data-theme="light"] .integration-card:hover { border-color: var(--border-strong); }
body[data-theme="light"] .sidebar,
body[data-theme="light"] .topbar,
body[data-theme="light"] .card { box-shadow: var(--shadow-sm); }
body[data-theme="light"] .kpi-value,
body[data-theme="light"] .rt-hero-stat b,
body[data-theme="light"] .vp-kpi-value,
body[data-theme="light"] .fp-card b,
body[data-theme="light"] .rt-stat b {
    /* 浅色下 primary 已经是深色 #4f46e5，不再需要 saturate hack；加重字重提升数字辨识度 */
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
body[data-theme="light"] .sb-name {
    /* 浅色下 brand 名走 primary-strong 单色，避免白底 gradient 太花 */
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
    color: var(--primary-strong);
}
body[data-theme="light"] .sb-item.active {
    background: var(--gradient-soft);
    color: var(--primary-strong);
    box-shadow: inset 3px 0 0 var(--primary);
}
body[data-theme="light"] .sb-item { color: var(--muted); }
body[data-theme="light"] .sb-item:hover { background: var(--surface-2); color: var(--text); }
body[data-theme="light"] .tbl th { background: var(--surface-2); color: var(--muted); }
body[data-theme="light"] .tbl tbody tr:hover { background: var(--primary-soft); }
body[data-theme="light"] .chip-sel option { background: var(--surface); color: var(--text); }
body[data-theme="light"] .modal-overlay { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px); }
body[data-theme="light"] .toast { box-shadow: var(--shadow-md); background: var(--surface); }
body[data-theme="light"] .rt-hero,
body[data-theme="light"] .sld-meta-card { background: var(--gradient-soft); }
body[data-theme="light"] .code-block pre,
body[data-theme="light"] .rt-code,
body[data-theme="light"] .url-preview,
body[data-theme="light"] .form-input,
body[data-theme="light"] .inline-search,
body[data-theme="light"] .wh-multi-select { background: var(--surface-2); color: var(--text); }
body[data-theme="light"] .ic-btn { color: var(--primary); }

/* ================================================================
 *  GLOBAL RESETS & A11Y
 * ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
body {
    font: var(--fs-base)/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
code { font-family: "JetBrains Mono", "SF Mono", Monaco, Consolas, monospace; font-size: 0.9em; }

/* 统一 focus 环（只在键盘导航时显示，鼠标点击不干扰） */
:focus { outline: none; }
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
    box-shadow: var(--shadow-glow);
    outline: none;
}

/* 选中文字色 */
::selection { background: var(--primary-soft); color: var(--text); }

/* 滚动条：两套主题通用、窄细、点击区加 border 贴边 */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.28);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: background var(--fast);
}
*::-webkit-scrollbar-thumb:hover { background: rgba(var(--primary-rgb), 0.55); background-clip: padding-box; }
*::-webkit-scrollbar-corner { background: transparent; }

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: rgba(var(--primary-rgb), 0.4) transparent; }

/* prefers-reduced-motion 尊重 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ================================================================
 *  K4: PRINT STYLESHEET（导出报告专用）
 *
 *  Ctrl/Cmd+P 时，浏览器用这套样式渲染 → 另存为 PDF
 *  目标: 白底单色、隐藏 chrome、展开所有内容、分页友好
 * ================================================================ */
@media print {
    /* 强制浅色主题避免深色背景耗墨 */
    html, body {
        background: #fff !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body { overflow: visible !important; }

    /* 隐藏所有 app chrome */
    .sidebar, .topbar, .sb-footer, .app-footer,
    .tb-hamburger, .tb-right, .cmd-palette,
    #visitor-modal, #snippet-modal, #sl-modal, #bulk-modal,
    #csv-modal, #confirm-modal, #keys-modal, #qr-modal,
    .js-canary, .stream-canary, .no-print,
    .sl-actions, .card-tools, .batch-bar,
    .pagination, .bell-drop, .user-drop { display: none !important; }

    /* 全页宽度展开 */
    .app { grid-template-columns: 1fr !important; display: block !important; height: auto !important; overflow: visible !important; }
    .main { display: block !important; height: auto !important; overflow: visible !important; }
    .views { padding: 0 !important; overflow: visible !important; }
    .view.active { display: block !important; }
    .view:not(.active) { display: none !important; }

    /* 报告页眉（打印时才显示）*/
    body::before {
        content: 'FAFAlink Analytics · 报告';
        display: block;
        font-size: 20px;
        font-weight: 700;
        color: #000;
        padding: 12px 0;
        margin-bottom: 16px;
        border-bottom: 2px solid #000;
        text-align: center;
    }
    body::after {
        content: '生成时间: ' attr(data-print-time) ' · 查看范围: ' attr(data-print-range);
        display: block;
        margin-top: 20px;
        padding-top: 10px;
        border-top: 1px solid #ccc;
        font-size: 11px;
        color: #555;
        text-align: center;
    }

    /* 卡片扁平化，防止阴影耗墨 */
    .card, .kpi, .sld-meta-card, .empty-state, .vm-stat {
        background: #fff !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        margin-bottom: 12px !important;
    }
    .card { padding: 16px !important; }

    /* KPI 字更黑更清晰 */
    .kpi-value, .vm-stat-value, .rt-hero-stat b {
        color: #000 !important;
        -webkit-text-fill-color: #000 !important;
        background: none !important;
    }
    .kpi-label, .vm-stat-label { color: #555 !important; }

    /* Grid 布局让图表并排打印 */
    .grid, .kpi-row, .vm-summary { page-break-inside: avoid; }

    /* 表格：边框加深，第一行 sticky 不适用于打印 */
    .tbl {
        border-collapse: collapse;
        width: 100%;
        font-size: 11px;
    }
    .tbl th, .tbl td {
        border: 1px solid #888 !important;
        padding: 6px 8px !important;
        background: #fff !important;
        color: #000 !important;
    }
    .tbl th { background: #f0f0f0 !important; font-weight: 700 !important; }
    .tbl tbody tr:hover { background: #fff !important; }

    /* Chart 容器保持 —— echarts canvas 会被当图打印 */
    .chart { page-break-inside: avoid; }

    /* 分页断点：card 之间优先断 */
    .card { page-break-after: auto; }
    h1, h2, h3, h4 { page-break-after: avoid; }

    /* Link 打印时显示 URL */
    a[href^="http"]::after { content: ' (' attr(href) ')'; font-size: 9px; color: #666; }
    a.sc-link::after { content: ''; /* 短链 chip 已经显示路径，不追加 */ }
    a.sb-item::after { content: ''; }

    /* Hide scrollbars/overflow */
    ::-webkit-scrollbar { display: none; }
}

/* 非打印时，no-print 不影响 */
.no-print {}

/* ================================================================
 *  APP SHELL
 * ================================================================ */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    overflow: hidden;
    transition: grid-template-columns var(--mid);
}
body[data-sidebar="collapsed"] .app {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ================================================================
 *  SIDEBAR
 * ================================================================ */

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sb-brand {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-h);
    position: relative;
}
.sb-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sb-name {
    font-size: 17px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 0.3px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
}
/* ----- 侧栏折叠按钮 ----- */
/* 独立悬浮在 sidebar 右边缘，从 brand 区移出 —— 避免折叠态下的布局挤压 */
.sb-collapse {
    position: absolute;
    /* 垂直居中在 topbar 那一行 */
    top: calc(var(--topbar-h) / 2);
    /* 悬浮右边缘：中心对准 sidebar 右分割线 */
    left: calc(var(--sidebar-w) - 13px);
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    z-index: calc(var(--z-topbar) + 1);
    transition: left var(--mid), color var(--fast), background var(--fast), transform var(--fast), box-shadow var(--fast);
}
.sb-collapse:hover {
    color: var(--primary);
    background: var(--surface);
    box-shadow: var(--shadow-md), 0 0 0 4px rgba(var(--primary-rgb), 0.12);
}
.sb-collapse:active { transform: translateY(-50%) scale(0.92); }
.sb-collapse svg { transition: transform var(--mid) var(--ease-out); }

/* 折叠态：按钮跟着 sidebar 右边缘移动，图标翻转指向"展开" */
body[data-sidebar="collapsed"] .sb-collapse {
    left: calc(var(--sidebar-w-collapsed) - 13px);
}
body[data-sidebar="collapsed"] .sb-collapse svg { transform: rotate(180deg); }

.sb-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}
.sb-group {
    margin-bottom: 16px;
    padding: 0 8px;
}
/* K1: sb-label 升级为可点击折叠按钮 */
.sb-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 10px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--subtle);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    border-radius: var(--r-sm);
    transition: color var(--fast), background var(--fast);
}
.sb-label:hover { color: var(--text); background: var(--surface-2); }
.sb-group-chevron {
    color: inherit;
    opacity: 0.6;
    transition: transform var(--mid), opacity var(--fast);
    flex-shrink: 0;
}
.sb-label:hover .sb-group-chevron { opacity: 1; }

/* 折叠态：chevron 旋转 + 菜单项隐藏 */
.sb-group.collapsed .sb-group-chevron { transform: rotate(-90deg); }
.sb-group.collapsed .sb-item { display: none; }

/* 折叠态下的分组标题有淡紫色指示 */
.sb-group.collapsed > .sb-label { color: var(--primary); opacity: 0.75; }

/* 折叠态（全局 sidebar 收起）下，分组标题也隐藏 —— 让图标条更干净 */
body[data-sidebar="collapsed"] .sb-label { display: none; }
.sb-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 2px;
    border-radius: var(--r-md);
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--fast);
    position: relative;
}
.sb-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.sb-item.active {
    background: var(--gradient-soft);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--primary);
}
.sb-icon {
    font-size: 17px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.sb-txt {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
}
body[data-sidebar="collapsed"] .sb-label,
body[data-sidebar="collapsed"] .sb-txt,
body[data-sidebar="collapsed"] .sb-name,
body[data-sidebar="collapsed"] .sb-home {
    opacity: 0;
    pointer-events: none;
}

.sb-badge {
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
}
/* sb-pulse 和 live-dot 使用同一视觉语言（F4）：实时流量菜单项的"在线"脉冲 */
.sb-pulse {
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    animation: live-pulse 1.8s infinite;
    flex-shrink: 0;
}
body[data-sidebar="collapsed"] .sb-pulse { display: none; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    50% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
}

.sb-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--muted);
}
.sb-online {
    display: flex;
    align-items: center;
    gap: 6px;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}
.sb-home { color: var(--subtle); }

/* ================================================================
 *  P3: 密码保护 gate（快照查看者端）
 * ================================================================ */
.snap-pw-gate {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--bg);
    display: flex !important;
    align-items: center;
    justify-content: center;
}
.snap-pw-box {
    max-width: 400px;
    width: 90%;
    padding: 40px 36px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.snap-pw-icon {
    width: 72px; height: 72px;
    margin: 0 auto 20px;
    background: var(--gradient-soft);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}
.snap-pw-box h3 { margin: 0 0 6px; font-size: var(--fs-xl); font-weight: 700; color: var(--text); }
.snap-pw-box .hint { color: var(--muted); margin-bottom: 24px; font-size: var(--fs-sm); }
#snap-pw-form { display: flex; flex-direction: column; gap: 10px; }
#snap-pw-input {
    padding: 12px 16px;
    font-size: var(--fs-md);
    text-align: center;
    letter-spacing: 0.3em;
}
#snap-pw-submit { padding: 12px; font-size: var(--fs-md); font-weight: 600; }
.snap-pw-err {
    color: var(--red);
    font-size: var(--fs-sm);
    margin-top: 12px;
    min-height: 18px;
    animation: shake 0.3s var(--ease);
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* ================================================================
 *  P4: 运维面板
 * ================================================================ */
.ops-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin: 12px 0;
}
.ops-stat {
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color var(--fast);
}
.ops-stat:hover { border-color: var(--primary); }
.ops-stat-label {
    font-size: var(--fs-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    margin-bottom: 4px;
}
.ops-stat-value {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.ops-stat-sub {
    font-size: var(--fs-xs);
    color: var(--subtle);
    margin-top: 2px;
}
.ops-stat-value.ok { color: var(--green); }
.ops-stat-value.warn { color: var(--orange); }
.ops-stat-value.err { color: var(--red); }

/* share item 里 views 徽章 */
.share-item-views {
    background: rgba(var(--primary-rgb), 0.15);
    color: var(--primary);
    padding: 1px 6px;
    border-radius: var(--r-pill);
    font-size: 10px;
    font-weight: 700;
    margin-left: 6px;
}

/* ================================================================
 *  O7: 我的分享列表
 * ================================================================ */
.shares-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: var(--sp-md);
}
.share-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: all var(--fast);
}
.share-item:hover { border-color: var(--primary); }
.share-item-icon {
    width: 32px; height: 32px;
    background: var(--gradient-soft);
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: var(--primary);
}
.share-item-body { flex: 1; min-width: 0; }
.share-item-label {
    font-weight: 600;
    color: var(--text);
    font-size: var(--fs-sm);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.share-item-meta {
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-top: 2px;
    font-family: "JetBrains Mono", "SF Mono", monospace;
}
.share-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.share-item-actions button {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    cursor: pointer;
    transition: all var(--fast);
}
.share-item-actions button:hover { color: var(--text); border-color: var(--primary); }
.share-item-actions button.danger:hover { color: var(--red); border-color: var(--red); }

/* ================================================================
 *  Q3: Vim 双键序列提示器
 * ================================================================ */
.vim-seq-indicator {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    padding: 10px 16px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(var(--primary-rgb), 0.15);
    font-size: var(--fs-sm);
    display: none;
    align-items: center;
    gap: 12px;
    animation: vim-seq-in 0.15s var(--ease-out);
}
.vim-seq-indicator.is-visible { display: flex; }
@keyframes vim-seq-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}
.vim-seq-key {
    display: inline-block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    background: var(--gradient);
    color: #fff;
    border-radius: var(--r-sm);
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-weight: 700;
    font-size: var(--fs-md);
}
.vim-seq-hint {
    color: var(--muted);
    white-space: nowrap;
}
.vim-seq-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    margin: 0 2px 0 8px;
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-size: var(--fs-xs);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    color: var(--primary);
    font-weight: 600;
}
.vim-seq-action,
.vim-seq-show {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1;
    transition: border-color var(--fast), background var(--fast), color var(--fast), transform var(--fast);
}
.vim-seq-action {
    padding: 7px 9px;
    flex: 0 0 auto;
}
.vim-seq-show {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: var(--z-toast);
    display: none;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    box-shadow: var(--shadow-md);
}
.vim-seq-show.is-visible { display: inline-flex; }
.vim-seq-action:hover,
.vim-seq-show:hover {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
    transform: translateY(-1px);
}
@media (max-width: 760px) {
    .vim-seq-indicator {
        left: 12px;
        right: 12px;
        transform: none;
        bottom: 16px;
        flex-wrap: wrap;
    }
    .vim-seq-hint { white-space: normal; }
    .vim-seq-show {
        right: 12px;
        bottom: 16px;
    }
    @keyframes vim-seq-in {
        from { opacity: 0; transform: translateY(8px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* ================================================================
 *  Q4: Boot 加载进度条 (nprogress 风)
 * ================================================================ */
#boot-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: var(--gradient);
    z-index: 999999;
    box-shadow: 0 0 10px rgba(var(--primary-rgb), 0.5);
    transition: width 0.2s var(--ease-out), opacity 0.3s;
    pointer-events: none;
}
#boot-progress.done { opacity: 0; }

/* ================================================================
 *  Q2: 贡献日历 (365 天活跃度热力图)
 * ================================================================ */
.contrib-card { margin-bottom: var(--sp-lg); }
.contrib-wrap {
    overflow-x: auto;
    padding: var(--sp-md) 0 var(--sp-sm);
    -webkit-overflow-scrolling: touch;
    border-radius: var(--r-md);
    background:
        radial-gradient(circle at 50% -20%, rgba(var(--primary-rgb), 0.14), transparent 58%),
        linear-gradient(180deg, rgba(var(--primary-rgb), 0.04), transparent 45%);
}
.contrib-grid {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    gap: 3px;
    min-width: 53 * (13px + 3px);
}
.contrib-cell {
    width: 13px;
    height: 13px;
    border-radius: 3px;
    background: var(--contrib-empty-cell);
    border: 1px solid var(--contrib-empty-border);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
    transition: transform 0.12s var(--ease), box-shadow var(--fast), border-color var(--fast);
    cursor: pointer;
}
.contrib-cell:hover {
    transform: scale(1.18);
    box-shadow: 0 0 0 2px var(--surface), 0 2px 8px rgba(var(--primary-rgb), 0.4);
    z-index: 2;
    position: relative;
}
/* 5 档颜色（无数据=底色、1-4 档渐变紫蓝）*/
.contrib-cell.l1 {
    background: linear-gradient(180deg, var(--contrib-l1-core), rgba(var(--primary-rgb), 0.44));
    border-color: rgba(var(--primary-rgb), 0.42);
    box-shadow: inset 0 0 0 1px var(--contrib-low-dot), 0 0 0 1px rgba(var(--primary-rgb), 0.12);
}
.contrib-cell.l2 { background: rgba(var(--primary-rgb), 0.58); border-color: rgba(var(--primary-rgb), 0.5); }
.contrib-cell.l3 { background: rgba(var(--primary-rgb), 0.78); border-color: rgba(var(--primary-rgb), 0.6); }
.contrib-cell.l4 {
    background: rgba(var(--primary-rgb), 0.95);
    border-color: rgba(var(--primary-rgb), 0.7);
    box-shadow: 0 0 5px rgba(var(--primary-rgb), 0.52), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.contrib-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 8px;
    font-size: var(--fs-xs);
    color: var(--muted);
}
.contrib-legend-cell {
    width: 10px; height: 10px; border-radius: 2px;
}
.contrib-months {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    font-size: var(--fs-xs);
    color: var(--muted);
    margin-bottom: 4px;
    gap: 3px;
    padding-left: 24px;
}
.contrib-layout {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.contrib-weekdays {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    gap: 3px;
    font-size: 9px;
    color: var(--subtle);
    padding-top: 0;
}
.contrib-weekdays > div { line-height: 13px; text-align: right; padding-right: 4px; }

/* 悬停时展开一个极简 tooltip */
.contrib-tooltip {
    position: absolute;
    pointer-events: none;
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    color: var(--text);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    z-index: var(--z-dropdown);
    opacity: 0;
    transition: opacity 0.1s;
}
.contrib-tooltip.show { opacity: 1; }
.contrib-tooltip b { color: var(--primary); font-variant-numeric: tabular-nums; }

/* ================================================================
 *  O5: SHARE SNAPSHOT MODAL
 * ================================================================ */

.share-step { min-height: 180px; }

.share-field { margin: var(--sp-md) 0; }
.share-field label {
    display: block;
    font-size: var(--fs-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    margin-bottom: 6px;
}

.share-meta {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    border: 1px dashed var(--border);
    margin: var(--sp-md) 0 var(--sp-lg);
    font-size: var(--fs-sm);
    color: var(--muted);
}
.share-meta b { color: var(--text); }

.share-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: var(--sp-md);
    border-top: 1px dashed var(--border);
    margin-top: var(--sp-md);
}

.share-success {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-radius: var(--r-md);
    margin-bottom: var(--sp-md);
}
.share-success-icon {
    width: 36px;
    height: 36px;
    background: var(--green);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}
.share-success-title { font-weight: 700; color: var(--text); font-size: var(--fs-md); }
.share-success-meta { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }

.share-url-box {
    display: flex;
    gap: 8px;
}
.share-url-box input {
    flex: 1;
    padding: 10px 12px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--primary);
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-size: var(--fs-sm);
}
.share-url-box input:focus { outline: none; border-color: var(--primary); }

.share-preview-wrap { margin-top: 10px; }

/* 快照只读模式下的 UI 屏蔽 (O6) */
body[data-mode="snapshot"] {
    /* 隐藏所有编辑性侧栏项目，只保留 overview (和将来扩展的其他只读视图) */
}
body[data-mode="snapshot"] .sb-group[data-group="shortlink"],
body[data-mode="snapshot"] .sb-group[data-group="admin"],
body[data-mode="snapshot"] .sb-group[data-group="insights"],
body[data-mode="snapshot"] #share-btn,
body[data-mode="snapshot"] #export-btn,
body[data-mode="snapshot"] #refresh-btn,
body[data-mode="snapshot"] #theme-toggle-btn,
body[data-mode="snapshot"] .filter-chip,
body[data-mode="snapshot"] .tb-bell-badge,
body[data-mode="snapshot"] #tb-bell,
body[data-mode="snapshot"] #user-btn,
body[data-mode="snapshot"] .sb-item:not([data-view="overview"]) {
    display: none !important;
}
body[data-mode="snapshot"] .sb-pulse { display: none; }
body[data-mode="snapshot"] .sb-footer { justify-content: flex-start; }

/* 顶栏显示"只读快照"横幅 */
body[data-mode="snapshot"] .topbar::before {
    content: '🔒 只读快照 · 数据冻结于 ' attr(data-snapshot-time);
    position: absolute;
    top: 0; left: 0; right: 0;
    background: var(--gradient);
    color: #fff;
    text-align: center;
    padding: 4px 12px;
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.3px;
    z-index: calc(var(--z-topbar) + 1);
}
body[data-mode="snapshot"] .topbar { padding-top: 28px; height: calc(var(--topbar-h) + 28px); }

/* ================================================================
 *  M4: ONBOARDING TOUR
 * ================================================================ */

.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    pointer-events: none;
}
.tour-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(1px);
    animation: tour-fade-in 0.3s var(--ease);
    pointer-events: auto;
}
@keyframes tour-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* 聚光灯：透明矩形，JS 动态设 left/top/width/height */
.tour-spotlight {
    position: absolute;
    border-radius: var(--r-md);
    box-shadow:
        0 0 0 9999px rgba(0, 0, 0, 0.72),
        0 0 0 3px var(--primary),
        0 0 32px rgba(var(--primary-rgb), 0.6);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}
/* 当 spotlight 位置在屏幕外（中心态）隐藏，仅保留 backdrop */
.tour-spotlight.tour-centered {
    display: none;
}
body.tour-centered .tour-backdrop { background: rgba(0, 0, 0, 0.85); }

.tour-popover {
    position: absolute;
    pointer-events: auto;
    max-width: 380px;
    padding: 20px 22px;
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(var(--primary-rgb), 0.12);
    animation: tour-pop-in 0.25s var(--ease-out);
}
@keyframes tour-pop-in {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}
/* 中央态（首末步或找不到锚点时）*/
.tour-popover.tour-center-align {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
.tour-popover.tour-center-align.tour-exit { animation: tour-pop-in 0.25s var(--ease-out) reverse; }

.tour-progress {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}
.tour-progress-dot {
    height: 3px;
    flex: 1;
    background: var(--border);
    border-radius: 2px;
    transition: background var(--fast);
}
.tour-progress-dot.active { background: var(--primary); }

.tour-title {
    margin: 0 0 6px;
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.tour-desc {
    margin: 0 0 14px;
    font-size: var(--fs-sm);
    color: var(--muted);
    line-height: 1.55;
}
.tour-desc kbd {
    display: inline-block;
    padding: 1px 6px;
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-size: 0.85em;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    color: var(--text);
}

.tour-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.tour-skip {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: var(--fs-sm);
    cursor: pointer;
    padding: 6px 0;
    transition: color var(--fast);
}
.tour-skip:hover { color: var(--text); }
.tour-step {
    margin-left: auto;
    font-size: var(--fs-xs);
    color: var(--subtle);
    font-variant-numeric: tabular-nums;
}
.tour-prev, .tour-next {
    padding: 6px 14px;
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--fast);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}
.tour-prev:hover { border-color: var(--primary); color: var(--primary); }
.tour-prev:disabled { opacity: 0.35; cursor: not-allowed; }
.tour-next {
    background: var(--gradient);
    color: #fff;
    border-color: transparent;
}
.tour-next:hover { opacity: 0.92; transform: translateY(-1px); }

/* ================================================================
 *  M1: 告警规则模板
 * ================================================================ */

.alert-templates {
    margin-top: var(--sp-lg);
    padding-top: var(--sp-lg);
    border-top: 1px dashed var(--border);
}
.alert-templates-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 12px;
}
.alert-templates-head .sb-label-text {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0;
    text-transform: none;
}

.alert-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.alert-tpl {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    cursor: pointer;
    text-align: left;
    transition: all var(--fast);
    color: var(--text);
    position: relative;
    overflow: hidden;
}
.alert-tpl::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--gradient);
    transform: scaleY(0);
    transform-origin: bottom;
    transition: transform var(--mid);
}
.alert-tpl:hover {
    border-color: var(--primary);
    background: var(--gradient-soft);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.15);
}
.alert-tpl:hover::before { transform: scaleY(1); }
.alert-tpl:active { transform: translateY(0); }

.atpl-icon { font-size: 22px; line-height: 1; margin-bottom: 2px; }
.atpl-title { font-weight: 700; font-size: var(--fs-sm); color: var(--text); }
.atpl-meta { font-size: var(--fs-xs); color: var(--muted); }

#rule-tpl-hint { margin-left: 8px; color: var(--primary); font-style: normal; }

/* ================================================================
 *  L2: TAGS CLOUD + VIEW TOGGLE
 * ================================================================ */

.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 10px 16px;
    padding: 32px 20px;
    min-height: 140px;
    text-align: center;
}
.tag-cloud-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: var(--r-pill);
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--fast);
    line-height: 1.3;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.tag-cloud-item:hover {
    background: var(--chip-bg-strong);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.25);
}
.tag-cloud-item .tc-count {
    font-size: 0.65em;
    color: var(--chip-text-muted);
    font-weight: 500;
}
/* 5 档字号（基于使用次数分位数动态分配 class）*/
.tag-cloud-item.tc-xs { font-size: 12px; opacity: 1; }
.tag-cloud-item.tc-sm { font-size: 14px; opacity: 1; }
.tag-cloud-item.tc-md { font-size: 17px; opacity: 1; }
.tag-cloud-item.tc-lg { font-size: 22px; }
.tag-cloud-item.tc-xl {
    font-size: 28px;
    background: var(--chip-bg-strong);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
}

/* view toggle (卡片 / 表格) */
.view-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
}
.vt-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--fast);
    line-height: 1;
}
.vt-btn.active {
    background: var(--primary);
    color: #fff;
}
.vt-btn:not(.active):hover { color: var(--text); background: var(--surface-3); }

/* ================================================================
 *  L3: 数据导出面板
 * ================================================================ */
.export-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 20px;
    margin: 12px 0 16px;
}
@media (max-width: 760px) { .export-grid { grid-template-columns: 1fr; } }

.export-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.export-row label {
    font-size: var(--fs-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.export-format-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.export-fmt {
    flex: 1;
    min-width: 90px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--muted);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: all var(--fast);
}
.export-fmt:hover { color: var(--text); border-color: var(--border-strong); }
.export-fmt.active {
    background: var(--gradient);
    color: #fff;
    border-color: transparent;
    font-weight: 600;
}

.export-filter-opts {
    display: flex;
    align-items: center;
    padding: 8px 0;
}

.export-actions {
    display: flex;
    align-items: center;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}
.export-actions #export-status { font-style: italic; }

/* tags-list: grid (卡片) vs table 样式切换（通过父元素 data-mode）*/
.tags-list[data-mode="table"] .tag-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 0;
    border-top: 1px solid var(--border);
    box-shadow: none;
}
.tags-list[data-mode="table"] .tag-card:first-child { border-top: none; }

/* ================================================================
 *  K3: ACCENT COLOR PICKER (设置页主题色快选)
 *  每个 accent 包 4 个变量：--primary, --primary-strong, --accent,
 *  --primary-rgb（rgb 三元数用于 rgba()）
 * ================================================================ */

.accent-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.accent-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: all var(--fast);
    position: relative;
}
.accent-swatch:hover { transform: scale(1.1); border-color: var(--border-strong); }
.accent-swatch.active {
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--primary);
    transform: scale(1.05);
}
.accent-swatch.active::after {
    content: '✓';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Accent 主题覆盖：dark 主题 variant */
body[data-accent="blue"] {
    --primary-rgb: 59, 130, 246;
    --accent-rgb: 14, 165, 233;
    --primary: #60a5fa;
    --primary-strong: #2563eb;
    --primary-soft: rgba(59, 130, 246, 0.25);
    --accent: #38bdf8;
    --gradient: linear-gradient(135deg, #2563eb, #0891b2);
    --gradient-soft: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(14, 165, 233, 0.10));
}
body[data-accent="teal"] {
    --primary-rgb: 20, 184, 166;
    --accent-rgb: 16, 185, 129;
    --primary: #5eead4;
    --primary-strong: #0d9488;
    --primary-soft: rgba(20, 184, 166, 0.25);
    --accent: #34d399;
    --gradient: linear-gradient(135deg, #0d9488, #059669);
    --gradient-soft: linear-gradient(135deg, rgba(20, 184, 166, 0.22), rgba(16, 185, 129, 0.10));
}
body[data-accent="rose"] {
    --primary-rgb: 244, 63, 94;
    --accent-rgb: 219, 39, 119;
    --primary: #fb7185;
    --primary-strong: #e11d48;
    --primary-soft: rgba(244, 63, 94, 0.25);
    --accent: #f472b6;
    --gradient: linear-gradient(135deg, #e11d48, #db2777);
    --gradient-soft: linear-gradient(135deg, rgba(244, 63, 94, 0.22), rgba(219, 39, 119, 0.10));
}
body[data-accent="amber"] {
    --primary-rgb: 245, 158, 11;
    --accent-rgb: 239, 68, 68;
    --primary: #fbbf24;
    --primary-strong: #d97706;
    --primary-soft: rgba(245, 158, 11, 0.25);
    --accent: #f87171;
    --gradient: linear-gradient(135deg, #d97706, #dc2626);
    --gradient-soft: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(239, 68, 68, 0.10));
}
body[data-accent="slate"] {
    --primary-rgb: 100, 116, 139;
    --accent-rgb: 71, 85, 105;
    --primary: #94a3b8;
    --primary-strong: #475569;
    --primary-soft: rgba(100, 116, 139, 0.25);
    --accent: #64748b;
    --gradient: linear-gradient(135deg, #475569, #1e293b);
    --gradient-soft: linear-gradient(135deg, rgba(100, 116, 139, 0.22), rgba(71, 85, 105, 0.10));
}

/* 浅色主题下的 accent 重新下沉（白底要更深的色以保对比度）*/
body[data-theme="light"][data-accent="blue"]  { --primary: #2563eb; --primary-strong: #1d4ed8; --accent: #0891b2; }
body[data-theme="light"][data-accent="teal"]  { --primary: #0d9488; --primary-strong: #0f766e; --accent: #059669; }
body[data-theme="light"][data-accent="rose"]  { --primary: #e11d48; --primary-strong: #be123c; --accent: #db2777; }
body[data-theme="light"][data-accent="amber"] { --primary: #d97706; --primary-strong: #b45309; --accent: #dc2626; }
body[data-theme="light"][data-accent="slate"] { --primary: #475569; --primary-strong: #334155; --accent: #1e293b; }

/* ================================================================
 *  KEYBOARD SHORTCUTS LEGEND (I3)
 * ================================================================ */
.keys-grid {
    display: flex;
    flex-direction: column;
    gap: var(--sp-lg);
}
.keys-section h4 {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.keys-section h4::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--gradient);
    border-radius: 3px;
}
.keys-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-md);
    padding: 8px 12px;
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    color: var(--text);
    transition: background var(--fast);
}
.keys-row:hover { background: var(--surface-2); }
.keys-row > span:first-child { color: var(--muted); }
.keys-row kbd {
    display: inline-block;
    padding: 2px 8px;
    margin: 0 2px;
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace;
    font-size: var(--fs-xs);
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    line-height: 1.4;
    min-width: 18px;
    text-align: center;
}
.keys-or { color: var(--subtle); font-size: var(--fs-xs); margin: 0 6px; }

/* ----- I1: JS Canary 健康指示点 ----- */
/* 默认 dim 灰 → boot 跑完后变绿（.alive） → 抛错时变红（.dead） */
.js-canary {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 6px;
    color: var(--subtle);
    font-size: 8px;
    line-height: 1;
    transition: color var(--mid), text-shadow var(--mid);
    vertical-align: middle;
}
.js-canary.alive {
    color: var(--green);
    text-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}
.js-canary.dead {
    color: var(--red);
    text-shadow: 0 0 6px rgba(239, 68, 68, 0.7);
    animation: live-pulse 1.2s infinite;
}
body[data-sidebar="collapsed"] .js-canary { display: none; }

/* ================================================================
 *  N2: 访客追踪徽章 + WS 高亮
 * ================================================================ */

.track-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 8px;
    padding: 3px 8px 3px 7px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.5);
    border-radius: var(--r-pill);
    color: var(--red);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--fast);
    line-height: 1.2;
    font-family: inherit;
}
.track-badge:hover {
    background: rgba(239, 68, 68, 0.25);
    transform: scale(1.05);
}
.track-badge::before {
    content: '✕';
    margin-left: 2px;
    order: 99;
    opacity: 0.6;
    font-size: 9px;
}
.track-dot {
    width: 6px;
    height: 6px;
    background: var(--red);
    border-radius: 50%;
    animation: live-pulse 1.4s infinite;
    flex-shrink: 0;
}
.track-label { letter-spacing: 0.3px; }
.track-id {
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-size: 9px;
    opacity: 0.85;
    background: rgba(0,0,0,0.2);
    padding: 1px 4px;
    border-radius: 3px;
}
body[data-sidebar="collapsed"] .track-badge { display: none !important; }

/* WS 事件命中追踪 visitor 时的高亮闪烁 */
@keyframes track-hit-flash {
    0%   { background: rgba(239, 68, 68, 0.4); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    50%  { background: rgba(239, 68, 68, 0.25); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { background: var(--surface-2); box-shadow: none; }
}
.track-hit { animation: track-hit-flash 1.5s ease-out; }

/* 访客详情 modal 里的"追踪"按钮 */
.vm-track-btn {
    padding: 6px 14px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--red);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--fast);
    margin-left: 8px;
}
.vm-track-btn:hover { background: rgba(239, 68, 68, 0.2); transform: translateY(-1px); }
.vm-track-btn.tracking { background: var(--red); color: #fff; border-color: transparent; }
.vm-track-btn.tracking::before { content: '🔴 '; animation: live-pulse 1.4s infinite; display: inline-block; }

/* J3: Stream canary — WS 未连=橙, 连上=绿, 收事件=闪白光 */
.stream-canary.live {
    color: var(--green);
    text-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}
.stream-canary.flash {
    color: #fff;
    text-shadow: 0 0 8px rgba(16, 185, 129, 0.9);
    transform: scale(1.3);
}
.stream-canary.offline {
    color: var(--orange);
    text-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
}
.stream-canary { transition: color var(--fast), text-shadow var(--fast), transform 0.15s var(--ease); }

/* ================================================================
 *  MAIN / TOPBAR / VIEWS
 * ================================================================ */

.main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}
.tb-left {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    flex: 0 0 auto;
    min-width: 0;
}
.tb-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tb-sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tb-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
}

.filter-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 6px 10px;
    transition: border-color var(--fast);
    min-width: 0;
    flex: 0 1 auto;
}
.filter-chip:hover { border-color: var(--border-strong); }
.chip-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.chip-sel {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    min-width: 0;
    max-width: 160px;
}
.chip-sel option { background: var(--surface); color: var(--text); }
.chip-sel option[disabled] {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 700;
}
.range-custom-wrap {
    gap: 6px;
}
.chip-date {
    appearance: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    min-width: 126px;
}
.chip-date:focus-visible {
    border-color: var(--primary);
}
.chip-sep {
    color: var(--muted);
    font-size: 12px;
}
.chip-mini-btn {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text);
    border-radius: var(--r-sm);
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 600;
    transition: border-color var(--fast), background var(--fast), color var(--fast);
}
.chip-mini-btn:hover {
    border-color: var(--primary);
}
.chip-mini-btn.primary {
    background: var(--primary-soft);
    border-color: rgba(var(--primary-rgb), 0.45);
    color: var(--primary);
}
.chip-mini-btn.primary:hover {
    background: var(--primary);
    color: #fff;
}
.chip-toggle {
    cursor: pointer;
    user-select: none;
    color: var(--muted);
    font-size: 12px;
}
.chip-toggle input { width: 13px; height: 13px; accent-color: var(--primary); cursor: pointer; }

.tb-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 8px 10px;
    border-radius: var(--r-md);
    transition: all var(--fast);
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}
.tb-btn:hover { color: var(--text); border-color: var(--border-strong); }
.tb-btn.icon-only { padding: 8px; }
.tb-bell-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
    line-height: 1.3;
}

.bell-drop {
    position: absolute;
    top: calc(100% + 8px);
    right: 24px;
    width: 340px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: all var(--fast);
    z-index: 100;
}
.bell-drop.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.bell-head {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.bell-head span { font-weight: 600; }
.bell-all { color: var(--primary); font-size: 11px; }
.bell-list { max-height: 360px; overflow-y: auto; padding: 4px; }
.bell-item {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    font-size: 12px;
    cursor: pointer;
    transition: background var(--fast);
    border-left: 3px solid transparent;
}
.bell-item:hover { background: var(--surface-2); }
.bell-item.sev-critical { border-left-color: var(--red); }
.bell-item.sev-warning { border-left-color: var(--orange); }
.bell-item.sev-info { border-left-color: var(--primary); }
.bell-item b { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.bell-item i { font-style: normal; color: var(--muted); font-size: 11px; }
.bell-item em { font-style: normal; color: var(--subtle); font-size: 10px; display: block; margin-top: 2px; }

/* ================================================================
 *  VIEWS
 * ================================================================ */

.views {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}
.view {
    display: none;
    animation: viewIn 0.3s var(--ease);
}
.view.active { display: block; }
@keyframes viewIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ================================================================
 *  CARDS / GRID
 * ================================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 18px;
    margin-bottom: 16px;
    transition: border-color var(--fast);
}
.card:hover { border-color: var(--border-strong); }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.card-head h3 {
    margin: 0;
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: -0.01em;
}
/* J2: Card hover 时头部 emoji 微微放大 — 增加"活着"的交互感 */
.card:hover .card-head h3 { color: var(--primary); }
.card-head h3 > :first-child {
    transition: transform var(--fast);
    display: inline-block;
}
.card:hover .card-head h3 > :first-child { transform: scale(1.15); }

.card-sub {
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 500;
    padding: 2px 8px;
    background: var(--surface-2);
    border-radius: var(--r-pill);
}
.card-sub.js-sample-meta {
    border: 1px solid rgba(var(--primary-rgb), 0.2);
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--chip-text-muted);
}
.card-sub.js-sample-meta.is-concentrated {
    border-color: rgba(245, 158, 11, 0.55);
    background: rgba(245, 158, 11, 0.14);
    color: var(--orange);
}
.card-sub.js-sample-meta.is-low-sample {
    border-color: rgba(var(--primary-rgb), 0.36);
    background: rgba(var(--primary-rgb), 0.12);
}
.card-sub.js-sample-meta[data-mode="empty"] {
    border-style: dashed;
    opacity: 0.9;
}
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-1 { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 1200px) {
    .g-2-1, .g-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
    .g-2-1, .g-3, .g-1-1 { grid-template-columns: 1fr; }
}

/* Chart containers */
.chart { width: 100%; height: 260px; }
.chart.tall { height: 360px; }

/* 热图容器：提升低值层次，避免暗色下“整块发空” */
#sld-heatmap,
#alert-calendar {
    border-radius: var(--r-md);
    background:
        linear-gradient(180deg, rgba(var(--primary-rgb), 0.08), transparent 46%),
        radial-gradient(circle at 50% 130%, rgba(var(--primary-rgb), 0.08), transparent 60%);
}

/* 时区/语言分布：单条数据时提供轨道、条纹和次级信息位 */
#chart-timezone,
#chart-language {
    position: relative;
    overflow: hidden;
    border-radius: var(--r-md);
    background:
        linear-gradient(180deg, rgba(var(--primary-rgb), 0.06), transparent 50%),
        repeating-linear-gradient(
            0deg,
            var(--dist-track-bg) 0 calc(var(--fx-track-size) - 1px),
            transparent calc(var(--fx-track-size) - 1px) var(--fx-track-size)
        );
}
#chart-timezone::before,
#chart-language::before {
    content: '';
    position: absolute;
    inset: 10px 10px 12px;
    border-radius: calc(var(--r-md) - 2px);
    border: 1px dashed var(--dist-track-border);
    background:
        repeating-linear-gradient(
            var(--fx-kpi-sheen-angle),
            transparent 0 calc(var(--fx-stripe-step) - 5px),
            var(--dist-track-stripe) calc(var(--fx-stripe-step) - 5px) var(--fx-stripe-step)
        );
    opacity: 0.65;
    pointer-events: none;
}
#chart-timezone::after,
#chart-language::after {
    content: '单条分布时启用基准轨道';
    position: absolute;
    right: 10px;
    bottom: 8px;
    color: var(--dist-meta-text);
    background: var(--dist-meta-bg);
    border: 1px solid var(--dist-meta-border);
    border-radius: var(--r-pill);
    padding: 2px 8px;
    font-size: 10px;
    line-height: 1.4;
    letter-spacing: 0.2px;
    pointer-events: none;
}

/* ================================================================
 *  KPI ROW
 * ================================================================ */

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.kpi-row.kpi-small { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 48%);
    transition: border-color var(--fast), box-shadow var(--fast), transform var(--fast), background-color var(--fast);
}
.kpi:hover,
.kpi:focus-within {
    border-color: var(--border-strong);
    transform: translateY(var(--fx-hover-lift-y));
    box-shadow: var(--shadow-md);
}
.kpi:active {
    transform: translateY(var(--fx-active-press-y)) scale(0.998);
    box-shadow: var(--feedback-press-shadow);
}
.kpi::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gradient);
    opacity: 0.6;
}
.kpi::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        var(--fx-kpi-sheen-angle),
        transparent 35%,
        rgba(255, 255, 255, 0.07) 50%,
        transparent 65%
    );
    opacity: 0;
    transform: translateX(-16%);
    transition: opacity var(--mid), transform var(--mid);
    pointer-events: none;
}
.kpi:hover::after,
.kpi:focus-within::after {
    opacity: 1;
    transform: translateX(0);
}
.kpi-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    font-weight: 600;
}
.kpi-value {
    font-size: 26px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.kpi-sub {
    color: var(--muted);
    font-size: 11px;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kpi-sub .delta-up { color: var(--green); }
.kpi-sub .delta-down { color: var(--red); }
.kpi-small .kpi-value { font-size: 22px; }

/* ================================================================
 *  TOP LIST (overview)
 * ================================================================ */

.top-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.top-row {
    display: grid;
    grid-template-columns: 24px 1fr 60px;
    gap: 8px;
    align-items: center;
    padding: 8px 4px;
    border-radius: var(--r-sm);
    position: relative;
    overflow: hidden;
}
.top-row::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--gradient-soft);
    border-radius: var(--r-sm);
    z-index: 0;
}
.top-row > * { position: relative; z-index: 1; }
.top-rank {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--muted);
}
.top-row:nth-child(1) .top-rank { background: var(--gradient); color: #fff; }
.top-row:nth-child(2) .top-rank { background: rgba(var(--primary-rgb),0.4); color: #fff; }
.top-row:nth-child(3) .top-rank { background: rgba(var(--primary-rgb),0.25); color: var(--text); }
.top-name {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.top-val {
    text-align: right;
    color: var(--primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

/* ================================================================
 *  REALTIME HERO
 * ================================================================ */

.rt-hero {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 24px;
    background: var(--gradient-soft);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    margin-bottom: 20px;
}
.rt-hero-stat { text-align: center; }
.rt-hero-stat b {
    display: block;
    font-size: 48px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.rt-hero-stat i {
    font-style: normal;
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.rt-hero-pulse {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.rt-hero-pulse span {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-red 1.5s infinite;
}
@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.rt-stream {
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.rt-event {
    display: grid;
    grid-template-columns: 60px auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    font-size: 12px;
    animation: rtIn 0.35s var(--ease);
    transition: background var(--fast);
}
.rt-event:hover { background: var(--surface-2); }
@keyframes rtIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}
.rt-time { color: var(--subtle); font-size: 11px; font-variant-numeric: tabular-nums; }
.rt-flag { font-size: 16px; }
.rt-where { color: var(--text); }
.rt-where em { color: var(--muted); font-style: normal; font-size: 11px; margin-left: 4px; }
.rt-code {
    background: var(--chip-bg);
    padding: 2px 6px;
    border-radius: var(--r-sm);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 11px;
}

/* ================================================================
 *  TABLES
 * ================================================================ */

.table-wrap { overflow-x: auto; }
.tbl {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.tbl th, .tbl td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.tbl th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.tbl th.sortable:hover { background: rgba(var(--primary-rgb),0.1); color: var(--text); }
.tbl th.sort-asc::after { content: ' ↑'; color: var(--primary); }
.tbl th.sort-desc::after { content: ' ↓'; color: var(--primary); }

/* JS 交互类（由 dashboard.js 动态注入） */
.motion-ready {
    opacity: 0.92;
    transform: translateY(3px);
    transition:
        opacity var(--mid),
        transform var(--mid),
        box-shadow var(--fast),
        border-color var(--fast),
        background-color var(--fast);
}
.motion-ready.motion-entered {
    opacity: 1;
    transform: translateY(0);
}
.motion-ready.motion-hover {
    transform: translateY(var(--fx-hover-lift-y));
}
.motion-ready.motion-focus {
    box-shadow: 0 0 0 2px var(--feedback-focus-glow);
    border-color: var(--border-strong);
}
.motion-ready.motion-press {
    transform: translateY(var(--fx-active-press-y)) scale(var(--fx-active-scale));
}
.tbl tbody tr { transition: background-color var(--fast); }
.tbl tbody tr td { transition: background-color var(--fast), box-shadow var(--fast); }
.tbl tbody tr:hover td { background: var(--feedback-hover-bg); }
.tbl tbody tr:focus-within td {
    background: var(--feedback-hover-bg);
    box-shadow: inset 0 0 0 1px var(--feedback-focus-glow);
}
.tbl tbody tr:active td { background: var(--feedback-active-bg); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.code {
    font-family: "SF Mono", Monaco, Consolas, monospace;
    color: var(--primary);
    font-weight: 600;
}
.tbl td.flag { font-size: 16px; }

.inline-search {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: var(--r-md);
    font-size: 13px;
    outline: none;
    min-width: 200px;
    transition: border-color var(--fast);
}
.inline-search:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }

/* ================================================================
 *  FORMS / BUTTONS
 * ================================================================ */

.form-input {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--r-md);
    font-size: 13px;
    outline: none;
    font-family: inherit;
    transition: border-color var(--fast);
}
.form-input:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }

.btn-primary {
    background: var(--gradient);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--r-md);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--fast);
}
.btn-primary:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(var(--primary-rgb),0.35); }
.btn-secondary {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: var(--r-md);
    font-size: 12px;
}
.btn-secondary:hover { border-color: var(--border-strong); }

/* 常用按钮的 hover / active / focus 微反馈统一 */
.tb-btn,
.btn-primary,
.btn-secondary,
.ic-btn,
.copy-btn,
.pg-btn,
.sl-action-btn,
.btn-danger,
.pagination button,
.batch-actions button,
.sld-meta-actions button {
    transform: translateY(0);
    outline-offset: 2px;
    transition: transform var(--fast), box-shadow var(--fast), border-color var(--fast), background-color var(--fast), color var(--fast), filter var(--fast);
}
.tb-btn:hover,
.btn-primary:hover,
.btn-secondary:hover,
.ic-btn:hover,
.copy-btn:hover,
.pg-btn:hover:not(:disabled),
.sl-action-btn:hover,
.btn-danger:hover,
.pagination button:hover:not([disabled]),
.batch-actions button:hover,
.sld-meta-actions button:hover {
    transform: translateY(var(--fx-hover-lift-y));
    filter: saturate(1.04);
}
.tb-btn:active,
.btn-primary:active,
.btn-secondary:active,
.ic-btn:active,
.copy-btn:active,
.pg-btn:active:not(:disabled),
.sl-action-btn:active,
.btn-danger:active,
.pagination button:active:not([disabled]),
.batch-actions button:active,
.sld-meta-actions button:active {
    transform: translateY(var(--fx-active-press-y)) scale(var(--fx-active-scale));
    box-shadow: var(--feedback-press-shadow);
}
.tb-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.ic-btn:focus-visible,
.copy-btn:focus-visible,
.pg-btn:focus-visible,
.sl-action-btn:focus-visible,
.btn-danger:focus-visible,
.pagination button:focus-visible,
.batch-actions button:focus-visible,
.sld-meta-actions button:focus-visible {
    outline: var(--fx-focus-outline-size) solid var(--feedback-focus-outline);
    box-shadow: 0 0 0 4px var(--feedback-focus-glow);
}

.add-form {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.add-form summary {
    cursor: pointer;
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    color: var(--primary);
    font-weight: 600;
    font-size: 13px;
    user-select: none;
    list-style: none;
}
.add-form summary::-webkit-details-marker { display: none; }
.add-form[open] summary { background: var(--gradient-soft); }

.rule-form-grid, .site-form-grid, .webhook-form-grid {
    display: grid;
    gap: 10px;
    padding: 14px 12px 4px;
}
.rule-form-grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
.site-form-grid { grid-template-columns: 1fr 1fr; }
.webhook-form-grid { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: span 4; }

.wh-multi-select {
    padding: 8px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    max-height: 120px;
    overflow-y: auto;
    grid-column: span 4;
}
.wh-multi-select label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: var(--r-sm);
    font-size: 12px;
}
.wh-multi-select label:hover { background: rgba(var(--primary-rgb),0.08); }
.wh-multi-select input { accent-color: var(--primary); }

.wh-platform-hint {
    padding: 10px 12px;
    background: rgba(var(--primary-rgb),0.08);
    border-radius: var(--r-sm);
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
}
.wh-platform-hint b { color: var(--primary); }
.wh-platform-hint code { background: var(--chip-bg); padding: 1px 5px; border-radius: 3px; color: var(--chip-text); border: 1px solid var(--chip-border); }

/* ================================================================
 *  INTEGRATION CARDS
 * ================================================================ */

.sites-list, .webhooks-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}
.integration-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all var(--fast);
}
.integration-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.ic-head { display: flex; justify-content: space-between; gap: 8px; }
.ic-title { font-weight: 600; font-size: 13px; color: var(--text); }
.ic-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.ic-meta { display: flex; gap: 16px; padding-top: 4px; }
.ic-stat { display: flex; flex-direction: column; line-height: 1.1; }
.ic-stat b { color: var(--primary); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ic-stat span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 2px; }
.ic-actions { display: flex; gap: 6px; margin-top: 4px; }
.ic-btn {
    padding: 5px 10px;
    background: rgba(var(--primary-rgb),0.12);
    border: 1px solid rgba(var(--primary-rgb),0.25);
    color: var(--primary);
    border-radius: var(--r-sm);
    font-size: 11px;
    transition: all var(--fast);
}
.ic-btn:hover { background: rgba(var(--primary-rgb),0.22); }
.ic-btn.success { background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.25); color: #6ee7b7; }
.ic-btn.success:hover { background: rgba(16,185,129,0.22); }
.ic-btn.danger { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.25); color: #fca5a5; }
.ic-btn.danger:hover { background: rgba(239,68,68,0.2); }
.ic-btn.copied { background: var(--green); color: #fff; }

.ic-platform-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.url-preview {
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 10px;
    color: var(--muted);
    word-break: break-all;
    background: var(--surface);
    padding: 4px 8px;
    border-radius: var(--r-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ================================================================
 *  ALERT RULES / TRIGGERED
 * ================================================================ */

.alert-rule-row {
    display: grid;
    grid-template-columns: 1fr 100px 80px 120px auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    margin-bottom: 6px;
    transition: border-color var(--fast);
    border: 1px solid transparent;
}
.alert-rule-row:hover { border-color: var(--border-strong); }
.alert-rule-row.disabled { opacity: 0.55; }
.rule-title { font-weight: 600; font-size: 13px; }
.rule-meta { color: var(--muted); font-size: 11px; }
.rule-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
}
.rule-btn-del {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.25);
    color: #fca5a5;
    padding: 4px 10px;
    border-radius: var(--r-sm);
    font-size: 11px;
    transition: all var(--fast);
}
.rule-btn-del:hover { background: rgba(239,68,68,0.22); }

.triggered-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 440px;
    overflow-y: auto;
}
.trig-item {
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    border-left: 3px solid var(--primary);
    font-size: 12px;
    transition: background var(--fast);
}
.trig-item:hover { background: var(--surface-3); }
.trig-item.sev-critical { border-left-color: var(--red); }
.trig-item.sev-warning { border-left-color: var(--orange); }
.trig-item.sev-info { border-left-color: var(--cyan); }
.trig-time { color: var(--subtle); font-size: 10px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.trig-name { font-weight: 600; color: var(--text); }
.trig-msg { color: var(--muted); font-size: 11px; margin-top: 4px; line-height: 1.5; }

/* ================================================================
 *  FUNNEL / COHORT
 * ================================================================ */

.funnel-result { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.funnel-step {
    display: grid;
    grid-template-columns: 40px 1fr 120px 140px;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    position: relative;
    overflow: hidden;
}
.funnel-step > * { position: relative; z-index: 1; }
.funnel-step > .funnel-bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--gradient-soft);
    z-index: 0;
    transition: width 0.6s var(--ease);
}
.fs-idx {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
}
.fs-label { font-weight: 600; }
.fs-count { text-align: right; color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; }
.fs-conv { text-align: right; color: var(--muted); font-size: 11px; line-height: 1.5; }

.cohort-matrix { overflow-x: auto; padding-top: 4px; }
.cohort-table { border-collapse: separate; border-spacing: 0; font-size: 11px; }
.cohort-table th, .cohort-table td {
    padding: 6px 8px;
    text-align: center;
    min-width: 42px;
    border: 1px solid var(--surface-3);
}
.cohort-table th { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.cohort-table td.ch-cohort { background: var(--surface-2); text-align: left; font-weight: 600; white-space: nowrap; }
.cohort-table td.ch-size { background: var(--surface-2); color: var(--primary); font-weight: 700; }
.cohort-cell { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ================================================================
 *  MODAL
 * ================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
    animation: fadeIn 0.2s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    width: min(900px, 92vw);
    max-height: 88vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s var(--ease);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gradient-soft);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 18px;
    padding: 4px 10px;
    border-radius: var(--r-sm);
    transition: all var(--fast);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-body h4 { margin: 20px 0 10px; font-size: 13px; font-weight: 600; color: var(--primary); }
.modal-body h4:first-child { margin-top: 0; }
.modal-body code { background: var(--chip-bg); padding: 1px 5px; border-radius: 3px; color: var(--chip-text); border: 1px solid var(--chip-border); }

.code-block {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    position: relative;
    margin-bottom: 8px;
}
.code-block pre {
    margin: 0;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
}
.copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    background: var(--gradient);
    color: #fff;
    border: none;
    border-radius: var(--r-sm);
    font-size: 11px;
    font-weight: 600;
    transition: all var(--fast);
}
.copy-btn:hover { opacity: 0.92; transform: translateY(-1px); }
.copy-btn.copied { background: var(--green); }

/* ================================================================
 *  COMMAND PALETTE
 * ================================================================ */

.cmd-palette {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    z-index: 1001;
    backdrop-filter: blur(6px);
}
.cmd-box {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    width: min(600px, 90vw);
    max-height: 60vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.cmd-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.cmd-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 15px;
}
.cmd-hint { color: var(--subtle); font-size: 11px; padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--r-sm); }
.cmd-results { max-height: 400px; overflow-y: auto; padding: 6px; }
.cmd-result {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background var(--fast);
}
.cmd-result:hover, .cmd-result.selected {
    background: var(--gradient-soft);
    border-left: 3px solid var(--primary);
    padding-left: 9px;
}
.cmd-result.selected .cmd-result-text { color: var(--text); font-weight: 500; }
.cmd-result-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.cmd-result-text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cmd-result-meta { color: var(--muted); font-size: var(--fs-xs); flex-shrink: 0; }

/* F7: 分组标签 */
.cmd-group-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--subtle);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 10px 10px 4px;
    margin-top: 4px;
}
.cmd-group-label:first-child { margin-top: 0; }

/* F7: 快捷键提示徽章 */
.cmd-result-hint {
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace;
    font-size: var(--fs-xs);
    color: var(--muted);
    background: var(--surface-3);
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    flex-shrink: 0;
    min-width: 18px;
    text-align: center;
}
.cmd-result.selected .cmd-result-hint { border-color: var(--primary); color: var(--primary); }

/* F7: 空态 */
.cmd-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--muted);
    font-size: var(--fs-sm);
}
.cmd-empty code {
    background: var(--surface-3);
    color: var(--primary);
    padding: 1px 5px;
    border-radius: var(--r-sm);
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace;
    font-size: 0.9em;
}

/* ================================================================
 *  SETTINGS
 * ================================================================ */

.settings-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    align-items: center;
}
.settings-row:last-child { border-bottom: none; }
.settings-label { color: var(--muted); }
.settings-value code { background: var(--chip-bg); padding: 3px 8px; border-radius: var(--r-sm); color: var(--chip-text); border: 1px solid var(--chip-border); font-size: 11.5px; }
.theme-picker {
    display: inline-flex;
    gap: 6px;
    background: var(--surface-2);
    padding: 4px;
    border-radius: var(--r-md);
}
.theme-option {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all var(--fast);
}
.theme-option:hover { color: var(--text); }
.theme-option.active { background: var(--gradient); color: #fff; box-shadow: 0 2px 8px rgba(var(--primary-rgb),0.3); }
.theme-option span { font-size: 14px; }

.about-block { padding: 6px 0; font-size: 13px; line-height: 1.7; }
.about-block p { margin: 4px 0; }

.link { color: var(--primary); }
.link:hover { text-decoration: underline; }

/* Fingerprint stats grid (visitors view) */
.fp-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 6px 0;
}
.fp-card {
    background: var(--surface-2);
    border-radius: var(--r-md);
    padding: 14px;
    text-align: center;
}
.fp-card b {
    display: block;
    font-size: 22px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.fp-card i { font-style: normal; font-size: 11px; color: var(--muted); margin-top: 4px; display: block; }
.fp-note {
    grid-column: 1 / -1;
    border-radius: var(--r-md);
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.55;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
}
.fp-note.warn {
    border-color: rgba(245, 158, 11, 0.4);
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}
.fp-note.ok {
    border-color: rgba(var(--primary-rgb), 0.28);
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--chip-text-muted);
}
.fp-note.info {
    border-color: rgba(148, 163, 184, 0.4);
    background: rgba(148, 163, 184, 0.1);
    color: #cbd5e1;
}

/* Visitor link */
a.visitor-link {
    color: var(--primary);
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 11px;
}
a.visitor-link:hover { text-decoration: underline; }

/* ================================================================
 *  EMPTY / LOADING STATES
 * ================================================================ */

/* ================================================================
 *  EMPTY STATE & HINTS (小/大两档)
 * ================================================================ */

/* 小空态：局部空（单个 widget / 小 KPI 卡） */
.empty-mini {
    padding: 18px;
    color: var(--muted);
    text-align: center;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    border-radius: var(--r-md);
    border: 1px dashed var(--border);
}
.empty-mini code { background: var(--chip-bg); color: var(--chip-text); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--chip-border); }
.empty-mini a.link { color: var(--primary); font-weight: 600; }
.empty-mini a.link:hover { text-decoration: underline; }

/* 大空态：整个视图级别（短链管理 / 访客画像 / 告警列表） */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-md);
    padding: var(--sp-3xl) var(--sp-xl);
    text-align: center;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: var(--r-lg);
    border: 1px dashed var(--border);
    min-height: 280px;
}
.empty-state .es-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-soft);
    border-radius: 50%;
    color: var(--primary);
    margin-bottom: var(--sp-xs);
}
.empty-state .es-icon svg { width: 36px; height: 36px; }
.empty-state .es-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.empty-state .es-desc {
    font-size: var(--fs-sm);
    color: var(--muted);
    max-width: 420px;
    line-height: 1.6;
}
.empty-state .es-cta {
    margin-top: var(--sp-sm);
    display: flex;
    gap: var(--sp-sm);
    flex-wrap: wrap;
    justify-content: center;
}
.empty-state .es-cta button,
.empty-state .es-cta a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: all var(--fast);
}
.empty-state .es-cta .btn-primary {
    background: var(--gradient);
    color: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}
.empty-state .es-cta .btn-primary:hover { opacity: 0.92; transform: translateY(-1px); }
.empty-state .es-cta .btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border-strong);
}
.empty-state .es-cta .btn-ghost:hover { color: var(--text); border-color: var(--primary); }

.hint {
    color: var(--muted);
    font-size: var(--fs-sm);
    margin: 4px 0;
}

/* ================================================================
 *  SKELETON (loading 占位)
 * ================================================================ */

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(var(--primary-rgb), 0.04) 0%,
        rgba(var(--primary-rgb), 0.12) 50%,
        rgba(var(--primary-rgb), 0.04) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s infinite ease-in-out;
    border-radius: var(--r-sm);
    display: inline-block;
    vertical-align: middle;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 变体 */
.skel-text { width: 120px; height: 12px; border-radius: var(--r-sm); }
.skel-text.sm { width: 60px; height: 10px; }
.skel-text.lg { width: 180px; height: 14px; }
.skel-text.xl { width: 240px; height: 16px; }
.skel-block { width: 100%; height: 60px; border-radius: var(--r-md); }
.skel-circle { width: 32px; height: 32px; border-radius: 50%; }
.skel-chip { width: 48px; height: 20px; border-radius: var(--r-pill); }

/* 表格骨架行：统一 height 免抖动 */
.skel-row {
    display: grid;
    gap: var(--sp-md);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.skel-row > .skeleton { height: 14px; border-radius: var(--r-sm); }
.skel-row.sl-cols {
    /* 匹配 sl-table 列：checkbox + 短链 + 目标 + 标题 + 访问 + 标签 + 创建 + 操作 */
    grid-template-columns: 32px 120px 1fr 120px 60px 100px 80px 80px;
}
.skel-row.vl-cols {
    /* 匹配 visitors-table 列：id + 地域 + 设备/OS + 浏览器 + 访问 + 首次 + 最近 */
    grid-template-columns: 140px 1fr 140px 100px 60px 150px 150px;
}
@media (max-width: 1200px) {
    .skel-row.sl-cols { grid-template-columns: 32px 100px 1fr 80px 60px 80px; }
    .skel-row.sl-cols > :nth-child(7), .skel-row.sl-cols > :nth-child(8) { display: none; }
    .skel-row.vl-cols { grid-template-columns: 120px 1fr 120px 80px 60px; }
    .skel-row.vl-cols > :nth-child(6), .skel-row.vl-cols > :nth-child(7) { display: none; }
}

/* ----- 访客列表表格微样式 ----- */
.vl-tbl .visitor-id {
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace;
    font-size: var(--fs-xs);
    background: var(--surface-3);
    color: var(--primary);
    padding: 3px 8px;
    border-radius: var(--r-sm);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--fast);
}
.vl-tbl .visitor-id:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}
.vl-tbl td .muted { color: var(--muted); font-size: var(--fs-sm); }

/* ----- J3: Live event 进场动画 + visitors 新访客提示条 ----- */
.rt-live-enter {
    animation: rt-live-slide 0.4s var(--ease-out);
    background: rgba(var(--primary-rgb), 0.08);
}
@keyframes rt-live-slide {
    0%   { opacity: 0; transform: translateY(-12px); background: rgba(16, 185, 129, 0.25); }
    40%  { opacity: 1; background: rgba(16, 185, 129, 0.18); }
    100% { opacity: 1; transform: translateY(0); background: rgba(var(--primary-rgb), 0.08); }
}

.vl-live-nudge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: var(--gradient-soft);
    border: 1px solid var(--primary);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    color: var(--text);
    animation: rt-live-slide 0.3s var(--ease-out);
}
.vl-live-nudge b { color: var(--primary); font-weight: 700; }
.vl-live-nudge button {
    margin-left: auto;
    padding: 4px 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--fast);
}
.vl-live-nudge button:hover { opacity: 0.88; }

/* ----- 实时在线指示点 (E4) ----- */
.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.live-dot.online {
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55);
    animation: live-pulse 1.8s infinite;
}
.live-dot.recent {
    background: var(--orange);
    opacity: 0.8;
}
@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ================================================================
 *  VISITOR DETAIL MODAL (E2)
 * ================================================================ */
.modal-box-wide { max-width: 860px; width: calc(100vw - 80px); }

.vm-title-label { margin-right: 8px; }
.vm-title-id {
    font-family: "JetBrains Mono", "SF Mono", Consolas, monospace;
    font-size: var(--fs-sm);
    background: var(--surface-2);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: var(--r-sm);
    font-weight: 500;
}

.vm-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-md);
    margin-bottom: var(--sp-lg);
}
@media (max-width: 700px) { .vm-summary { grid-template-columns: repeat(2, 1fr); } }

.vm-stat {
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}
.vm-stat-label {
    font-size: var(--fs-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.vm-stat-value {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.vm-section-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: var(--sp-xl) 0 var(--sp-md);
    display: flex;
    align-items: center;
    gap: 8px;
}
.vm-section-title::before {
    content: '';
    width: 3px;
    height: 14px;
    background: var(--gradient);
    border-radius: 3px;
}

/* Timeline */
.vm-timeline {
    position: relative;
    padding-left: 24px;
    max-height: 420px;
    overflow-y: auto;
}
.vm-timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: linear-gradient(to bottom, var(--primary) 0%, var(--border-strong) 100%);
    opacity: 0.4;
}
.vm-event {
    position: relative;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    transition: border-color var(--fast), transform var(--fast);
}
.vm-event:hover {
    border-color: var(--primary);
    transform: translateX(2px);
}
.vm-event::before {
    content: '';
    position: absolute;
    left: -21px;
    top: 14px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px var(--surface-2);
}
.vm-event.latest::before {
    background: var(--green);
    box-shadow: 0 0 0 3px var(--surface-2), 0 0 0 5px rgba(16,185,129,0.3);
}
.vm-event-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}
.vm-event-code {
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-weight: 700;
    color: var(--primary);
    font-size: var(--fs-sm);
}
.vm-event-time {
    color: var(--muted);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
}
.vm-event-target {
    display: block;
    color: var(--muted);
    font-size: var(--fs-sm);
    margin-top: 4px;
    word-break: break-all;
}
.vm-event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.vm-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--fs-xs);
    color: var(--chip-text-muted);
    background: var(--chip-bg);
    border: 1px solid var(--chip-border);
    padding: 2px 8px;
    border-radius: var(--r-pill);
}
.vm-chip.utm { background: var(--chip-bg); color: var(--chip-text); }
.vm-chip.ref { background: rgba(245, 158, 11, 0.1); color: var(--orange); }

/* ----- 分页按钮（vl / 通用）----- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: var(--sp-md) 0;
    flex-wrap: wrap;
}
.pg-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: var(--fs-sm);
    transition: all var(--fast);
}
.pg-btn:hover:not(:disabled):not(.active) {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}
.pg-btn.active {
    background: var(--gradient);
    color: #fff;
    border-color: transparent;
    font-weight: 600;
}
.pg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pg-total {
    margin-left: auto;
    font-size: var(--fs-sm);
    color: var(--muted);
}

/* ================================================================
 *  FOOTER
 * ================================================================ */

.app-footer {
    padding: 14px;
    color: var(--subtle);
    font-size: 11px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.geo-attribution a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}

.geo-attribution a:hover {
    text-decoration: underline;
}

.visit-total {
    font-weight: 700;
    color: var(--text);
}

.visit-breakdown {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.2;
    color: var(--muted);
    white-space: nowrap;
}

.test-data-toggle {
    border-color: rgba(251, 191, 36, 0.38);
}

.test-data-active .test-data-toggle {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.72);
    background: rgba(251, 191, 36, 0.12);
}

/* ================================================================
 *  RESPONSIVE (tablet + mobile)  — J1
 *
 *  断点策略:
 *    ≤ 760px (手机):    单列 KPI, 抽屉侧栏, 隐藏 card sub 标题
 *    761–1100px (平板):  KPI 2 列, 图表 1 列, 筛选 chip 精简
 *    1101–1440px (笔记本): 3 列 KPI / grid
 *    ≥ 1441px (桌面):    完整布局
 * ================================================================ */

/* ---- Tablet (中屏) ---- */
@media (max-width: 1100px) {
    .topbar { padding: 0 12px; gap: 8px; }
    .tb-left { flex-basis: 120px; max-width: 120px; }
    .tb-title { font-size: 15px; }
    .tb-sub { display: none; }
    .tb-right {
        overflow-x: auto;
        scrollbar-width: none;
        justify-content: flex-start;
        padding-bottom: 2px;
    }
    .tb-right::-webkit-scrollbar { display: none; }
    .filter-chip { padding: 5px 8px; flex: 0 0 auto; }
    .chip-label { display: none; }
    .chip-sel { max-width: 120px; font-size: 12px; }
    .range-custom-wrap { padding: 5px 6px; }
    .chip-date { min-width: 112px; font-size: 11px; }
    .chip-mini-btn { font-size: 11px; padding: 0 6px; }
    .tb-btn { padding: 7px 8px; flex: 0 0 auto; }
    #compare-toggle-wrap,
    #export-btn,
    #share-btn {
        display: none;
    }
    .user-chip { padding: 5px !important; }
    .user-chip .user-name { display: none; }
    .kpi-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
    .kpi-value { font-size: 22px; }
    .g-2-1, .g-3 { grid-template-columns: 1fr; }
    .card { padding: 14px; }
    /* 访客表隐藏次要列 */
    .vl-tbl th:nth-child(3), .vl-tbl td:nth-child(3),
    .vl-tbl th:nth-child(6), .vl-tbl td:nth-child(6) { display: none; }
}

/* ---- Mobile (手机) ---- */
@media (max-width: 760px) {
    /* App 栅格：侧栏缩到 0，主内容占满 */
    .app { grid-template-columns: 0 1fr; }

    /* 侧栏改抽屉：fixed + 完整宽度 + 遮罩 */
    .sidebar {
        position: fixed;
        z-index: var(--z-modal);
        height: 100vh;
        width: min(var(--sidebar-w), 85vw);
        transform: translateX(-100%);
        transition: transform var(--mid);
        box-shadow: var(--shadow-lg);
    }
    body[data-sidebar="mobile-open"] .sidebar { transform: translateX(0); }

    /* 遮罩 —— 只在抽屉展开时出现 */
    body[data-sidebar="mobile-open"]::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: calc(var(--z-modal) - 1);
        animation: fade-in 0.2s var(--ease);
    }
    @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

    /* 悬浮折叠按钮在移动端隐藏，改用 topbar 汉堡 */
    .sb-collapse { display: none; }

    /* 汉堡按钮显示 */
    .tb-hamburger { display: flex !important; }

    /* Topbar 精简 */
    .topbar { padding: 0 12px; gap: 8px; }
    .tb-title { font-size: 15px; }
    .tb-sub { display: none; }

    /* 筛选 chip 折叠：只显示 select 不显示 label */
    .tb-right { flex-wrap: wrap; gap: 6px; }
    .filter-chip { padding: 4px 8px; }
    .chip-label { display: none; }
    .range-custom-wrap { width: 100%; justify-content: flex-start; }
    .chip-date { min-width: 108px; }
    .chip-mini-btn { padding: 0 7px; }
    /* 环比对比 chip + "含 Bot" chip 隐藏给更多空间 */
    .filter-chip.chip-toggle { display: none; }

    /* 视图区紧凑 */
    .views { padding: 12px; }
    .kpi-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .kpi-row.kpi-small { grid-template-columns: 1fr 1fr; }
    .kpi { padding: 12px; }
    .kpi-value { font-size: 20px; }
    .kpi-label { font-size: var(--fs-xs); }

    /* 表格允许水平滚动 —— 不再挤压内容 */
    .table-wrap, .tbl-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px; /* 反向 padding，让滚动条贴屏幕边缘 */
        padding: 0 12px;
    }
    .table-wrap .tbl, .tbl-scroll .tbl { min-width: 640px; }

    /* Real-time hero 缩放 */
    .rt-hero { padding: 16px; gap: 8px; flex-direction: column; text-align: center; }
    .rt-hero-stat b { font-size: 32px; }

    /* Form grid 单列 */
    .rule-form-grid,
    .site-form-grid,
    .webhook-form-grid { grid-template-columns: 1fr; }

    /* Modal 全屏化 */
    .modal-box, .modal-box-wide {
        max-width: 100vw;
        width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    /* 命令面板移动端适配 */
    .cmd-box { max-width: 100vw; width: 100vw; border-radius: 0; margin-top: 0; height: 100vh; }
    .cmd-results { max-height: calc(100vh - 80px); }

    /* 访客列表进一步隐列（手机只保留 ID + 地域 + 设备 + 最近）*/
    .vl-tbl th:nth-child(4), .vl-tbl td:nth-child(4),
    .vl-tbl th:nth-child(5), .vl-tbl td:nth-child(5) { display: none; }
}

/* ---- 汉堡按钮（默认隐藏，移动端显示）---- */
.tb-hamburger {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--muted);
    cursor: pointer;
    transition: all var(--fast);
    flex-shrink: 0;
}
.tb-hamburger:hover { color: var(--primary); border-color: var(--primary); }
.tb-hamburger:active { transform: scale(0.94); }

/* ================================================================
 *  SHORT LINK MANAGEMENT
 * ================================================================ */

.sl-actions { display: flex; gap: 4px; }
.sl-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 4px 8px;
    border-radius: var(--r-sm);
    font-size: 12px;
    transition: all var(--fast);
    cursor: pointer;
}
.sl-action-btn:hover { color: var(--primary); border-color: var(--border-strong); }
.sl-action-btn.danger:hover { color: #fca5a5; border-color: rgba(239,68,68,0.4); }

.sl-url {
    font-size: 12px;
    color: var(--muted);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sl-url:hover { color: var(--text); }

.sl-domain-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: var(--r-sm);
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    margin-right: 2px;
}

.sl-tag-chip {
    display: inline-block;
    padding: 2px 8px;
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    margin-right: 4px;
}
.sl-title-auto {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid rgba(var(--primary-rgb), 0.35);
    color: var(--chip-text-muted);
    background: rgba(var(--primary-rgb), 0.12);
    font-size: 10px;
    line-height: 1.3;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 12px 0 4px;
}
.pagination button {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 5px 10px;
    border-radius: var(--r-sm);
    font-size: 12px;
    min-width: 32px;
    transition: all var(--fast);
    cursor: pointer;
}
.pagination button:hover:not([disabled]) { border-color: var(--border-strong); color: var(--text); }
.pagination button.active { background: var(--gradient); color: #fff; border-color: transparent; }
.pagination button[disabled] { opacity: 0.35; cursor: not-allowed; }

/* ================================================================
 *  FORM GROUPS (modals)
 * ================================================================ */

.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }
.form-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
}
.form-label.required::after, .form-label .required { color: var(--red); }
.hint-inline {
    font-weight: normal;
    color: var(--subtle);
    font-size: 11px;
    margin-left: 4px;
}
.form-input-lg {
    font-size: 14px;
    padding: 10px 14px;
    width: 100%;
}
.form-input { width: 100%; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-advanced {
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}
.form-advanced summary {
    cursor: pointer;
    padding: 6px 10px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    list-style: none;
    user-select: none;
}
.form-advanced summary::-webkit-details-marker { display: none; }
.form-advanced[open] summary { margin-bottom: 10px; }
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
    color: var(--text);
    font-weight: normal;
}
.checkbox-label input { accent-color: var(--primary); width: 14px; height: 14px; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

.modal-box-sm { width: min(480px, 92vw); }
.modal-box-xs { width: min(380px, 92vw); }

.btn-danger {
    background: var(--red);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--r-md);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--fast);
}
.btn-danger:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(239,68,68,0.3); }

.confirm-msg { font-size: 14px; line-height: 1.6; margin: 0; color: var(--text); }

/* Tag chips input */
.tag-input-wrap {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    min-height: 38px;
}
.tag-input-wrap:focus-within { border-color: var(--primary); box-shadow: var(--shadow-glow); }
.tag-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--chip-bg);
    color: var(--chip-text);
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--chip-border);
}
.tag-chip .tag-x {
    cursor: pointer;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
}
.tag-chip .tag-x:hover { opacity: 1; color: var(--red); }
.tag-input {
    background: transparent;
    border: none;
    color: var(--text);
    outline: none;
    flex: 1;
    min-width: 100px;
    font-size: 13px;
}

/* ================================================================
 *  QR CODE MODAL
 * ================================================================ */

.qr-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 24px 20px;
}
.qr-preview-wrap {
    background: #fff;
    padding: 16px;
    border-radius: var(--r-md);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.qr-preview-wrap img { display: block; max-width: 100%; }
.qr-url {
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 13px;
    color: var(--primary);
    background: var(--surface-2);
    padding: 6px 12px;
    border-radius: var(--r-sm);
    word-break: break-all;
    text-align: center;
}
.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.qr-actions > * { font-size: 12px; padding: 6px 12px; text-decoration: none; }
.qr-size-control {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.qr-size-control input[type=range] { accent-color: var(--primary); width: 120px; }

/* ================================================================
 *  BULK CREATE MODAL
 * ================================================================ */

.bulk-textarea {
    width: 100%;
    min-height: 180px;
    max-height: 400px;
    resize: vertical;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.55;
    padding: 12px;
    margin-bottom: 10px;
}
.bulk-progress {
    margin-top: 12px;
    padding: 12px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    font-size: 12px;
    max-height: 200px;
    overflow-y: auto;
}

/* CSV import */
.csv-input-wrap { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.csv-upload-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--r-md);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--fast);
    background: var(--surface-2);
}
.csv-upload-zone:hover { border-color: var(--primary); background: var(--gradient-soft); }
.csv-upload-zone.drag-over { border-color: var(--green); background: rgba(16,185,129,0.08); }
.csv-upload-icon { font-size: 32px; margin-bottom: 6px; }
.csv-upload-text { color: var(--text); font-weight: 600; font-size: 13px; }
.csv-upload-hint { color: var(--muted); font-size: 11px; margin-top: 4px; }

.csv-preview {
    max-height: 240px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 12px;
}
.csv-preview table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.csv-preview th, .csv-preview td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.csv-preview th { background: var(--surface-2); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
.csv-preview .csv-count { padding: 8px 12px; background: var(--surface-2); color: var(--primary); font-weight: 600; font-size: 12px; }

/* Batch operation bar */
.batch-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--gradient-soft);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    margin-bottom: 12px;
    animation: batchIn 0.2s var(--ease);
}
@keyframes batchIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.batch-count { font-weight: 700; color: var(--primary); font-size: 13px; }
.batch-actions { display: flex; gap: 6px; margin-left: auto; }
.batch-actions button {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all var(--fast);
}
.batch-actions button:hover { border-color: var(--border-strong); }
.batch-actions button.danger { color: #fca5a5; }
.batch-actions button.danger:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); }

.row-checkbox {
    accent-color: var(--primary);
    cursor: pointer;
    width: 14px;
    height: 14px;
}
.row-check-header { width: 32px; }
.bulk-progress div { padding: 4px 0; border-bottom: 1px solid var(--border); }
.bulk-progress .ok { color: var(--green); }
.bulk-progress .fail { color: var(--red); }

/* ================================================================
 *  TAGS & DOMAINS LIST
 * ================================================================ */

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 0;
}
.tag-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px 6px 14px;
    transition: all var(--fast);
}
.tag-item:hover { border-color: var(--border-strong); }
.tag-item-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 13px;
}
.tag-item-count {
    color: var(--muted);
    font-size: 11px;
    padding: 2px 8px;
    background: var(--surface);
    border-radius: 999px;
}
.tag-item-actions { display: flex; gap: 4px; }
.tag-action {
    background: transparent;
    border: none;
    color: var(--subtle);
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    border-radius: 4px;
    transition: all var(--fast);
}
.tag-action:hover { color: var(--text); background: var(--surface); }
.tag-action.danger:hover { color: #fca5a5; }

.domains-list, #keys-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 10px;
    padding: 8px 0;
}
.domain-item, .key-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.domain-item .domain-host {
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 14px;
    color: var(--primary);
    font-weight: 600;
}
.domain-item .domain-meta { color: var(--muted); font-size: 11px; }
.domain-item .domain-default {
    display: inline-block;
    background: var(--gradient);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    width: fit-content;
    letter-spacing: 0.5px;
}
.domain-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    width: fit-content;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(34, 197, 94, 0.25);
    background: rgba(34, 197, 94, 0.14);
    color: #86efac;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;
}
.domain-status-badge.badge-warn {
    border-color: rgba(245, 158, 11, 0.28);
    background: rgba(245, 158, 11, 0.14);
    color: #fcd34d;
}

/* ================================================================
 *  TOAST NOTIFICATIONS
 * ================================================================ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
    pointer-events: none;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-left: 4px solid var(--primary);
    border-radius: var(--r-md);
    padding: 12px 14px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.25s var(--ease), toastOut 0.25s var(--ease) 3.5s forwards;
    pointer-events: auto;
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--cyan); }
.toast-icon { font-size: 18px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.toast-msg { color: var(--muted); font-size: 12px; line-height: 1.5; }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateX(40px); }
}

/* Light theme specific tweaks */
body[data-theme="light"] .sidebar,
body[data-theme="light"] .topbar {
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
body[data-theme="light"] .kpi-value {
    /* Keep gradient text visible on light */
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
body[data-theme="light"] .filter-chip {
    background: var(--surface-2);
}
body[data-theme="light"] .tb-btn,
body[data-theme="light"] .form-input,
body[data-theme="light"] .inline-search {
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
body[data-theme="light"] .card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
body[data-theme="light"] .card:hover {
    box-shadow: 0 4px 12px rgba(var(--primary-rgb),0.12);
}
body[data-theme="light"] .sb-item.active {
    background: linear-gradient(135deg, rgba(var(--primary-rgb),0.1), rgba(var(--accent-rgb),0.04));
    color: var(--primary);
    box-shadow: inset 3px 0 0 var(--primary);
}
body[data-theme="light"] .code-block {
    background: var(--surface-2);
}
body[data-theme="light"] .code-block pre {
    color: var(--text);
}
body[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(var(--primary-rgb), 0.22);
}
body[data-theme="light"] .sl-domain-badge,
body[data-theme="light"] .sl-tag-chip {
    background: var(--chip-bg);
    color: var(--chip-text);
    border-color: var(--chip-border);
}
body[data-theme="light"] .tag-item,
body[data-theme="light"] .domain-item,
body[data-theme="light"] .key-item {
    background: #f8fafc;
    border-color: #cbd5e1;
}
body[data-theme="light"] .tag-item-name,
body[data-theme="light"] .domain-item .domain-host,
body[data-theme="light"] .add-form summary,
body[data-theme="light"] .form-advanced summary {
    color: #3730a3;
}
body[data-theme="light"] .tag-action {
    color: #64748b;
}
body[data-theme="light"] .tag-action:hover {
    color: #1e293b;
    background: #e2e8f0;
}
body[data-theme="light"] .tag-action.danger:hover {
    color: #b91c1c;
}
body[data-theme="light"] .add-form summary {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
}
body[data-theme="light"] .add-form[open] summary {
    background: #e0e7ff;
}
body[data-theme="light"] .domain-status-badge.badge-ok {
    background: #d1fae5;
    color: #065f46;
    border-color: #a7f3d0;
}
body[data-theme="light"] .domain-status-badge.badge-warn {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

/* ================================================================
 *  THEME SWITCHER
 * ================================================================ */

.theme-switch {
    display: inline-flex;
    gap: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 3px;
}
.theme-opt {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: var(--r-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--fast);
    display: flex;
    align-items: center;
    gap: 5px;
}
.theme-opt:hover { color: var(--text); }
.theme-opt.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
body[data-theme="dark"] .theme-opt.active { background: var(--surface-3); }

/* ================================================================
 *  USER MENU / LOGOUT
 * ================================================================ */

.user-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px 5px 5px !important;
}
.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
}
.user-name {
    font-size: 12px;
    color: var(--text);
    font-weight: 500;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-drop {
    position: absolute;
    top: calc(100% + 8px);
    right: 24px;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: all var(--fast);
    z-index: 100;
    overflow: hidden;
}
.user-drop.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.user-drop-head {
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--gradient-soft);
    border-bottom: 1px solid var(--border);
}
.user-drop-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    text-transform: uppercase;
}
.user-drop-info { flex: 1; min-width: 0; }
.user-drop-name { font-weight: 700; color: var(--text); font-size: 14px; }
.user-drop-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

.user-drop-items { padding: 6px; }
.user-drop-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    font-size: 13px;
    color: var(--text);
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
    transition: background var(--fast);
}
.user-drop-item:hover { background: var(--surface-2); }
.user-drop-item.danger { color: #fca5a5; }
.user-drop-item.danger:hover { background: rgba(239,68,68,0.12); }
.user-drop-item span { font-size: 14px; }
.user-drop-sep { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ================================================================
 *  KPI DELTA (compare)
 * ================================================================ */

.kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    margin-left: 6px;
    vertical-align: middle;
}
.kpi-delta.up    { background: rgba(16,185,129,0.15); color: #6ee7b7; }
.kpi-delta.down  { background: rgba(239,68,68,0.15); color: #fca5a5; }
.kpi-delta.flat  { background: var(--surface-2); color: var(--muted); }

/* ================================================================
 *  SHORT LINK DETAIL
 * ================================================================ */

.sld-meta-card {
    background: linear-gradient(135deg, rgba(var(--primary-rgb),0.12), rgba(var(--accent-rgb),0.06));
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    padding: 20px 24px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
}
.sld-meta-left { flex: 1; min-width: 280px; }
.sld-meta-url {
    font-size: 22px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.sld-meta-url a { color: inherit; text-decoration: none; }
.sld-meta-url a:hover { text-decoration: underline; }
.sld-meta-target {
    color: var(--text);
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    opacity: 0.9;
}
.sld-meta-target::before {
    content: '→';
    color: var(--muted);
    margin-right: 6px;
}
.sld-meta-info {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
}
.sld-meta-info b { color: var(--text); font-weight: 600; }
.sld-meta-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.sld-meta-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.sld-meta-actions button {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: var(--r-md);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--fast);
    display: flex;
    align-items: center;
    gap: 5px;
}
.sld-meta-actions button:hover { border-color: var(--border-strong); }
.sld-meta-actions button.primary { background: var(--gradient); border-color: transparent; color: #fff; }
.sld-meta-actions button.primary:hover { opacity: 0.92; transform: translateY(-1px); }
.sld-meta-actions button.danger:hover { color: #fca5a5; border-color: rgba(239,68,68,0.3); }

/* Short code badge in tables (clickable) */
a.sc-link {
    color: var(--chip-text);
    font-family: "JetBrains Mono", "SF Mono", Monaco, Consolas, monospace;
    text-decoration: none;
    padding: 2px 6px;
    background: var(--chip-bg);
    border-radius: var(--r-sm);
    border: 1px solid var(--chip-border);
    transition: all var(--fast);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: color var(--fast);
}
a.sc-link:hover {
    background: var(--chip-bg-strong);
    border-color: var(--chip-border);
    color: var(--chip-text);
    text-decoration: none;
}
a.sc-link::after {
    content: ' ↗';
    opacity: 0;
    transition: opacity var(--fast);
    font-size: 0.85em;
}
a.sc-link:hover::after { opacity: 0.7; }

/* (旧 scrollbar 规则已移到文件头部与 GLOBAL RESETS & A11Y 一起，避免两套规则冲突) */
