/* ============================================
   WebStats - 深色科技风统计看板 v4.0
   侧边导航 · 分页 · 真实世界地图 · 全响应式
   ============================================ */

:root {
    --bg: #060a13;
    --bg2: #0c1220;
    --bg3: #141d2e;
    --border: #1a2740;
    --border-glow: rgba(0,212,255,0.15);
    --text: #e2e8f0;
    --text2: #6b7f99;
    --accent: #00d4ff;
    --accent2: #7c3aed;
    --green: #10b981;
    --red: #ef4444;
    --orange: #f59e0b;
    --pink: #ec4899;
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 8px;
    --glow: 0 0 20px rgba(0,212,255,0.08);
    --sidebar-w: 200px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%; height: 100%;
    position: fixed;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

/* ====== 背景网格 ====== */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        linear-gradient(rgba(0,212,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,212,255,0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 0;
}

/* ====== 侧边栏 ====== */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0; right: -1px; bottom: 0;
    width: 1px;
    background: linear-gradient(180deg, var(--accent), transparent, var(--accent2));
    opacity: 0.2;
}

.sidebar-logo {
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    width: 24px; height: 24px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-ring {
    position: absolute;
    width: 20px; height: 20px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    animation: logoSpin 4s linear infinite;
    border-top-color: transparent;
}

.logo-dot {
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent);
}

@keyframes logoSpin { to { transform: rotate(360deg); } }

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 1px;
    text-shadow: 0 0 20px rgba(0,212,255,0.3);
}

.sidebar-site {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.site-select {
    width: 100%;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.3s;
}

.site-select:focus { border-color: var(--accent); box-shadow: 0 0 8px rgba(0,212,255,0.2); }

/* 导航列表 */
.nav-list {
    list-style: none;
    padding: 8px 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 18px;
    cursor: pointer;
    color: var(--text2);
    font-size: 13px;
    transition: all 0.2s;
    position: relative;
}

.nav-item:hover {
    color: var(--text);
    background: rgba(0,212,255,0.04);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(0,212,255,0.08);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(0,212,255,0.4);
}

.nav-item svg { flex-shrink: 0; }

/* 侧边栏底部 */
.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.online-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--green);
}

.online-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.refresh-info {
    font-size: 11px;
    color: var(--text2);
}

/* ====== 移动端顶栏（默认隐藏）====== */
.mobile-topbar {
    display: none;
    height: 48px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 12px;
    gap: 12px;
    position: relative;
    z-index: 25;
}

.menu-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}

.mobile-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    flex: 1;
}

/* ====== 移动端底部导航（默认隐藏）====== */
.mobile-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 56px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 25;
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    color: var(--text2);
    font-size: 10px;
    padding: 4px 12px;
    transition: color 0.2s;
}

.mobile-nav-item.active {
    color: var(--accent);
}

.mobile-nav-item svg { flex-shrink: 0; }

/* ====== 主体内容 ====== */
.main-content {
    position: fixed;
    left: var(--sidebar-w);
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    z-index: 1;
}

.main-content::-webkit-scrollbar { width: 4px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ====== 页面切换 ====== */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ====== 概览卡片行 ====== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--glow);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background: linear-gradient(180deg, var(--accent), var(--accent2));
}

.stat-card-total::before {
    background: linear-gradient(180deg, var(--green), var(--accent));
}

.stat-icon-wrap {
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-total { background: rgba(16,185,129,0.12); color: var(--green); }
.icon-pv { background: rgba(0,212,255,0.12); color: var(--accent); }
.icon-uv { background: rgba(124,58,237,0.12); color: var(--accent2); }
.icon-bounce { background: rgba(245,158,11,0.12); color: var(--orange); }
.icon-duration { background: rgba(236,72,153,0.12); color: var(--pink); }

.stat-info { flex: 1; min-width: 0; }

.stat-label {
    font-size: 11px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-card-total .stat-value {
    font-size: 28px;
    color: var(--green);
}

.stat-change { font-size: 11px; margin-top: 4px; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* ====== 2D 世界地图 ====== */
.panel-map {
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
}

.panel-map::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--accent2), transparent);
    z-index: 2;
}

