:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5a6472;
  --border: #d5dae1;
  --accent: #1f4fc5;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #c62a37;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --surface: #171c23;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #2d343e;
    --accent: #7eb0ff;
    --ok: #4cc264;
    --warn: #e0a928;
    --bad: #ff6b6b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }
h1 { margin: 0; font-size: 1.4rem; }
h2 { margin: 1.5rem 0 .5rem; font-size: 1.05rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* header and navigation */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1.25rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.top nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.top nav a {
  padding: .25rem .65rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.top nav a:hover { background: var(--bg); }
.top nav a[aria-current="page"] { background: var(--bg); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }

main { flex: 1; width: 100%; max-width: 90rem; margin: 0 auto; padding: 1rem; outline: none; }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .75rem; }
.head .spacer { flex: 1; }

/* the always-visible rule #1 */
.rule {
  position: sticky;
  bottom: 0;
  padding: .5rem 1rem;
  background: var(--surface);
  border-top: 3px solid var(--bad);
  font-size: .85rem;
}
.rule p { margin: .1rem 0; }

/* controls */
.btn, select, input[type="search"], input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem .6rem;
}
.btn { cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; border-color: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn-small { padding: .05rem .4rem; font-size: .8rem; white-space: nowrap; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: .75rem; }
.toolbar label { display: inline-flex; align-items: center; gap: .35rem; }
.toolbar input[type="search"] { min-width: 14rem; }

/* messages */
.banner {
  margin: 0 0 .75rem;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--surface);
}
.banner-warn { border-left-color: var(--warn); }
.banner-error { border-left-color: var(--bad); }
.banner-info { border-left-color: var(--accent); }
.banner p { margin: .15rem 0; }
.note { color: var(--muted); font-size: .9rem; margin: .5rem 0; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card { padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.card-label { color: var(--muted); font-size: .85rem; }
.card-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.card-sub { color: var(--muted); font-size: .85rem; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .4rem .65rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
tr.err td { background: color-mix(in srgb, var(--bad) 10%, transparent); }
th .sort {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
th .sort:hover { color: var(--text); }
th[aria-sort="ascending"] .sort::after { content: " \25B2"; }
th[aria-sort="descending"] .sort::after { content: " \25BC"; }
td.err-text { max-width: 22rem; overflow-wrap: anywhere; }
td.urls { max-width: 28rem; overflow-wrap: anywhere; }
td.url-cell { min-width: 20rem; }
.url { display: flex; align-items: flex-start; gap: .4rem; }
.url code { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* badges and chips */
.badge {
  display: inline-block;
  padding: 0 .45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: .78rem;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--muted);
}
.badge-ok { color: var(--ok); }
.badge-warn { color: var(--warn); }
.badge-bad { color: var(--bad); }
.badges { display: flex; flex-wrap: wrap; gap: .2rem; }
.chips { display: inline-flex; flex-wrap: wrap; gap: .25rem; }

/* chain info */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .5rem 1rem; margin: 0 0 1rem; padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.kv div { min-width: 0; }
.kv dt { color: var(--muted); font-size: .8rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .6rem; }

/* the key form */
.key-form { max-width: 28rem; margin: 2rem auto; padding: 1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.key-form label { display: block; margin: .6rem 0 .25rem; }
.key-form input { width: 100%; }
.key-form .actions { display: flex; gap: .5rem; margin-top: .9rem; }

@media (max-width: 40rem) {
  main { padding: .6rem; }
  .top { gap: .3rem .75rem; }
  .top nav { order: 3; flex-basis: 100%; }
  .top .btn { margin-left: auto; }
  .rule { padding: .35rem .6rem; font-size: .72rem; }
  .toolbar input[type="search"] { min-width: 0; flex: 1; }
}
