:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eef2ff;
  /* Markenfarben: dunkles Blau für Flächen und Wortmarke, Rot für den Produktnamen. */
  --brand-dark: #0f0f3c;
  --brand-dark-line: #24246b;
  --brand-red: #f44336;
  --user-bg: #2563eb;
  --user-text: #ffffff;
  --error: #b91c1c;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  font-weight: 700;
  font-size: 20px;
  color: var(--brand-dark);
}
.brand span {
  color: var(--brand-red);
  font-weight: 600;
}
.brand .tagline {
  display: block;
  /* Ohne eigene Größe erbt der Untertitel die 20px der Hauptzeile. */
  font-size: 14px;
  margin-top: 2px;
  color: var(--text);
  font-weight: 400;
  font-style: italic;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-indicator {
  font-size: 13px;
  color: var(--muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--brand-dark);
}
.icon-btn[hidden] {
  display: none;
}

/* Verlaufsleiste – von links, damit die Kopfzeile sichtbar bleibt. */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  background: rgba(15, 15, 60, 0.35);
}
.drawer[hidden] {
  display: none;
}
.drawer-panel {
  display: flex;
  flex-direction: column;
  width: min(320px, 85vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-newbtn {
  margin: 12px 14px 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.drawer-newbtn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 10px;
}
.drawer-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: var(--radius);
}
.drawer-item:hover {
  background: var(--bg);
}
.drawer-item.current {
  background: var(--accent-soft);
}
.drawer-open {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  min-width: 0;
}
.drawer-title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-meta {
  font-size: 12px;
  color: var(--muted);
}
.drawer-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 10px;
  cursor: pointer;
  border-radius: var(--radius);
}
.drawer-del:hover {
  color: var(--error);
}
.drawer-empty {
  padding: 12px 10px;
  font-size: 13px;
  color: var(--muted);
}
.drawer-note {
  margin: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* Fertige Stufenergebnisse zum Sichern – erscheint erst, wenn es etwas gibt. */
.downloads {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: #506487;
  border-bottom: 1px solid var(--border);
}
.downloads[hidden] {
  display: none;
}
.downloads-hint {
  /* Erzwingt den Umbruch nach dem Hinweis, damit die Knöpfe gemeinsam in die
     nächste Zeile rutschen, statt einzeln umzubrechen. */
  flex-basis: 100%;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
}
.dl-btn {
  display: inline-block;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #f44336;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.dl-btn:hover {
  background: #ffffff;
  color: #f44336;
}

.chat {
  flex: 1;
  overflow-y: auto;
  /* Seitlich 16px wie im Composer, damit Antworten und Eingabefeld bündig stehen. */
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: normal;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

/* Das Gespräch selbst (Nachfragen, Erläuterungen, Systemfragen) steht dunkel.
   Die eigentlichen Ergebnisse heben sich als helle Inseln davon ab – sie sehen
   damit so aus, wie der Kunde sie später in skillworx sieht. */
.msg.assistant {
  --surface: var(--brand-dark);
  --on-surface: #e5e7eb;
  --line: rgba(255, 255, 255, 0.18);
  --soft: rgba(255, 255, 255, 0.08);
  align-self: flex-start;
  /* Volle Breite: Die Ergebnisblöcke darin brauchen den Platz und stehen so
     bündig mit dem Eingabefeld. Die eigene Nachricht bleibt schmal. */
  max-width: 100%;
  width: 100%;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--brand-dark-line);
  border-bottom-left-radius: 4px;
}

/* Helle Inseln: Ergebnisblöcke und die Kundenansicht einer Lektion.
   Sie überschreiben die Variablen, sodass Ränder, Tabellen und Auszeichnungen
   darin automatisch mitziehen. */
.msg.assistant pre,
.msg.assistant .lesson-html {
  --surface: var(--panel);
  --on-surface: var(--text);
  --line: var(--border);
  --soft: #f3f4f6;
  background: var(--surface);
  color: var(--on-surface);
}

.msg.assistant a {
  color: #93c5fd;
}
.msg.assistant .lesson-html a,
.msg.assistant pre a {
  color: var(--accent);
}

.msg.assistant h1,
.msg.assistant h2 {
  font-size: 1.02em;
  margin: 0.6em 0 0.3em;
}
.msg.assistant p {
  margin: 0.5em 0;
}
.msg.assistant ul,
.msg.assistant ol {
  margin: 0.4em 0;
  padding-left: 1.3em;
}
.msg.assistant code {
  background: var(--soft);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.9em;
}
.msg.assistant pre {
  border: 1px solid var(--line);
  padding: 12px 14px;
  border-radius: 8px;
  margin: 0.6em 0;
  /* Kein Quelltext, sondern das fertige Ergebnis – es liest sich in derselben
     Schrift wie der spätere Kursinhalt, nur mit erhaltenen Zeilenumbrüchen. */
  font-family: inherit;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
}
.msg.assistant .table-wrap {
  overflow-x: auto;
  margin: 0.6em 0;
}
.msg.assistant table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.msg.assistant th,
.msg.assistant td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
}
.msg.assistant th {
  background: var(--soft);
  font-weight: 600;
  white-space: nowrap;
}