.map-container {
    position: relative;
    height: 380px;
    overflow: hidden;
}

.map-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text2);
}

.map-legend-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
}

.server-dot {
    animation: serverPulse 1.5s ease-in-out infinite;
}

@keyframes serverPulse {
    0%, 100% { box-shadow: 0 0 4px #FF6B9D; opacity: 1; }
    50% { box-shadow: 0 0 10px #FF6B9D, 0 0 20px rgba(255,107,157,0.3); opacity: 0.7; }
}

.map-reset-btn {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(0,212,255,0.3);
    background: rgba(6,10,19,0.8);
    color: rgba(0,212,255,0.7);
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 5;
    line-height: 1;
    padding: 0;
}
.map-reset-btn:hover {
    border-color: rgba(0,212,255,0.6);
    color: #00d4ff;
    background: rgba(0,212,255,0.1);
}

.map-zoom-hint {
    position: absolute;
    bottom: 8px;
    right: 10px;
    font-size: 10px;
    color: rgba(107,127,153,0.5);
    pointer-events: none;
    z-index: 5;
}

/* ====== 面板 ====== */
.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s;
    margin-bottom: 12px;
}

.panel:hover {
    border-color: rgba(0,212,255,0.12);
    box-shadow: 0 0 15px rgba(0,212,255,0.04);
}

.panel h2 {
    font-size: 13px;
    font-weight: 600;
    padding: 12px 14px 0;
    color: var(--text);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 0;
}

.panel-header h2 { padding: 0; }

.panel-body { padding: 10px 14px; }

.scroll-list { max-height: 260px; overflow-y: auto; }
.scroll-list::-webkit-scrollbar { width: 3px; }
.scroll-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ====== 图表 ====== */
.chart-area { height: 220px; padding: 6px 14px 14px; }

canvas { display: block; width: 100%; height: 100%; }

/* ====== Tab ====== */
.tab-group { display: flex; gap: 4px; }

.tab {
    background: var(--bg3); color: var(--text2);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 3px 10px; font-size: 11px;
    cursor: pointer; transition: all 0.2s;
}

.tab.active {
    background: var(--accent); color: var(--bg);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(0,212,255,0.3);
}

.tab:hover:not(.active) { border-color: var(--accent); color: var(--text); }

/* ====== 两列 ====== */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

/* ====== 列表 ====== */
.rank-list { list-style: none; }

.rank-list li {
    display: flex;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(26,39,64,0.6);
    font-size: 12px;
}

.rank-list li:last-child { border-bottom: none; }

.rank-num {
    width: 20px; height: 20px;
    border-radius: 3px;
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text2);
    margin-right: 8px;
    flex-shrink: 0;
}

