:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2128;
  --muted: #5f6b7a;
  --border: #d8dde3;
  --accent: #2457c5;
  --accent-text: #ffffff;
  --hover: #eef2f8;
  --ok-bg: #e7f5ec; --ok: #1d6b3a;
  --warn-bg: #fff4dc; --warn: #7a5300;
  --err-bg: #fdecec; --err: #a3212a;
  --code-bg: #f0f2f5;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --text: #e3e7ec;
    --muted: #8e99a7;
    --border: #2c333c;
    --accent: #6c9cff;
    --accent-text: #0b0e12;
    --hover: #1f252d;
    --ok-bg: #12301f; --ok: #7fd59d;
    --warn-bg: #3a2c0d; --warn: #f1c46b;
    --err-bg: #3b1518; --err: #ff9aa1;
    --code-bg: #1f252d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--code-bg); padding: 0 3px; border-radius: 3px; }
pre { background: var(--code-bg); padding: 8px 10px; border-radius: 6px; overflow: auto; margin: 6px 0; white-space: pre-wrap; word-break: break-word; }
pre.json { max-height: 480px; }
h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
h4 { font-size: 14px; margin: 0; }
h5 { font-size: 12px; margin: 10px 0 4px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
p { margin: 6px 0; }
.dim { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 600; color: var(--text); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 4px 10px; border-radius: 6px; color: var(--text); }
.nav a.active, .nav a:hover { background: var(--hover); text-decoration: none; }
.who { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.who .user { font-weight: 600; }
.exp.warn { color: var(--err); font-weight: 600; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.crumbs { margin: 0; font-size: 12.5px; }

/* controls */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input:not([type]), select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
textarea.sql-edit { min-height: 140px; tab-size: 2; }
button { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .55; cursor: progress; }
a.button { display: inline-block; text-decoration: none; color: inherit; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 7px 16px; }
button.primary, a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
a.button.primary:hover, button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--err); border-color: var(--err); }
button.small, a.small { padding: 2px 8px; font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; flex: 1 1 160px; min-width: 0; }
.field .label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select { width: 100%; }
.check { display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
td .row { margin: 0; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.toolbar input[type=search] { flex: 1 1 220px; }
.filters { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; align-items: flex-start; }
.filter { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 4px 0; }
.pager { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.spacer { flex: 1; }

/* layout blocks */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 10px 0; min-width: 0; }
.card.sub { background: var(--bg); padding: 8px 10px; }
.card > h3:first-child { margin-top: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.split { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; }
.side-list ul { list-style: none; padding: 0; margin: 8px 0; }
.side-list li a { display: block; padding: 3px 8px; border-radius: 5px; font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.side-list li a.active { background: var(--hover); font-weight: 600; }
.grow { min-width: 0; }
.rel-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.block { margin: 14px 0; }
.kpi { font-size: 28px; font-weight: 600; font-family: var(--mono); }
.preview { margin: 6px 0; }
.signin { max-width: 640px; margin: 24px auto; }
.stats { font-size: 12.5px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.broken { margin: 4px 0; padding-left: 18px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: 10px; scrollbar-width: thin; }
.tabs a { padding: 7px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* tables */
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); margin: 6px 0; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; box-shadow: inset 0 -1px 0 var(--border); font-size: 12.5px; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
table.grid td { font-family: var(--mono); font-size: 12.5px; white-space: pre; max-width: 480px; overflow: hidden; text-overflow: ellipsis; }
table.grid td.num { text-align: right; }
table.grid td.null { color: var(--muted); font-style: italic; opacity: .7; }
table.grid td.json { color: var(--muted); }
th .type { display: block; font-weight: 400; color: var(--muted); font-family: var(--mono); font-size: 11px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: var(--hover); }
th .arrow { color: var(--accent); }
table.list td { font-size: 13px; }
.empty { color: var(--muted); padding: 8px; margin: 0; }

/* badges and messages */
.badge { display: inline-block; padding: 0 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--hover); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.error { background: var(--err-bg); color: var(--err); border-color: transparent; }
.badge.dim { opacity: .75; }
.msg { padding: 8px 10px; border-radius: 6px; margin: 8px 0; word-break: break-word; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.error { background: var(--err-bg); color: var(--err); }
.msg .code { font-family: var(--mono); font-size: 12px; opacity: .8; }
.loading { color: var(--muted); padding: 8px 0; }
.loading::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); z-index: 10; box-shadow: 0 4px 16px rgba(0,0,0,.18); border-radius: 6px; }
.toast .msg { margin: 0; }
.snippet { display: flex; gap: 6px; align-items: flex-start; }
.snippet pre { flex: 1; margin: 4px 0; }
.snippet button { margin-top: 6px; }
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 6px 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }
details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 6px; }

@media (max-width: 720px) {
  main { padding: 10px; }
  .split { grid-template-columns: 1fr; }
  .who { margin-left: 0; width: 100%; }
  .cols { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: 4px; }
}
