:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5b6573;
  --border: #dfe3e8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #c4312b;
  --danger-soft: #fdecea;
  --ok: #1f7a46;
  --ok-soft: #e5f4ea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #2b323c;
    --accent: #6d93ff;
    --accent-text: #0b1020;
    --accent-soft: #1c2742;
    --danger: #ff7b72;
    --danger-soft: #3a1d1c;
    --ok: #5cd08a;
    --ok-soft: #16301f;
    --warn: #f2c35b;
    --warn-soft: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 13px;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 6px 12px; border-radius: 6px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.crumbs { color: var(--muted); margin-bottom: 4px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-body { padding: 16px 18px; }
.card.danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px 24px; margin: 0; }
.details dt { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.details dd { margin: 0; word-break: break-all; display: flex; gap: 6px; align-items: flex-start; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.icon { padding: 2px 8px; border-color: transparent; background: transparent; color: var(--muted); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

input[type="text"], input[type="password"], input[type="search"], input[type="number"], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 80px; }
textarea.mono, input.mono { font-family: var(--mono); font-size: 13px; }
input:disabled { background: var(--surface-2); color: var(--muted); }
input.search { width: 280px; max-width: 100%; }

.field { margin-bottom: 14px; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; font-weight: 400; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin: 8px 0 0; }
.radio-group { display: grid; gap: 8px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card strong { display: block; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; font: inherit; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.kv-rows { display: grid; gap: 6px; margin-bottom: 6px; }
.kv-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) auto; gap: 6px; align-items: start; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
td .mono, td.mono { word-break: break-all; }
.value-cell { font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-all; }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

pre.value {
  margin: 0; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-all; max-height: 420px; overflow: auto;
}

/* ---------- badges & banners ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

.form-error { color: var(--danger); margin: 8px 0 0; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.login-card .brand { margin-bottom: 20px; font-size: 18px; }
.login-card .btn { width: 100%; padding: 10px; margin-top: 4px; }

/* ---------- modal ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog.modal::backdrop { background: rgba(10, 14, 20, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .topbar { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  th, td { padding: 8px 12px; }
  .kv-row { grid-template-columns: 1fr auto; }
  .kv-row > :nth-child(2) { grid-column: 1; }
  input.search { width: 100%; }
}

/* utilities (no inline styles: CSP forbids them) */
.mt-0 { margin-top: 0; } .mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-10 { margin-top: 10px; } .mt-16 { margin-top: 16px; }
.mb-10 { margin-bottom: 10px; } .mb-12 { margin-bottom: 12px; }
.details.one-col { grid-template-columns: 1fr; }
input.w-90 { width: 90px; display: inline-block; padding: 2px 6px; margin: 0 4px; }
.check { margin-bottom: 0; }
.check.mb-12 { margin-bottom: 12px; }