.rank-list li:nth-child(1) .rank-num { background: var(--accent); color: var(--bg); }
.rank-list li:nth-child(2) .rank-num { background: var(--accent2); color: #fff; }
.rank-list li:nth-child(3) .rank-num { background: var(--orange); color: var(--bg); }

.rank-name {
    flex: 1; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    color: var(--text); font-size: 12px;
}

.rank-value {
    font-weight: 600; color: var(--accent);
    margin-left: 8px; flex-shrink: 0; font-size: 12px;
}

.rank-bar { height: 3px; background: var(--bg3); border-radius: 2px; margin-top: 2px; overflow: hidden; }
.rank-bar-fill {
    height: 100%; border-radius: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    transition: width 0.5s ease;
    box-shadow: 0 0 6px rgba(0,212,255,0.3);
}

/* ====== 热力图 ====== */
.heatmap-select {
    width: 100%; background: var(--bg3); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 5px 8px; font-size: 11px;
    margin-bottom: 8px; outline: none;
}
.heatmap-select:focus { border-color: var(--accent); }
.heatmap-area {
    height: 220px; background: var(--bg);
    border-radius: 4px; overflow: hidden;
    position: relative; border: 1px solid var(--border);
}

/* ====== 性能 ====== */
.perf-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.perf-item { background: var(--bg3); border-radius: 4px; padding: 8px; text-align: center; border: 1px solid rgba(26,39,64,0.5); }
.perf-item-label { font-size: 10px; color: var(--text2); margin-bottom: 2px; }
.perf-item-value { font-size: 16px; font-weight: 700; color: var(--accent); }
.perf-item-unit { font-size: 10px; color: var(--text2); margin-left: 1px; }

/* ====== 访客 ====== */
.visitor-row { display: flex; align-items: center; padding: 5px 0; border-bottom: 1px solid rgba(26,39,64,0.6); font-size: 11px; gap: 6px; }
.visitor-row:last-child { border-bottom: none; }
.visitor-time { color: var(--text2); flex-shrink: 0; width: 42px; }
.visitor-region { color: var(--orange); flex-shrink: 0; width: 42px; }
.visitor-browser { color: var(--accent); flex-shrink: 0; width: 48px; }
.visitor-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* ====== 错误 ====== */
.error-row { padding: 6px 0; border-bottom: 1px solid rgba(26,39,64,0.6); font-size: 11px; }
.error-row:last-child { border-bottom: none; }
.error-msg { color: var(--red); font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-meta { color: var(--text2); font-size: 10px; }

/* ====== 蜘蛛 ====== */
.spider-row { display: flex; align-items: center; padding: 5px 0; border-bottom: 1px solid rgba(26,39,64,0.6); font-size: 12px; }
.spider-row:last-child { border-bottom: none; }
.spider-name { flex: 1; color: var(--text); }
.spider-count { font-weight: 600; color: var(--accent); margin-right: 6px; }

/* ====== 路径 ====== */
.path-row { padding: 5px 0; border-bottom: 1px solid rgba(26,39,64,0.6); font-size: 11px; }
.path-row:last-child { border-bottom: none; }
.path-step { display: inline-block; background: var(--bg3); padding: 1px 6px; border-radius: 3px; color: var(--text); margin: 1px 0; border: 1px solid var(--border); }
.path-arrow { color: var(--accent); margin: 0 3px; }

/* ====== 空状态 ====== */
.empty { color: var(--text2); text-align: center; padding: 20px 0; font-size: 12px; }

/* ============================
   响应式
   ============================ */

/* ≤1100px：概览卡片3列，地图高度降 */
@media (max-width: 1100px) {
    .stats-row { grid-template-columns: repeat(3, 1fr); }
    .map-container { height: 300px; }
}

/* ≤768px：切换为移动端布局 */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 100;
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-topbar {
        display: flex;
    }

    .mobile-nav {
        display: flex;
    }

    .main-content {
        left: 0;
        top: 48px;
        bottom: 56px;
        padding: 12px;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stat-card-total { grid-column: span 2; }
    .stat-card { padding: 10px 12px; gap: 8px; }
    .stat-value { font-size: 20px; }
    .stat-card-total .stat-value { font-size: 24px; }
    .stat-icon-wrap { width: 34px; height: 34px; }
    .stat-icon-wrap svg { width: 18px; height: 18px; }

    .two-col { grid-template-columns: 1fr; gap: 8px; }

    .map-container { height: 220px; }
    .chart-area { height: 180px; }
    .scroll-list { max-height: 200px; }
    .heatmap-area { height: 160px; }
}

/* ≤480px：更紧凑 */
@media (max-width: 480px) {
    .stats-row { grid-template-columns: 1fr 1fr; gap: 6px; }
    .stat-value { font-size: 18px; }
    .stat-card-total .stat-value { font-size: 20px; }
    .stat-label { font-size: 10px; }
    .main-content { padding: 8px; }
}

/* 遮罩层 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.sidebar-overlay.show { display: block; }
