:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #2563eb;
  --accent-text: #fff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --row-hover: #f8f9fb;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e6e8eb;
    --muted: #8b93a1;
    --border: #262a33;
    --accent: #3b82f6;
    --row-hover: #1c2029;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); margin: 8px 0 0; }
.spacer { flex: 1; }

button {
  font: inherit;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.secondary { border-color: var(--accent); color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 6px; margin: 0; color: var(--text); }
label.check input { width: auto; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p.muted { margin: 0 0 20px; }
.login-card button { width: 100%; margin-top: 8px; padding: 9px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px; display: grid; gap: 20px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.actions { display: flex; align-items: center; gap: 10px; }
.actions input[type=search] { width: 180px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--border);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--ok); }
.pill.bad::before { background: var(--bad); }
.pill.warn::before { background: var(--warn); }

.agent-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.agent-grid div span { display: block; font-size: 12px; color: var(--muted); }
.agent-grid div strong { font-weight: 500; word-break: break-word; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
td.arrow { color: var(--muted); padding: 0; text-align: center; }
td.right { text-align: right; white-space: nowrap; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
tr.disabled td:not(.right) { opacity: .5; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); margin-left: 4px; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--bad); }
.status-off { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 18px 0 6px; margin: 0; }
td .actions-cell { display: inline-flex; gap: 6px; }

/* toggle switch */
.switch { position: relative; width: 34px; height: 20px; display: inline-block; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(14px); }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text);
  padding: 22px; width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-bottom: 16px; }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; }
.row > label.grow { flex: 2; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px;
  font-size: 13px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .row { flex-direction: column; gap: 0; }
  .topbar { padding: 10px 14px; }
}
