:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --border: #d9e1dc;
  --text: #17201c;
  --muted: #5d6b64;
  --accent: #2f8f66;
  --accent-soft: #dcefe5;
  --ok: #2f8f66;
  --warn: #b7791f;
  --warn-soft: #fbefd9;
  --bad: #c0392b;
  --bad-soft: #f8dedb;
  --info-soft: #e1e8f5;
  --info: #3d5a99;
  --radius: 12px;
  --card-radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --surface: #18211e;
    --surface-2: #1f2a26;
    --border: #2b3833;
    --text: #e6ece9;
    --muted: #93a39b;
    --accent: #4fb286;
    --accent-soft: #1d3a2e;
    --ok: #4fb286;
    --warn: #e0a84a;
    --warn-soft: #3a2f1a;
    --bad: #ef7466;
    --bad-soft: #3d2320;
    --info-soft: #1f2a3f;
    --info: #8fa8e0;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85rem; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand svg { fill: var(--accent); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.nav a:hover { text-decoration: none; background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.me { color: var(--muted); font-size: .85rem; }

.main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--card-radius); padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head .spacer { flex: 1; }
a.card { color: inherit; display: block; transition: border-color .15s; }
a.card:hover { text-decoration: none; border-color: var(--accent); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.stats { display: flex; gap: 18px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.stat b { display: block; font-size: 1.25rem; }
.stat span { color: var(--muted); font-size: .8rem; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.chip.active, .chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.blocked, .chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.invited, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.revoked { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.chip.info { background: var(--info-soft); color: var(--info); }

.btn { font: inherit; font-size: .88rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: .8rem; border-radius: 9px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--card-radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
td.center, th.center { text-align: center; }
.person-name { font-weight: 600; }

.empty { padding: 28px; text-align: center; color: var(--muted); }
.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; background: var(--warn-soft); color: var(--warn); font-size: .9rem; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
input[type=email], input[type=text], input[type=search], select { font: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); }

.setting { display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: none; }
.setting .label { flex: 1; }
.setting .label small { display: block; color: var(--muted); }

.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: .5; cursor: default; }

dialog { border: 1px solid var(--border); border-radius: var(--card-radius); background: var(--surface); color: var(--text); padding: 22px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin-bottom: 14px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: var(--radius); font-size: .9rem; box-shadow: 0 6px 24px rgb(0 0 0 / .2); z-index: 20; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

.err-item { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.err-item:last-child { border-bottom: none; }
.err-item .msg { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; word-break: break-word; margin-top: 4px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .me { display: none; }
  .main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  th, td { padding: 8px 10px; }
}
