:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f4; --border: #dde1e8;
  --text: #1b1f27; --muted: #626b7a; --accent: #1f6feb; --accent-text: #fff;
  --ok: #1a7f37; --ok-bg: #dcf5e3; --bad: #c62828; --bad-bg: #fde2e1; --off: #8a93a3;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --border: #2b313b;
    --text: #e6e9ee; --muted: #9aa3b2; --accent: #4c8dff; --accent-text: #fff;
    --ok: #4ac26b; --ok-bg: #12301c; --bad: #ff6b6b; --bad-bg: #3a1618; --off: #6b7482;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.small { padding: 3px 9px; font-size: 13px; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

header.top {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.top-spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .top-spacer { flex: 1; }

.summary { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  flex: 1; min-width: 120px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.on { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--bad-bg); color: var(--bad); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.editable { border: 1px dashed transparent; border-radius: 5px; padding: 2px 5px; cursor: text; }
.editable:hover { border-color: var(--border); }
.editable:focus { outline: 2px solid var(--accent); border-style: solid; }

.row-actions { display: flex; gap: 6px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px;
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--bad); color: #fff; }

.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
  align-items: center; justify-content: center; z-index: 40; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 20px; width: 100%;
  max-width: 460px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { margin: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.hidden { display: none !important; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { justify-content: center; font-size: 20px; }
.login-card .error { color: var(--bad); font-size: 13px; min-height: 18px; }

.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

code.token { background: var(--surface-2); padding: 6px 10px; border-radius: 6px; display: block;
  word-break: break-all; margin-top: 6px; }
