:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e4e8ef;
  --text: #1f2733;
  --text-2: #5b6675;
  --muted: #8b95a5;
  --primary: #2b6cf6;
  --primary-dark: #1f57cc;
  --green: #16a34a;
  --red: #e5484d;
  --amber: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

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

/* ---------- Topbar ---------- */
.topbar {
  height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #2b6cf6, #5b8cff);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.brand-text strong { display: block; font-size: 15px; }
.brand-text small { color: var(--muted); font-size: 11px; letter-spacing: .3px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.health-text { color: var(--text-2); font-size: 12px; }
.api-chip {
  font-size: 12px; color: var(--text-2); background: var(--bg);
  border: 1px solid var(--border); padding: 3px 9px; border-radius: 20px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.dot-off { background: var(--red); box-shadow: 0 0 0 3px rgba(229,72,77,.15); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 58px); }
.sidebar {
  width: 190px; background: var(--panel); border-right: 1px solid var(--border);
  padding: 14px 10px; flex-shrink: 0;
}
.nav-item {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text-2);
  cursor: pointer; margin-bottom: 3px; font-size: 14px; user-select: none;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: #eaf1fe; color: var(--primary); font-weight: 600; }
.content { flex: 1; padding: 22px 26px; max-width: 1400px; }
.view.hidden { display: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat-num { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat-label { color: var(--text-2); font-size: 13px; margin-top: 4px; }

.cat-chart { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: 110px 1fr 46px; align-items: center; gap: 12px; font-size: 13px; }
.cat-bar { height: 10px; border-radius: 6px; background: linear-gradient(90deg, #2b6cf6, #7aa6ff); }
.cat-count { text-align: right; color: var(--text-2); }

.guide { margin: 0; padding-left: 20px; color: var(--text-2); line-height: 1.9; }
.guide code { background: var(--bg); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- Toolbar & form ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.input {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px;
  font-size: 13px; background: var(--panel); color: var(--text); outline: none;
  font-family: inherit; min-width: 160px;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43,108,246,.12); }
.select { min-width: 140px; }
textarea.input { width: 100%; resize: vertical; }

.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--panel); }
.btn-danger { color: var(--red); border-color: #f3c9ca; }
.btn-danger:hover { background: #fdf1f1; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fafbfd;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: #fafbfd; }
.table .name-cell { font-weight: 600; }
.table .sub { color: var(--muted); font-size: 12px; }
.tag {
  display: inline-block; background: #eef2f8; color: var(--text-2); border-radius: 4px;
  padding: 1px 7px; font-size: 11px; margin-right: 4px;
}
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-on { background: #e7f6ec; color: var(--green); }
.badge-off { background: #f2f4f7; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 30px; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16,24,40,.42); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-mask.hidden { display: none; }
.modal {
  background: var(--panel); border-radius: 12px; width: 640px; max-width: 100%;
  max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(16,24,40,.2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.btn-close { border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.form-row .input { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.actions { margin-top: 6px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 13px; }
.kv .k { color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.hidden { display: none; }
.toast.err { background: var(--red); }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 130px; }
  .grid2 { grid-template-columns: 1fr; }
}
