:root {
  --bg: #0b1020; --bg2: #111830; --panel: #141c36; --line: #24304f; --fg: #dbe3f4; --dim: #8a97b4;
  --acc: #38bdf8; --acc2: #f472b6; --err: #f87171; --warn: #fbbf24; --ok: #34d399; --info: #60a5fa; --debug: #a78bfa;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f7fb; --bg2: #eef1f7; --panel: #fff; --line: #dfe4ee; --fg: #18223a; --dim: #5d6b88; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 13px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
a { color: var(--acc); text-decoration: none; }
button, select, input, textarea {
  font: inherit; color: var(--fg); background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px;
}
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--acc); }
button.primary { background: var(--acc); color: #04111d; border-color: var(--acc); font-weight: 600; }
button.icon { padding: 4px 8px; }
button:disabled { opacity: .5; cursor: default; }
input:focus, textarea:focus, select:focus { outline: 1px solid var(--acc); }
textarea, .mono, code { font-family: var(--mono); font-size: 12px; }
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--bg2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--fg); font-size: 15px; }
nav { display: flex; gap: 2px; }
nav a, .top > a.icon { color: var(--dim); padding: 5px 10px; border-radius: 6px; }
nav a.on, nav a:hover, .top > a.icon:hover { color: var(--fg); background: var(--panel); }
.spacer { flex: 1; }
.timectl { display: flex; gap: 6px; }
main { padding: 14px 16px 40px; }
h1 { font-size: 18px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 14px; margin: 18px 0 8px; color: var(--dim); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.dim { color: var(--dim); }
.err { color: var(--err); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.qbox { display: flex; gap: 8px; align-items: stretch; margin-bottom: 10px; }
.qbox textarea { flex: 1; min-height: 38px; resize: vertical; }
.meta { font-size: 12px; color: var(--dim); margin: 6px 0; }
.banner { padding: 8px 12px; border-radius: 8px; margin: 8px 0; background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); white-space: pre-wrap; }
.banner.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--dim); font-weight: 600; font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; margin: 6px 0; }
.tabs button.on { border-color: var(--acc); color: var(--acc); }

/* charts */
.chart { position: relative; width: 100%; }
.chart canvas { display: block; width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; max-height: 64px; overflow: auto; margin-top: 4px; }
.legend span { cursor: pointer; white-space: nowrap; color: var(--dim); display: inline-flex; align-items: center; gap: 5px; }
.legend span.off { opacity: .35; }
.legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; max-width: 460px; box-shadow: 0 6px 20px #0006; }
.tip div { display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tip i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tip b { margin-left: auto; padding-left: 10px; font-variant-numeric: tabular-nums; }

/* dashboards */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); grid-auto-rows: 34px; gap: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.panel .ph { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
.panel .ph .dim { font-weight: 400; }
.panel .ph a { margin-left: auto; font-weight: 400; font-size: 11px; opacity: 0; }
.panel:hover .ph a { opacity: 1; }
.panel .pb { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.panel .pb .chart { flex: 1; min-height: 0; }
.stat { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 0; }
.stat .v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat canvas { width: 100%; height: 34px; }
.vars { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.vars label { display: flex; gap: 6px; align-items: center; color: var(--dim); }
.rowtitle { grid-column: 1 / -1; font-weight: 600; color: var(--dim); align-self: end; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.dlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.dlist a.card { color: var(--fg); display: block; }
.dlist a.card:hover { border-color: var(--acc); }
.tag { display: inline-block; font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; margin: 4px 4px 0 0; }

/* logs */
.logs { display: grid; grid-template-columns: 220px 1fr; gap: 12px; }
.lbrowser { max-height: calc(100vh - 140px); overflow: auto; font-size: 12px; }
.lbrowser details { margin-bottom: 4px; }
.lbrowser summary { cursor: pointer; color: var(--dim); padding: 2px 0; }
.lbrowser .chip { display: inline-block; margin: 2px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbrowser .chip:hover { border-color: var(--acc); }
.vol { height: 110px; }
.lv { position: relative; overflow: auto; height: calc(100vh - 330px); min-height: 240px; font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.lv .sz { position: relative; }
.lr { position: absolute; left: 0; right: 0; height: 20px; line-height: 20px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 3px solid transparent; }
.lr:hover { background: var(--bg2); }
.lr .t { color: var(--dim); margin-right: 8px; }
.lr .s { color: var(--acc); margin-right: 8px; }
.lr.error, .lr.fatal { border-left-color: var(--err); }
.lr.warn { border-left-color: var(--warn); }
.lr.info { border-left-color: var(--info); }
.lr.debug, .lr.trace { border-left-color: var(--debug); }
.ldetail { position: fixed; right: 16px; top: 60px; bottom: 16px; width: min(560px, 45vw); z-index: 10; overflow: auto; box-shadow: 0 10px 30px #0008; }
.ldetail pre { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12px; margin: 6px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.kv span:nth-child(odd) { color: var(--dim); }
.kv span.f { cursor: pointer; }
.kv span.f:hover { text-decoration: underline; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--bg2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; z-index: 30; }
.modal { position: fixed; inset: 0; background: #0009; display: flex; align-items: center; justify-content: center; z-index: 25; }
.modal .card { width: min(900px, 94vw); max-height: 90vh; display: flex; flex-direction: column; gap: 8px; }
.modal textarea { min-height: 50vh; width: 100%; }
.empty { color: var(--dim); text-align: center; padding: 30px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--err) 20%, transparent); color: var(--err); }
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .grid > * { grid-column: 1 / -1 !important; }
  .logs { grid-template-columns: 1fr; }
  .lbrowser { max-height: 160px; }
  nav a { padding: 5px 6px; }
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-top: 12px; align-items: start; }
.cards h2 { margin: 0 0 8px; }
table.kvt td { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1 button { font-size: 13px; font-weight: 500; }
