:root {
  --bg: #0b0b0d;
  --canvas: #121216;
  --surface: #18181e;
  --field: #22222a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f2f4;
  --muted: #9a9aa6;
  --red: #dc2626;
  --red-hover: #ef4444;
  --red-soft: rgba(220, 38, 38, 0.14);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--red-hover); outline-offset: 2px; }

/* ------------------------------------------------ Anmeldung */
#login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login-card { width: 100%; max-width: 400px; }
.login-logo { display: block; margin: 0 0 20px; }
.login-card h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.01em; }
.lead { margin: 0 0 28px; color: var(--muted); }
label { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }
input {
  width: 100%;
  margin: 0 0 18px;
  padding: 13px 14px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
}
#code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.08em; text-transform: uppercase; }
input:focus { border-color: var(--red); outline: none; }
.primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--red);
  font-weight: 600;
}
.primary:hover { background: var(--red-hover); }
.primary:disabled { opacity: 0.6; cursor: default; }
.hint { margin: 20px 0 0; font-size: 14px; color: var(--muted); }
.error { margin: -6px 0 14px; color: #fca5a5; font-size: 14px; }

/* ------------------------------------------------ App-Gerüst */
#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 820px;
  margin: 0 auto;
  background: var(--canvas);
  border-inline: 1px solid var(--line);
}
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.title { flex: 1; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; fill: var(--text);
}
.icon-btn:hover { background: var(--field); }
.menu {
  position: absolute;
  top: calc(100% - 4px);
  right: 12px;
  z-index: 10;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.menu button {
  display: block; width: 100%;
  min-height: 44px; padding: 0 12px;
  text-align: left;
  border: 0; border-radius: 10px;
  background: transparent;
}
.menu button:hover { background: var(--field); }
.menu .danger { color: #fca5a5; }

/* ------------------------------------------------ Nachrichten */
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.welcome { margin: auto 0 8px; padding: 8px 2px; }
.welcome h2 { margin: 0 0 6px; font-size: 22px; }
.welcome p { margin: 0 0 16px; color: var(--muted); }
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestion {
  min-height: 44px;
  padding: 10px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.suggestion:hover { border-color: var(--red); }

.msg { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  background: var(--red);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.msg.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.bot p { margin: 0 0 8px; }
.msg.bot p:last-child, .msg.bot ul:last-child, .msg.bot ol:last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { margin: 0 0 8px; padding-left: 22px; }
.msg.bot li { margin: 2px 0; }
.msg.bot h3 { margin: 4px 0 6px; font-size: 16px; }
.msg.bot a { color: #fca5a5; }
.msg.bot code { padding: 1px 5px; background: var(--field); border-radius: 5px; font-size: 0.92em; }
.msg .time { display: block; margin-top: 4px; font-size: 12px; color: rgba(255, 255, 255, 0.6); text-align: right; font-variant-numeric: tabular-nums; }
.msg.bot .time { color: var(--muted); text-align: left; }
.msg.error-msg { border-color: rgba(220, 38, 38, 0.5); background: var(--red-soft); }
.retry {
  margin-top: 8px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--field);
}

.typing { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.8; } }

/* ------------------------------------------------ Eingabe */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  max-height: 160px;
  padding: 12px 14px;
  resize: none;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--red); outline: none; }
.send {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--red); fill: #fff;
}
.send:hover { background: var(--red-hover); }
.send:disabled { background: var(--field); fill: var(--muted); cursor: default; }

/* ------------------------------------------------ Dialog */
dialog {
  width: min(440px, calc(100% - 32px));
  padding: 22px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
dialog p { margin: 0 0 12px; color: #d4d4da; }
dialog .sub { white-space: normal; }

@media (max-width: 820px) { #app { border-inline: 0; } }
