:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #18212c;
  --border: #243042;
  --text: #e6edf3;
  --muted: #8b98a9;
  --faint: #5b6778;
  --pos: #22c55e;
  --neg: #ef4444;
  --amber: #f59e0b;
  --accent: #38bdf8;
  --grey: #6b7280;
  --b-wt: #38bdf8;
  --b-wa: #a78bfa;
  --b-wd: #f472b6;
  --b-ls: #2dd4bf;
  --b-mb: #fb923c;
  --b-unk: #9ca3af;
  --radius: 12px;
  --gap: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin-bottom: 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--text); }
.warn-text { color: var(--amber); }
.mono { font-family: var(--mono); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 22px; display: flex; flex-direction: column; gap: 10px;
}
.login-logo { align-self: flex-start; }
.login-card h1 { font-size: 22px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
input, select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font: inherit; min-height: 40px; width: 100%;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--neg); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--surface-2);
  color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; font: inherit;
  cursor: pointer; min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #05202c; font-weight: 600; margin-top: 10px; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; color: var(--muted); border: 0; padding: 6px 12px; font: inherit; font-size: 13px;
  cursor: pointer; min-height: 32px;
}
.seg button.on { background: var(--surface-2); color: var(--text); }

/* ---------- top bar */
.banner {
  background: var(--neg); color: #fff; font-weight: 800; text-align: center; padding: 10px 16px;
  letter-spacing: .08em; position: sticky; top: 0; z-index: 30;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: .04em; border: 1px solid var(--border); background: var(--surface-2);
}
.badge-paper { background: #1e3a2a; border-color: #2c6b45; color: #86efac; }
.badge.ok { color: #86efac; border-color: #2c6b45; }
.badge.bad { background: var(--neg); color: #fff; border-color: var(--neg); }
.badge.unknown { color: var(--amber); border-color: var(--amber); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 12.5px; color: var(--muted); background: var(--surface-2);
  white-space: nowrap;
}
.chip.good { color: #86efac; border-color: #2c6b45; }
.chip.amber { color: var(--amber); border-color: #7a5410; }
.chip.bad { color: #fca5a5; border-color: #7f1d1d; }
.chip-active { color: #86efac; border-color: #2c6b45; }
.chip-active:hover { text-decoration: none; }
.refresh { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.on { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- tabs */
.tabs {
  display: flex; gap: 2px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  display: inline-flex; align-items: center; gap: 6px; padding: 11px 12px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; font-size: 14px;
}
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.l-short { display: none; }
.tab-chips { display: inline-flex; gap: 2px; min-height: 18px; align-items: center; }

/* ---------- layout */
main { padding: 16px; max-width: 1280px; margin: 0 auto; padding-bottom: 40px; }
.tab { display: none; }
.tab.on { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  margin-bottom: var(--gap); min-width: 0;
}
.grid { display: grid; gap: var(--gap); margin-bottom: var(--gap); }
.grid > .card { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sec-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 12px; }
.card > .sec-head { margin-top: 0; }
.sec-head h2 { margin-right: auto; }
.sec-head .sec-chips + .seg, .sec-head h2 + .seg { margin-left: auto; }
.sec-chips { display: inline-flex; gap: 4px; min-height: 22px; align-items: center; }
.note {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 12px; color: var(--muted); font-size: 13.5px; margin: 0 0 12px;
}
.skeleton { height: 90px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.5s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
.inline-error {
  color: #fca5a5; background: #2a1215; border: 1px solid #7f1d1d; border-radius: 8px; padding: 6px 10px;
  font-size: 13px; margin: 6px 0;
}
.inline-warn {
  color: #fcd34d; background: #2a210c; border: 1px solid #7a5410; border-radius: 8px; padding: 6px 10px;
  font-size: 13px; margin: 6px 0;
}

/* ---------- hero */
.hero-big { font-size: 44px; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.hero-sub { display: flex; flex-wrap: wrap; gap: 18px 28px; margin-top: 12px; }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .val { font-size: 19px; font-weight: 600; }
.hero-eq { margin-top: 12px; color: var(--muted); }
.hero-eq strong { color: var(--text); }

/* ---------- book cards */
.book-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.book-head h3 { margin: 0; font-size: 18px; }
.light { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; background: var(--grey); }
.light.green { background: var(--pos); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.light.amber { background: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.light.red { background: var(--neg); box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); }
.light.grey { background: var(--grey); }
.state { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.state.active { color: #86efac; border-color: #2c6b45; }
.state.winding { color: var(--amber); border-color: #7a5410; }
.big-row { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; margin-bottom: 10px; }
.big-row .big { font-size: 28px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin: 8px 0; }
.kv .lbl { font-size: 12px; color: var(--muted); }
.kv .val { font-weight: 600; }
.now-line { font-size: 13.5px; margin: 10px 0 4px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.foot { font-size: 12.5px; color: var(--muted); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.mini h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; }
.mini p { margin: 0 0 6px; font-size: 13.5px; }

/* ---------- charts */
.chart { position: relative; width: 100%; }
.chart .empty { min-height: 160px; display: grid; place-items: center; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .bars text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .zero-line { stroke: var(--faint); stroke-dasharray: 3 3; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; white-space: nowrap; z-index: 5;
}
.tip .row { display: flex; gap: 8px; align-items: center; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.sw-0 { background: #60a5fa; } .sw-1 { background: #c084fc; } .sw-2 { background: #fbbf24; } .sw-3 { background: #f472b6; }
.sw-total { background: #e5e7eb; }
.bars svg { display: block; width: 100%; height: auto; }
.bars .bar-pos { fill: var(--pos); } .bars .bar-neg { fill: var(--neg); }
.bars .lbl-text { fill: var(--text); }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; background: var(--surface); }
.table td.num, .table th.num { text-align: right; }
.table tr.new td { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: rgba(56, 189, 248, .22); } to { background: transparent; } }
.table tbody tr.new { animation: slide .35s ease-out; }
@keyframes slide { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
.compare td.best { background: rgba(34, 197, 94, .10); font-weight: 700; }
.compare td:first-child { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; border: 1px solid var(--border); }
.pill.yes { color: #86efac; border-color: #2c6b45; }
.pill.no { color: #fca5a5; border-color: #7f1d1d; }
.pill.buy { color: var(--accent); border-color: #1e4f66; }
.pill.sell { color: var(--amber); border-color: #7a5410; }
.pill.sev-info { color: var(--muted); }
.pill.sev-warn { color: var(--amber); border-color: #7a5410; }
.pill.sev-error, .pill.sev-urgent { color: #fff; background: var(--neg); border-color: var(--neg); }
.flag { font-size: 11px; color: var(--amber); margin-left: 4px; }
.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.trunc.open { white-space: normal; max-width: 420px; overflow: visible; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 110px; }
.filters label.grow { flex: 1 1 200px; }
.filters select, .filters input { min-height: 36px; padding: 6px 8px; }
.more { text-align: center; margin-top: 12px; }
.pill-new {
  position: sticky; top: 52px; z-index: 15; display: block; margin: 0 auto 8px; background: var(--accent); color: #05202c;
  border: 0; border-radius: 999px; padding: 7px 16px; font-weight: 700; cursor: pointer; font: inherit; font-weight: 700;
}

/* ---------- positions */
details.grp { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface-2); }
details.grp > summary {
  list-style: none; cursor: pointer; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline;
}
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::before { content: "▸"; color: var(--muted); }
details.grp[open] > summary::before { content: "▾"; }
details.grp > summary .t { font-weight: 600; margin-right: auto; }
details.grp .table-wrap { margin: 0; padding: 0 8px 8px; }
.settle-line { white-space: normal; font-size: 12px; color: var(--muted); max-width: 520px; }

/* ---------- bots */
.bot-card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.bot-card .role { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.bot-card .headline { margin: 8px 0; }
.bot-card ul { margin: 4px 0 8px; padding-left: 18px; }
.bot-card li { margin: 2px 0; font-size: 13.5px; }
.bot-card .sub { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 10px; }
.kvlist { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 13px; margin: 4px 0; }
.kvlist dt { color: var(--muted); }
.kvlist dd { margin: 0; overflow-wrap: anywhere; }
.activity { font-size: 13.5px; margin: 6px 0; color: #bbf7d0; }
.activity.idle { color: var(--muted); }
.server-line { font-size: 12.5px; color: var(--muted); border: 1px dotted var(--muted); border-radius: 8px; padding: 3px 8px; margin: 4px 0; display: inline-block; }
.active-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; color: #86efac;
  border: 1px solid #2c6b45; border-radius: 999px; padding: 1px 8px;
}
.active-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--pos); animation: pulse 1.2s ease-in-out infinite; }
.live-chip { font-size: 11.5px; font-weight: 700; color: #86efac; border: 1px solid #2c6b45; border-radius: 999px; padding: 1px 8px; }
pre.log { font-family: var(--mono); font-size: 12px; background: var(--bg); border-radius: 8px; padding: 8px; overflow-x: auto; margin: 4px 0; white-space: pre; }

/* ---------- bot avatar chips (presence) */
.av {
  width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 9.5px;
  font-weight: 800; color: #0b0f14; position: relative; flex: none; cursor: default; transition: opacity .6s;
  border: 0; padding: 0; font-family: var(--font);
}
.av.fade { opacity: 0; }
.av.notes::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid currentColor;
  animation: ring 1.6s ease-out infinite; color: inherit;
}
.av.server { outline: 2px dotted var(--muted); outline-offset: 1px; }
.av-more { font-size: 11px; color: var(--muted); margin-left: 2px; }
@keyframes ring { from { transform: scale(.9); opacity: .9; } to { transform: scale(1.45); opacity: 0; } }
.b-wt { background: var(--b-wt); color: var(--b-wt); } .b-wa { background: var(--b-wa); color: var(--b-wa); }
.b-wd { background: var(--b-wd); color: var(--b-wd); } .b-ls { background: var(--b-ls); color: var(--b-ls); }
.b-mb { background: var(--b-mb); color: var(--b-mb); } .b-unk { background: var(--b-unk); color: var(--b-unk); }
.av .ini { color: #0b0f14; position: relative; z-index: 1; }
.bot-tag {
  display: inline-block; font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 1px 7px; color: #0b0f14;
  white-space: nowrap;
}
.bot-tag .ini { color: #0b0f14; }
.chipbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chipbar button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 999px;
  padding: 4px 10px; font: inherit; font-size: 12.5px; cursor: pointer; min-height: 30px;
}
.chipbar button.on { color: var(--text); border-color: var(--accent); }

/* ---------- update log */
.updates { list-style: none; padding: 0; margin: 0; }
.updates li {
  display: grid; grid-template-columns: 128px auto auto 1fr; gap: 4px 10px; align-items: baseline;
  padding: 8px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.updates li .tm { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.updates li .tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.updates li.open .tx { white-space: pre-wrap; overflow-wrap: anywhere; }
.updates li .ex { grid-column: 1 / -1; white-space: pre-wrap; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- report dialog + markdown */
.dlg {
  width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
}
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.md { padding: 8px 18px 18px; overflow-wrap: anywhere; }
.md h2, .md h3, .md h4 { margin: 16px 0 6px; }
.md pre { background: var(--bg); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.md blockquote { border-left: 3px solid var(--border); margin: 6px 0; padding-left: 10px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-size: 13.5px; z-index: 50;
  max-width: calc(100vw - 32px);
}

/* ---------- mobile: single column, bottom nav */
@media (max-width: 767px) {
  body { font-size: 14.5px; }
  main { padding: 12px 16px 96px; }
  .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .tabs {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--border); border-bottom: 0;
    padding: 0 0 env(safe-area-inset-bottom); justify-content: space-around; gap: 0; overflow: visible;
  }
  .tabs a {
    flex: 1 1 0; flex-direction: column; gap: 2px; padding: 8px 2px 9px; font-size: 11.5px; border-bottom: 0;
    border-top: 2px solid transparent; min-width: 0;
  }
  .tabs a.on { border-top-color: var(--accent); }
  .l-long { display: none; }
  .l-short { display: inline; }
  .tab-chips .av { width: 15px; height: 15px; font-size: 7px; }
  .hero-big { font-size: 36px; }
  .topbar { padding: 8px 12px; gap: 6px; }
  .tb-left, .tb-right { display: contents; }
  .topbar { justify-content: flex-start; }
  .topbar .badge { order: 0; }
  #logout { order: 1; margin-left: auto; }
  .topbar::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  #active-chip, #hb-chip, .refresh { order: 3; }
  .badge { font-size: 11px; padding: 2px 8px; }
  .chip { font-size: 11.5px; padding: 2px 8px; }
  #logout { min-height: 26px; padding: 2px 8px; font-size: 12px; }
  .refresh #last-refresh { font-size: 12px; }
  .updates li { grid-template-columns: auto auto 1fr; }
  .updates li .tm { grid-column: 1 / -1; }
  .pill-new { top: 8px; }
  .toast { bottom: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
