:root {
  --bg: #0f1218;
  --panel: #171c26;
  --panel-2: #1e2430;
  --border: #2d3544;
  --text: #e6e9ef;
  --muted: #a3acbd;
  --accent: #5b9dff;
  --accent-fg: #07101f;
  --danger: #ff6b6b;
  --danger-bg: #3a1c20;
  --warn: #ffc857;
  --ok: #4cd6a0;
  --focus: #ffd166;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
pre { background: #0b0e13; border: 1px solid var(--border); border-radius: 6px; padding: .6rem; overflow: auto; max-height: 18rem; margin: .3rem 0; white-space: pre-wrap; word-break: break-word; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-fg); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
.noscript { padding: 1rem; color: var(--warn); }

/* shell */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; padding: .6rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; letter-spacing: .08em; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 6px; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.whoami { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9rem; }
main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
main:focus { outline: none; }

/* controls */
button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: .4rem .8rem; border-radius: 6px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger-bg); color: var(--danger); border-color: #6b2b32; }
button.small { padding: .2rem .55rem; font-size: .85rem; }
input, select, textarea { font: inherit; color: var(--text); background: #0b0e13; border: 1px solid var(--border); border-radius: 6px; padding: .4rem .6rem; max-width: 100%; }
input:disabled, select:disabled { opacity: .55; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; padding: 0; vertical-align: middle; }
textarea { width: 100%; min-height: 4.5rem; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .8rem; }
.field input:not([type="checkbox"]), .field select { width: 100%; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }
.toolbar .spacer { flex: 1; }
.row-actions { display: flex; flex-wrap: wrap; gap: .3rem; }

/* cards, tables */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.login-card { max-width: 380px; margin: 12vh auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
td.detail-cell { background: var(--panel-2); }
.wrap-anywhere { overflow-wrap: anywhere; max-width: 28ch; }
.muted { color: var(--muted); }
.mono { font-size: .85rem; }
.pager { display: flex; align-items: center; gap: .6rem; margin-top: .8rem; color: var(--muted); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: #1f6b52; }
.badge.warn { color: var(--warn); border-color: #7a6226; }
.badge.bad { color: var(--danger); border-color: #6b2b32; }
.badge.info { color: var(--accent); border-color: #2c4f85; }

.state { padding: 1.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.state.error { color: var(--danger); border-color: #6b2b32; }
.msg-error { color: var(--danger); margin: .5rem 0; }
.msg-warn { color: var(--warn); margin: .5rem 0; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .4rem 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs button { border: none; border-radius: 6px 6px 0 0; background: none; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--panel); box-shadow: inset 0 -2px 0 var(--accent); }
.picker { border: 1px solid var(--border); border-radius: 6px; padding: .6rem; margin-bottom: .8rem; }
.picker .line { display: flex; gap: .5rem; margin-bottom: .5rem; }
.picker .line input { flex: 1; }
.picker .line:last-child { margin-bottom: 0; }
.picker legend { color: var(--muted); font-size: .85rem; padding: 0 .3rem; }
fieldset.picker { min-width: 0; }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
.dlg-head { padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); font-weight: 700; }
.dlg-body { padding: 1rem 1.1rem; }
.dlg-foot { padding: .8rem 1.1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.secret-box { font-size: 1.25rem; letter-spacing: .06em; padding: .8rem; background: #0b0e13; border: 1px solid var(--warn); border-radius: 6px; text-align: center; user-select: all; overflow-wrap: anywhere; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; max-width: min(420px, 92vw); }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: .6rem .9rem; border-radius: 6px; overflow-wrap: anywhere; }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 720px) {
  main { padding: .8rem; }
  .topbar { padding: .5rem .8rem; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .nav a { transition: background-color .12s, border-color .12s; }
}
