:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --accent: #c8102e;
  --border: #e2e2dd;
  --user-bg: #eef1f6;
  --ok: #2e7d32;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ececea;
    --muted: #9a9a94;
    --accent: #ff4d5e;
    --border: #33332f;
    --user-bg: #262a33;
    --ok: #66bb6a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 860px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header { padding: 24px 0 8px; border-bottom: 1px solid var(--border); }
h1 { margin: 0; font-size: 1.5rem; color: var(--accent); }
.subtitle { margin: 4px 0 0; color: var(--muted); }

/* AI disclosure shown at the start of every session (Anthropic usage policy) */
.ai-notice {
  margin: 12px 0 0; padding: 10px 14px; font-size: 0.85rem; line-height: 1.45;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px;
}
.ai-label { margin: 10px 0 0; font-size: 0.75rem; color: var(--muted); }

/* Account bar and e-mail login */
.account { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.link-button {
  padding: 0; font: inherit; color: var(--accent); background: none; border: 0; cursor: pointer;
  text-decoration: underline;
}
/* The login form is a plain block, not the sticky flex bar used for the question composer. */
form.login { display: block; position: static; margin: 24px 0; padding: 16px; max-width: 560px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.login label { display: block; margin-bottom: 10px; }
.login button { white-space: nowrap; }
#code-step { margin-top: 8px; }
.login-row { display: flex; gap: 8px; }
.login input {
  flex: 1; padding: 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.login button { padding: 10px 16px; }
[hidden] { display: none !important; }

main { flex: 1; padding: 16px 0; display: flex; flex-direction: column; gap: 12px; }

.msg { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border); overflow-wrap: anywhere; }
.msg.user { background: var(--user-bg); align-self: flex-end; max-width: 85%; white-space: pre-wrap; }
.msg.assistant { background: var(--surface); }
.msg.error { border-color: var(--accent); color: var(--accent); }

/* Research status panel */
.status {
  margin-bottom: 12px; padding: 8px 12px; font-size: 0.85rem; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.status-head { display: flex; align-items: center; gap: 10px; }
.status-text { color: var(--text); overflow-wrap: anywhere; }
.status.finished .status-text, .status.failed .status-text { color: var(--muted); }
.spinner {
  flex: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.status.finished .spinner, .status.failed .spinner { display: none; }
.status.finished .status-head::before { content: "✓"; color: var(--ok); font-weight: 700; }
.status.failed .status-head::before { content: "✕"; color: var(--accent); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.status-steps { margin-top: 6px; }
.status-steps summary { cursor: pointer; }
/* Custom counter so interim notes are not numbered. */
.status-steps ol { margin: 6px 0 0; padding-left: 4px; list-style: none; counter-reset: step; }
.step { margin: 2px 0; }
.step:not(.note) { counter-increment: step; }
.step:not(.note)::before { content: counter(step) ". "; font-variant-numeric: tabular-nums; }
.step.running::before { color: var(--accent); font-weight: 700; }
.step.done::after { content: " ✓"; color: var(--ok); }
.step.failed::after { content: " ✕ fehlgeschlagen"; color: var(--accent); }
.step.note { font-style: italic; opacity: 0.8; }
/* Sources under an answer */
.sources { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.9rem; }
.sources h4 { margin: 0 0 6px; font-size: 0.9rem; }
.sources ul { margin: 0 0 6px; padding-left: 20px; }
.sources li { margin: 2px 0; }
.sources a { color: var(--accent); font-weight: 600; text-decoration: none; }
.sources a:hover { text-decoration: underline; }
.sources details { color: var(--muted); }
.sources summary { cursor: pointer; }
.version-note { margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); }

.notice { font-size: 0.85rem; color: var(--muted); margin-top: 8px; }

form { display: flex; gap: 8px; padding: 12px 0; position: sticky; bottom: 0; background: var(--bg); }
textarea {
  flex: 1; resize: vertical; padding: 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
button {
  padding: 0 20px; font: inherit; font-weight: 600; color: #fff;
  background: var(--accent); border: 0; border-radius: 8px; cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: wait; }

footer { padding: 8px 0 16px; font-size: 0.8rem; color: var(--muted); text-align: center; }
footer p { margin: 2px 0; }
.credit { font-weight: 600; }
