:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e8ec;
  --text: #1f2933;
  --muted: #8a94a6;
  --accent: #2563eb;
  --up: #dc2626;   /* 涨 = 红（国内习惯） */
  --down: #16a34a; /* 跌 = 绿 */
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }
.error { color: #dc2626; font-size: 12px; }
.muted { color: var(--muted); }

/* 登录 */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 320px;
  text-align: center;
}
.login-box h1 { font-size: 28px; margin-bottom: 4px; }
.login-box p { color: var(--muted); margin-bottom: 20px; }
.login-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}
.login-box button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}

/* 顶栏 */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.brand .sub { font-size: 12px; color: var(--muted); font-weight: 400; }

/* 品牌图标：与 public/icon.svg 同一造型，内联版用纯色（不依赖渐变 defs，避免同页 id 冲突） */
.mark { width: 22px; height: 22px; flex: none; display: block; }
.mark-lg { width: 48px; height: 48px; margin: 0 auto 14px; }
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#site-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-size: 13px;
}
.periods { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.periods button {
  padding: 7px 14px;
  border: none;
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.periods button + button { border-left: 1px solid var(--border); }
.periods button.active { background: var(--accent); color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 30px; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat-delta { font-size: 12px; color: var(--muted); }
.stat-delta.up { color: var(--up); }
.stat-delta.down { color: var(--down); }

.chart-card { margin-top: 16px; }
.chart-card h2 { font-size: 15px; margin-bottom: 14px; }

/* TopN 网格 */
.grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.grid h2 { font-size: 15px; margin-bottom: 12px; }
.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.metric-row:first-of-type { border-top: none; }
.metric-key {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 65%;
}
.metric-nums { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric-empty { color: var(--muted); padding: 12px 0; }

/* TopN 占比条 */
.bar { height: 3px; background: #eef1f5; border-radius: 2px; overflow: hidden; margin-bottom: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); opacity: .55; }

/* 总览：各站点并排看（首页）—— 单行紧凑列表 */
.ov-card { margin-top: 16px; }
.ov-card h2 { font-size: 15px; margin-bottom: 2px; }
.ov-card h2 .hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.ov-list { display: flex; flex-direction: column; }

/* 表头与数据行共用同一套栅格，保证 PV/UV 数字列严格对齐 */
.ov-head,
.ov-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px 54px 54px 18px;
  align-items: center;
  gap: 14px;
}
.ov-head {
  padding: 4px 8px 6px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.ov-head .ov-h-num { text-align: right; }

.ov-row {
  padding: 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
}
.ov-row:last-child { border-bottom: none; }
.ov-row:hover { background: #f7f8fa; }
.ov-row:hover .ov-go { color: var(--accent); }

/* 站名 + 域名 挤在同一行 */
.ov-main { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.ov-name { font-size: 14px; font-weight: 600; flex: none; max-width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-bar { height: 4px; margin-bottom: 0; }
.ov-num { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.ov-num.zero { color: var(--muted); font-weight: 400; }
.ov-go { font-size: 14px; color: var(--muted); text-align: right; }

/* 演示模式提示条 */
.demo-banner {
  background: #fff7e6;
  border-bottom: 1px solid #f5d9a0;
  color: #8a6100;
  padding: 8px 24px;
  font-size: 13px;
  text-align: center;
}
.demo-banner code { background: #f7e7c6; padding: 1px 5px; border-radius: 3px; }

/* 表格 */
.table-card { margin-top: 16px; }
.table-card h2 { font-size: 15px; margin-bottom: 12px; }
.table-card h2 .hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 8px 10px; border-bottom: 1px solid #f0f2f5; }
td.nowrap { white-space: nowrap; color: var(--muted); }
.path-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.path-host { display: block; font-size: 11px; color: var(--muted); }
tbody tr:hover { background: #fafbfc; }

.more-btn {
  margin-top: 12px;
  padding: 8px 18px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.more-btn:hover { background: #f7f8fa; }

.refresh-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.refresh-btn:hover { background: #f7f8fa; }
.refresh-btn:disabled { opacity: .45; cursor: default; }
.refresh-btn:disabled:hover { background: var(--card); }

/* 空状态提示 */
.empty-hint { margin-bottom: 16px; }
.empty-hint strong { display: block; font-size: 15px; margin-bottom: 6px; }
.empty-hint p { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

/* 站点管理弹窗 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-box {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 680px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(15, 23, 42, .18);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; }
.icon-btn {
  border: none; background: transparent; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}
.icon-btn:hover { color: var(--text); }
.modal-body { padding: 18px 20px 20px; overflow-y: auto; }

.add-form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-form input {
  flex: 1 1 150px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.primary-btn {
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:disabled { opacity: .6; cursor: default; }
.form-msg { font-size: 12px; margin: 8px 0 0; min-height: 16px; color: var(--muted); }
.form-msg.error { color: #dc2626; }
.form-msg.ok { color: #16a34a; }

.sub-title { font-size: 13px; color: var(--muted); font-weight: 500; margin: 18px 0 8px; }
.site-list { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.site-row { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.site-row:last-child { border-bottom: none; }
.site-row.flash { background: #eef4ff; }
.site-row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.site-name { font-size: 14px; font-weight: 600; }
.site-meta { font-size: 12px; color: var(--muted); margin-top: 3px; word-break: break-all; }
.site-actions { display: flex; gap: 8px; }
.mini-btn {
  padding: 5px 11px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.mini-btn:hover { background: #f7f8fa; }
.mini-btn.danger { color: #dc2626; border-color: #f0c9c9; }
.mini-btn.danger:hover { background: #fdeeee; }
.site-edit { display: flex; gap: 8px; flex: 1 1 240px; flex-wrap: wrap; }
.site-edit input {
  flex: 1 1 130px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.site-row.editing { background: #fafbfd; }
.site-snippet {
  margin-top: 9px;
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-all;
  cursor: pointer;
}
.site-snippet:hover { background: #eef1f5; }
.tip {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}
.tip p { margin-bottom: 5px; }
.tip code {
  background: #eef1f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: #334155;
}
.tip strong { color: var(--text); }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .container { padding: 16px 12px 40px; }
  .modal-box { max-height: 92vh; }
  .ov-head,
  .ov-row { grid-template-columns: minmax(0, 1fr) 40px 40px 14px; gap: 10px; }
  .ov-head .ov-h-bar,
  .ov-bar { display: none; }   /* 窄屏省掉进度条，先保住站名和数字 */
  .ov-meta { display: none; }
  .ov-row { padding: 9px 6px; margin: 0 -6px; }
  .ov-name { max-width: 100%; }
  .ov-num { font-size: 14px; }
}
