:root {
  --bg: #0b0d12;
  --bg-soft: #10131a;
  --panel: #141821;
  --panel-2: #1a1f2b;
  --border: #252c3a;
  --border-soft: #1e2430;
  --text: #e6eaf2;
  --muted: #8b95a8;
  --muted-2: #667085;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --ok: #37d39b;
  --warn: #f4b740;
  --bad: #ff6b6b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --input-bg: #0e1219;
  --hover: #222938;
  --row-hover: rgba(255, 255, 255, 0.018);
  --danger-text: #ffb4b4;
  --sidebar-bg: #0e1118;
  --topbar-bg: rgba(11, 13, 18, 0.7);
  --auth-card-bg: #141821;
}

:root[data-theme="light"] {
  --bg: #f4f7fc;
  --bg-soft: #edf2f9;
  --panel: #ffffff;
  --panel-2: #f1f4fa;
  --border: #d7dfeb;
  --border-soft: #e6ebf3;
  --text: #121826;
  --muted: #5b677b;
  --muted-2: #7c879a;
  --accent: #3567f0;
  --accent-2: #6948ed;
  --ok: #0c8f64;
  --warn: #a86b12;
  --bad: #cf3f3f;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
  --input-bg: #ffffff;
  --hover: #e9eef7;
  --row-hover: rgba(15, 23, 42, 0.035);
  --danger-text: #b42318;
  --sidebar-bg: #ffffff;
  --topbar-bg: rgba(244, 247, 252, 0.82);
  --auth-card-bg: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.right { text-align: right; }
.inline { display: inline; }
.tight { gap: 10px; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 248px;
  height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
}

.brand-center {
  justify-content: center;
  padding-bottom: 18px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.03em;
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.25);
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 550;
}

.nav-link:hover {
  color: var(--text);
  background: var(--panel);
  text-decoration: none;
}

.nav-link.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(91, 140, 255, 0.16), rgba(124, 92, 255, 0.08));
  border: 1px solid rgba(91, 140, 255, 0.22);
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted-2);
}

.nav-link.active .nav-dot { background: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 26px 34px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 26px 34px 48px;
  max-width: 1440px;
  width: 100%;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 108px;
  justify-content: center;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.03em;
}

.stat-sub { color: var(--muted); font-size: 12.5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.22);
}
.btn-primary:hover { background: linear-gradient(135deg, #6b98ff, #8b6dff); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: rgba(255, 107, 107, 0.35); }
.btn-danger:hover { background: rgba(255, 107, 107, 0.1); }
.btn-small { padding: 5px 9px; font-size: 12.5px; }
.btn-block { width: 100%; }

.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { color: var(--ok); border-color: rgba(55, 211, 155, 0.35); background: rgba(55, 211, 155, 0.08); }
.badge-warn { color: var(--warn); border-color: rgba(244, 183, 64, 0.35); background: rgba(244, 183, 64, 0.08); }
.badge-bad { color: var(--bad); border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.08); }
.badge-off { color: var(--muted-2); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.field > small, .hint { color: var(--muted-2); font-size: 12px; }
.field > small code, .hint code { color: var(--muted); }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(91, 140, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.14);
}
textarea { resize: vertical; min-height: 76px; font-family: var(--mono); font-size: 12.5px; }
select { appearance: auto; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13.5px;
  user-select: none;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.alert {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--muted);
  font-size: 13.5px;
}
.alert-error {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.08);
  color: var(--danger-text);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 4px;
  color: var(--muted);
}

.sparkline {
  width: 100%;
  height: 120px;
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(91, 140, 255, 0.04), transparent);
}
.sparkline path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 8px rgba(91, 140, 255, 0.35));
}
.sparkline-axis {
  display: flex;
  justify-content: space-between;
  color: var(--muted-2);
  font-size: 11.5px;
  padding: 6px 2px 0;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(91, 140, 255, 0.14), transparent 60%),
    radial-gradient(800px 600px at 90% 100%, rgba(124, 92, 255, 0.12), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--auth-card-bg);
  box-shadow: var(--shadow);
}
.auth-title { font-size: 22px; }
.auth-subtitle { margin-top: 5px; margin-bottom: 20px; font-size: 13.5px; }
.auth-card .stack { gap: 13px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar input[type="search"] { max-width: 320px; }
.toolbar select { max-width: 160px; }

.test-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  width: 100%;
}
.test-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 13px;
}
.test-row .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; }
  .nav-link { white-space: nowrap; font-size: 13px; }
  .nav-dot { display: none; }
  .sidebar-footer { margin: 0; padding: 0; }
  .sidebar-footer .btn { padding: 7px 10px; }
  .topbar { padding: 20px 18px 14px; flex-direction: column; align-items: flex-start; }
  .content { padding: 18px 18px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.ban-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.ban-form input[name="ip"] { max-width: 240px; }
.ban-form input[name="duration_secs"] { max-width: 140px; }
