:root {
  --primary: #3b6ef6;
  --primary-dark: #2b56c8;
  --primary-light: #eef3ff;
  --primary-2: #6a8dff;
  --green: #25b865;
  --green-light: #e8f7ef;
  --red: #ef4d5a;
  --red-light: #fdecee;
  --orange: #f5a623;
  --orange-light: #fdf3e3;
  --gray: #7a869a;
  --text: #1f2733;
  --text-2: #5b6675;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e7ebf2;
  --sidebar-bg: #171d2b;
  --sidebar-text: #9aa6bd;
  --sidebar-active: var(--primary);
  --radius: 12px;
  --shadow: 0 1px 3px rgba(23,29,43,.06), 0 6px 18px rgba(23,29,43,.05);
  --shadow-lg: 0 10px 40px rgba(23,29,43,.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}

#app { display: flex; min-height: 100vh; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.logo-title { color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.logo-sub { font-size: 11px; color: #6b7890; margin-top: -2px; }

nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-group { margin: 8px 0; }
.nav-group-title {
  font-size: 11px; color: #56617a; text-transform: uppercase;
  padding: 8px 20px 4px; letter-spacing: 1px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; margin: 1px 10px;
  color: var(--sidebar-text); cursor: pointer; border-radius: 8px;
  font-size: 14px; transition: all .15s; text-decoration: none;
  position: relative;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-item.active { color: #fff; background: var(--sidebar-active); }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-item .badge {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 10px; border-radius: 8px; padding: 1px 6px; display: none;
}
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #b6c0d4; }
.user-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.btn-ghost {
  background: transparent; border: 1px solid #39435c; color: #b6c0d4;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; margin-top: 8px; width: 100%;
}
.btn-ghost:hover { color: #fff; border-color: #5a6b8a; }

/* ===== 主区 ===== */
.main { flex: 1; margin-left: 232px; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px 14px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar p { color: var(--gray); font-size: 13px; margin-top: 1px; }
.topbar-right { display: flex; gap: 10px; align-items: center; }

.content { padding: 24px 28px 40px; max-width: 1320px; width: 100%; }

/* ===== 卡片 ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card .label { color: var(--gray); font-size: 13px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; color: var(--text); }
.card .value.small { font-size: 20px; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.card .value.blue { color: var(--primary); }
.card .value.orange { color: var(--orange); }
.card-link { display: block; text-decoration: none; color: var(--primary); }

/* ===== 面板 ===== */
.panel {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { font-size: 16px; font-weight: 700; }
.panel-head .muted { color: var(--gray); font-size: 12px; }

/* ===== 工具栏 ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.spacer { flex: 1; }

/* ===== 表格 ===== */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; color: var(--gray); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tr:hover td { background: #fafbfd; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.muted { color: var(--gray); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); cursor: pointer; font-size: 13.5px;
  transition: all .15s; text-decoration: none; font-weight: 500;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: var(--red-light); color: var(--red); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ===== 标签 ===== */
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag.ok { background: var(--green-light); color: var(--green); }
.tag.fail { background: var(--red-light); color: var(--red); }
.tag.wait { background: var(--orange-light); color: var(--orange); }
.tag.off { background: #eef0f4; color: var(--gray); }
.tag.blue { background: var(--primary-light); color: var(--primary); }

/* ===== 表单 ===== */
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff;
  width: 100%; outline: none; transition: border .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { font-size: 13px; color: var(--text-2); display: block; margin-bottom: 5px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-item { margin-bottom: 2px; }

/* ===== 标签页 ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 16px; cursor: pointer; color: var(--gray); border-bottom: 2px solid transparent;
  font-size: 14px; background: none; border-top: none; border-left: none; border-right: none;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .badge { background: var(--primary-light); color: var(--primary); border-radius: 10px; padding: 1px 7px; font-size: 12px; margin-left: 4px; }

/* ===== 进度条 ===== */
.progress { height: 8px; background: #eef1f7; border-radius: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 10px; transition: width .4s; width: 0; }

/* ===== 分页 ===== */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.pager .info { color: var(--gray); font-size: 13px; }

/* ===== Toast ===== */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 10px; color: #fff; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: slideIn .25s; max-width: 380px;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ===== 模态框 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 500;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 640px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.modal-close { cursor: pointer; font-size: 22px; color: var(--gray); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== 富文本编辑器 ===== */
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: #f7f9fc;
  border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0;
}
.editor-toolbar button {
  min-width: 30px; height: 30px; border: 1px solid transparent; background: transparent;
  border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text-2);
}
.editor-toolbar button:hover { background: #eef1f7; color: var(--text); }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 4px 6px; }
.editor-body {
  min-height: 280px; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 8px 8px; padding: 14px; outline: none; background: #fff; overflow-y: auto;
}
.code-editor {
  width: 100%; min-height: 300px; font-family: Consolas, monospace; font-size: 12.5px;
  padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: #1e2430; color: #d6deeb;
}

/* ===== 变量芯片 ===== */
.var-chip {
  display: inline-block; padding: 3px 10px; background: var(--primary-light); color: var(--primary);
  border-radius: 6px; cursor: pointer; font-size: 12px; margin: 2px 4px 2px 0; font-family: Consolas, monospace;
}
.var-chip:hover { background: var(--primary); color: #fff; }
.group-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; background: #f2f4f8;
  border-radius: 16px; cursor: pointer; font-size: 13px; margin: 3px 4px 3px 0;
}
.group-chip.active { background: var(--primary); color: #fff; }
.group-chip b { font-weight: 600; }

/* ===== 图表 ===== */
.chart-box { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-cell { background: #fafbfd; border-radius: 10px; padding: 16px; text-align: center; }
.chart-cell h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-2); }
@media (max-width: 900px) { .chart-box { grid-template-columns: 1fr; } .form-grid { grid-template-columns: 1fr; } }

/* ===== 统计卡片行 ===== */
.stats-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats-cards .card { padding: 16px; }
.stats-cards .num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stats-cards .lbl { font-size: 12px; color: var(--gray); margin-top: 2px; }

/* 告警横幅 */
.alert-banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--orange-light);
  border-left: 4px solid var(--orange); border-radius: 8px; margin-bottom: 16px;
}
.alert-banner .ab-icon { font-size: 20px; }
.alert-banner .ab-text { flex: 1; font-size: 13.5px; }
.alert-banner .ab-link { color: var(--primary); margin-left: 8px; }
.alert-banner .ab-close { cursor: pointer; color: var(--gray); }

/* AI 生成卡片 */
.ai-group { margin-bottom: 16px; }
.ai-group-head { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; }
.ai-list { display: flex; flex-direction: column; gap: 8px; }
.ai-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: #f8fafc; border-radius: 8px; }
.ai-item textarea { min-height: 56px; font-size: 13px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kv-grid > div { background: #f8fafc; padding: 12px; border-radius: 8px; }
.kv-grid b { display: block; margin-bottom: 4px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-row input { width: auto; }
.hint { font-size: 12px; color: var(--gray); margin-top: 4px; }
.detail-head { display: flex; flex-wrap: wrap; gap: 14px; padding: 12px; background: #f8fafc; border-radius: 8px; margin-bottom: 14px; }
.detail-head b { color: var(--text); }

/* ===== 长耗时任务的「忙碌」遮罩 =====
   导入、批量测试、读取退信这类操作在后端是**跑完才返回**的，可能几十秒到几分钟。
   旧版点完按钮界面上一点变化都没有，用户分不清是在跑还是卡死了，
   于是反复点击（导致重复导入）或直接关页面。这里解决三件事：
     ① 立刻转圈 + 会跳动的「已用 N 秒」，证明进程还活着；
     ② 盖住整屏，挡住重复点击；
     ③ 上传/检测阶段能给出进度条，让等待有预期。 */
.busy-mask {
  position: fixed; inset: 0; background: rgba(15,20,30,.5); z-index: 900;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.busy-mask.show { display: flex; }
.busy-box {
  background: #fff; border-radius: 14px; padding: 26px 30px;
  width: 100%; max-width: 380px; text-align: center; box-shadow: var(--shadow-lg);
  animation: busyIn .18s ease-out;
}
@keyframes busyIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.busy-spin {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid #e3e9f5; border-top-color: var(--primary); border-radius: 50%;
  animation: busySpin .8s linear infinite;
}
@keyframes busySpin { to { transform: rotate(360deg); } }
.busy-title { font-size: 15px; font-weight: 700; color: var(--text); }
.busy-sub { font-size: 13px; color: var(--gray); margin-top: 6px; line-height: 1.6; word-break: break-all; }
.busy-elapsed { font-size: 12px; color: var(--gray); margin-top: 10px; font-variant-numeric: tabular-nums; }
.busy-box .progress { margin-top: 14px; }
.busy-tip { font-size: 12px; color: var(--gray); margin-top: 12px; line-height: 1.6; text-align: left; }

/* ===== 导入/任务结果统计卡片 ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.stat-grid > div { background: #f8fafc; border-radius: 8px; padding: 12px 8px; text-align: center; }
.stat-grid b { display: block; font-size: 20px; line-height: 1.35; color: var(--text); }
.stat-grid span { font-size: 12px; color: var(--gray); }
.stat-grid .s-ok b { color: var(--green); }
.stat-grid .s-warn b { color: var(--orange); }
.stat-grid .s-err b { color: var(--red); }
