:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1f232c; --border: #2a2f3a;
  --text: #e6e8ec; --muted: #9aa3b2; --accent: #5b8cff; --user: #2b3450;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
.hidden { display: none !important; }

/* Gate */
.gate { height: 100%; display: grid; place-items: center; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 2rem; width: min(92vw, 360px); display: flex; flex-direction: column; gap: .75rem;
}
.card h1 { margin: 0; font-size: 1.4rem; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; }
input, textarea, button { font: inherit; }
input, textarea {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .6rem .7rem; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: .6rem .9rem; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
.err { color: #ff6b6b; min-height: 1.1em; }

/* App layout */
.app { height: 100%; display: grid; grid-template-columns: 260px 1fr; overflow: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sidebar-head { display: flex; gap: .5rem; padding: .75rem; border-bottom: 1px solid var(--border); }
.sidebar-head #new-session { flex: 1; }
.sidebar-head #logout { background: var(--panel2); }
.session-list { list-style: none; margin: 0; padding: .5rem; overflow-y: auto; flex: 1; }
.session-list li {
  display: flex; align-items: center; gap: .25rem;
  padding: .4rem .5rem; border-radius: 8px; color: var(--muted); font-size: .85rem;
}
.session-list li:hover { background: var(--panel2); }
.session-list li.active { background: var(--panel2); color: var(--text); }
.session-list li .s-label {
  flex: 1; min-width: 0; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-list li .s-rename {
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
  padding: .1rem .35rem; border-radius: 6px; opacity: 0; flex: 0 0 auto;
}
.session-list li:hover .s-rename { opacity: 1; }
.session-list li .s-rename:hover { background: var(--border); color: var(--text); }

/* Chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.msg { max-width: 760px; width: fit-content; padding: .7rem .9rem; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.assistant { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); }
.msg.error { align-self: center; background: #3a1f23; border: 1px solid #5a2b30; color: #ffb3b3; font-size: .85rem; }

/* Markdown im Assistant-Bubble */
.msg.assistant { white-space: normal; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p { margin: .5em 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3, .msg.assistant h4 { margin: .6em 0 .3em; line-height: 1.25; }
.msg.assistant h1 { font-size: 1.35em; } .msg.assistant h2 { font-size: 1.2em; }
.msg.assistant h3 { font-size: 1.08em; } .msg.assistant h4 { font-size: 1em; }
.msg.assistant ul, .msg.assistant ol { margin: .4em 0; padding-left: 1.4em; }
.msg.assistant li { margin: .15em 0; }
.msg.assistant a { color: var(--accent); }
.msg.assistant code {
  background: #11141b; border: 1px solid var(--border); border-radius: 5px;
  padding: .08em .35em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em;
}
.msg.assistant pre {
  background: #11141b; border: 1px solid var(--border); border-radius: 8px;
  padding: .7rem .8rem; overflow-x: auto; margin: .5em 0;
}
.msg.assistant pre code { background: none; border: 0; padding: 0; font-size: .88em; }
/* Zweigleisig: Kurz-/Sprech-Zusammenfassung unter der Agent-Antwort. */
.msg.assistant .msg-summary {
  margin-top: .5rem; padding-top: .45rem; border-top: 1px dashed var(--border);
  color: var(--muted); font-size: .85rem; font-style: italic;
}
.composer { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; max-height: 180px; }
@media (max-width: 640px) { .app { grid-template-columns: 0 1fr; } .sidebar { display: none; } }
