:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e3e3e6;
  --text: #1b1b1f;
  --muted: #6b6b74;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --gold-bg: #fef6e0;
  --gold-border: #e6c25a;
  --good: #15803d;
  --bad: #b91c1c;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar h1 { font-size: 17px; }

.badge {
  font-size: 12px;
  font-family: var(--mono);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--bg);
}

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* Controls */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-row {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 7px 16px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.corpus-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
select:focus, textarea:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.ask-row { display: flex; gap: 10px; align-items: stretch; }
.ask-row textarea { flex: 1; }

button.primary {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 0 22px;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: default; }

.callout {
  background: var(--accent-soft);
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.callout p { margin: 0; }
.callout p + p { margin-top: 4px; }

.status { font-size: 14px; color: var(--muted); }
.status.error { color: var(--bad); }

.hidden { display: none !important; }

/* Loading overlay */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}
.loading-overlay.error { color: var(--bad); }
.loading-overlay.error .spinner { display: none; }
.loading-overlay p { margin: 0; max-width: 480px; text-align: center; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */

.results {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 1100px) { .results { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px)  { .results { grid-template-columns: 1fr; } }

.arch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.arch-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.arch-name { font-size: 15px; text-transform: capitalize; }
.arch-latency {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
  white-space: nowrap;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
}
.metric .metric-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.metric .metric-value {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
}
.metric .metric-delta { display: block; font-size: 11px; font-family: var(--mono); }
.metric-delta.up { color: var(--good); }
.metric-delta.down { color: var(--bad); }
.metric-delta.flat { color: var(--muted); }

.answer h3, .chunks h3, .metrics-block h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.answer-text { margin: 0; font-size: 14px; line-height: 1.5; }
.answer-text > *:first-child { margin-top: 0; }
.answer-text > *:last-child { margin-bottom: 0; }
.answer-text p { margin: 0 0 8px; }
.answer-text h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 10px 0 4px;
}
.answer-text ul, .answer-text ol { margin: 0 0 8px; padding-left: 20px; }
.answer-text li { margin-bottom: 2px; }
.answer-text code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(127, 127, 127, 0.15);
  padding: 1px 4px;
  border-radius: 3px;
}
.answer-text pre {
  margin: 0 0 8px;
  padding: 8px;
  overflow-x: auto;
  background: rgba(127, 127, 127, 0.12);
  border-radius: 4px;
}
.answer-text pre code { background: none; padding: 0; }

.chunk-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chunk {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
  background: var(--bg);
}
.chunk.gold {
  background: var(--gold-bg);
  border-color: var(--gold-border);
}
.chunk-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.chunk-meta .gold-tag {
  color: #92700c;
  font-weight: 700;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
}
.chunk-snippet { color: var(--text); }

/* Cloudflare Turnstile widget (only rendered when the backend has a site key). */
.turnstile-box { margin-top: 8px; }
.turnstile-box:empty { display: none; }
