:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #e6edf5;
  --text: #1a2332;
  --muted: #6b7a90;
  --primary: #2f6fed;
  --primary-soft: #eaf1ff;
  --ok: #1a9e63;
  --ok-soft: #e7f8ef;
  --warn: #c47a12;
  --warn-soft: #fff4e5;
  --danger: #d14343;
  --danger-soft: #fdecec;
  --shadow: 0 10px 30px rgba(24, 48, 96, 0.06);
  --radius: 14px;
  --sidebar: 240px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
button, input, select { font: inherit; }
a { color: var(--primary); text-decoration: none; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 400px at 10% -10%, #d9e7ff 0%, transparent 60%),
    radial-gradient(700px 300px at 100% 0%, #e8f7ef 0%, transparent 50%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 22px;
}
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #2f6fed, #4aa3ff);
  color: #fff; display: grid; place-items: center; font-weight: 700;
}
.login-brand h1 { margin: 0; font-size: 18px; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.12); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 7px 10px; font-size: 13px; font-weight: 500; }
.hint { margin-top: 12px; color: var(--muted); font-size: 12px; }

/* Shell */
.app { display: none; min-height: 100vh; }
.app.show { display: grid; grid-template-columns: var(--sidebar) 1fr; }
.sidebar {
  background: #12233f; color: #dbe7ff; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px;
}
.side-brand .logo { width: 36px; height: 36px; font-size: 14px; }
.side-brand strong { display: block; font-size: 14px; color: #fff; }
.side-brand span { font-size: 12px; color: #8ea4c7; }
.nav button {
  width: 100%; text-align: left; background: transparent; border: none;
  color: #c9d7f0; padding: 11px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 4px;
}
.nav button:hover { background: rgba(255,255,255,.06); }
.nav button.active { background: rgba(47,111,237,.28); color: #fff; font-weight: 600; }
.side-foot { position: absolute; left: 12px; right: 12px; bottom: 16px; font-size: 12px; color: #7f95b8; }

.main { padding: 22px 26px 40px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 22px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(4, 1fr); }
.grid.two { grid-template-columns: 1.2fr .8fr; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat .foot { color: var(--muted); font-size: 12px; margin-top: 6px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr:last-child td { border-bottom: none; }
.tag {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.muted { background: #eef2f7; color: #5d6b80; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.rule-block {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  margin-bottom: 12px; background: #fbfcfe;
}
.rule-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-bottom: 12px;
}
.rule-head strong { font-size: 14px; }
.rule-head span { color: var(--muted); font-size: 12px; }
.switch {
  position: relative; width: 44px; height: 24px; flex: none;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #c9d3e2; border-radius: 999px; cursor: pointer;
  transition: .2s;
}
.switch span::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input, .toolbar select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  background: #12233f; color: #fff; padding: 12px 14px; border-radius: 10px;
  box-shadow: var(--shadow); display: none; max-width: min(360px, calc(100vw - 36px));
}
.toast.show { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

.mobile-bar {
  display: none; position: sticky; top: 0; z-index: 20;
  background: #12233f; color: #fff; padding: 12px 14px;
  align-items: center; justify-content: space-between;
}
.mobile-bar button {
  background: rgba(255,255,255,.1); border: none; color: #fff;
  border-radius: 8px; padding: 8px 10px; cursor: pointer;
}

@media (max-width: 980px) {
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app.show { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(80vw, 260px);
    transform: translateX(-105%); transition: .2s; z-index: 30;
  }
  .sidebar.open { transform: none; }
  .mobile-bar { display: flex; }
  .main { padding: 16px; }
}

.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1.2em; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
