:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #dde1e6;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #ef6c00;
  --read: #1f6feb;
  --write: #2e7d32;
  --delete: #c62828;
  --list: #8e24aa;
  --other: #9e9e9e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --line: #2a313a;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #4c8dff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 28px 32px; width: 360px;
}
.login-box h1 { margin: 0 0 4px; font-size: 22px; }

/* layout */
.app { min-height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 6px 12px; border-radius: 6px; color: var(--text); }
.top nav a.active { background: var(--accent); color: var(--accent-text); }
.who { color: var(--muted); }
main { padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 0 0 8px; font-size: 15px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.row > * { flex: 1 1 300px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.panel-head h3 { flex: 1; margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.card .sub { color: var(--muted); font-size: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr.click { cursor: pointer; }
tr.click:hover td { background: rgba(127, 127, 127, .08); }
td.actions { text-align: right; white-space: nowrap; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px;
  background: var(--line); color: var(--text); margin-right: 4px;
}
.tag.on { background: var(--ok); color: #fff; }
.tag.off { background: var(--danger); color: #fff; }
.tag.cfg { background: var(--muted); color: #fff; }

/* forms */
label { display: block; margin: 8px 0; }
label > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
label.inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
button {
  font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); }

/* charts */
canvas.chart { width: 100%; height: 180px; display: block; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* modal + toast */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex;
  align-items: center; justify-content: center; z-index: 10;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 20px 24px; width: 480px; max-width: 95vw; max-height: 90vh; overflow: auto;
}
.modal-box h3 { margin-top: 0; }
.secret {
  background: var(--bg); border: 1px dashed var(--warn); border-radius: 6px; padding: 10px;
  word-break: break-all;
}
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px; z-index: 20;
}
.toast.err { background: var(--danger); color: #fff; }
.grants { margin: 0; padding: 0; list-style: none; }
.grants li { display: flex; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.grants li span.b { flex: 1; }
.sub-rows td { background: rgba(127, 127, 127, .05); }
