:root {
  --bg: #eef1f5; --panel: #ffffff; --surface: #f3f5f8; --text: #16202c; --muted: #5b6878;
  --border: #d9dee5; --accent: #1565c0; --ok: #1b873f; --warn: #b26a00; --error: #c62828;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161d; --panel: #18202a; --surface: #222c38; --text: #e8edf3; --muted: #9aa7b6;
    --border: #334152; --accent: #64a6f0; --ok: #3fb866; --warn: #f0a43a; --error: #ef5350;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.btn { display: inline-block; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--error); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.msg { margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.msg.error { background: color-mix(in srgb, var(--error) 12%, transparent); color: var(--error); }
.msg.info { background: var(--surface); color: var(--muted); }

.login { max-width: 360px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input:not([type="checkbox"]), select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); width: 100%; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }

.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px 12px; }
.nav nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav nav a { padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav nav a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 600; }
.content { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 18px; }
.tenant-filter { flex-direction: row; align-items: center; gap: 8px; margin-left: auto; }
.tenant-filter select { width: auto; min-width: 180px; }
.who { color: var(--muted); font-size: 13px; margin-left: auto; }
.tenant-filter:not([hidden]) + .who { margin-left: 0; }
main { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { border-right: none; border-bottom: 1px solid var(--border); }
  .nav nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 12px; }
}

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface); }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface); }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.off { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); }
.usage { display: flex; flex-direction: column; gap: 3px; min-width: 70px; font-variant-numeric: tabular-nums; }
.usage .bar { height: 4px; border-radius: 2px; background: var(--surface); overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--accent); }
.usage.full { color: var(--warn); }
.usage.full .bar i { background: var(--warn); }
.secret { cursor: pointer; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0 0 14px; font-size: 17px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields .wide { grid-column: 1 / -1; }
.fields .hint { font-size: 11px; color: var(--muted); }
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog .msg { margin-top: 12px; }
.list-field { display: flex; flex-direction: column; gap: 6px; }
.list-caption { font-size: 12px; color: var(--muted); }
.list-editor { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.list-editor > div:not(.list-row) { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.list-row { display: grid; grid-template-columns: var(--cols); gap: 6px; align-items: center; width: 100%; }
.list-row input[type="checkbox"] { justify-self: center; }
.list-head span { font-size: 11px; color: var(--muted); }
@media (max-width: 640px) {
  .list-head { display: none; }
  .list-row { grid-template-columns: 1fr 1fr; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
}

dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

ol.events { list-style: none; margin: 0; padding: 4px 0; max-height: calc(100vh - 220px); overflow-y: auto; font-size: 13px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
ol.events li { display: grid; grid-template-columns: 150px 80px minmax(0, 1fr); gap: 8px; padding: 5px 12px; border-left: 3px solid transparent; }
ol.events li[data-level="ok"] { border-left-color: var(--ok); }
ol.events li[data-level="warn"] { border-left-color: var(--warn); }
ol.events li[data-level="error"] { border-left-color: var(--error); }
ol.events li[data-level="error"] .text { color: var(--error); }
ol.events .time { color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
ol.events .src { font-size: 11px; font-weight: 600; }
ol.events .text { overflow-wrap: anywhere; }
