:root {
  --bg: #0b0d10;
  --bg-elev: #11141a;
  --bg-elev2: #181c24;
  --bg-elev3: #202632;
  --text: #e8eef6;
  --text-dim: #9aa5b8;
  --text-faint: #5e687a;
  --border: #232936;
  --border-strong: #2d3442;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --green: #22c55e;
  --green-dim: #16a34a;
  --red: #f87171;
  --red-dim: #dc2626;
  --amber: #f59e0b;
  --amber-dim: #d97706;
  --violet: #a78bfa;
  --cyan: #22d3ee;
  --rose: #fb7185;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.45);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { 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.45;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green-dim), var(--cyan));
  color: #06130d;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: -0.03em;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-tagline {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 12px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.status-pill.status-live::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-pill.status-stale::before { background: var(--amber); }
.status-pill.status-fallback::before { background: var(--red); }
.status-pill.status-loading::before { background: var(--cyan); animation: pulse 1.2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-time {
  color: var(--text-dim);
  font-size: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .08s;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:hover:not(:disabled) { background: var(--bg-elev3); border-color: var(--text-faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { background: var(--green-dim); color: #05140a; border-color: var(--green-dim); }
.btn-primary:hover:not(:disabled) { background: var(--green); border-color: var(--green); }

.btn-refresh { color: var(--cyan); border-color: var(--cyan); background: rgba(34,211,238,0.08); }
.btn-refresh:hover:not(:disabled) { background: rgba(34,211,238,0.16); }

.btn-ghost { background: transparent; color: var(--text-dim); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-elev2); }

.btn-toggle { padding: 6px 10px; font-size: 15px; }
.btn-toggle.active { background: var(--bg-elev3); color: var(--accent-2); border-color: var(--accent); }

.btn-close { padding: 6px 9px; font-size: 13px; color: var(--text-dim); }

/* Workload bar */
.workload-bar {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.workload-row {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.workload-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 140px;
  min-width: 130px;
}

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
}

input[type="number"], input[type="search"], input[type="text"], input[type="range"] {
  background: var(--bg-elev2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

input[type="number"]:focus, input[type="search"]:focus, input[type="text"]:focus, input[type="range"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

input[type="number"] { font-family: var(--font-mono); text-align: right; }
input[type="search"] { width: 100%; }
input[type="range"] { width: 100%; padding: 0; height: 6px; accent-color: var(--accent); }

.workload-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  color: var(--text-dim);
  font-size: 13px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card.cheap { border-left: 3px solid var(--green); }
.stat-card.new { border-left: 3px solid var(--cyan); }
.stat-card.free { border-left: 3px solid var(--violet); }
.stat-card.save { border-left: 3px solid var(--amber); }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-dim);
}

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  margin-top: 16px;
  flex: 1;
}

.filters {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  height: fit-content;
  position: sticky;
  top: 16px;
}

.filter-search { margin-bottom: 16px; }

.filter-group { margin-bottom: 18px; }
.filter-group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
}

.filter-check, .filter-chip, .sort-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.filter-check input { accent-color: var(--accent); }

.filter-chips, .sort-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip, .sort-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  font-size: 12px;
  transition: background .12s, border-color .12s, color .12s;
}

.filter-chip:hover, .sort-chip:hover { border-color: var(--text-faint); color: var(--text); }

.filter-chip.active, .sort-chip.active {
  background: rgba(59,130,246,0.14);
  border-color: var(--accent);
  color: var(--accent-2);
}

.filter-range { display: block; font-size: 13px; color: var(--text-dim); }

.filter-actions { display: flex; gap: 8px; margin-top: 20px; }

/* Results */
.results {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-width: 0;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.results-count { font-size: 13px; color: var(--text-dim); }

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-height: 70vh;
  overflow-y: auto;
}

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

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elev3);
  color: var(--text-dim);
  font-weight: 700;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.data-table th.numeric { text-align: right; }

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tr {
  cursor: pointer;
  transition: background .08s;
}

.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table tbody tr:focus-within { background: rgba(59,130,246,0.08); outline: none; }

.model-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.model-avatar {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800;
  color: rgba(255,255,255,0.92);
  text-transform: uppercase;
  flex: 0 0 auto;
}

.model-name { display: flex; flex-direction: column; }
.model-title { font-weight: 600; color: var(--text); }
.model-slug { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }

.provider-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.provider-logo {
  width: 16px; height: 16px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-elev3);
}

.price {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.price-free { color: var(--green); }
.price-cheap { color: #86efac; }
.price-mid { color: var(--text); }
.price-high { color: var(--red); }

.savings {
  color: var(--amber);
  font-weight: 600;
  font-family: var(--font-mono);
}

.spread {
  color: var(--text-dim);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-elev3);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.badge-green { color: var(--green); border-color: rgba(34,197,94,0.3); }
.badge-amber { color: var(--amber); border-color: rgba(245,158,11,0.3); }
.badge-red { color: var(--red); border-color: rgba(248,113,113,0.3); }
.badge-cyan { color: var(--cyan); border-color: rgba(34,211,238,0.3); }
.badge-violet { color: var(--violet); border-color: rgba(167,139,250,0.3); }

/* Cards view */
.cards-wrap.hidden, .table-wrap.hidden, .empty-state.hidden { display: none; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.model-card {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-card:hover { border-color: var(--accent); background: var(--bg-elev3); }

.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.card-prices { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.card-price-block { display: flex; flex-direction: column; gap: 2px; }
.card-price-label { font-size: 10px; color: var(--text-faint); text-transform: uppercase; }
.card-price-value { font-family: var(--font-mono); font-weight: 700; font-size: 15px; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }

/* Detail panel */
.detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 5vh 16px;
  overflow-y: auto;
}

.detail-backdrop.hidden { display: none; }

.detail-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(900px, 100%);
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 { margin: 0; font-size: 18px; }

.detail-body {
  padding: 16px;
  overflow-y: auto;
}

.detail-section { margin-bottom: 18px; }
.detail-section h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

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

.provider-table th, .provider-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.provider-table th.numeric, .provider-table td.numeric { text-align: right; }
.provider-table th { color: var(--text-dim); font-weight: 700; }

.detail-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Compare bar */
.compare-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  z-index: 90;
  max-height: 280px;
  display: flex;
  flex-direction: column;
}

.compare-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.compare-head h3 { margin: 0; font-size: 14px; }

.compare-body {
  padding: 12px 16px;
  overflow-x: auto;
  display: flex;
  gap: 14px;
}

.compare-col {
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg-elev2);
}

.compare-col h4 { margin: 0 0 8px; font-size: 14px; }

/* Footer & toast */
.site-footer {
  margin-top: 24px;
  padding: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 13px;
  z-index: 200;
  transform: translateY(120%);
  transition: transform .25s ease-out;
}

.toast.show { transform: translateY(0); }

/* Responsive */
@media (max-width: 980px) {
  .main { grid-template-columns: 1fr; }
  .filters { position: static; }
  .workload-row { gap: 12px; }
  .table-wrap { max-height: none; }
}

@media (max-width: 640px) {
  .app { padding: 10px; }
  .top-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .status-bar { justify-content: space-between; }
  .brand h1 { font-size: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .results-header { flex-direction: column; align-items: stretch; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .provider-pill { font-size: 11px; }
  .model-cell { min-width: 160px; }
  .cards-grid { grid-template-columns: 1fr; }
  .detail-panel { padding: 0; border-radius: var(--radius); max-height: 95vh; }
}

@media (max-width: 460px) {
  .brand { gap: 8px; }
  .brand-mark { width: 34px; height: 34px; font-size: 13px; }
  .stats-grid { grid-template-columns: 1fr; }
  .filter-actions { flex-direction: column; }
  .workload-field { flex: 1 1 100%; }
}

/* Accessibility */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sort-chip[aria-checked="true"], .filter-chip[aria-checked="true"] { background: rgba(59,130,246,0.14); border-color: var(--accent); color: var(--accent-2); }
