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

:root {
  --bg: #0d0f14;
  --bg2: #141720;
  --bg3: #1c1f2e;
  --bg4: #242838;
  --border: #2a2e3f;
  --text: #e2e4f0;
  --text2: #8b90a8;
  --text3: #5a5f75;
  --accent: #6c8aff;
  --accent2: #4a6bff;
  --green: #3dd68c;
  --red: #f06292;
  --yellow: #ffca62;
  --orange: #ff8c5a;
  --purple: #b48eff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

html, body { background: var(--bg); color: var(--text); min-height: 100vh; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.link-muted { color: var(--text2); font-size: 13px; font-weight: 500; }
.link-muted:hover { color: var(--text); text-decoration: none; }
.muted { color: var(--text2); font-size: 13px; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 18px 28px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f06292, #ff8c5a);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff; font-weight: 700;
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.01em; }
.brand-tag { font-size: 12px; color: var(--text2); margin-top: 2px; }
.topbar-right { display: flex; gap: 18px; }

/* Container */
.container { max-width: 1280px; margin: 0 auto; padding: 28px; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-card[data-key="total_cost_usd"] .stat-value { color: var(--red); }
.stat-card[data-key="last_7_days"] .stat-value { color: var(--yellow); }
.stat-card[data-key="total"] .stat-value { color: var(--accent); }
.stat-card[data-key="distinct_vendors"] .stat-value { color: var(--purple); }

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--bg2), var(--bg3));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--red), var(--orange));
}
.hero-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--red);
  font-weight: 700;
  margin-bottom: 14px;
}
.hero-body { display: grid; grid-template-columns: auto 1fr auto; gap: 22px; align-items: center; }
.hero-favicon {
  border-radius: 12px;
  background: var(--bg4);
  padding: 6px;
  width: 64px; height: 64px;
  object-fit: contain;
}
.hero-company { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.hero-tool { font-size: 16px; color: var(--text2); margin-bottom: 8px; }
.hero-meta { font-size: 18px; color: var(--red); font-weight: 600; margin-bottom: 6px; }
.hero-reason { font-style: italic; color: var(--purple); font-size: 14px; max-width: 600px; }
.hero-actions { display: flex; flex-direction: column; gap: 8px; }

/* Filters */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  align-items: center;
}
.filters input[type=text], .filters select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.filters input[type=text]:focus, .filters select:focus { border-color: var(--accent); }
.filters input[type=text] { flex: 1; min-width: 260px; }
.filters select { min-width: 140px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  padding: 0 6px;
}
.toggle input { accent-color: var(--accent); }

/* Card */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 22px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.table-card { padding: 18px 20px; }
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.table-meta { font-size: 12px; color: var(--text3); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}
th.num { text-align: right; }
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }
.td-company { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.td-favicon { width: 22px; height: 22px; border-radius: 5px; background: var(--bg4); object-fit: contain; flex-shrink: 0; }
.td-company-name { font-weight: 600; }
.td-tool { max-width: 280px; }
.td-reason { color: var(--text2); max-width: 320px; font-style: italic; }
.td-truncate { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.td-date { color: var(--text3); font-size: 12px; white-space: nowrap; }
.td-source { color: var(--text2); font-size: 12px; }
.td-source a { color: var(--text2); }
.td-source a:hover { color: var(--accent); }

/* Pills */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-left: 6px;
  vertical-align: 1px;
  text-transform: uppercase;
}
.pill-yellow { background: rgba(255,202,98,0.18); color: var(--yellow); }
.pill-green { background: rgba(61,214,140,0.15); color: var(--green); }
.pill-source {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  background: var(--bg4);
  color: var(--text2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent2); }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg4); }
.btn-ghost { background: transparent; color: var(--text2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px 0 4px; color: var(--text2); font-size: 12px; }

/* Two col */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

/* Leaderboard list */
.lb-list { list-style: none; counter-reset: lb; }
.lb-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  counter-increment: lb;
}
.lb-list li:last-child { border-bottom: none; }
.lb-list li::before {
  content: counter(lb);
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg3);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--text2);
  flex-shrink: 0;
}
.lb-co { font-weight: 600; }
.lb-tool { color: var(--text2); font-size: 12.5px; }
.lb-stat { margin-left: auto; color: var(--red); font-weight: 700; white-space: nowrap; font-size: 13px; }
.lb-stat.life { color: var(--orange); }
.lb-favicon { width: 22px; height: 22px; border-radius: 5px; background: var(--bg4); object-fit: contain; }

/* Collapsible */
.collapsible-toggle {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  font-family: inherit;
}
.collapsible-toggle:hover { color: var(--accent); }
.collapsible-toggle .caret { color: var(--text3); font-size: 14px; }
.collapsible-body { padding-top: 16px; }

/* Submit */
.form-row-stack { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.form-row-stack input[type=url] { grid-column: 1; }
.form-row-stack input[type=text] { grid-column: 1; }
.form-row-stack button { grid-column: 2; grid-row: 1 / span 2; align-self: stretch; padding: 0 24px; }
.form-row-stack input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
  width: 100%;
}
.form-row-stack input:focus { border-color: var(--accent); }
.submit-msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.submit-msg.ok { color: var(--green); }
.submit-msg.err { color: var(--red); }

/* Sources list */
.sources-list { display: flex; flex-direction: column; gap: 10px; }
.source-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) 1.5fr auto;
  gap: 14px;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  align-items: center;
  font-size: 13px;
}
.source-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.source-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.source-dot.green { background: var(--green); }
.source-dot.red { background: var(--red); }
.source-dot.grey { background: var(--text3); }
.source-url { font-size: 11px; color: var(--text3); font-family: 'SF Mono','Fira Code',monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-meta { color: var(--text2); font-size: 12px; text-align: right; white-space: nowrap; }
.source-meta strong { color: var(--text); font-weight: 600; }

/* Footer */
.footer { text-align: center; padding: 30px 0 10px; color: var(--text3); font-size: 12px; }

/* Toast */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  background: var(--bg4);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  max-width: 360px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.err { border-left-color: var(--red); color: var(--red); }
#toast.ok { border-left-color: var(--green); }

/* Empty state */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text2);
}
.empty .empty-title { font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* Mobile-ish niceties */
@media (max-width: 700px) {
  .container { padding: 18px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .hero-body { grid-template-columns: 1fr; }
  .hero-actions { flex-direction: row; }
  .topbar-inner { padding: 14px 18px; gap: 10px; }
  .brand-tag { display: none; }
  .td-tool, .td-reason { max-width: 200px; }
}
