:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --line: #e6e8ef;
  --text: #111827;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-weak: #eef2ff;
  --ok: #059669;
  --ok-weak: #ecfdf5;
  --danger: #dc2626;
  --danger-weak: #fef2f2;
  --warn: #b45309;
  --warn-weak: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: 12px; color: var(--muted); }

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

/* ---------- sidebar ---------- */
.sidebar {
  width: 226px;
  flex: 0 0 226px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #f8fafc; font-size: 15px; letter-spacing: .2px; }
.brand-text span { color: #64748b; font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: #94a3b8; font-size: 13.5px;
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; }
.nav-item:hover { background: rgba(148,163,184,.09); color: #e2e8f0; text-decoration: none; }
.nav-item.active { background: rgba(99,102,241,.18); color: #c7d2fe; }
.nav-item.active svg { color: #a5b4fc; }
.sidebar-foot { padding: 12px 18px 18px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot a { color: #64748b; font-size: 12px; }
.sidebar-foot a:hover { color: #cbd5e1; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 14px;
  gap: 16px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: #eef0f5; color: var(--muted);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-weak); color: var(--ok); }
.pill-muted { background: #f1f2f6; color: #6b7280; }

.flash {
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 13.5px;
  border: 1px solid transparent;
}
.flash-ok { background: var(--ok-weak); border-color: #a7f3d0; color: #065f46; }
.flash-err { background: var(--danger-weak); border-color: #fecaca; color: #991b1b; }
.flash-warn { background: var(--warn-weak); border-color: #fde68a; color: #92400e; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px;
}
.card-head h2 { font-size: 14.5px; margin: 0; font-weight: 650; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card-body { padding: 18px; }
.card-body.tight { padding: 12px 18px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } .main { padding: 0 14px 30px; } .sidebar { display: none; } }

.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.stat .v { font-size: 26px; font-weight: 680; letter-spacing: .5px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }

/* ---------- table ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-weight: 550; font-size: 12.5px; white-space: nowrap; background: #fafbfc; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #fafbff; }
table.data td.wrap { max-width: 420px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px;
  background: #eef0f5; color: #475569; white-space: nowrap;
}
.badge-green { background: var(--ok-weak); color: var(--ok); }
.badge-red { background: var(--danger-weak); color: var(--danger); }
.badge-warn { background: var(--warn-weak); color: var(--warn); }
.badge-blue { background: var(--primary-weak); color: var(--primary); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: #374151;
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; cursor: pointer;
  transition: .15s; text-decoration: none; line-height: 1.2;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; color: #fff; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-weak); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 550; color: #374151; }
.field .desc { font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d8dbe4; border-radius: 8px;
  font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99,102,241,.13);
}
input[readonly], textarea[readonly] { background: #f8fafc; color: #64748b; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.check input { width: 15px; height: 15px; accent-color: var(--primary); }
.actions { display: flex; gap: 10px; align-items: center; }
.actions .spacer { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.switch input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- misc ---------- */
.empty { padding: 36px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 140px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
pre.code {
  background: #0f172a; color: #cbd5e1; padding: 14px 16px; border-radius: 10px;
  overflow: auto; font-size: 12.5px; line-height: 1.65; margin: 0;
}
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { margin-top: 10px; max-height: 320px; }
.callout {
  border-radius: 10px; padding: 12px 14px; font-size: 13px; line-height: 1.7;
  background: var(--primary-weak); border: 1px solid #dfe3ff; color: #3730a3;
}
.callout-warn { background: var(--warn-weak); border-color: #fde68a; color: #92400e; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.hr { height: 1px; background: var(--line); margin: 18px 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tabs a {
  padding: 7px 12px; border-radius: 8px; font-size: 13px; color: var(--muted);
}
.tabs a.active { background: #fff; color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--line); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 0%, #eef2ff 0%, #f5f6fa 45%, #f5f6fa 100%);
  padding: 24px;
}
.login-card {
  width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(16,24,40,.10); padding: 30px 28px;
}
.login-logo {
  width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-err { background: var(--danger-weak); color: #991b1b; border: 1px solid #fecaca; padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* ---------- rule list ---------- */
.rule-targets { display: flex; flex-wrap: wrap; gap: 4px; }
.rule-targets .badge { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- code chip ---------- */
.chip {
  display: inline-block; padding: 1px 6px; border-radius: 5px; background: #eef1f6;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: #334155;
}
