:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #334155;
  --text: #e8eef5;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --user-bg: #1e3a5f;
  --bot-bg: #1f2937;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.status {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface2);
}

.status.ok {
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.status.err {
  color: var(--err);
}

.auth {
  margin-left: auto;
  display: flex;
  align-items: end;
  gap: 0.5rem;
}

.auth label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 0.25rem;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
}

input[type="password"],
input[type="text"] {
  min-width: 12rem;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.tab.active {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

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

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-toolbar label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--muted);
  gap: 0.25rem;
}

.checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

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

h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -0.5rem 0 0.75rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stack-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--muted);
  gap: 0.25rem;
}

.chat-messages {
  min-height: 320px;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.bubble {
  max-width: 85%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bg);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bot-bg);
}

.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 100%;
}

.bubble .meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.sources,
.timing {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.timing {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.7rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

.chat-form textarea {
  resize: vertical;
  min-height: 4rem;
}

.item-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
}

.item-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.item-list .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.item-list button.danger {
  background: var(--err);
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.source-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
}

.source-list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.source-list .meta {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.source-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.35rem;
}

.source-actions button {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.source-actions button.danger {
  background: var(--err);
}

.source-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.log {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  min-height: 4rem;
  color: var(--muted);
}

.ingest-preview {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.ingest-preview h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.preview-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.75rem;
}

.preview-entry {
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.preview-entry h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.preview-entry .preview-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
  margin-bottom: 0.5rem;
}

.preview-entry .preview-error {
  color: var(--err);
  font-size: 0.85rem;
  margin: 0.35rem 0 0;
}

.ingest-preview .source-text,
.chunk-card pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16rem;
  overflow: auto;
}

.chunk-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.chunk-card {
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.chunk-card h4 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.ingest-preview details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  max-width: 24rem;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 100;
}

.toast.err {
  border-color: var(--err);
  color: #fecaca;
}

/* Modellvergleich */
.bench-models {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 260px;
  overflow-y: auto;
}

#benchQuestions {
  width: 100%;
}

#benchSummary,
.bench-question {
  overflow-x: auto;
}

.bench-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 1.25rem;
  font-size: 0.85rem;
}

.bench-table th,
.bench-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.bench-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.bench-table details summary {
  cursor: pointer;
}

.bench-answer {
  white-space: pre-wrap;
  margin-top: 0.4rem;
  color: var(--muted);
}

.bench-question h3 {
  margin: 1rem 0 0.25rem;
  font-size: 0.95rem;
}

.bench-err,
.hint.err {
  color: var(--err);
}

.bench-tag,
.hint.warn {
  color: var(--warn);
}

.bench-tag {
  font-size: 0.75rem;
}

/* Anmeldung: Menü und Inhalt erst nach geprüftem API-Key */
[hidden] {
  display: none !important;
}

.auth-form {
  display: flex;
  align-items: end;
  gap: 0.5rem;
}

.auth-gate {
  max-width: 40rem;
  margin: 3rem auto;
  padding: 1.5rem 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-gate h2 {
  margin-top: 0;
}
