/* ============================================================
   Capper Aggregator — dark theme dashboard
   ============================================================ */

:root {
  --bg: #0f1419;
  --surface: #1a1f29;
  --surface2: #222936;
  --border: #2a3140;
  --text: #e1e5ec;
  --muted: #8a92a3;
  --accent: #5eead4;
  --positive: #22c55e;
  --negative: #ef4444;
  --warning: #f59e0b;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.tab {
  padding: 6px 14px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { background: var(--surface2); color: var(--text); }
.tab.active { background: var(--accent); color: #0f1419; font-weight: 700; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.last-updated { font-size: 12px; color: var(--muted); }

.btn-refresh {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.btn-refresh:hover { background: var(--border); }

/* ── Main content ── */
main { padding: 24px 20px; max-width: 1200px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.visible { display: block; }

/* ── Cards ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.card-value.positive { color: var(--positive); }
.card-value.negative { color: var(--negative); }
.card-value.accent { color: var(--accent); }

/* ── Section titles ── */
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Tables ── */
.tbl-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

th:hover { color: var(--accent); }
th.sort-asc::after { content: " ▲"; font-size: 10px; }
th.sort-desc::after { content: " ▼"; font-size: 10px; }

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

tr:nth-child(even) td { background: var(--surface2); }
tr:hover td { background: var(--border); }

.td-pos { color: var(--positive); }
.td-neg { color: var(--negative); }
.td-accent { color: var(--accent); }
.td-muted { color: var(--muted); }

/* ── Event cards (upcoming / consensus) ── */
.event-cards { display: grid; gap: 12px; }

.event-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.event-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.event-name { font-weight: 600; font-size: 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.badge-accent { background: rgba(94,234,212,.15); color: var(--accent); }
.badge-muted  { background: rgba(138,146,163,.15); color: var(--muted); }
.badge-pos    { background: rgba(34,197,94,.15);  color: var(--positive); }
.badge-neg    { background: rgba(239,68,68,.15);  color: var(--negative); }
.badge-warn   { background: rgba(245,158,11,.15); color: var(--warning); }

.variants { display: flex; flex-direction: column; gap: 6px; }

.variant-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 8px;
  background: var(--surface2);
  border-radius: 6px;
}

.variant-pick { flex: 1; color: var(--text); }
.variant-meta { color: var(--muted); }

/* ── Fade indicator ── */
.fade-yes { color: var(--negative); font-weight: 700; }
.fade-no  { color: var(--positive); }

/* ── Stat header card (Fade tab) ── */
.stat-header {
  display: flex;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-item label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.stat-item span  { font-size: 22px; font-weight: 700; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar label { font-size: 13px; color: var(--muted); }

.filter-bar input[type=range] { accent-color: var(--accent); }

.filter-bar input[type=checkbox] { accent-color: var(--accent); }

/* ── Loading / empty states ── */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}

.loading::before { content: "⏳ "; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* ── Rank-by toggle ── */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Override section-title margin when inside section-title-row */
.section-title-row .section-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.rank-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rank-toggle-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}

.rank-btn {
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.rank-btn:hover { background: var(--border); color: var(--text); }
.rank-btn.rank-btn-active {
  background: rgba(94,234,212,.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Paper Bet tab ── */
.pb-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.pb-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.pb-field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.pb-field input,
.pb-field select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 13px;
  min-width: 80px;
}

.pb-field input:focus,
.pb-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-run {
  background: var(--accent);
  color: #0f1419;
  border: none;
  border-radius: var(--radius);
  padding: 7px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-run:hover { opacity: 0.85; }

.pb-results { }

.pb-balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.pb-balance-main {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 6px;
}

.pb-balance-sub {
  font-size: 15px;
  font-weight: 600;
}

.pb-stats-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 13px;
  font-weight: 500;
}

/* ── Paper Bet v2 additions ── */
.pb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pb-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.pb-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1419;
  font-weight: 600;
}

.pb-chip:hover:not(.active) {
  border-color: var(--accent);
  color: var(--text);
}

.pb-mode {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.pb-mode-insample {
  background: rgba(255, 180, 0, 0.15);
  color: #c8900a;
  border: 1px solid rgba(255, 180, 0, 0.35);
}

.pb-mode-fwd {
  background: rgba(0, 200, 120, 0.12);
  color: #00c87a;
  border: 1px solid rgba(0, 200, 120, 0.3);
}

.pb-warn {
  background: rgba(255, 180, 0, 0.1);
  border: 1px solid rgba(255, 180, 0, 0.4);
  border-radius: var(--radius);
  color: #c8900a;
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.btn-optimize {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  margin-left: 8px;
}
.btn-optimize:hover { background: rgba(94, 234, 212, .12); opacity: 1; }

.pb-warn-soft {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 14px;
}

.pb-best-row {
  background: rgba(94, 234, 212, .08);
}
.pb-best-row:hover { background: rgba(94, 234, 212, .14); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px; }
  .tab-nav { order: 3; width: 100%; }
  main { padding: 16px 12px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .stat-header { flex-direction: column; gap: 12px; }
}
