/*
 * Chat-Oberfläche. Farben zentral als Variablen - dieselben Töne wie in
 * den Melde-E-Mails des Voicebots (Dunkelblau #1F3B57, Hinweisrot #B0362E).
 * Hell- und Dunkelmodus folgen der Einstellung des Geräts.
 */
:root {
  --primaer: #1f3b57;
  --primaer-dunkel: #152a3f;
  --primaer-hell: #e8eef4;
  /* Schrift in Primärfarbe auf hellem Grund; ein System mit kräftiger
     Markenfarbe setzt hier einen dunkleren Ton (Lesbarkeit). */
  --primaer-text: var(--primaer);
  --kopf: var(--primaer);
  --notfall: #b0362e;
  --notfall-hell: #fbeceb;
  --hintergrund: #f3f5f8;
  --flaeche: #ffffff;
  --text: #1c1f26;
  --text-leise: #5f6773;
  --rand: #dde2e8;
  --blase-bot: #ffffff;
  --blase-ich: #1f3b57;
  --blase-ich-text: #ffffff;
  --radius: 16px;
  --schrift: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primaer: #7fa7cc;
    --primaer-dunkel: #a9c6e0;
    --primaer-hell: #1d2b38;
    --kopf: #16222e;
    --notfall: #ff8f86;
    --notfall-hell: #3a1f1d;
    --hintergrund: #11161c;
    --flaeche: #1a2129;
    --text: #e8ecf1;
    --text-leise: #9aa6b2;
    --rand: #2c3743;
    --blase-bot: #1f2831;
    --blase-ich: #2f5478;
    --blase-ich-text: #ffffff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--hintergrund);
  color: var(--text);
  font-family: var(--schrift);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

/* "hidden" muss immer gewinnen - auch gegen display-Regeln der Klassen. */
[hidden] { display: none !important; }

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

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--hintergrund);
}

/* --- Kopf ------------------------------------------------------------ */
.kopf {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--kopf);
  color: #fff;
  flex: 0 0 auto;
}

.kopf__marke {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.14);
  flex: 0 0 auto;
}
.kopf__marke--wort {
  /* Schriftzug des Kunden (12.10.2026) - weißes Schild, damit die
     Kundenfarbe auf jeder Kopffarbe lesbar bleibt. */
  width: auto; min-width: 38px; padding: 0 7px;
  background: #fff;
  color: var(--marke);
  font-weight: 800; font-size: 14px; letter-spacing: 0.03em;
}
.kopf__marke--bild {
  /* Logo des Kunden (13.10.2026), ebenfalls auf weißem Schild. */
  width: auto; padding: 4px 7px;
  background: #fff;
}
.kopf__marke--bild img { display: block; height: 30px; width: auto; }
.kopf__titel { min-width: 0; flex: 1 1 auto; }
.kopf__titel h1 { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.25; }
/* Volle Deckkraft: Auf hellen Kopffarben reicht weiße Schrift mit 85 %
   nicht für den Kontrast nach WCAG AA (axe, test/browser). */
.kopf__titel p { margin: 2px 0 0; font-size: 12.5px; line-height: 1.3; }

