:root {
  --bg: #f8f7f4;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e0ddd5;
  --accent: #8b1e1e;       /* BGB-typical deep red */
  --accent-soft: #f5e6e6;
  --ok: #2e7d32;
  --warn: #c77700;
  --tag: #ece9e0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

a { color: var(--accent); }

/* --- top bar --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 2rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--accent); color: #fff;
  font-size: 24px; font-weight: 700;
  border-radius: 8px;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand .subtitle { margin: 0; color: var(--muted); font-size: 12px; }

.status { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 11px;
  background: var(--tag);
  color: var(--muted);
  letter-spacing: 0.02em;
}
.badge.ok { background: #e3f4e4; color: var(--ok); }
.badge.warn { background: #fbe7cf; color: var(--warn); }
.badge.mute { background: var(--tag); }

/* --- layout --- */
main {
  max-width: 920px;
  margin: 2rem auto;
  padding: 0 1rem 4rem;
}

.query-panel {
  background: var(--panel);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1.5rem;
}
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.8rem; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field textarea {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
}
.field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.small { display: flex; flex-direction: column; gap: 0.2rem; font-size: 12px; color: var(--muted); }
.small input { width: 80px; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.small.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; }
.small.checkbox input { width: auto; }

button.primary {
  margin-left: auto;
  padding: 0.55rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover { background: #6d1717; }
button.primary:disabled { opacity: 0.5; cursor: default; }

.htmx-indicator { display: none; color: var(--muted); font-size: 13px; }
.htmx-request .htmx-indicator { display: inline; }

/* --- results --- */
.results { min-height: 200px; }
.result-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
}
.result-card h2 { margin: 0 0 0.5rem; font-size: 16px; }

.meta-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 11px; background: var(--tag); color: var(--muted); }
.chip.detect { background: var(--accent-soft); color: var(--accent); }
.chip.model { background: #e3f4e4; color: var(--ok); }

details { margin: 0.8rem 0; }
details > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  padding: 0.3rem 0;
}
details[open] > summary { color: var(--ink); }

.chunk-list { list-style: decimal; padding-left: 1.5rem; margin: 0.5rem 0; }
.chunk {
  border-left: 3px solid var(--line);
  padding: 0.5rem 0.8rem;
  margin: 0.5rem 0;
  background: #fbfaf7;
  border-radius: 0 4px 4px 0;
}
.chunk.origin-dense     { border-left-color: #6b6b6b; }
.chunk.origin-filter    { border-left-color: var(--accent); background: var(--accent-soft); }
.chunk.origin-expansion { border-left-color: #1c6dd2; }
.chunk.origin-definition{ border-left-color: var(--warn); background: #fdf6ec; }

.chunk-head { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; }
.chunk-head .abs, .chunk-head .nr { color: var(--muted); font-size: 12px; }
.origin-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  color: #fff; background: #6b6b6b; padding: 1px 6px; border-radius: 9px;
}
.chunk.origin-filter .origin-tag    { background: var(--accent); }
.chunk.origin-expansion .origin-tag { background: #1c6dd2; }
.chunk.origin-definition .origin-tag{ background: var(--warn); }
.prov { font-size: 12px; color: var(--muted); font-style: italic; }
.score { margin-left: auto; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }

.chunk-meta { font-size: 11px; color: var(--muted); margin: 0.2rem 0; }
.chunk-text {
  margin: 0.3rem 0 0;
  padding: 0.4rem 0.6rem;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 4px;
  font: 12px/1.45 ui-monospace, "SFMono-Regular", Menlo, monospace;
  white-space: pre-wrap;
  color: #2a2a2a;
}

.answer { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.answer h3 { margin: 0 0 0.4rem; font-size: 14px; color: var(--accent); }
.answer-body {
  white-space: pre-wrap;
  padding: 0.8rem 1rem;
  background: #fbfaf7;
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
}
.stub-note { font-size: 11px; color: var(--warn); font-style: italic; }

.context-text {
  font: 11px/1.45 ui-monospace, monospace;
  white-space: pre-wrap;
  background: #fbfaf7;
  padding: 0.6rem;
  border: 1px dashed var(--line);
  border-radius: 4px;
  max-height: 320px;
  overflow: auto;
}

/* --- footer --- */
footer {
  margin-top: 3rem;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
