/* ===================================================================
   Chat — Widget
   ===================================================================

   Alle Farben und Masse stehen als Variablen ganz oben. Eine
   einbindende Seite überschreibt sie einfach:

       .chat { --chat-akzent: #2C3241; }

   Damit bleibt dieses Stylesheet für alle Seiten dasselbe und muss
   nie kopiert werden.
   =================================================================== */

.chat {
  /* --- Farben ---------------------------------------------------- */
  --chat-akzent:        #2C3241;   /* Kopfzeile, eigene Blasen, Knopf */
  --chat-akzent-hell:   #4A5164;   /* Hover                           */
  --chat-auf-akzent:    #FAF1E0;   /* Text auf dem Akzent             */
  --chat-auf-akzent-2:  #B7B0A2;   /* Nebentext auf dem Akzent        */

  --chat-grund:         #FFFFFF;   /* Fensterhintergrund              */
  --chat-blase:         #FBF8F2;   /* Blase der Gegenseite            */
  --chat-linie:         #E4DFD5;   /* Trenner, rein zierend           */
  --chat-rahmen:        #8A9099;   /* Umriss von Bedienelementen      */
  --chat-text:          #23262E;
  --chat-text-leise:    #5E626B;
  /* Nicht heller als das: Platzhalter und Fusszeile müssen 4.5:1
     erreichen — der Kontrast-Prüfstand rechnet das nach. */
  --chat-text-still:    #6B7078;

  --chat-fehler-grund:  #FDF2F2;
  --chat-fehler-linie:  #E8C4C4;
  --chat-fehler-text:   #9B2C2C;

  /* --- Masse ----------------------------------------------------- */
  --chat-radius:        14px;
  --chat-radius-klein:  6px;
  --chat-schrift:       -apple-system, BlinkMacSystemFont, "Segoe UI",
                        Roboto, Helvetica, Arial, sans-serif;
  --chat-groesse:       14px;

  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  overflow: hidden;

  background: var(--chat-grund);
  border: 1px solid var(--chat-linie);
  border-radius: var(--chat-radius);
  font-family: var(--chat-schrift);
  color: var(--chat-text);
}

.chat *,
.chat *::before,
.chat *::after { box-sizing: border-box; }

/* ── Abschottung gegen das Stylesheet der Seite ──────────────────
   Dieses Widget läuft in fremden Seiten. Deren globale Typografie
   greift sonst hinein: colors_and_type.css setzt zum Beispiel
   p { color: var(--rt-fg) } — dunkel. In einer dunklen eigenen
   Sprechblase stand der Text dann dunkel auf dunkel.

   Die Blase gibt ihre Textfarbe per Vererbung weiter; ein globales
   p { color: … } schlägt diese Vererbung aber, weil eine gesetzte
   Farbe immer gegen eine geerbte gewinnt. Also wird sie hier
   ausdrücklich zurückgeholt.

   :where() hat die Spezifität null — die einbindende Seite kann
   also weiterhin gezielt eingreifen, nur eben nicht versehentlich. */
.chat :where(p, h1, h2, h3, h4, h5, h6, ul, ol, li, dl, dt, dd,
             strong, b, em, i, span, small, blockquote,
             table, thead, tbody, tr, th, td, figure, figcaption) {
  color: inherit;
  font-family: inherit;
}


/* ── Kopfzeile ─────────────────────────────────────────────────── */

.chat__kopf {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 12px 16px;
  background: var(--chat-akzent);
  border-bottom: 1px solid var(--chat-linie);
}

.chat__marke {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.chat__marke img { width: 22px; height: auto; display: block; }

.chat__titelblock { flex: 1; min-width: 0; }

.chat__titel {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--chat-auf-akzent);
}

.chat__untertitel {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--chat-auf-akzent-2);
}

.chat__punkt {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #6FCF6F;
  animation: chat-pulsieren 2s ease-in-out infinite;
}
@keyframes chat-pulsieren { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }

.chat__neustart {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: .05em;
  color: var(--chat-auf-akzent-2);
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--chat-radius-klein);
  transition: color .15s, border-color .15s, background .15s;
}
.chat__neustart:hover {
  color: var(--chat-auf-akzent);
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.08);
}


/* ── Verlauf ───────────────────────────────────────────────────── */

