:root {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-input: #1e2230;
  --border: #2a2f3d;
  --text: #e8e9ee;
  --text-muted: #9aa0b0;
  --primary: #6366f1;
  --primary-hover: #7577f5;
  --accent: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; width: 100%; }

/* ---- Nav ---- */
.navbar { border-bottom: 1px solid var(--border); background: var(--bg-elevated); }
.nav-inner { max-width: 1300px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 20px; }
.nav-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.logo-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link { padding: 8px 12px; border-radius: 8px; color: var(--text-muted); font-size: 0.92rem; }
.nav-link:hover { background: var(--bg-input); color: var(--text); }
.nav-auth { display: flex; align-items: center; gap: 12px; }
.nav-credit-pill { background: var(--bg-input); border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.nav-username { color: var(--text-muted); font-size: 0.88rem; }
.nav-link--cta, .nav-link--signout { background: var(--primary); color: #fff; }
.nav-link--cta:hover, .nav-link--signout:hover { background: var(--primary-hover); }

.flash { max-width: 1300px; margin: 10px auto 0; padding: 0 20px; }
.flash p { margin: 6px 0; padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; }
.flash--error p { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.4); color: #fca5a5; }
.flash--success p { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.35); color: #86efac; }

/* ---- Buttons / forms ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); font-size: 0.9rem; cursor: pointer; }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: #fca5a5; }
.btn-full { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
input, select, textarea { background: var(--bg-input); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 0.9rem; font-family: inherit; }
label { font-size: 0.82rem; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.main-content { flex: 1; padding: 20px 0 40px; }
.empty-card { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ---- Chat ---- */
.chat-container { display: flex; gap: 16px; height: calc(100vh - 130px); max-width: 1300px; margin: 0 auto; padding: 16px 20px 0; }
.chat-sidebar { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.model-select-wrap { display: flex; flex-direction: column; gap: 4px; }
.model-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: 0.68rem; padding: 2px 6px; border-radius: 999px; background: var(--bg-input); border: 1px solid var(--border); color: var(--text-muted); }
.est-cost { font-size: 0.78rem; color: var(--text-muted); }
.chat-convo-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-convo-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; color: var(--text-muted); gap: 6px; }
.chat-convo-item:hover, .chat-convo-item.active { background: var(--bg-input); color: var(--text); }
.chat-convo-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-convo-delete { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; }
.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.chat-empty-state { margin: auto; color: var(--text-muted); text-align: center; }
.chat-msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 0.92rem; white-space: pre-wrap; }
.chat-msg--user { align-self: flex-end; background: var(--primary); color: #fff; }
.chat-msg--assistant { align-self: flex-start; background: var(--bg-input); border: 1px solid var(--border); }
.chat-msg-meta { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 0.75rem; color: var(--text-muted); }
.chat-msg-meta button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; }
.chat-msg-meta button.active { color: var(--accent); }
.chat-input-form { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input { flex: 1; resize: none; }
.chat-error { align-self: center; color: #fca5a5; font-size: 0.85rem; }

/* ---- Compare ---- */
.compare-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.compare-models-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.compare-model-chip { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; font-size: 0.85rem; }
.compare-model-chip.selected { border-color: var(--primary); background: rgba(99,102,241,0.15); }
.compare-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.compare-result-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.compare-result-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.85rem; font-weight: 600; }
.compare-result-body { font-size: 0.88rem; white-space: pre-wrap; line-height: 1.5; max-height: 340px; overflow-y: auto; }
.compare-result-meta { margin-top: 8px; font-size: 0.75rem; color: var(--text-muted); display: flex; justify-content: space-between; }

/* ---- Tables (usage/admin) ---- */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-wrap { overflow-x: auto; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.78rem; color: var(--text-muted); }
h1, h2, h3 { font-weight: 700; }
h2 { margin-top: 32px; }
section { margin-bottom: 28px; }

/* ---- Admin shell ---- */
.admin-shell { display: flex; max-width: 1400px; margin: 0 auto; gap: 20px; padding: 20px; }
.admin-sidebar { width: 190px; flex-shrink: 0; display: flex; flex-direction: column; gap: 2px; }
.admin-nav-link { padding: 8px 12px; border-radius: 8px; font-size: 0.86rem; color: var(--text-muted); }
.admin-nav-link:hover { background: var(--bg-input); color: var(--text); }
.admin-content { flex: 1; min-width: 0; }

.site-footer { text-align: center; padding: 16px; font-size: 0.75rem; color: var(--text-muted); border-top: 1px solid var(--border); }

@media (max-width: 800px) {
  .chat-container { flex-direction: column; height: auto; }
  .chat-sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .chat-convo-list { display: none; }
  .admin-shell { flex-direction: column; }
  .admin-sidebar { flex-direction: row; overflow-x: auto; width: 100%; }
}
