:root {
  --bg: #09090b;
  --bg-1: #0f0f12;
  --bg-2: #16161b;
  --bg-3: #1f1f25;
  --border: #27272a;
  --text: #f4f4f5;
  --text-dim: #a1a1aa;
  --text-mute: #71717a;
  --accent: #10b981;
  --accent-2: #34d399;
  --accent-dim: rgba(16, 185, 129, .15);
  --danger: #f87171;
  --warn: #f59e0b;
  --link: #93c5fd;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo { font-size: 22px; }
.title {
  font-family: var(--font-mono);
  font-weight: 700; font-size: 18px;
  letter-spacing: -.02em;
}
.tag { color: var(--text-mute); font-size: 13px; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--bg-2); }
.tab.active {
  color: var(--text);
  background: var(--bg-2);
  border-color: var(--border);
}

main { padding: 24px; max-width: 1280px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

.controls {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: end;
  margin-bottom: 16px;
}
.ctrl-group { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.ctrl-group.grow { flex: 1 1 200px; }
.ctrl-group label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .05em; }
.ctrl-group select, .ctrl-group input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.ctrl-group select:focus, .ctrl-group input:focus {
  border-color: var(--accent);
}
.btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { background: var(--bg-3); }
.btn.ghost { background: transparent; }

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; }

.leaderboard-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-1);
}
.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.leaderboard thead {
  background: var(--bg-2);
  position: sticky; top: 0;
}
.leaderboard th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-mute);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.leaderboard th.num, .leaderboard td.num { text-align: right; font-family: var(--font-mono); }
.leaderboard th.rank, .leaderboard td.rank { width: 50px; text-align: center; font-family: var(--font-mono); color: var(--text-mute); }
.leaderboard tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.leaderboard tbody tr:hover { background: var(--bg-2); }
.leaderboard tbody tr:last-child { border-bottom: none; }
.leaderboard td { padding: 10px 12px; vertical-align: middle; }
.agent-cell { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
.agent-name { font-weight: 600; color: var(--text); }
.agent-login { font-family: var(--font-mono); font-size: 11px; color: var(--text-mute); }
.agent-vendor { display: inline-block; font-size: 10px; padding: 2px 6px; border-radius: 3px; background: var(--bg-3); color: var(--text-dim); margin-top: 2px; width: max-content; }
.dim { color: var(--text-mute); }
.danger { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--accent-2); }
.pos { color: var(--accent-2); }
.zero { color: var(--text-mute); }
.loading {
  text-align: center;
  color: var(--text-mute);
  padding: 32px;
}
.error {
  text-align: center;
  color: var(--danger);
  padding: 32px;
}

.badge-cell a { font-family: var(--font-mono); font-size: 11px; }

/* Sparkline (inline SVG) */
.sparkline { display: inline-block; vertical-align: middle; }
.sparkline-large { width: 100%; height: 100px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px; }
.sparkline-large svg { width: 100%; height: 100%; }

/* Feed */
.feed-header { margin-bottom: 16px; }
.feed-header h2 { margin: 0 0 4px; font-size: 18px; }
.feed-header p { margin: 0; }
.muted { color: var(--text-mute); }
.feed-list {
  list-style: none; padding: 0; margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-1);
}
.feed-list li {
  display: flex; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.feed-list li:last-child { border-bottom: none; }
.feed-list .who {
  flex: 0 0 160px;
  display: flex; flex-direction: column; gap: 2px;
}
.feed-list .who .name { font-weight: 600; font-size: 13px; }
.feed-list .who .vendor { font-size: 11px; color: var(--text-mute); }
.feed-list .what { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.feed-list .what .title { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-list .what .meta { font-size: 11px; color: var(--text-mute); font-family: var(--font-mono); }
.feed-list .when { flex: 0 0 110px; text-align: right; font-size: 11px; color: var(--text-mute); font-family: var(--font-mono); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: stretch; justify-content: flex-end; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-panel {
  position: relative;
  background: var(--bg-1);
  width: min(720px, 100%);
  height: 100%;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding: 28px 32px;
  box-shadow: -8px 0 32px rgba(0,0,0,.4);
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: transparent; border: none; color: var(--text-mute);
  font-size: 28px; cursor: pointer; padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.bot-header h2 { margin: 0; font-size: 22px; }
.bot-sub { color: var(--text-mute); margin: 4px 0 0; font-size: 13px; }
.bot-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 20px 0;
}
.bot-kpis .kpi { background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.bot-kpis .kpi .l { font-size: 10px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .05em; }
.bot-kpis .kpi .v { font-family: var(--font-mono); font-size: 18px; font-weight: 600; }
.bot-section { margin-top: 24px; }
.bot-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); margin: 0 0 10px; font-weight: 600; }
.repo-list { padding: 0; margin: 0; list-style: none; }
.repo-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-family: var(--font-mono); font-size: 12px; }
.repo-list li:last-child { border-bottom: none; }
.repo-list li .n { color: var(--accent-2); }
.pr-list { padding: 0; margin: 0; list-style: none; }
.pr-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.pr-list li:last-child { border-bottom: none; }
.pr-list .title { display: block; font-size: 13px; color: var(--text); }
.pr-list .meta { font-size: 11px; color: var(--text-mute); font-family: var(--font-mono); }

#methodology-frame { width: 100%; height: calc(100vh - 200px); border: 1px solid var(--border); border-radius: 8px; background: var(--bg-1); }

.footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  color: var(--text-mute);
  font-size: 12px;
  margin-top: 32px;
}

@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 16px; }
  main { padding: 16px; }
  .tag { display: none; }
  .feed-list li { flex-direction: column; }
  .feed-list .when { text-align: left; }
  .agent-cell { min-width: 140px; }
  .modal-panel { width: 100%; padding: 20px 16px; }
}
