:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --sidebar: #111a2e;
  --sidebar-soft: #1b2743;
  --accent: #3b6cf6;
  --accent-soft: #e8efff;
  --text: #1c2436;
  --muted: #6b7688;
  --border: #e3e7ef;
  --success: #17925a;
  --success-soft: #e6f6ee;
  --warn: #c2740b;
  --warn-soft: #fdf3e2;
  --danger: #d0453c;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }

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

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--sidebar);
  color: #cfd7e6;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { font-size: 15px; font-weight: 700; color: #fff; padding: 4px 10px 14px; letter-spacing: .5px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #7f8bab; margin-top: 2px; letter-spacing: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: #c3ccdd;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--sidebar-soft); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }

.sidebar-foot { border-top: 1px solid #263149; padding-top: 12px; font-size: 12px; color: #8d99b4; }
.sidebar-foot .btn { width: 100%; margin-top: 8px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(23, 34, 59, .04);
}
.card h2 { font-size: 14.5px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- 指标卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 21px; font-weight: 650; margin-top: 4px; letter-spacing: -.3px; }
.stat .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.accent .value { color: var(--accent); }
.stat.ok .value { color: var(--success); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--danger); }

/* ---------- 表单 ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: #45536b; margin-bottom: 5px; font-weight: 500; }
label.field > span em { font-style: normal; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 10px; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }
.inline-note { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2f5ee0; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.danger { color: var(--danger); border-color: #f2cfcd; }
.btn.danger:hover { background: var(--danger-soft); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfe; white-space: nowrap; }
tbody tr:hover { background: #f9fbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 26px 0; font-size: 13px; }

/* ---------- 徽标 ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.success, .badge.duplicate, .badge.dry_run { background: var(--success-soft); color: var(--success); }
.badge.api_failed, .badge.invalid_sign, .badge.decrypt_failed, .badge.invalid_request,
.badge.price_missing, .badge.invalid_price, .badge.ip_blocked { background: var(--danger-soft); color: var(--danger); }
.badge.capped, .badge.pending, .badge.placement_disabled { background: var(--warn-soft); color: var(--warn); }

.pill { background: #eef1f7; color: #495468; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; }

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

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 190px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .bar-label { fill: #fff; font-size: 9.5px; text-anchor: middle; }

/* ---------- 提示 / 抽屉 ---------- */
#toast { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: #1f2a44; color: #fff; padding: 10px 15px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .25); max-width: 380px; animation: fadein .18s ease;
}
.toast.err { background: #a3312a; }
.toast.ok { background: #147a4b; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.drawer-mask { position: fixed; inset: 0; background: rgba(17, 26, 46, .45); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(620px, 94vw); background: #fff;
  z-index: 51; box-shadow: -12px 0 36px rgba(16, 24, 40, .18); overflow-y: auto; padding: 20px 22px 40px;
}
.drawer h2 { font-size: 16px; margin: 0 0 4px; }
.drawer .close { position: absolute; top: 14px; right: 16px; }
.hidden { display: none !important; }
dl.kv { display: grid; grid-template-columns: 128px 1fr; gap: 7px 12px; margin: 14px 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; }
pre.code {
  background: #f6f8fc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 14px; max-height: 260px; overflow: auto;
}
.formula { background: #f6f8fc; border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12px; }
.steps { display: grid; gap: 6px; font-size: 13px; }
.steps .step { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; background: #f8fafd; border-radius: 7px; }
.steps .step b { font-variant-numeric: tabular-nums; }

/* ---------- 登录页 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(140deg, #111a2e 0%, #22325c 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; padding: 30px 30px 26px; width: 360px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); font-size: 12.5px; margin: 0 0 20px; }
.login-err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-top: 6px; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: column; }
  .nav { flex-direction: row; overflow-x: auto; }
  .main { padding: 16px; }
}
