:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #18202b; --muted: #5b6676; --line: #dde2ea;
  --accent: #1f5fbf; --accent-ink: #ffffff; --ok: #1d7a46; --ok-bg: #e5f4ec; --bad: #b42318; --bad-bg: #fdecea;
  --warn: #8a5a00; --warn-bg: #fff4dc; --code: #eef1f5; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --panel: #171e26; --ink: #e6ebf1; --muted: #9aa6b4; --line: #2a3441;
    --accent: #5b9bff; --accent-ink: #0b1220; --ok: #5fd08f; --ok-bg: #12301f; --bad: #ff8a80; --bad-bg: #3a1714;
    --warn: #f3c060; --warn-bg: #352a10; --code: #1f2833; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.mono-box { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap;
  word-break: break-all; max-height: 360px; overflow: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; margin: 0; }

/* auth page */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; }
.narrow { max-width: 400px; width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.brand .tag { font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 10px; }

/* forms */
label { display: block; font-size: 12px; font-weight: 600; margin: 10px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; margin: 4px 12px 4px 0; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
textarea { min-height: 70px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.help { font-size: 12px; color: var(--muted); margin-top: 3px; }
button, .btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small, .btn.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 14px; }
.msg { padding: 8px 12px; border-radius: 8px; font-size: 13px; margin: 10px 0; }
.msg.err { background: var(--bad-bg); color: var(--bad); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }

/* shell */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .brand { margin: 0; }
.top .spacer { flex: 1; }
.user { font-size: 12px; color: var(--muted); text-align: right; }
.shell { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 53px); }
nav.side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px; }
nav.side a { display: block; padding: 8px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
nav.side a.on { background: var(--accent); color: var(--accent-ink); }
nav.side a:hover:not(.on) { background: var(--code); }
main { padding: 18px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* tables */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .row { flex-wrap: nowrap; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--code); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--accent); color: var(--accent-ink); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; white-space: nowrap; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); }

.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.action { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.action h4 { margin: 0; font-size: 13px; }
.action .help { margin: 0 0 4px; }
.action label { margin: 4px 0 2px; }
.action button { margin-top: 6px; align-self: flex-start; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; font-weight: 700; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 20; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; padding: 18px; width: 100%; max-width: 560px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  nav.side { display: flex; align-items: center; overflow-x: auto; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  nav.side a { white-space: nowrap; margin: 0; }
  main { padding: 12px; }
  .top { padding: 8px 12px; }
  .brand .tag { display: none; }
  .user .roles { display: none; }
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--code); }
