:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #1a73e8;
  --accent-d: #1557b0;
  --danger: #d93025;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
code {
  background: #eef1f4; padding: 1px 5px; border-radius: 3px;
  font: 12px/1 ui-monospace, Consolas, monospace;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); padding: 36px 32px; border-radius: 10px;
  border: 1px solid var(--line); width: 320px; text-align: center;
  box-shadow: 0 2px 16px rgba(0, 0, 0, .06);
}
.login-box .logo { font-size: 22px; font-weight: 600; color: var(--accent); }
.login-box .sub { color: var(--muted); margin: 4px 0 22px; font-size: 13px; }
.login-box input { width: 100%; margin-bottom: 12px; }
.login-box button { width: 100%; }

.error { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 10px; }

/* ---------- 头部 ---------- */
header {
  display: flex; align-items: center; gap: 22px;
  padding: 0 20px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 600; color: var(--accent); font-size: 16px; }
nav { display: flex; gap: 2px; flex: 1; }
nav button {
  background: none; border: none; padding: 7px 14px; font-size: 14px;
  color: var(--muted); cursor: pointer; border-radius: 6px;
}
nav button:hover { background: #f0f2f5; color: var(--text); }
nav button.active { background: #e8f0fe; color: var(--accent); font-weight: 500; }

/* ---------- 工具条 ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; gap: 6px; align-items: center; }
.toolbar .group.right { margin-left: auto; }
.lbl { color: var(--muted); font-size: 13px; }
.tilde { color: var(--muted); }

input, select, button {
  font: inherit; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #cfe0fb; border-color: var(--accent); }
input[type=search] { min-width: 240px; }

button { cursor: pointer; }
button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
button.primary:hover { background: var(--accent-d); }
button.ghost { background: #fff; color: var(--text); }
button.ghost:hover { background: #f0f2f5; }
button.small { padding: 5px 10px; font-size: 13px; }

/* ---------- 主体 ---------- */
main { padding: 18px 20px 40px; }
.tab { display: none; }
.tab.active { display: block; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.panel h3 {
  margin: 0 0 12px; font-size: 14px; font-weight: 600;
  display: flex; align-items: baseline; gap: 8px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 统计卡 ---------- */
.cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px 20px; flex: 1; min-width: 160px;
}
.card .num { font-size: 26px; font-weight: 600; color: var(--accent); }
.card .key { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- 柱状图 ---------- */
.bars {
  display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px;
}
.bars .bar {
  flex: 1; background: var(--accent); border-radius: 2px 2px 0 0;
  min-height: 2px; position: relative;
}
.bars .bar:hover { background: var(--accent-d); }
.bars .bar span {
  position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--muted);
}
.bars-wrap { padding-bottom: 20px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
th {
  color: var(--muted); font-weight: 500; font-size: 12px;
  position: sticky; top: 0; background: var(--panel);
}
tbody tr:hover { background: #fafbfc; }
td.mono {
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- 分页 ---------- */
.pager {
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  padding-top: 12px; color: var(--muted); font-size: 13px;
}

/* ---------- 表单 ---------- */
.form-row {
  display: flex; gap: 10px; align-items: center; margin-bottom: 10px;
  flex-wrap: wrap;
}
.form-row label { width: 88px; color: var(--muted); font-size: 13px; flex: none; }
.form-row input, .form-row select { flex: 1; min-width: 200px; }

/* ---------- IP 相关 ---------- */
.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; text-decoration: underline dotted;
}
.link-btn:hover { color: var(--accent-d); }

.ip-badge {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  background: #e8f0fe; color: var(--accent); font-size: 12px; font-weight: 500;
  font-family: ui-monospace, Consolas, monospace;
}
.ip-badge.hot { background: #fde8e8; color: var(--danger); }
.ip-badge.zero { background: #f0f2f5; color: var(--muted); }

/* 时间线 */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.tl-item { position: relative; padding: 9px 0; }
.tl-item::before {
  content: ''; position: absolute; left: -20px; top: 15px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
  box-shadow: 0 0 0 2px var(--line);
}
.tl-item .tl-ip {
  font-family: ui-monospace, Consolas, monospace; font-weight: 600; font-size: 13px;
}
.tl-item .tl-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tl-head {
  display: flex; gap: 18px; flex-wrap: wrap;
  padding: 12px 14px; background: #f8f9fb;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px;
}
.tl-head div { font-size: 13px; }
.tl-head .k { color: var(--muted); font-size: 12px; }
.tl-head .v { font-weight: 600; font-size: 18px; color: var(--accent); }

/* 弹层 */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--panel); border-radius: 10px; width: 100%; max-width: 620px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .2);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); flex: none;
}
.modal-head h3 { margin: 0; font-size: 14px; }
#modal-body { padding: 16px 18px; overflow-y: auto; }

/* 勾选框跟着文字走，别被 input 样式撑开 */
label.lbl input[type=checkbox] { vertical-align: -1px; margin-right: 4px; }

/* ---------- 网段聚集 ---------- */
.seg-switch { display: flex; gap: 0; }
.seg-switch button {
  border-radius: 0; border-right-width: 0; background: #fff;
  color: var(--text); font-size: 13px; padding: 6px 16px;
}
.seg-switch button:first-child { border-radius: 6px 0 0 6px; }
.seg-switch button:last-child { border-radius: 0 6px 6px 0; border-right-width: 1px; }
.seg-switch button.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
  font-weight: 500;
}
.seg-switch button.active + button { border-left-color: var(--accent); }

/* 横向聚集条 */
.seg-bars { display: flex; flex-direction: column; gap: 7px; }
.seg-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.seg-row .seg-name {
  width: 120px; flex: none; font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; text-align: right; color: var(--text);
}
.seg-row .seg-track {
  flex: 1; height: 20px; background: #f0f2f5; border-radius: 4px;
  overflow: hidden; min-width: 60px;
}
.seg-row .seg-fill {
  height: 100%; background: var(--accent); border-radius: 4px;
  transition: width .25s ease;
}
.seg-row .seg-fill.hot { background: var(--danger); }
.seg-row .seg-val {
  width: 150px; flex: none; color: var(--muted); font-size: 12px;
}
.seg-row .seg-val b { color: var(--text); font-size: 13px; }

/* 段内 IP 展开 */
.ip-chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 520px; }
.ip-chip {
  font-family: ui-monospace, Consolas, monospace; font-size: 11px;
  padding: 1px 6px; border-radius: 4px; background: #f0f2f5; color: var(--muted);
  white-space: nowrap;
}
.ip-chip.multi { background: #fde8e8; color: var(--danger); font-weight: 500; }

details.seg-detail summary {
  cursor: pointer; color: var(--accent); font-size: 12px;
  list-style: none; user-select: none;
}
details.seg-detail summary::-webkit-details-marker { display: none; }
details.seg-detail summary::before { content: '▸ '; }
details.seg-detail[open] summary::before { content: '▾ '; }
details.seg-detail[open] .ip-chips { margin-top: 8px; }

/* 自动结论条 */
.verdict {
  border-radius: 10px; padding: 14px 16px; margin: 0 0 16px;
  border: 1px solid var(--line); background: var(--panel);
  border-left: 4px solid var(--muted);
}
.verdict.hot  { border-left-color: var(--danger); background: #fef6f5; }
.verdict.warn { border-left-color: #e8a33d;        background: #fffaf1; }
.verdict.ok   { border-left-color: #2e9e5b;        background: #f5fbf7; }
.verdict .vt { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.verdict.hot .vt { color: var(--danger); }
.verdict .vd { font-size: 13px; color: var(--muted); line-height: 1.7; margin-top: 6px; }
.verdict .vd b { color: var(--text); }

/* ================================================================
   地区分布页
   ================================================================ */

/* 卡片副标题 */
.card .card-sub { color: var(--muted); font-size: 11px; margin-top: 4px; opacity: .85; }

/* 地区名标签：带左侧色条，比纯文字更醒目 */
.rg-badge {
  display: inline-block; padding: 2px 10px 2px 8px;
  border-radius: 4px; font-weight: 600; font-size: 13px;
  background: linear-gradient(90deg, #e8f0fe 0%, #f3f7ff 100%);
  color: var(--accent-d);
  border-left: 3px solid var(--accent);
  white-space: nowrap;
}
/* 未解析地区：灰调，视觉上明确"这不是真实地区" */
.rg-badge.unknown { background: #f3f4f6; color: var(--muted); border-left-color: #9ca3af; }

/* 归属地徽标（IP 列表用） */
.loc-badge {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  background: #eef6ff; color: #1a5fb4; font-size: 12px;
  white-space: nowrap; border: 1px solid #d5e6fb;
}
.pending-badge {
  padding: 1px 8px; border-radius: 4px; background: #f5f5f5;
  font-size: 12px; border: 1px dashed #d0d0d0; cursor: help;
}

/* 运营商列：长名字截断，hover 看全称 */
.isp-cell {
  display: inline-block; max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: bottom;
}

/* 排行条的地区名列（宽度按中文调整） */
.seg-row .seg-name.rg-name {
  width: 110px; text-align: left; padding-right: 8px;
  font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg-row .seg-name.rg-name.cold { color: var(--muted); font-weight: 400; }
.seg-row .seg-fill.cold { background: #c9cdd4; }

/* 未解析的告警条 */
.verdict .geo-warn {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line);
  color: #b06d00;
}

/* ---------------------------------------------------------------- 归属地补全进度 */

.geo-prog {
  margin-top: 14px; padding: 12px 14px;
  background: #fbfcfe; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 8px;
}
.geo-prog.off {
  margin-top: 14px; padding: 10px 14px; border-radius: 8px;
  background: #f7f7f7; border: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.geo-prog .gp-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 8px; flex-wrap: wrap;
}
.geo-prog .gp-title { font-weight: 600; font-size: 13px; color: var(--text); }
.geo-prog .gp-stat { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.geo-prog .gp-track {
  height: 6px; background: #e9edf3; border-radius: 3px; overflow: hidden;
}
.geo-prog .gp-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, #4d9bf0 100%);
  transition: width .4s ease;
}
.geo-prog .gp-note {
  margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.7;
}
.geo-prog .gp-note b { color: #b06d00; }
.geo-prog .gp-note button { margin-left: 6px; }

/* 加载动画：进度条跑马灯，提示"后台正在干活" */
.geo-prog .gp-fill.active {
  background-size: 24px 24px;
  background-image: linear-gradient(45deg,
    rgba(255,255,255,.25) 25%, transparent 25%,
    transparent 50%, rgba(255,255,255,.25) 50%,
    rgba(255,255,255,.25) 75%, transparent 75%, transparent);
  animation: gp-stripe .8s linear infinite;
}
@keyframes gp-stripe {
  from { background-position: 0 0; }
  to   { background-position: 24px 0; }
}