.msg.assistant .kundenansicht-label {
  margin: 0.8em 0 0.3em;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.65;
}

/* Kundenansicht einer Lektion – so, wie sie später in skillworx aussieht. */
.msg.assistant .lesson-html {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0.6em 0;
}
.msg.assistant .lesson-html h1,
.msg.assistant .lesson-html h2,
.msg.assistant .lesson-html h3,
.msg.assistant .lesson-html h4 {
  font-size: 1.05em;
  font-weight: 700;
  margin: 0.7em 0 0.3em;
}
.msg.assistant .lesson-html p {
  margin: 0.5em 0;
}
.msg.assistant .lesson-html hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0.8em 0;
}
.msg.assistant .lesson-html details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  margin: 0.4em 0;
  background: var(--soft);
}
.msg.assistant .lesson-html summary {
  cursor: pointer;
  font-weight: 600;
}
.msg.assistant .lesson-html [data-type="detailsContent"] {
  margin-top: 6px;
}
.msg.assistant .lesson-html img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.msg.assistant .lesson-html button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: default;
  margin: 0.3em 0;
}

.system-line {
  align-self: center;
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}

.stage-divider {
  align-self: center;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  border-top: 1px solid var(--border);
  width: 100%;
  text-align: center;
  padding-top: 10px;
  margin-top: 2px;
}

.error-line {
  align-self: center;
  color: var(--error);
  font-size: 13px;
}

/* Gesprächsstarter: eigenes Chat-Element, damit Streaming sie nicht überschreibt. */
.choices {
  align-self: flex-start;
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choices-q {
  color: var(--muted);
  font-size: 13px;
}

.choice-btn {
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.choice-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.choice-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.choice-hint {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
}

.choice-btn:hover:not(:disabled) .choice-hint,
.choice-btn.selected .choice-hint {
  color: inherit;
}

.typing {
  align-self: flex-start;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  /* Pulsiert, damit eine lange Denkphase nicht wie ein eingefrorenes Fenster wirkt. */
  animation: typing-pulse 1.8s ease-in-out infinite;
}

@keyframes typing-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.composer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
}
.composer-box:focus-within {
  border-color: var(--accent);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-spacer {
  flex: 1;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachments[hidden] {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
}
.chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip .chip-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.chip .chip-remove:hover {
  color: var(--error);
}
.chip.pending {
  opacity: 0.6;
}

.attach-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.attach-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}
.attach-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.mic-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mic-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}
.mic-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.mic-btn.recording {
  color: var(--error);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* Anhang-Chips in der eigenen Nachrichtenblase */
.msg.user .msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.msg.user .msg-attachments .chip {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--user-text);
}

#input {
  width: 100%;
  resize: none;
  max-height: 160px;
  padding: 4px 2px;
  border: none;
  font: inherit;
  color: var(--text);
  background: transparent;
  outline: none;
}

.send-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.send-btn:hover:not(:disabled) {
  background: #1d4ed8;
}
.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: var(--muted);
}
