/* =========================================================
 * Cloudflare 数据分析面板 —— 现代化深色主题
 * ========================================================= */
:root {
    --bg-0:        #0b0d12;
    --bg-1:        #10131b;
    --bg-2:        #161a26;
    --bg-3:        #1d2231;
    --border:      #262b3d;
    --border-soft: #1c2030;
    --text:        #e8ebf5;
    --text-muted:  #8b93a7;
    --text-dim:    #60687e;

    --brand:       #f6821f;   /* Cloudflare Orange */
    --brand-2:     #faae40;
    --accent:      #4f8cff;
    --green:       #2fd673;
    --red:         #ff5370;
    --purple:      #a479ff;

    --radius:      14px;
    --radius-sm:   10px;
    --shadow:      0 10px 30px rgba(0,0,0,.35);
    --shadow-sm:   0 4px 16px rgba(0,0,0,.25);

    --grad-card: linear-gradient(135deg, rgba(246,130,31,.12), rgba(79,140,255,.08) 60%, transparent 100%);
    --grad-brand: linear-gradient(135deg, #f6821f 0%, #faae40 100%);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: radial-gradient(1200px 800px at 80% -10%, rgba(246,130,31,.12), transparent 60%),
                radial-gradient(1000px 600px at -10% 100%, rgba(79,140,255,.12), transparent 60%),
                var(--bg-0);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: .85; }

/* ========== 顶部导航 ========== */
.topbar {
    position: sticky; top: 0; z-index: 20;
    backdrop-filter: blur(14px);
    background: rgba(11,13,18,.72);
    border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
    max-width: 1400px; margin: 0 auto;
    display: flex; align-items: center; gap: 24px;
    padding: 14px 28px;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 16px; letter-spacing: .5px;
}
.brand-logo {
    width: 32px; height: 32px; border-radius: 10px;
    background: var(--grad-brand);
    display: grid; place-items: center;
    box-shadow: 0 6px 20px rgba(246,130,31,.35);
    font-size: 18px;
}
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
    color: var(--text-muted);
    padding: 8px 14px; border-radius: 10px;
    font-weight: 500;
    transition: all .15s;
}
.nav a:hover { color: var(--text); background: var(--bg-2); }
.nav a.active {
    color: var(--text);
    background: linear-gradient(135deg, rgba(246,130,31,.18), rgba(79,140,255,.14));
    box-shadow: inset 0 0 0 1px rgba(246,130,31,.35);
}

.top-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.top-actions select,
.top-actions .btn {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color .15s;
}
.top-actions select:hover,
.top-actions .btn:hover { border-color: var(--brand); }
.range-tabs {
    display: inline-flex;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
}
.range-tabs a {
    padding: 5px 12px;
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 12px; font-weight: 600;
}
.range-tabs a.active {
    background: var(--grad-brand);
    color: #111;
}

/* ========== 主体布局 ========== */
.container {
    max-width: 1400px; margin: 0 auto;
    padding: 28px;
}
h1.page-title {
    font-size: 22px; margin: 0 0 4px;
    display: flex; align-items: center; gap: 10px;
}
.page-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }

/* ========== 卡片 / KPI ========== */
.kpi-grid {
    display: grid; gap: 18px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    margin-bottom: 24px;
}
.kpi {
    position: relative;
    background: var(--bg-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 20px 22px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.kpi::before {
    content: "";
    position: absolute; inset: 0;
    background: var(--grad-card);
    opacity: .7; pointer-events: none;
}
.kpi > * { position: relative; }
.kpi .label {
    font-size: 12px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
    display: flex; align-items: center; gap: 8px;
}
.kpi .label .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--brand);
}
.kpi .value {
    margin: 10px 0 4px;
    font-size: 30px; font-weight: 700;
    letter-spacing: -.5px;
}
.kpi .hint { color: var(--text-dim); font-size: 12px; }

.kpi.green .label .dot  { background: var(--green); }
.kpi.blue  .label .dot  { background: var(--accent); }
.kpi.purple .label .dot { background: var(--purple); }
.kpi.red   .label .dot  { background: var(--red); }