.chat__verlauf {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.chat__verlauf::-webkit-scrollbar { width: 4px }
.chat__verlauf::-webkit-scrollbar-track { background: transparent }
.chat__verlauf::-webkit-scrollbar-thumb {
  background: var(--chat-linie);
  border-radius: 2px;
}


/* ── Nachrichten ───────────────────────────────────────────────── */

.chat__nachricht {
  display: flex;
  gap: 9px;
  max-width: 88%;
  animation: chat-herein .2s ease-out both;
}
@keyframes chat-herein {
  from { opacity: 0; transform: translateY(6px) }
  to   { opacity: 1; transform: translateY(0) }
}

.chat__nachricht--ai   { align-self: flex-start }
.chat__nachricht--user { align-self: flex-end; flex-direction: row-reverse }

.chat__bild {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  margin-top: 3px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
}
.chat__nachricht--ai   .chat__bild { background: var(--chat-akzent) }
.chat__nachricht--ai   .chat__bild img { width: 18px; height: auto }
.chat__nachricht--user .chat__bild {
  background: var(--chat-linie);
  color: var(--chat-text);
}

.chat__blase {
  min-width: 0;
  padding: 10px 14px;
  border-radius: var(--chat-radius);
  font-size: var(--chat-groesse);
  line-height: 1.65;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat__nachricht--ai .chat__blase {
  background: var(--chat-blase);
  border: 1px solid var(--chat-linie);
  border-top-left-radius: 4px;
}
.chat__nachricht--user .chat__blase {
  background: var(--chat-akzent);
  color: var(--chat-auf-akzent);
  border-top-right-radius: 4px;
}
.chat__nachricht--fehler .chat__blase {
  background: var(--chat-fehler-grund);
  border: 1px solid var(--chat-fehler-linie);
  color: var(--chat-fehler-text);
}


/* ── Inhalt der Blasen (aus Markdown) ──────────────────────────── */

.chat__blase p { margin: 0 0 8px }
.chat__blase p:last-child { margin-bottom: 0 }

.chat__blase strong { font-weight: 600 }
.chat__blase em     { font-style: italic }

.chat__blase h3 {
  margin: 10px 0 4px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}
.chat__blase h3:first-child { margin-top: 0 }

.chat__blase ul,
.chat__blase ol {
  margin: 6px 0 6px 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat__blase li { line-height: 1.55 }

.chat__blase a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}

.chat__blase img {
  display: block;
  max-width: 100%;
  margin: 6px 0;
  border: 1px solid var(--chat-linie);
  border-radius: var(--chat-radius-klein);
}

.chat__blase code {
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  background: rgba(0, 0, 0, .06);
  border-radius: 4px;
}

.chat__blase hr {
  margin: 10px 0;
  border: none;
  border-top: 1px solid var(--chat-linie);
}

/* Tabellen dürfen für sich scrollen — die Seite kippt sonst quer. */
.chat__tabellenrahmen {
  margin: 8px 0;
  overflow-x: auto;
}
.chat__tabelle {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  border: 1px solid var(--chat-linie);
  border-radius: var(--chat-radius-klein);
  overflow: hidden;
}
.chat__tabelle th,
.chat__tabelle td {
  padding: 7px 11px;
  text-align: left;
  border-bottom: 1px solid var(--chat-linie);
  border-right: 1px solid var(--chat-linie);
}
.chat__tabelle th:last-child,
.chat__tabelle td:last-child { border-right: none }
.chat__tabelle tr:last-child td { border-bottom: none }
.chat__tabelle thead th {
  background: var(--chat-akzent);
  color: var(--chat-auf-akzent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}
.chat__tabelle tbody tr:nth-child(even) { background: rgba(0, 0, 0, .025) }


/* ── Tippen ────────────────────────────────────────────────────── */

.chat__tippen {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}
.chat__tippen span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-text-leise);
  animation: chat-hüpfen 1.1s ease-in-out infinite;
}
.chat__tippen span:nth-child(2) { animation-delay: .18s }
.chat__tippen span:nth-child(3) { animation-delay: .36s }
@keyframes chat-hüpfen {
  0%, 60%, 100% { transform: translateY(0) }
  30%           { transform: translateY(-6px) }
}


/* ── Eingabe ───────────────────────────────────────────────────── */

.chat__eingabe {
  flex-shrink: 0;
  padding: 12px 16px;
  background: var(--chat-grund);
  border-top: 1px solid var(--chat-linie);
}

.chat__zeile {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat__feld {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  max-height: 120px;
  padding: 9px 13px;
  resize: none;
  overflow-y: auto;
  outline: none;
  font-family: inherit;
  /* 16px, damit iOS beim Fokus nicht hineinzoomt. */
  font-size: 16px;
  line-height: 1.5;
  color: var(--chat-text);
  background: var(--chat-blase);
  /* Der Umriss eines Bedienelements muss sichtbar sein (WCAG 1.4.11),
     darum --chat-rahmen und nicht die zierende --chat-linie. */
  border: 1px solid var(--chat-rahmen);
  border-radius: var(--chat-radius);
  transition: border-color .15s;
}
.chat__feld:focus {
  border-color: var(--chat-akzent);
  outline: 2px solid var(--chat-akzent);
  outline-offset: 1px;
}
.chat__feld::placeholder { color: var(--chat-text-still) }
.chat__feld:disabled { opacity: .45; cursor: not-allowed }

.chat__senden {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--chat-auf-akzent);
  background: var(--chat-akzent);
  border: none;
  border-radius: var(--chat-radius-klein);
  transition: background .15s;
}
.chat__senden:hover:not(:disabled) { background: var(--chat-akzent-hell) }
.chat__senden:disabled { opacity: .35; cursor: not-allowed }

.chat__fussnote {
  margin: 7px 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: .03em;
  color: var(--chat-text-still);
}


/* ── Rücksicht auf Bewegungsempfindlichkeit ────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .chat *,
  .chat *::before,
  .chat *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
