:root {
  --bg: #fff;
  --bg2: #f8f9fa;
  --bg3: #e9ecef;
  --text: #1a1a2e;
  --text2: #495057;
  --border: #dee2e6;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --star: #f59e0b;
  --star-empty: #d1d5db;
  --pill-bg: #e0e7ff;
  --pill-text: #4338ca;
  --free: #10b981;
  --pro: #f59e0b;
  --max: #ef4444;
  --row-hover: #f1f4f8;
  --detail-bg: #fff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

[data-theme="dark"] {
  --bg: #0f1123;
  --bg2: #1a1d33;
  --bg3: #252845;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --border: #2d3154;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --pill-bg: #1e1b4b;
  --pill-text: #a5b4fc;
  --star-empty: #374151;
  --row-hover: #1e2038;
  --detail-bg: #1a1d33;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

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

body {
  font-family: var(--font);
  background: var(--bg2);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

header h1 { font-size: 1.3rem; font-weight: 700; }

.subtitle {
  font-size: 0.85rem;
  color: var(--text2);
  margin-top: 0.25rem;
}
.subtitle a { color: var(--accent); text-decoration: none; }
.subtitle a:hover { text-decoration: underline; }

.pricing-note {
  margin-top: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: var(--bg3);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text2);
}
.note-badge { margin-right: 0.25rem; }

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-icon { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.4rem 0.55rem; font-size: 1rem; cursor: pointer; color: var(--text); transition: background 0.2s; }
.btn-icon:hover { background: var(--bg3); }
.btn-small { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: 0.35rem 0.65rem; font-size: 0.8rem; cursor: pointer; font-weight: 600; transition: background 0.2s; }
.btn-small:hover { background: var(--accent-hover); }

nav.controls {
  position: sticky;
  top: 76px;
  z-index: 99;
  background: var(--bg2);
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.search-bar { width: 100%; }
.search-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  font-family: var(--font);
}
.search-input:focus { border-color: var(--accent); }

.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-pill {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  border-radius: 100px;
  font-size: 0.8rem;
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  font-family: var(--font);
}
.filter-pill:has(input:checked) {
  background: var(--pill-bg);
  color: var(--pill-text);
  border-color: var(--accent);
}
.filter-pill input { display: none; }

.filter-select {
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text2);
  flex-wrap: wrap;
  gap: 0.5rem;
}

main { padding: 1rem 1.5rem; max-width: 100%; }

.table-container {
  overflow-x: auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 1500px;
  table-layout: auto;
}

thead { position: sticky; top: 0; z-index: 1; }

th {
  background: var(--bg2);
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: default;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--accent); }
th.sorted-asc::after { content: " ▲"; font-size: 0.65rem; color: var(--accent); }
th.sorted-desc::after { content: " ▼"; font-size: 0.65rem; color: var(--accent); }

