/* ============ 流量统计后台样式 ============ */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-weak: rgba(79, 70, 229, .09);
  --cyan: #0891b2;
  --green: #059669;
  --red: #dc2626;
  --amber: #d97706;
  --sidebar: #0f172a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---- 布局 ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: none;
  background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 20px 18px; font-size: 17px; font-weight: 700; color: #fff;
  letter-spacing: .5px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: #94a3b8; font-size: 14px;
}
.nav a:hover { color: #e2e8f0; background: rgba(255,255,255,.06); }
.nav a.active { color: #fff; background: var(--primary); }
.sidebar-foot { padding: 14px 18px; font-size: 12px; color: #475569; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot a { color: #94a3b8; }

.main { flex: 1; padding: 26px 30px 60px; max-width: 1400px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ---- 卡片 ---- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-title-row h2 { margin: 0; }

.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.metric-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px;
}
.metric-card .k { color: var(--muted); font-size: 12.5px; }
.metric-card .v { font-size: 25px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric-card .d { font-size: 12px; margin-top: 2px; color: var(--muted); }

.delta-up { color: var(--green); }
.delta-down { color: var(--red); }
.delta-flat { color: var(--muted); }

/* ---- 总览站点卡片 ---- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.site-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.site-card .head { display: flex; align-items: baseline; gap: 8px; }
.site-card .name { font-size: 15.5px; font-weight: 600; }
.site-card .domain { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-card .nums { display: flex; gap: 22px; margin: 12px 0 6px; }
.site-card .nums .n b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.site-card .nums .n span { color: var(--muted); font-size: 12px; }
.site-card .foot { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.spark-wrap { height: 44px; margin-top: 6px; }
.spark-wrap canvas { width: 100% !important; height: 44px !important; }

.live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--green); font-weight: 600;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); display: inline-block;
  animation: pulse 1.6s ease infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, .45); }
  50% { box-shadow: 0 0 0 5px rgba(5, 150, 105, 0); }
}
.badge-off { color: var(--muted); font-size: 12px; }

/* ---- 表格 ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .ellip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar { position: relative; height: 17px; min-width: 90px; }
.bar i {
  position: absolute; inset: 2px auto 2px 0;
  background: var(--primary-weak); border-radius: 4px;
}
.bar span { position: relative; z-index: 1; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---- 徽标 ---- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.badge-direct { background: #f1f5f9; color: #475569; }
.badge-search { background: #dbeafe; color: #1d4ed8; }
.badge-social { background: #fce7f3; color: #be185d; }
.badge-referral { background: #fef3c7; color: #b45309; }
.badge-on { background: #d1fae5; color: #047857; }
.badge-paused { background: #f1f5f9; color: #64748b; }

/* ---- 按钮 / 表单 ---- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; font-size: 13.5px;
  background: var(--primary); color: #fff; line-height: 1.4;
}
.btn:hover { background: var(--primary-dark); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { border-color: #cbd5e1; background: #f8fafc; color: var(--text); }
.btn.danger { background: #fee2e2; color: var(--red); }
.btn.danger:hover { background: #fecaca; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary-weak); border-color: var(--primary); }
.form-narrow { max-width: 420px; }

/* ---- 提示条 ---- */
.flash { padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 13.5px; }
.flash-ok { background: #d1fae5; color: #065f46; }
.flash-err { background: #fee2e2; color: #991b1b; }

/* ---- 详情页 ---- */
.range-tabs { display: inline-flex; background: #e2e8f0; border-radius: 9px; padding: 3px; gap: 2px; }
.range-tabs a { padding: 5px 13px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.range-tabs a.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.custom-range-form { display: inline-flex; gap: 6px; align-items: center; }
.custom-range-form input[type=date] {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px;
}

.chart-card { height: 320px; position: relative; }
.chart-card canvas { width: 100% !important; height: 300px !important; }

.tops-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.top-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.top-card h3 { font-size: 13.5px; margin: 0 0 8px; color: var(--text); }
.top-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: var(--muted); }
.pager a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 7px; }
.pager a.disabled { opacity: .4; pointer-events: none; }

details.embed { margin-top: 8px; }
details.embed summary { cursor: pointer; color: var(--primary); font-size: 13px; user-select: none; }
.codebox {
  position: relative; background: #0f172a; color: #e2e8f0;
  border-radius: 9px; padding: 12px 90px 12px 14px; margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; word-break: break-all; white-space: pre-wrap;
}
.codebox .copy-btn { position: absolute; right: 8px; top: 8px; }
.copy-btn {
  background: rgba(255,255,255,.12); color: #e2e8f0; border: 0;
  padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.copy-btn:hover { background: rgba(255,255,255,.22); }
td .code-key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: #f1f5f9; padding: 2px 7px; border-radius: 6px; }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 380px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 30px 30px 26px; }
.auth-card .logo { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.auth-card .hint { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.error-box { background: #fee2e2; color: #991b1b; padding: 9px 13px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .big { font-size: 34px; margin-bottom: 8px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .brand { border: 0; padding: 12px 16px; }
  .nav { flex-direction: row; padding: 8px; overflow-x: auto; }
  .sidebar-foot { display: none; }
  .main { padding: 18px 14px 50px; }
}
