:root {
  --bg: #0b0f17;
  --bg-elev: #111827;
  --bg-card: #151d2e;
  --bg-input: #0e1422;
  --border: #243047;
  --border-strong: #344566;
  --text: #e5ecf6;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --purple: #8b5cf6;
  --purple-soft: rgba(139, 92, 246, 0.16);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, textarea, select {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand-badge {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
}
.brand small {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  line-height: 1.1;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elev);
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--border);
}
.nav-tab {
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-tab.active { background: var(--accent); color: #fff; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.pill-btn:hover { border-color: var(--border-strong); background: #1a2438; }

.credits-pill {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.08);
}
.credits-pill .amount { color: #34d399; font-weight: 700; font-variant-numeric: tabular-nums; }
.credits-pill.error { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.08); }
.credits-pill.error .amount { color: #f87171; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot.green { background: var(--green); box-shadow: 0 0 8px rgba(16, 185, 129, 0.7); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

/* Layout */
.app-shell {
  max-width: 1620px;
  margin: 0 auto;
  padding: 16px 18px 40px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.split-layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 980px) {
  .split-layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: #1b2538; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success {
  background: var(--green);
  border-color: var(--green);
  color: #052e16;
  font-weight: 600;
}
.btn-danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.45);
  color: #f87171;
}
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 11.5px; }

/* Inputs */
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Model Picker */
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 8px;
}
.model-chip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  position: relative;
}
.model-chip:hover { border-color: var(--border-strong); }
.model-chip.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.4);
}
.model-chip.local.selected {
  border-color: var(--purple);
  background: rgba(139, 92, 246, 0.14);
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.45);
}
.model-chip-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.model-chip-name { font-weight: 600; font-size: 13px; }
.model-chip-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.tier-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}
.tier-flash { background: var(--green-soft); color: #34d399; }
.tier-frontier { background: var(--amber-soft); color: #fbbf24; }
.tier-local { background: var(--purple-soft); color: #c4b5fd; }
.tier-custom { background: var(--accent-soft); color: #93c5fd; }

/* Sidebar History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}
.history-item {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.15s;
}
.history-item:hover { border-color: var(--border-strong); }
.history-item.active { border-color: var(--accent); background: rgba(59, 130, 246, 0.1); }
.history-item-title {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

/* Parallel Responses Grid */
.responses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
@media (max-width: 600px) {
  .responses-grid { grid-template-columns: 1fr; }
}

.response-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.response-card.winner {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}
.response-card.error {
  border-color: rgba(239, 68, 68, 0.5);
}

.resp-head {
  padding: 10px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.resp-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 20, 34, 0.6);
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.metric-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 5px;
}
.metric-chip strong { color: var(--text); }
.metric-chip.cost strong { color: #34d399; }

.resp-body {
  padding: 12px 14px;
  flex: 1;
  max-height: 460px;
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.58;
  word-break: break-word;
}
.resp-body pre {
  background: #090d14;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.resp-body code {
  background: rgba(255,255,255,0.07);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12.5px;
}
.resp-body pre code { background: transparent; padding: 0; }
.resp-body p { margin: 0 0 8px; }
.resp-body p:last-child { margin-bottom: 0; }

.reasoning-box {
  margin: 0 12px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(139, 92, 246, 0.06);
}
.reasoning-box summary {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  color: #c4b5fd;
  font-weight: 500;
}
.reasoning-box pre {
  margin: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--text-muted);
  max-height: 180px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.resp-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* Star rating */
.stars { display: inline-flex; gap: 2px; }
.star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
  color: #334155;
  transition: transform 0.1s, color 0.1s;
}
.star-btn.filled, .star-btn:hover { color: #fbbf24; }
.star-btn:hover { transform: scale(1.15); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-green { background: var(--green-soft); color: #34d399; }
.badge-amber { background: var(--amber-soft); color: #fbbf24; }
.badge-red { background: var(--red-soft); color: #f87171; }
.badge-blue { background: var(--accent-soft); color: #93c5fd; }
.badge-purple { background: var(--purple-soft); color: #c4b5fd; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.data-table th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg-elev);
}
table.data-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Score bar */
.score-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}
.score-bar-track {
  flex: 1;
  height: 8px;
  background: #1e293b;
  border-radius: 99px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kpi-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 18px; font-weight: 700; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Progress bar */
.progress-track {
  width: 100%;
  height: 10px;
  background: #1e293b;
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  transition: width 0.25s;
}

/* Question editor row */
.q-editor-row {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 16px; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.toast.ok { border-left: 4px solid var(--green); }
.toast.err { border-left: 4px solid var(--red); }

.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Print styles for reports */
@media print {
  body { background: #fff !important; color: #111 !important; }
  .no-print { display: none !important; }
  .card, .kpi-card {
    background: #fff !important;
    border-color: #cbd5e1 !important;
    color: #111 !important;
    break-inside: avoid;
  }
  table.data-table th { background: #f1f5f9 !important; color: #334155 !important; }
  table.data-table td, table.data-table th { border-color: #cbd5e1 !important; color: #111 !important; }
  .muted { color: #475569 !important; }
}
