:root {
  --paper: #f1f4f7;
  --surface: #ffffff;
  --surface-2: #e6ecf1;
  --ink: #10222e;
  --ink-soft: #4e6070;
  --ink-faint: #7c8d9b;
  --rule: #c9d4de;
  --accent: #17558c;
  --accent-ink: #ffffff;
  --danger: #a63d2e;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0c1820;
    --surface: #12242f;
    --surface-2: #1a303d;
    --ink: #dde8ef;
    --ink-soft: #9cb0be;
    --ink-faint: #6d8394;
    --rule: #294452;
    --accent: #4f97cf;
    --accent-ink: #06131b;
    --danger: #e07c6b;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.55rem 1.1rem;
  border-radius: 2px;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }
button.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--rule);
  padding: 0.4rem 0.8rem;
  font-size: 0.88rem;
}
button.ghost:hover { color: var(--ink); border-color: var(--ink-faint); filter: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------- Anmeldeseite */

body.centered { display: grid; place-items: center; padding: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 2.25rem 2rem;
  width: min(400px, 100%);
}
.brand {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 1.25rem;
}
.card h1 { font-size: 1.5rem; margin: 0 0 1.5rem; letter-spacing: -0.01em; }
.card label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}
.card input {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.7rem;
  margin-bottom: 1.1rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.card button[type="submit"] { width: 100%; margin-top: 0.25rem; }
.card .hint { font-size: 0.82rem; color: var(--ink-faint); margin: 1.25rem 0 0; }
.error {
  background: transparent;
  border-left: 3px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem 0.85rem;
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

/* -------------------------------------------------------------- Grundriss */

.layout { display: flex; height: 100%; }

.sidebar {
  width: 270px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
}
.sidebar-head { padding: 1.25rem 1rem 0.75rem; border-bottom: 1px solid var(--rule); }
.sidebar-head .brand { margin-bottom: 0.85rem; }
.sidebar-head button { width: 100%; }

.conversations { flex: 1; overflow-y: auto; padding: 0.5rem; }
.conversations button {
  display: block;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  border-radius: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversations button:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.conversations button[aria-current="true"] {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-foot { border-top: 1px solid var(--rule); padding: 0.9rem 1rem; }
.sidebar-foot .who { margin: 0; font-size: 0.9rem; }
.sidebar-foot .meta {
  margin: 0.1rem 0 0.75rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
}
.sidebar-foot button { width: 100%; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}
.topbar h1 {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#toggle-sidebar { display: none; }

/* -------------------------------------------------------------- Nachrichten */

.messages { flex: 1; overflow-y: auto; padding: 2rem 1.5rem; }

.empty { max-width: 60ch; margin: 3rem auto; color: var(--ink-soft); }
.empty h2 { color: var(--ink); font-size: 1.35rem; margin: 0 0 0.6rem; }
.empty p { margin: 0; }

.msg { max-width: 74ch; margin: 0 auto 1.75rem; }
.msg .role {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}
.msg .body { overflow-wrap: anywhere; }
.msg.user .body {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 0.8rem 1rem;
}
.msg.assistant .role { color: var(--accent); }
.msg .body pre {
  background: var(--surface-2);
  border: 1px solid var(--rule);
  padding: 0.8rem 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.86rem;
  white-space: pre;
  margin: 0.75rem 0;
}
.msg .body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
}
.msg .body pre code { background: none; padding: 0; font-size: inherit; }

.msg.error .body {
  border-left: 3px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem 0.85rem;
}

.cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1.1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .cursor::after { animation: none; }
}

/* --------------------------------------------------------------- Eingabe */

.composer {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--rule);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  font: inherit;
  resize: none;
  max-height: 40vh;
  padding: 0.65rem 0.8rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
  line-height: 1.5;
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  #toggle-sidebar { display: inline-block; }
  .messages { padding: 1.25rem 1rem; }
  .composer { padding: 0.75rem 1rem 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* Zeile in der Gesprächsliste: Titel plus Löschen bei Hover/Fokus */
.conv-row { display: flex; align-items: stretch; }
.conv-row .conv-title { flex: 1; min-width: 0; }
.conv-row .conv-del {
  flex: none;
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  padding: 0 0.55rem;
  font-size: 1rem;
  line-height: 1;
}
.conv-row:hover .conv-del,
.conv-row:focus-within .conv-del { opacity: 1; }
.conv-row .conv-del:hover { color: var(--danger); filter: none; }

/* ---------------------------------------------------------- Lückenregister */

body.page { display: block; height: auto; background: var(--paper); }

.page-head {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 2.5rem 0 1.75rem;
}
.page-head-inner, .page-body {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.page-body { padding-top: 2rem; padding-bottom: 4rem; }
.page-head h1 { font-size: 1.7rem; margin: 0 0 0.6rem; letter-spacing: -0.015em; }
.page-lede { color: var(--ink-soft); max-width: 68ch; margin: 0 0 1.25rem; }

.stats { display: flex; flex-wrap: wrap; gap: 0.4rem 2rem; margin-bottom: 1.1rem; }
.stats span { font-size: 0.88rem; color: var(--ink-soft); }
.stats b { font-family: var(--mono); font-size: 1.15rem; color: var(--ink); margin-right: 0.3rem; }

a { color: var(--accent); }
.back { font-size: 0.88rem; text-decoration: none; }
.back:hover { text-decoration: underline; }

.notice {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  padding: 1.25rem 1.4rem;
  max-width: 68ch;
}
.notice p { margin: 0 0 0.7rem; color: var(--ink-soft); }
.notice p:last-child { margin-bottom: 0; }
.notice strong { color: var(--ink); }

.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 720px; background: var(--surface); font-size: 0.92rem; }
th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--rule); }
thead th {
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 400;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.strong { font-weight: 600; }
td.warn { color: var(--danger); font-weight: 600; }
td.date { font-variant-numeric: tabular-nums; color: var(--ink-soft); white-space: nowrap; }
tr.selected { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
form.inline { margin: 0; }

.footnote { font-size: 0.86rem; color: var(--ink-soft); max-width: 68ch; margin: 1.25rem 0 0; }

.detail { margin-top: 2.5rem; }
.detail h2 { font-size: 1.15rem; margin: 0 0 1rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--rule); }
.gap { background: var(--surface); border: 1px solid var(--rule); padding: 0.9rem 1.1rem; margin-bottom: 0.75rem; }
.gap-meta { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); margin: 0 0 0.4rem; }
.gap-q { margin: 0; }

/* Quellenangaben unter einer Antwort */
.sources {
  max-width: 74ch;
  margin: 0 auto 0.75rem;
  border-left: 2px solid var(--rule);
  padding: 0.5rem 0 0.5rem 0.9rem;
}
.sources-label {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.4rem;
}
.sources ol { margin: 0; padding-left: 1.2rem; }
.sources li { font-size: 0.84rem; color: var(--ink-soft); margin-bottom: 0.2rem; }
.src-path { font-family: var(--mono); font-size: 0.94em; color: var(--ink); }
.src-meta { margin-left: 0.5rem; }
.src-meta.stale { color: var(--danger); font-weight: 600; }
.sources ul { margin: 0; padding: 0; list-style: none; }
.sources ul li { margin-bottom: 0.35rem; }
.src-sections {
  display: block;
  font-size: 0.94em;
  color: var(--ink-faint);
  padding-left: 0.1rem;
}

/* ------------------------------------------------------- Editor und Aktionen */

.knopf {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  padding: 0.5rem 1rem;
  border-radius: 2px;
  text-decoration: none;
  font-size: 0.9rem;
  margin-right: 1rem;
}
.knopf:hover { filter: brightness(1.08); }
.knopf-klein {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  font-size: 0.84rem;
  text-decoration: none;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  border-radius: 2px;
  margin-right: 0.4rem;
}
.knopf-klein:hover { color: var(--ink); border-color: var(--ink-faint); }
.zeilen-aktionen { white-space: nowrap; }
.stats .warnung { color: var(--propose); font-weight: 600; }
.warnung-box { border-left-color: var(--propose); }

.editor { max-width: 90ch; }
.feld-reihe { display: flex; gap: 1rem; flex-wrap: wrap; }
.feld { flex: 1; min-width: 220px; margin-bottom: 1rem; }
.feld.schmal { flex: 0 0 190px; }
.feld label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 0.3rem;
}
.feld input, .feld select, .feld textarea {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.feld input[readonly] { color: var(--ink-faint); }
.feld textarea {
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  min-height: 320px;
}
.feld-hinweis {
  font-size: 0.84rem;
  color: var(--ink-soft);
  margin: -0.4rem 0 1.25rem;
  max-width: 76ch;
}
.feld-hinweis.merk {
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  padding: 0.8rem 1rem;
  margin: 0.5rem 0 1.5rem;
}
.aktionen { display: flex; align-items: center; gap: 1.25rem; margin-top: 1rem; }

.zusammen .paar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
  border-top: 1px solid var(--rule-soft);
}
.paar-text { font-size: 0.88rem; color: var(--ink-soft); }

ul.treffer { list-style: none; padding: 0; margin: 0 0 1rem; }
ul.treffer li {
  border-bottom: 1px solid var(--rule-soft);
  padding: 0.6rem 0;
}
ul.treffer label { display: flex; align-items: baseline; gap: 0.7rem; cursor: pointer; }
.treffer-topic { font-weight: 600; }
.treffer-meta { font-size: 0.84rem; color: var(--ink-faint); }

/* ------------------------------------------------------------- Interview */

.interview-start { margin-top: 0.6rem; }
.interview-start summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding: 0.3rem 0;
  list-style: none;
}
.interview-start summary::before { content: "⟡ "; color: var(--accent); }
.interview-start summary:hover { color: var(--ink); }
.interview-hilfe {
  font-size: 0.8rem;
  color: var(--ink-faint);
  line-height: 1.45;
  margin: 0.4rem 0 0.6rem;
}
.interview-start input {
  width: 100%;
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.5rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.interview-start button { width: 100%; }

.interview-leiste {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.interview-leiste p {
  margin: 0;
  flex: 1;
  min-width: 260px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
.interview-leiste strong { color: var(--accent); }
.interview-leiste form { margin: 0; flex: none; }

/* Das hidden-Attribut muss die Anzeige gewinnen — eine Autorenregel mit
   display: flex überstimmt sonst den Browser-Standard [hidden]. */
.interview-leiste[hidden] { display: none; }

/* ------------------------------------------------- Markdown in Antworten */

.msg .body > *:first-child { margin-top: 0; }
.msg .body > *:last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 0.85rem; }
.msg .body h2, .msg .body h3, .msg .body h4,
.msg .body h5, .msg .body h6 {
  font-weight: 600;
  line-height: 1.3;
  margin: 1.4rem 0 0.5rem;
}
.msg .body h2 { font-size: 1.18rem; }
.msg .body h3 { font-size: 1.1rem; }
.msg .body h4 { font-size: 1rem; }
.msg .body h5, .msg .body h6 { font-size: 0.94rem; color: var(--ink-soft); }
.msg .body ul, .msg .body ol { margin: 0 0 0.85rem; padding-left: 1.35rem; }
.msg .body li { margin-bottom: 0.3rem; }
.msg .body li::marker { color: var(--ink-faint); }
.msg .body strong { font-weight: 600; }
.msg .body em { font-style: italic; }
.msg .body a { color: var(--accent); }
.msg .body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 1.2rem 0;
}
.msg .body blockquote {
  margin: 0 0 0.85rem;
  padding: 0.1rem 0 0.1rem 0.9rem;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
}
.msg .body .tabelle-scroll { overflow-x: auto; margin: 0 0 0.95rem; }
.msg .body table {
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 0;
  background: transparent;
}
.msg .body th, .msg .body td {
  border: 1px solid var(--rule);
  padding: 0.4rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.msg .body th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.86rem;
  white-space: nowrap;
}
