:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #17202b;
  --muted: #6b7787;
  --line: #e3e8ef;
  --brand: #2f6bff;
  --brand-ink: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --sidebar: #111823;
  --sidebar-ink: #c7d2e0;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.right { text-align: right; }

/* --- login --- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 20% 0%, #1d2a3f 0%, #0d1219 60%, #0a0e14 100%);
}
.login-card {
  width: min(380px, 92vw);
  background: var(--panel);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: -8px 0 6px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #2f6bff, #7aa2ff);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 22px;
}
.brand-mark.small { width: 26px; height: 26px; font-size: 14px; border-radius: 8px; }

/* --- layout --- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: #fff; padding: 0 8px 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left; background: none; border: 0; color: var(--sidebar-ink);
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(47,107,255,.22); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.link-btn { background: none; border: 0; color: var(--sidebar-ink); text-align: left; padding: 0; cursor: pointer; font-size: 13px; }
.link-btn:hover { color: #fff; text-decoration: underline; }

.main { padding: 26px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.page-head h2 { margin: 0; font-size: 21px; }
.hint { color: var(--muted); margin: 4px 0 18px; line-height: 1.6; }

/* --- panels & tables --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 14px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfd; }
.table tr:last-child td { border-bottom: 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 16px 0 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 28px; font-weight: 650; line-height: 1; }
.small-value { font-size: 16px; font-weight: 600; }
.code-block {
  margin: 0; padding: 16px 18px; background: #0f1722; color: #c9d6e6;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.audit-list { list-style: none; margin: 0; padding: 8px 18px; }
.audit-list li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.audit-list li:last-child { border-bottom: 0; }
.audit-list .t { color: var(--muted); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }

.kv { display: flex; justify-content: space-between; gap: 20px; padding: 12px 18px; border-bottom: 1px solid var(--line); align-items: center; }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--muted); }

/* --- forms & buttons --- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,107,255,.12); }
textarea { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.input.inline { width: 220px; display: inline-block; }
.form-row { display: flex; gap: 14px; align-items: flex-end; padding: 16px 18px; flex-wrap: wrap; }
.form-row .field { min-width: 190px; }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; padding: 0 18px 10px; }
.login-card .form-error { padding: 0; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); border-color: #f3c4c4; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn + .btn { margin-left: 6px; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; border: 1px solid transparent; }
.pill.ok { color: var(--ok); background: #eafaf0; border-color: #c8efd7; }
.pill.bad { color: var(--bad); background: #fdeeee; border-color: #f6cccc; }
.pill.off { color: var(--muted); background: #f1f3f6; border-color: #e3e8ef; }
.pill.type { color: #33507f; background: #eef3fb; border-color: #d9e4f5; text-transform: uppercase; font-family: var(--mono); font-size: 11px; }

/* --- modal --- */
.modal-root { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,15,22,.55); }
.modal {
  position: relative; width: min(620px, 94vw); max-height: 88vh; overflow: auto;
  background: var(--panel); border-radius: 14px; box-shadow: 0 24px 80px rgba(0,0,0,.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--panel); }
.modal-foot .btn + .btn { margin-left: 0; }
.cmd-block { background: #0f1722; color: #c9d6e6; border-radius: 8px; padding: 12px 14px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; line-height: 1.6; }
.note { color: var(--warn); font-size: 13px; line-height: 1.6; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

/* --- toast --- */
.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 80;
  background: #111823; color: #e8eef7; padding: 11px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.28); max-width: 420px;
}
.toast.bad { background: #7f1d1d; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 14px; padding: 12px; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .brand { padding: 0; }
  .main { padding: 18px 14px 40px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}