td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { transition: background 0.15s; cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.expanded { background: var(--bg3); }

.model-name { font-weight: 600; color: var(--accent); white-space: nowrap; }
.provider-tag { font-size: 0.75rem; color: var(--text2); }

.cap-badges { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.cap-badge {
  display: inline-block; width: 22px; height: 22px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; background: var(--bg3); transition: all 0.2s;
}
.cap-badge.active { background: var(--pill-bg); }

.stars { display: flex; gap: 1px; white-space: nowrap; }
.star { color: var(--star-empty); font-size: 0.9rem; }
.star.filled { color: var(--star); }

.tier-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 100px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; }
.tier-badge.free { background: #d1fae5; color: #065f46; }
.tier-badge.pro { background: #fef3c7; color: #92400e; }
.tier-badge.max { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .tier-badge.free { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .tier-badge.pro { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .tier-badge.max { background: #7f1d1d; color: #fca5a5; }

.mono { font-family: var(--mono); font-size: 0.8rem; }

.score-bar-wrap { display: flex; align-items: center; gap: 0.35rem; min-width: 70px; }
.score-bar { flex: 1; height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.score-fill.high { background: #10b981; }
.score-fill.mid { background: #f59e0b; }
.score-fill.low { background: #ef4444; }

.detail-row { display: none; }
.detail-row.open { display: table-row; }
.detail-row td { padding: 0; border-bottom: 2px solid var(--accent); }

.detail-panel {
  background: var(--detail-bg); padding: 1rem 1.25rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem;
  font-size: 0.82rem;
}
.detail-section h4 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text2); margin-bottom: 0.4rem; }
.detail-section p { margin-bottom: 0.25rem; color: var(--text2); }
.detail-section strong { color: var(--text); }

.bench-grid { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.5rem; font-size: 0.78rem; }
.bench-grid span:nth-child(odd) { color: var(--text2); }
.bench-grid span:nth-child(even) { text-align: right; font-family: var(--mono); font-weight: 600; }

.rating-full label { display: block; font-size: 0.75rem; color: var(--text2); margin-bottom: 0.05rem; }

/* ── Sources Section ──────────────────────────────────── */
.sources-section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.sources-section h2 { font-size: 1.1rem; margin-bottom: 1rem; }

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.source-card {
  padding: 1rem;
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.source-card:hover { border-color: var(--accent); }
.source-card h3 { font-size: 0.85rem; margin-bottom: 0.35rem; color: var(--accent); }
.source-card p { font-size: 0.78rem; color: var(--text2); line-height: 1.5; }
.source-card a { display: inline-block; margin-top: 0.4rem; font-size: 0.78rem; color: var(--accent); text-decoration: none; }
.source-card a:hover { text-decoration: underline; }

.citation-note {
  padding: 0.75rem 1rem;
  background: var(--bg3);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text2);
}
.citation-note a { color: var(--accent); text-decoration: none; }
.citation-note a:hover { text-decoration: underline; }
.citation-note code { font-family: var(--mono); font-size: 0.75rem; background: var(--bg2); padding: 0.1rem 0.3rem; border-radius: 3px; }

/* ── Footer ───────────────────────────────────────────── */
footer {
  text-align: center; padding: 1.5rem; font-size: 0.75rem;
  color: var(--text2); border-top: 1px solid var(--border);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.no-results { text-align: center; padding: 2rem; color: var(--text2); }

@media (max-width: 768px) {
  header { padding: 0.75rem 1rem; }
  header h1 { font-size: 1.1rem; }
  nav.controls { padding: 0.5rem 1rem; top: 58px; }
  main { padding: 0.5rem; }
  table { font-size: 0.75rem; min-width: 1000px; }
  .detail-panel { grid-template-columns: 1fr; }
  .sources-grid { grid-template-columns: 1fr; }
  .sources-section { padding: 1rem; }
}

/* ── Compare Overlay ──────────────────────────────────── */
.compare-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.compare-overlay.hidden { display: none; }

.compare-panel {
  background: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.compare-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.compare-header h2 { font-size: 1.1rem; }
.compare-header-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-text {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
}
.btn-text:hover { background: var(--border); }

.compare-scroll {
  overflow: auto;
  flex: 1;
  padding: 0;
}
.compare-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.compare-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 600px;
}
.compare-table thead { position: sticky; top: 0; z-index: 2; }
.compare-table thead th {
  background: var(--bg2);
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.compare-table .cmp-model {
  text-align: center;
  min-width: 140px;
}
.compare-table .cmp-metric {
  font-weight: 600;
  white-space: nowrap;
  text-align: left;
  min-width: 160px;
  color: var(--text2);
  font-size: 0.78rem;
}

.compare-table td {
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
  transition: background 0.2s;
}

/* Color-coded cells — subtle, not overpowering */
.compare-table td.best { background: rgba(16, 185, 129, 0.08); }
.compare-table td.worst { background: rgba(239, 68, 68, 0.06); }
[data-theme="dark"] .compare-table td.best { background: rgba(16, 185, 129, 0.14); }
[data-theme="dark"] .compare-table td.worst { background: rgba(239, 68, 68, 0.12); }

/* Group headers */
.cmp-group-header td {
  background: var(--bg2) !important;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 0.85rem;
  border-bottom: 2px solid var(--border);
}

.compare-footer {
  padding: 0.6rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.compare-hint {
  font-size: 0.72rem;
  color: var(--text2);
}

/* ── Checkbox Column ─────────────────────────────────── */
.cb-col { width: 36px; text-align: center; }
.cb-col input { cursor: pointer; accent-color: var(--accent); }
.cb-cell { text-align: center; padding: 0.3rem; }
.cb-cell input { cursor: pointer; accent-color: var(--accent); }
.compare-table .star-num { font-size: 0.7rem; color: var(--text2); }
