:root {
  --bg: #0f1117;
  --surface: #1a1d28;
  --surface-2: #232734;
  --border: #2e3344;
  --text: #e4e7ef;
  --text-dim: #8b90a3;
  --accent: #6c8cff;
  --accent-dim: #4a6a8a;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface-2: #f1f3f8;
    --border: #e0e4ee;
    --text: #1a1d28;
    --text-dim: #6b7280;
    --accent: #4361ee;
    --accent-dim: #8597c8;
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

header h1 { font-size: 1.8rem; font-weight: 700; }
.subtitle { color: var(--text-dim); margin-top: 0.3rem; font-size: 0.95rem; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }

/* ── Controls ─────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.control-group { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; min-width: 160px; }
.control-group label { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }

select, input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
select:focus, input:focus { border-color: var(--accent); }

/* ── Token inputs ──────────────────────────────────────── */
.token-inputs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.usage-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.usage-summary #tokenBreakdown { font-variant-numeric: tabular-nums; }
.pct-ok { color: var(--green); font-weight: 600; }
.pct-warn { color: var(--yellow); font-weight: 600; }
.total-field input { font-size: 1.1rem; font-weight: 600; }

.token-field { display: flex; flex-direction: column; gap: 0.2rem; }
.token-field label { font-size: 0.85rem; font-weight: 600; }
.token-field input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s;
}
.token-field input[type="number"]:focus { border-color: var(--accent); }
.token-field small { font-size: 0.75rem; color: var(--text-dim); }

.presets { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1rem; }
.preset-label { font-size: 0.8rem; color: var(--text-dim); }
.presets button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.presets button:hover { border-color: var(--accent); color: var(--accent); }

/* ── Results ───────────────────────────────────────────── */
.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.results-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1rem; }
.last-updated { font-size: 0.78rem; color: var(--text-dim); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.6rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
.empty { text-align: center; color: var(--text-dim); padding: 2rem; }

.rank { color: var(--text-dim); font-weight: 600; width: 2rem; }
.cheapest { color: var(--green); font-weight: 700; font-size: 0.75rem; }
.provider-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.org-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.cost { font-weight: 700; }
.cost-zero { color: var(--green); }
.missing { color: var(--text-dim); font-style: italic; }

/* ── Footer ────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.footer-links a { color: var(--accent); text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  header { padding: 1.5rem 1rem 1rem; }
  header h1 { font-size: 1.4rem; }
  .controls { flex-direction: column; }
  .control-group { min-width: 100%; }
}
