:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d5d8de;
  --text: #14181f;
  --text-2: #4a515c;
  --muted: #848b98;
  --accent: #2f5bff;
  --accent-ink: #1c3fd4;
  --accent-soft: #eef2ff;
  --ok: #0f9d6e;
  --ok-soft: #e8f8f1;
  --warn: #c2790b;
  --warn-soft: #fdf6e7;
  --danger: #d93838;
  --danger-soft: #fdeeee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .16);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
::selection { background: #cfdcff; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -8%, #e7edff 0%, rgba(231, 237, 255, 0) 62%),
    radial-gradient(700px 420px at 100% 0%, #eef7f4 0%, rgba(238, 247, 244, 0) 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 384px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 30px 26px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, #3d66ff, #1f3ed0);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 12px -4px rgba(47, 91, 255, .6);
}
.brand-name { font-weight: 650; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

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

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head { padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; color: var(--muted); letter-spacing: .6px; padding: 12px 8px 6px; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  margin-bottom: 2px;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: .85; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px;
  flex: 0 0 56px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: .1px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn {
  display: none;
  width: 32px; height: 32px; padding: 0;
  align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); cursor: pointer; color: var(--text-2);
}
.menu-btn svg { width: 17px; height: 17px; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 35;
  background: rgba(15, 20, 30, .38);
  backdrop-filter: blur(1px);
}
.sidebar-backdrop.show { display: block; }
.content { padding: 20px 22px 40px; }

/* ---------- 卡片 / KPI ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(172px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 1px rgba(16, 24, 40, .03);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 620; font-size: 13.5px; }
.card-body { padding: 16px; }

.kpi { padding: 15px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 680; letter-spacing: -.5px; margin-top: 7px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.kpi-value.sm { font-size: 20px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 11.5px; letter-spacing: .3px; text-transform: uppercase;
  padding: 9px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
tbody tr:hover td { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: .2px; }
.nowrap { white-space: nowrap; }
.dim { color: var(--muted); }
.empty { padding: 44px 16px; text-align: center; color: var(--muted); }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 560; line-height: 18px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: #cfeade; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: #f2e3c2; }
.badge.muted { color: var(--muted); background: #f4f5f7; border-color: #e6e8ec; }
.badge.danger { color: var(--danger); background: var(--danger-soft); border-color: #f6d6d6; }
.badge.info { color: var(--accent-ink); background: var(--accent-soft); border-color: #dbe4ff; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  font-weight: 550;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: #c7cbd3; }
.btn:active { transform: translateY(.5px); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(47, 91, 255, .25);
}
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: #f0c9c9; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 27px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn.link { border: 0; background: none; color: var(--accent); height: auto; padding: 0 4px; }
.btn.link:hover { background: none; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; color: var(--text-2); font-weight: 560; margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: #fff; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 72px; line-height: 1.55; }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 91, 255, .12);
}
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input, .toolbar .select { width: auto; min-width: 130px; height: 32px; }
.toolbar .grow { flex: 1; }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(17, 24, 39, .34);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .14s ease-out;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh;
  background: var(--surface); border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 60px -20px rgba(16, 24, 40, .45);
  display: flex; flex-direction: column;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: .6 } to { transform: none; opacity: 1 } }
.modal.wide { max-width: 640px; }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 640; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; }
.close-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; }

/* ---------- 提示 ---------- */
.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 220px; max-width: 360px;
  background: #14181f; color: #fff;
  padding: 10px 14px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.5;
  box-shadow: 0 10px 28px -10px rgba(0, 0, 0, .5);
  animation: slide .18s ease-out;
}
.toast.err { background: #a52020; }
.toast.ok { background: #0c6b4d; }
@keyframes slide { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 168px; display: block; }
.legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); padding: 0 16px 12px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* ---------- 代码块 ---------- */
.code {
  background: #0f1420; color: #d7dceb;
  border-radius: 8px; padding: 12px 14px;
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  overflow-x: auto; white-space: pre;
}
.code .k { color: #8fb3ff; }
.code .s { color: #9ee6c0; }
.code .c { color: #6b7691; }

.keys-out {
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); padding: 10px 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.9;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.split { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -248px; z-index: 40; transition: left .2s ease; width: 248px; flex-basis: 248px; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .18); }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px 12px 32px; }
  .topbar { padding: 0 12px; }
  .topbar h1 { font-size: 14.5px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .badge { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi-value { font-size: 22px; }
  .card-head { padding: 12px 13px; }
  .card-body { padding: 13px; }
  .toolbar { padding: 10px 12px; }
  .toolbar .input, .toolbar .select { min-width: 0; flex: 1 1 44%; }
  .toolbar .input.grow { flex: 1 1 100%; }
  table { font-size: 12.5px; }
  th { padding: 8px 10px; }
  td { padding: 9px 10px; }
  .modal { max-height: 92vh; }
  .row > * { flex: 1 1 100%; }
  .login-card { padding: 26px 20px 22px; }
}
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.stat-sub { font-size: 11.5px; color: var(--muted); }
.tag { font-family: var(--mono); font-size: 11.5px; background: #f4f5f7; border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--text-2); }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
