/* ==========================================================================
   代理线数据后台 · 样式表（无外部依赖）
   ========================================================================== */
:root {
  --sidebar: #16203a;
  --sidebar-2: #1f2b4d;
  --primary: #3b6bf5;
  --primary-dark: #2c55d0;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #7a849b;
  --line: #e5e9f2;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 35, 66, .06), 0 8px 24px rgba(23, 35, 66, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB",
               system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 布局 */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: linear-gradient(180deg, var(--sidebar), #131b31);
  color: #c9d3ea;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  color: #fff; font-weight: 700; font-size: 15px;
}
.brand-mark.big { width: 46px; height: 46px; border-radius: 13px; font-size: 22px; }
.brand-text { font-weight: 600; font-size: 15px; color: #fff; letter-spacing: .3px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 9px;
  color: #b8c4de; font-size: 13.5px; text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-ico { width: 16px; text-align: center; opacity: .9; }

/* ---------------------------------------------------------------- 代理线三级树 */
.tree { margin: 6px 0 8px; }
.tree-root {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px; border-radius: 9px;
  color: #dbe3f4; font-size: 13.5px; font-weight: 600;
  background: rgba(255, 255, 255, .06);
}
.tree-root .tree-count { margin-left: auto; }
.tree-caret { font-size: 10px; opacity: .75; width: 10px; }
.tree-body {
  margin: 4px 0 0 8px; padding-left: 8px;
  border-left: 1px solid rgba(255, 255, 255, .1);
}
.tree-node { margin-top: 2px; }
.tree-link {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 9px; border-radius: 8px;
  color: #b8c4de; font-size: 13px; text-decoration: none;
}
.tree-link:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.tree-link.active { background: var(--primary); color: #fff; font-weight: 600; }
.tree-link.root { color: #93a1c0; font-size: 12.5px; }
.tree-link.lv1 { font-weight: 600; color: #cfd8ec; }
.tree-link.lv2 { margin-left: 10px; color: #b8c4de; }
.tree-link.lv3 { margin-left: 22px; font-size: 12.5px; padding: 5px 9px; }
/* 分类标题（不可点，只做层级展示；选站点在右上角） */
.tree-cat {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 9px 6px 19px; margin-left: 10px;
  color: #aab6d2; font-size: 12.5px;
}
.tree-cat.active { color: #fff; font-weight: 600; }
.tree-cat .tree-caret { opacity: .5; }
.tree-cat.lv3 { padding-left: 28px; margin-left: 10px; font-size: 12px; }
.tree-count {
  margin-left: auto; font-size: 11px; font-weight: 500;
  background: rgba(255, 255, 255, .1); color: #cfd8ec;
  border-radius: 999px; padding: 0 7px; line-height: 17px;
}
.tree-link.active .tree-count { background: rgba(255, 255, 255, .25); color: #fff; }
.tree-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: .5; flex: 0 0 5px;
}
.tree-link.active .tree-dot { opacity: 1; }
.tree-empty { padding: 6px 10px; color: #8b98b8; font-size: 12.5px; }

/* 顶部站点选择器 */
.site-picker {
  display: flex; align-items: center; gap: 7px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 8px 4px 12px;
  box-shadow: var(--shadow);
}
.site-picker-label { color: var(--muted); font-size: 12.5px; }
.site-picker select {
  border: none; background: transparent; font-size: 14px; font-weight: 600;
  color: var(--text); padding: 4px 2px; cursor: pointer;
}
.site-picker select:focus { box-shadow: none; outline: none; }
.badge-site { background: #eef2fd; border-color: #d5dffb; color: #2f4fb8; font-weight: 600; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.who { padding: 0 6px 10px; }
.who-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.who-role { color: #8b98b8; font-size: 12px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 30px; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { margin: 0; font-size: 21px; font-weight: 700; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------------------------------------------------------------- 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }

.cards {
  display: grid; gap: 14px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.stat { padding: 15px 17px; margin: 0; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 25px; font-weight: 700; letter-spacing: -.5px; margin: 3px 0 1px; }
.stat-foot { color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- 表单 */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; }
.filter-custom { display: flex; align-items: center; gap: 8px; }
.filter-right { margin-left: auto; }
.dash { color: var(--muted); }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-block; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: #48536b;
  font-size: 13px; cursor: pointer; text-decoration: none;
}
.pill:hover { border-color: #c3cee6; text-decoration: none; }
.pill.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pills.small .pill { padding: 3px 10px; font-size: 12.5px; }

input[type=text], input[type=password], input[type=date], select, textarea {
  padding: 7px 10px; border: 1px solid #d7dded; border-radius: 8px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,107,245,.13);
}
textarea { resize: vertical; min-height: 34px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field > span { font-size: 13px; color: #46506a; font-weight: 600; }
.field .hint-inline { font-size: 12px; color: var(--muted); font-weight: 400; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; margin-bottom: 14px; }

.grid-2 { display: grid; gap: 0 18px; grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px; border: 1px solid #d7dded;
  background: #fff; color: #38425c; font-size: 13.5px; font-family: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f7f9fe; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #f3c4c4; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.22); color: #d7e0f5; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-reset { display: flex; gap: 4px; align-items: center; }
.inline-reset input[type=password] { width: 96px; padding: 4px 8px; font-size: 12.5px; }

/* ---------------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td {
  padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left;
  vertical-align: middle;
}
.table thead th {
  background: #f8fafd; color: #5b6478;
  font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.table thead th a { color: #5b6478; }
.table tbody tr:hover { background: #fafbff; }
.table tfoot td { background: #f8fafd; font-weight: 600; border-top: 1px solid var(--line); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .strong { font-weight: 700; }
.th-sub { font-weight: 400; font-size: 11px; color: #98a1b5; }
.center { text-align: center; }

.line-name { font-weight: 600; }
.line-code { color: var(--muted); font-size: 12px; }
.rate { font-weight: 600; }
.rate-sub { color: var(--muted); font-size: 11.5px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: #eef2fd; color: #3355c4; font-size: 12px;
}
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: #fff; color: #48536b;
}
.badge-ok { background: #effaf3; border-color: #cbf0d9; color: #15803d; }
.badge-warn { background: #fff8ec; border-color: #f7e0b8; color: #b45309; }
.badge-danger { background: #fef2f2; border-color: #f6cfcf; color: #b91c1c; }
.badge-off { background: #f4f5f8; border-color: #e3e6ee; color: #6b7280; }

/* ---------------------------------------------------------------- 提示 */
.flashes { margin-bottom: 14px; }
.flash {
  padding: 9px 13px; border-radius: 9px; font-size: 13.5px;
  margin-bottom: 8px; border: 1px solid transparent;
}
.flash-ok { background: #effaf3; border-color: #cbf0d9; color: #166534; }
.flash-error { background: #fef2f2; border-color: #f6cfcf; color: #b91c1c; }
.flash-warn { background: #fff8ec; border-color: #f7e0b8; color: #b45309; }
.flash-info { background: #eff5ff; border-color: #cfe0ff; color: #1d4ed8; }

.muted { color: var(--muted); }
.text-ok { color: var(--ok); }
.text-danger { color: var(--danger); }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

/* 总代 / 代理线 下拉：放在筛选条里，跟日期控件同一行 */
.inline-field { display: inline-flex; align-items: center; gap: 6px; }
.inline-field > span { font-size: 13px; color: #46506a; font-weight: 600; white-space: nowrap; }
.inline-field select,
.inline-field input[type="text"] {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
  max-width: 260px;
}
.inline-field input[type="text"] { min-width: 190px; }
.inline-field input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 107, 245, .12);
}
/* 模糊匹配的提示（比如「输入『小』已匹配到总代『小高』」） */
.match-note {
  flex-basis: 100%;
  font-size: 12.5px;
  color: #7a5b12;
  background: #fff8e6;
  border: 1px solid #f2e0ab;
  border-radius: 7px;
  padding: 6px 10px;
  margin-top: 2px;
}

/* 有数据的代理线：仪表盘卡片 */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.tile {
  display: block;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.tile:hover {
  border-color: var(--primary);
  box-shadow: 0 3px 12px rgba(37, 99, 235, .12);
  transform: translateY(-1px);
  text-decoration: none;
}
.tile-name {
  font-size: 13.5px;
  font-weight: 600;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}
.tile-metric { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tile-k { font-size: 10.5px; color: var(--muted); }
.tile-v {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.code {
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 12.5px;
  overflow-x: auto;
  margin: 8px 0;
}
.empty { text-align: center; padding: 40px 20px; }
.empty h3 { margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0; color: var(--muted); }
.footer { margin-top: 22px; color: #9aa3b8; font-size: 12px; text-align: center; }

/* 还没选分类时的提示（站点下拉只在选中二级分类后出现） */
.picker-hint {
  font-size: 12.5px;
  color: var(--muted);
  background: #f4f6fb;
  border: 1px dashed var(--line);
  border-radius: 7px;
  padding: 7px 11px;
}

/* 代理线列表：精简、清晰，深浅双色隔行 */
.tile-table { min-width: 1020px; font-size: 12.5px; }
.tile-table th,
.tile-table td {
  white-space: nowrap;
  padding: 7px 10px;
  vertical-align: middle;
}
.tile-table th {
  font-size: 12px;
  font-weight: 600;
  color: #4a5470;
  background: #eef2f9;          /* 表头：深一档 */
  border-bottom: 1px solid var(--line);
}
/* 隔行深浅交替，长表格看得不串行 */
.tile-table tbody tr:nth-child(odd) { background: #fff; }
.tile-table tbody tr:nth-child(even) { background: #f6f8fc; }
.tile-table tbody tr:hover { background: #eaf0fd; }
.tile-table tbody tr { cursor: default; }
.tile-table td.strong { font-weight: 600; color: #1f2937; }
.tile-table tfoot td {
  background: #eef2f9;          /* 合计行也用深色，和表头呼应 */
  font-weight: 600;
  border-top: 1px solid var(--line);
}
.tile-table .col-name { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.tile-table .num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* 创建代理线表单 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 4px 18px;
}
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.check-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 7px; border-radius: 6px; cursor: pointer;
}
.check-row:hover { background: #eef2f9; }
.check-row input { margin: 0; }
.tag-ok { background: #e8f7ee; border-color: #b7e2c8; color: #14713c; }
.rule-box { margin-top: 6px; background: #f8fafd; }
.rule-box h3 { margin: 0 0 8px; font-size: 14px; }
.rule-list { display: flex; flex-wrap: wrap; gap: 7px; }

/* 创建代理线：首次读取后台选项要 20 多秒，用遮罩给出明确的「在跑」反馈 */
.page-loading {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(248, 250, 253, .82);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(1px);
}
.page-loading-box {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 28px; text-align: center; font-size: 14px;
  box-shadow: 0 8px 28px rgba(31, 41, 55, .12);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.page-loading-box .muted { font-size: 12.5px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid #dbe3f4; border-top-color: var(--primary);
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 渠道链接 + 一键复制 */
.link-row { display: flex; align-items: center; gap: 8px; }
.link-text {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
  color: var(--primary);
  word-break: break-all;
}
.copy-btn { flex: 0 0 auto; }
.copy-ok { background: #e8f7ee !important; border-color: #b7e2c8 !important; color: #14713c !important; }
.copy-fail { background: #fdecec !important; border-color: #f3c4c4 !important; color: var(--danger) !important; }

/* 提交中：用 pointer-events 阻止重复点击，**不能**用 disabled（会取消表单提交） */
.is-busy {
  pointer-events: none;
  opacity: .72;
  cursor: progress;
}

/* 列表上方的搜索框 */
.list-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}
.list-search input[type="search"] {
  width: 280px;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
}
.list-search input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 107, 245, .12);
}
.list-search .count { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------- 图表 */
.chart { width: 100%; min-height: 260px; }

/* ---------------------------------------------------------------- 登录页 */
.anon { background: linear-gradient(160deg, #17203a 0%, #26325a 60%, #3454c9 130%); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 384px; padding: 28px 26px; }
.login-head { text-align: center; margin-bottom: 18px; }
.login-head h1 { margin: 12px 0 4px; font-size: 19px; }
.login-head p { margin: 0; color: var(--muted); font-size: 13px; }
.login-tip { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- 代理线勾选 */
.line-picker {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  max-height: 320px; overflow: auto; background: #fbfcfe;
}
.line-picker.disabled { opacity: .5; }
.picker-group {
  font-size: 12px; font-weight: 700; color: #5b6478;
  margin: 8px 0 3px; padding-top: 6px; border-top: 1px dashed var(--line);
}
.picker-group:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.line-option {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 8px; font-size: 13.5px;
}
.line-option.lv2 { margin-left: 14px; }
.line-option.lv3 { margin-left: 28px; }
.line-option:hover { background: #f1f5ff; }
.line-option .code { color: var(--muted); font-size: 12px; }
.line-option .channel { margin-left: auto; color: #3355c4; font-size: 12px; }
.picker-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.picker-tools input[type=text] { flex: 1; min-width: 140px; }
