/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:        #0e1116;
  --bg-elev:   #161a22;
  --bg-elev-2: #1e2331;
  --border:    #242a38;
  --text:      #e8eaee;
  --text-mute: #8f97a8;
  --accent:    #6ba0ff;
  --accent-2:  #7bffb0;
  --danger:    #ff6b6b;
  --warn:      #f4c56a;

  --comp-a: #7bffb0;
  --comp-b: #a4e878;
  --comp-c: #f4c56a;
  --comp-d: #ff9c6b;
  --comp-e: #ff7f7f;
  --comp-f: #ff5f5f;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);

  --font-body: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #f7f8fa;
    --bg-elev:   #ffffff;
    --bg-elev-2: #f0f2f6;
    --border:    #e2e6ee;
    --text:      #1a1f2b;
    --text-mute: #6b7280;
    --accent:    #2f6fef;
    --accent-2:  #10b981;
    --shadow: 0 8px 32px rgba(20,30,60,0.06);
  }
}

/* ── Base ──────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}
.hidden { display: none !important; }
.muted { color: var(--text-mute); }

h1, h2, h3 { color: var(--text); margin: 0 0 12px; letter-spacing: -0.01em; }
h1 { font-size: 34px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 600; margin-top: 8px; }
h3 { font-size: 17px; font-weight: 600; margin-top: 32px; }

/* ── Header ────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(8px);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 17px;
}
.brand-mark {
  color: var(--accent);
  font-size: 20px;
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

.tabs {
  display: flex; gap: 4px;
}
.tab {
  background: transparent;
  color: var(--text-mute);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); background: var(--bg-elev-2); }
.tab.active { color: var(--text); background: var(--bg-elev-2); }

/* ── Tab panels ────────────────────────────────────────────── */
.tab-panel { display: none; padding: 40px 0 80px; }
.tab-panel.active { display: block; }

/* ── Hero (search) ─────────────────────────────────────────── */
.hero { text-align: center; padding: 40px 0; }
.hero h1 { font-size: 40px; margin-bottom: 12px; }
.hero-sub { color: var(--text-mute); font-size: 17px; max-width: 620px; margin: 0 auto 32px; }
.search-form {
  display: flex; gap: 8px;
  max-width: 720px; margin: 0 auto;
}
.search-form input {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 18px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s;
}
.search-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 24px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-loading { display: none; }
.btn-primary.loading .btn-label { display: none; }
.btn-primary.loading .btn-loading { display: inline; }

.hero-hints {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 20px; flex-wrap: wrap;
}
.hint-label { color: var(--text-mute); font-size: 13px; }
.chip {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 100px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Results ───────────────────────────────────────────────── */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 40px;
}
.rec-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex; flex-direction: column;
}
.rec-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 8px;
}
.rec-subtitle {
  color: var(--text-mute);
  font-size: 15px;
  margin-bottom: 12px;
  font-style: italic;
}
.rec-rationale {
  color: var(--text-mute);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.rec-meta {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  font-size: 13px;
}
.rec-meta span { color: var(--text-mute); }
.rec-meta strong { color: var(--text); font-weight: 600; }

.bundle-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  margin-bottom: 10px;
}
.bundle-list { list-style: none; padding: 0; margin: 0 0 20px; }
.bundle-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.bundle-item:last-child { border-bottom: none; }
.bundle-kw { font-family: var(--font-mono); font-size: 12.5px; }
.bundle-kw.primary { color: var(--accent); font-weight: 600; }
.bundle-type {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 100px;
  background: var(--bg-elev-2);
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.bundle-vol { font-family: var(--font-mono); font-size: 12px; color: var(--text-mute); }

.rec-totals {
  display: flex; gap: 20px;
  padding: 12px 16px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}
.rec-totals div span { color: var(--text-mute); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.rec-totals div strong { font-size: 16px; color: var(--text); font-weight: 600; }

.rec-actions { display: flex; gap: 8px; margin-top: auto; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.competition-badge {
  display: inline-block;
  width: 20px; height: 20px;
  border-radius: 100px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #0e1116;
  text-align: center; line-height: 20px;
}
.competition-A { background: var(--comp-a); }
.competition-B { background: var(--comp-b); }
.competition-C { background: var(--comp-c); }
.competition-D { background: var(--comp-d); }
.competition-E { background: var(--comp-e); }
.competition-F { background: var(--comp-f); }

/* ── Explore ───────────────────────────────────────────────── */
.explore-header { margin-bottom: 24px; }
.filters {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.filter { display: flex; flex-direction: column; gap: 6px; }
.filter.grow { flex: 1; min-width: 200px; }
.filter label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mute); font-weight: 600; }
.filter input, .filter select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  min-width: 140px;
}
.filter input:focus, .filter select:focus {
  outline: none; border-color: var(--accent);
}

.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  background: var(--bg-elev-2);
  font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-mute);
  position: sticky; top: 0;
}
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--bg-elev-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-size: 12.5px; }
td.center, th.center { text-align: center; }

.pagination {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-top: 20px;
}
.pagination button {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  cursor: pointer;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button:hover:not(:disabled) { border-color: var(--accent); }

/* ── Stats ─────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label { color: var(--text-mute); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; font-family: var(--font-mono); }
.stat-card.loading .stat-value { color: var(--text-mute); }

/* ── Detail overlay ────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadein 0.15s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.detail-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 700px; width: 100%;
  max-height: 85vh; overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
}
.close-btn {
  position: absolute; top: 12px; right: 16px;
  background: transparent; border: none;
  color: var(--text-mute);
  font-size: 24px; line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.close-btn:hover { color: var(--text); }

.detail-header { margin-bottom: 20px; padding-right: 40px; }
.detail-kw {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
  word-break: break-word;
}
.detail-bucket { color: var(--text-mute); font-size: 13px; margin-top: 4px; }
.detail-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}
.detail-metrics div span { font-size: 11px; color: var(--text-mute); text-transform: uppercase; }
.detail-metrics div strong { display: block; font-size: 20px; font-weight: 700; font-family: var(--font-mono); }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-top: 20px;
  border-left: 3px solid;
}
.alert-error { background: rgba(255,107,107,0.1); border-color: var(--danger); color: var(--danger); }

/* ── Footer ────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 60px;
  font-size: 13px;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
  .hero h1 { font-size: 28px; }
  .header-inner { flex-direction: column; gap: 8px; height: auto; padding: 12px 0; }
  .tabs { width: 100%; justify-content: center; }
  .search-form { flex-direction: column; }
  .filter { min-width: 100%; }
}
