:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --line: #e5e9f2;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --teal: #0d9488;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #047857;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font: 400 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
code { background: #eef2ff; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 10% 0%, #dbeafe 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 100%, #ccfbf1 0%, transparent 55%),
              var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .14);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: #fff; font-weight: 800; font-size: 20px;
}
.brand h1 { font-size: 17px; letter-spacing: .2px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.brand.small .brand-mark { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
.brand.small h1 { font-size: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: #334155; }
.login-card input {
  height: 42px; border: 1px solid #cbd5e1; border-radius: 10px; padding: 0 12px;
  outline: none; font-weight: 400;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-msg { min-height: 18px; margin: 0; font-size: 12px; color: var(--danger); }
.login-foot { margin: 0; font-size: 10.5px; color: var(--muted); text-align: center; }

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: none;
  background: #0f172a; color: #cbd5e1;
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand h1 { color: #f8fafc; }
.sidebar .brand p { color: #94a3b8; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 26px; }
.nav-btn {
  text-align: left; border: 0; background: transparent; color: #cbd5e1;
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 13px;
}
.nav-btn:hover { background: rgba(148, 163, 184, .14); color: #fff; }
.nav-btn.active { background: linear-gradient(135deg, rgba(37, 99, 235, .35), rgba(13, 148, 136, .3)); color: #fff; font-weight: 600; }
.sidebar-foot {
  margin-top: auto; display: flex; flex-direction: column; gap: 8px;
  font-size: 11.5px; color: #94a3b8; word-break: break-all;
  border-top: 1px solid rgba(148, 163, 184, .2); padding-top: 14px;
}
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.topbar h2 { font-size: 21px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe;
  padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}

/* ---------- cards / grid ---------- */
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 700; }
.stat b { font-size: 27px; line-height: 1.2; }
.stat small { color: var(--muted); font-size: 11.5px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; }
.card-head p { margin: 3px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.full { grid-column: 1 / -1; }

/* ---------- forms ---------- */
.input, select.input, textarea.input {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 9px; padding: 8px 10px;
  background: #fff; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: #334155; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form-msg, .settings-msg { min-height: 16px; margin: 0; font-size: 12px; color: var(--danger); }
.settings-msg.ok { color: var(--ok); }
.btn {
  border: 1px solid #cbd5e1; background: #fff; color: #0f172a;
  border-radius: 9px; padding: 8px 14px; font-weight: 600; font-size: 12.5px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--teal)); border: 0; color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: rgba(148, 163, 184, .35); }
.btn.ghost:hover { background: rgba(148, 163, 184, .16); }
.btn.small { padding: 5px 10px; font-size: 11.5px; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 16px; cursor: pointer; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left; font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .right, .table td.right { text-align: right; }
.table .sub { display: block; color: var(--muted); font-size: 11px; }
.table .actions { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 12.5px; padding: 14px 0 0; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 700;
  background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0;
}
.tag.off { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.tag.warn { background: #fffbeb; color: var(--warn); border-color: #fde68a; }
.tag.info { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.bar { height: 6px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 4px; min-width: 90px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--teal)); }
.bar.full > span { background: var(--danger); }

/* ---------- lists / details ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 8px 10px; border: 1px solid #f1f5f9; border-radius: 9px; background: #fcfdff; }
.list.compact .list-item { padding: 6px 9px; font-size: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-word; }
.code {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 12px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #0f172a; color: #e2e8f0; resize: vertical;
}
pre.code.block { margin: 8px 0 0; overflow: auto; }
.config-status { font-size: 12px; color: var(--muted); min-height: 18px; margin: 8px 0 0; }
.config-status.err { color: var(--danger); }
.config-status.ok { color: var(--ok); }
.details summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 16px; padding: 20px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .3);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 12.5px; box-shadow: 0 14px 40px rgba(15, 23, 42, .3); z-index: 80;
  max-width: 90vw;
}
.toast.err { background: #7f1d1d; }
.toast.ok { background: #065f46; }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; margin: 0 0 0 auto; }
  .sidebar-foot { flex-direction: row; align-items: center; border: 0; padding: 0; margin: 0; }
  .main { padding: 18px 14px 40px; }
  .topbar { flex-direction: column; }
}
