:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #14161a;
  --muted: #646b78;
  --line: #e3e6eb;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --ok: #178a4a;
  --ok-bg: #e4f5ec;
  --warn: #9a6500;
  --warn-bg: #fdf1d6;
  --bad: #c0352b;
  --bad-bg: #fbe5e3;
  --off: #8a909c;
  --track: #c9ced6;
  --shadow: 0 1px 2px rgba(20, 22, 26, .05), 0 4px 16px rgba(20, 22, 26, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --card: #171a1f;
    --text: #eceef2;
    --muted: #9aa1ae;
    --line: #272b33;
    --accent: #7c75ff;
    --accent-ink: #0e1013;
    --ok: #4cc984;
    --ok-bg: #14301f;
    --warn: #e9b44c;
    --warn-bg: #33270b;
    --bad: #ff7a70;
    --bad-bg: #3a1815;
    --off: #6c7380;
    --track: #3a3f49;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 24px;
  max-width: 980px; margin: 0 auto; padding: 24px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand h1 { font-size: 1.25rem; letter-spacing: -.01em; }
.brand p { color: var(--muted); font-size: .88rem; }
.mark { width: 36px; height: 36px; flex: none; }
.mark rect { fill: var(--accent); }
.mark path { stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; fill: none; }
.mark.big { width: 48px; height: 48px; }

.mem { width: 240px; font-size: .82rem; }
.mem-text { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin-bottom: 5px; }
.mem-text strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--ok); transition: width .4s ease, background .3s; }
.mem[data-level="warn"] .bar i { background: var(--warn); }
.mem[data-level="bad"] .bar i { background: var(--bad); }

/* ---------- toolbar ---------- */
main { max-width: 980px; margin: 0 auto; padding: 8px 16px 64px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0 14px; }
.search { flex: 1 1 200px; }
.search input {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit;
}
.chips { display: flex; gap: 6px; }
.chip {
  height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font: inherit; cursor: pointer;
}
.chip b { color: var(--text); font-weight: 600; margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: .9rem; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover:not([disabled]):not([aria-disabled="true"]) { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not([disabled]) { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; height: 42px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

.banner {
  margin: 8px 0 12px; padding: 10px 14px; border-radius: 10px;
  background: var(--bad-bg); color: var(--bad); font-size: .9rem;
}

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 4px 14px;
  padding: 14px 16px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.row[data-tone="ok"] .dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); }
.row[data-tone="warn"] .dot { background: var(--warn); }
.row[data-tone="bad"] .dot { background: var(--bad); }
.row[data-busy="1"] .dot { animation: pulse 1.1s ease-in-out infinite; }

.who { min-width: 0; }
.name { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-weight: 600; }
.pill { font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); letter-spacing: .01em; }
.row[data-tone="ok"] .pill { background: var(--ok-bg); color: var(--ok); }
.row[data-tone="warn"] .pill { background: var(--warn-bg); color: var(--warn); }
.row[data-tone="bad"] .pill { background: var(--bad-bg); color: var(--bad); }
.meta { color: var(--muted); font-size: .84rem; display: flex; flex-wrap: wrap; gap: 0 10px; margin-top: 1px; }
.meta .domain { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.meta .usage { font-variant-numeric: tabular-nums; }
.msg { grid-column: 2 / -1; font-size: .84rem; color: var(--muted); margin-top: 4px; }
.msg.error { color: var(--bad); }
.msg.warn { color: var(--warn); }
.msg:empty { display: none; }

.actions { display: flex; align-items: center; gap: 8px; }

/* on/off switch */
.switch {
  position: relative; width: 48px; height: 28px; flex: none; border: 0; border-radius: 99px;
  background: var(--track); cursor: pointer; transition: background .2s; padding: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch[disabled] { cursor: not-allowed; opacity: .55; }
.switch[data-busy="1"] { opacity: 1; animation: pulse 1.1s ease-in-out infinite; }

/* ---------- activity ---------- */
.activity { margin-top: 20px; color: var(--muted); font-size: .88rem; }
.activity summary { cursor: pointer; padding: 6px 0; }
.activity ol { list-style: none; margin: 6px 0 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.activity li { display: flex; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); }
.activity li:first-child { border-top: 0; }
.activity .when { flex: none; width: 90px; font-variant-numeric: tabular-nums; }
.activity .what { color: var(--text); }
.activity .bad { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* ---------- toasts and dialog ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); z-index: 10; }
.toast { padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: .9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: rise .2s ease-out; }
.toast.error { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 22px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 12, 16, .55); }
dialog h2 { font-size: 1.05rem; margin-bottom: 8px; }
dialog p { color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(360px, calc(100vw - 32px)); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 1.3rem; margin: 14px 0 2px; }
.login .sub { color: var(--muted); margin-bottom: 22px; }
.login label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.login input { width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; margin-bottom: 14px; }
.form-error { color: var(--bad); font-size: .86rem; margin: -4px 0 12px; }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 680px) {
  .top { flex-wrap: wrap; gap: 14px; }
  .mem { order: 3; width: 100%; }
  .row { grid-template-columns: 10px 1fr; }
  .actions { grid-column: 2; margin-top: 8px; }
  .actions .switch { margin-left: auto; }
  .chips { width: 100%; }
  .chip { flex: 1; }
  .btn.danger { width: 100%; }
}