/* ========== 通用区块 ========== */
.panel {
    background: var(--bg-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 22px;
    box-shadow: var(--shadow-sm);
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head .sub { color: var(--text-muted); font-size: 12px; }

.chart-wrap { position: relative; height: 320px; }
.chart-wrap.small { height: 220px; }

/* 两列 */
.cols-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; }
@media (max-width: 1000px) { .cols-2 { grid-template-columns: 1fr; } }

/* 表格 */
table.tbl {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
table.tbl th, table.tbl td {
    text-align: left; padding: 10px 14px;
    border-bottom: 1px solid var(--border-soft);
}
table.tbl th {
    color: var(--text-muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: .5px; font-size: 11px;
}
table.tbl tr:hover td { background: rgba(255,255,255,.02); }
.badge {
    display: inline-block; padding: 2px 8px;
    background: var(--bg-3); border: 1px solid var(--border);
    border-radius: 6px; font-size: 11px;
    color: var(--text-muted);
}
.badge.brand { color: var(--brand); border-color: rgba(246,130,31,.4); }
.badge.green { color: var(--green); border-color: rgba(47,214,115,.4); }
.bar {
    position: relative;
    height: 8px; border-radius: 4px;
    background: var(--bg-3); overflow: hidden;
}
.bar > i {
    position: absolute; inset: 0; width: 0;
    background: var(--grad-brand); border-radius: 4px;
    transition: width .4s ease;
}

/* 国旗图标 */
.flag {
    display: inline-block;
    width: 22px; height: 16px;
    margin-right: 8px;
    vertical-align: middle;
    border-radius: 3px;
    box-shadow: 0 0 0 1px rgba(255,255,255,.1), 0 1px 2px rgba(0,0,0,.4);
    object-fit: cover;
}

/* ========== 表单 ========== */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field label {
    display: block; margin-bottom: 6px;
    font-size: 12px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .5px;
}
.field input, .field select, .field textarea {
    width: 100%;
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(246,130,31,.18);
}
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.btn:hover { border-color: var(--brand); }
.btn-primary {
    background: var(--grad-brand);
    color: #111; border-color: transparent;
    box-shadow: 0 6px 20px rgba(246,130,31,.35);
}
.btn-primary:hover { opacity: .95; }
.btn-danger {
    color: var(--red); border-color: rgba(255,83,112,.35);
}
.btn-danger:hover { background: rgba(255,83,112,.1); }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    border: 1px solid;
    font-size: 13px;
}
.alert-ok   { background: rgba(47,214,115,.08); border-color: rgba(47,214,115,.35); color: #7fe7ad; }
.alert-err  { background: rgba(255,83,112,.08); border-color: rgba(255,83,112,.35); color: #ffa0b0; }
.alert-info { background: rgba(79,140,255,.08); border-color: rgba(79,140,255,.35); color: #a7c3ff; }

/* 登录页 */
.login-wrap {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 20px;
}
.login-card {
    width: 360px; max-width: 100%;
    background: var(--bg-1);
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    padding: 30px;
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p  { color: var(--text-muted); margin: 0 0 20px; }

/* 小工具 */
.muted { color: var(--text-muted); }
.right { text-align: right; }
.mb-0 { margin-bottom: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* 空状态 */
.empty {
    text-align: center;
    padding: 42px 20px;
    color: var(--text-muted);
}
.empty .icon { font-size: 40px; margin-bottom: 10px; opacity: .5; }


/* =========================================================
 * 响应式适配 —— 平板 / 手机
 * ========================================================= */

/* 平板（≤ 900px） */
@media (max-width: 900px) {
    .container { padding: 18px 14px; }

    /* 顶栏可折行 */
    .topbar-inner {
        padding: 12px 14px;
        gap: 12px;
        flex-wrap: wrap;
    }
    .nav {
        order: 3;
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav::-webkit-scrollbar { display: none; }
    .nav a {
        flex: 0 0 auto;
        padding: 7px 12px;
        font-size: 13px;
    }
    .top-actions {
        margin-left: auto;
        flex-wrap: wrap;
        gap: 8px;
    }
    .top-actions select { max-width: 160px; }

    /* KPI 卡换两列 */
    .kpi-grid { gap: 14px; }
    .kpi { padding: 16px 18px; }
    .kpi .value { font-size: 24px; }

    /* 标题缩小 */
    h1.page-title { font-size: 19px; }
    .panel { padding: 18px; }
    .panel-head { gap: 8px; }
    .panel-head h2 { font-size: 14px; }

    /* 表格：仅给含表格的 panel 整体横向滚动，不破坏 table 列宽，也不影响图表 panel */
    .panel:has(> table.tbl) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table.tbl th, table.tbl td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    /* 图表降高 */
    .chart-wrap { height: 260px; }
    .chart-wrap.small { height: 180px; }
}

/* 手机（≤ 640px） */
@media (max-width: 640px) {
    body { font-size: 13px; }
    .container { padding: 14px 10px; }

    /* 顶栏：logo 文字只留图标 */
    .topbar-inner { padding: 10px 12px; gap: 8px; }
    .brand span { display: none; }
    .brand-logo { width: 30px; height: 30px; font-size: 16px; }

    /* 范围切换 tabs 缩小 */
    .range-tabs { padding: 2px; }
    .range-tabs a { padding: 5px 9px; font-size: 11px; }

    /* 按钮缩小 */
    .top-actions .btn { padding: 7px 10px; font-size: 12px; }
    .top-actions select { padding: 7px 10px; font-size: 12px; max-width: 130px; }

    /* KPI: 单列 */
    .kpi-grid { grid-template-columns: 1fr 1fr !important; }
    .kpi { padding: 14px 14px; }
    .kpi .value { font-size: 22px; }
    .kpi .label { font-size: 11px; }
    .kpi .hint { font-size: 11px; }

    /* 标题再缩 */
    h1.page-title { font-size: 17px; }
    .page-sub { font-size: 12px; margin-bottom: 16px; }

    /* 面板 */
    .panel { padding: 14px; margin-bottom: 16px; border-radius: 12px; }
    .panel-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .panel-head .btn,
    .panel-head a.btn {
        align-self: flex-end;
    }

    /* 双列布局直接堆叠 */
    .cols-2 { grid-template-columns: 1fr; gap: 14px; }

    /* 图表 */
    .chart-wrap { height: 220px; }

    /* 表格更紧凑 */
    table.tbl th, table.tbl td {
        padding: 8px 8px;
        font-size: 12px;
    }
    table.tbl th { font-size: 10px; }
    .badge { font-size: 10px; padding: 2px 6px; }

    /* 国旗略小 */
    .flag { width: 18px; height: 13px; margin-right: 6px; }

    /* 表单 */
    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .field input, .field select { padding: 9px 11px; }

    /* 按钮 */
    .btn { padding: 9px 14px; font-size: 12px; }

    /* alert */
    .alert { padding: 10px 12px; font-size: 12px; }

    /* 登录卡 */
    .login-card { padding: 22px; border-radius: 14px; }
    .login-card h1 { font-size: 18px; }

    /* pre 代码块横向滚 */
    pre { font-size: 11px !important; }
}

/* 超小屏（≤ 380px） */
@media (max-width: 380px) {
    .kpi-grid { grid-template-columns: 1fr !important; }
    .nav a { padding: 6px 10px; font-size: 12px; }
    .top-actions select { max-width: 110px; }
}