.sprachwahl select {
  appearance: none;
  /* Abdunkeln statt Aufhellen - so bleibt weiße Schrift auf jeder
     Kopffarbe gut lesbar. */
  background: rgba(0, 0, 0, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.sprachwahl select option { color: #1c1f26; }

.kopf__knopf {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center;
}
.kopf__knopf:hover { background: rgba(255, 255, 255, 0.14); }

/* --- Verlauf ----------------------------------------------------------- */
.verlauf {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.blase {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 15.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: erscheinen 0.18s ease-out;
}
.blase--bot {
  align-self: flex-start;
  background: var(--blase-bot);
  border: 1px solid var(--rand);
  border-end-start-radius: 4px;
}
.blase--ich {
  align-self: flex-end;
  background: var(--blase-ich);
  color: var(--blase-ich-text);
  border-end-end-radius: 4px;
}
.blase--notfall {
  background: var(--notfall-hell);
  border: 1px solid var(--notfall);
  border-inline-start: 5px solid var(--notfall);
  max-width: 100%;
  align-self: stretch;
  font-weight: 500;
}
.blase--kontakt { border-inline-start: 5px solid var(--primaer); }
.blase--fehler { background: var(--notfall-hell); border-color: var(--notfall); }
.blase--hinweis { align-self: center; background: transparent; border: 0; color: var(--text-leise); font-size: 13px; text-align: center; }

.anruf {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
  max-width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--primaer);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  white-space: normal;
}
.anruf small { white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.blase--notfall .anruf { background: var(--notfall); }
.anruf small { font-weight: 400; opacity: 0.9; font-size: 14px; }

.fotoblase { align-self: flex-end; max-width: 60%; position: relative; }
.fotoblase img { display: block; max-width: 100%; max-height: 240px; border-radius: var(--radius); border: 1px solid var(--rand); }
.fotoblase span { display: block; font-size: 12px; color: var(--text-leise); margin-top: 4px; text-align: end; }
.fotoblase--laedt img { opacity: 0.55; }

.schreibt { align-self: flex-start; display: flex; gap: 5px; padding: 14px 16px; background: var(--blase-bot); border: 1px solid var(--rand); border-radius: var(--radius); }
.schreibt i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-leise); animation: punkt 1.2s infinite; }
.schreibt i:nth-child(2) { animation-delay: 0.2s; }
.schreibt i:nth-child(3) { animation-delay: 0.4s; }

@keyframes punkt { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }
@keyframes erscheinen { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
/* Der Verlauf ist per Tastatur erreichbar (Pfeiltasten zum Scrollen). */
.verlauf:focus-visible { outline: 2px solid var(--primaer); outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) { .blase, .schreibt i { animation: none; } .verlauf { scroll-behavior: auto; } }

/* --- Auswahlknöpfe ------------------------------------------------------ */
.auswahl { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.auswahl:empty { display: none; }
.auswahl button {
  border: 1.5px solid var(--primaer);
  background: var(--flaeche);
  color: var(--primaer-text);
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14.5px;
  cursor: pointer;
}
.auswahl button:hover, .auswahl button:focus-visible { background: var(--primaer); color: #fff; }

/* --- Testversion ------------------------------------------------------- */
.demo-hinweis {
  margin: 0; padding: 7px 14px;
  background: #fff4d6; color: #5c3b07;
  border-bottom: 1px solid #e6c47a;
  font-size: 13px; line-height: 1.35; text-align: center;
  flex: 0 0 auto;
}
#demo-meldungen { margin-bottom: 8px; }

/* Vor dem Chat: Wahl, den Schaden stattdessen am Telefon zu melden
   (Voicebot des Systems). Verschwindet mit der ersten eigenen Nachricht. */
.telefon-wahl {
  display: flex; align-items: center; gap: 12px;
  margin: 10px 12px 0; padding: 10px 12px;
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius);
  flex: 0 0 auto;
}
.telefon-wahl[hidden] { display: none; }
.telefon-wahl__text { margin: 0; flex: 1 1 auto; font-size: 13.5px; line-height: 1.35; color: var(--text); }
.telefon-wahl__knopf {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 8px;
  /* Farben wie die eigenen Chatblasen - in hell und dunkel kontraststark. */
  padding: 8px 12px; border-radius: 10px; background: var(--blase-ich); color: var(--blase-ich-text);
  font-weight: 600; font-size: 14px; text-decoration: none; line-height: 1.2;
}
.telefon-wahl__knopf small { display: block; font-weight: 400; font-size: 12px; white-space: nowrap; }
.telefon-wahl__knopf:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* --- Abschluss ---------------------------------------------------------- */
.abschluss {
  margin: 0 12px 10px;
  padding: 12px;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  text-align: center;
}
.abschluss p { margin: 0 0 10px; color: var(--text-leise); font-size: 14px; }
.abschluss__knoepfe { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
/* Hauswart-Zugang: Eingabe des Zugangscodes vor dem Chat. */
.zugang__feld {
  display: block; width: 100%; box-sizing: border-box; margin: 0 0 10px;
  padding: 10px 12px; border: 1px solid var(--rand); border-radius: 10px;
  background: var(--flaeche); color: var(--text); font: inherit; font-size: 16px;
}
.zugang__feld:focus { outline: 2px solid var(--primaer); outline-offset: -1px; }
.zugang .zugang__fehler { color: var(--notfall); font-weight: 600; }
.abschluss .knopf { font-size: 14px; padding: 10px 14px; }

.knopf {
  border: 0; border-radius: 10px; padding: 11px 18px;
  background: var(--primaer); color: #fff;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.knopf--zweit { background: var(--primaer-hell); color: var(--primaer-text); }
.knopf--erneut { margin-top: 10px; }

/* --- Eingabe ------------------------------------------------------------ */
.eingabe {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--flaeche);
  border-top: 1px solid var(--rand);
  flex: 0 0 auto;
}
.eingabe textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid var(--rand);
  border-radius: 22px;
  background: var(--hintergrund);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* unter 16px zoomt iOS beim Tippen */
  line-height: 1.4;
}
.eingabe textarea:focus { outline: 2px solid var(--primaer); outline-offset: -1px; }
.eingabe__foto, .eingabe__senden {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  cursor: pointer;
}
.eingabe__foto { background: transparent; color: var(--text-leise); }
.eingabe__foto:hover { background: var(--primaer-hell); color: var(--primaer-text); }
.eingabe__senden { background: var(--primaer); color: #fff; }
[dir="rtl"] .eingabe__senden svg { transform: scaleX(-1); }
.eingabe button:disabled, .eingabe textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.eingabe[hidden] { display: none; }

/* --- Fuß ----------------------------------------------------------------- */
.fuss {
  display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center;
  padding: 6px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--text-leise);
  background: var(--flaeche);
}
.fuss a, .fuss__link { color: var(--text-leise); text-decoration: underline; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
/* Kontaktzeile der Wohnungsgesellschaft (nur wenn das System eine hat). */
.fuss__kontakt { flex: 1 0 100%; margin: 0; text-align: center; font-size: 11.5px; line-height: 1.4; }
.fuss__kontakt a { white-space: nowrap; }

/* --- Eingebettet (iframe) ------------------------------------------------ */
.eingebettet .chat { max-width: none; }
.eingebettet .kopf { padding-top: 12px; }

@media (min-width: 761px) {
  body:not(.eingebettet) .chat { border-inline: 1px solid var(--rand); }
}
