/* Web-Chat (Ticket 21, Gestaltung Ticket 31). Grundstil, Farben, Button/Input/Badge/Dialog kommen aus ui.css (Tokens im Stil von shadcn/ui);
   hier nur Raster, Blasen, Chips und Eingabeleiste. Farben ausschliesslich als Tokens, damit Hell und Dunkel gleich gut lesbar bleiben;
   Zustaende tragen immer auch ein Wort oder Symbol, nie nur Farbe. Mobil zuerst: volle Hoehe (100dvh des Containers, siehe telefon.css),
   Eingabeleiste unten verankert. */
:root {
  --chat-breite: 45rem;
  --chat-ziel: var(--ziel); /* Touch-Ziele mindestens 44 px */
}

html { height: 100%; }
body.chat-seite { margin: 0; min-height: 100%; background: var(--background); }
html:not(.js) .nur-js { display: none !important; }

/* Fenster (Ticket 25): der Chat fuellt seinen Container (.telefon-inhalt in telefon.html.twig, siehe telefon.css). Die Hoehe kommt vom
   Container, nicht von der Fenstergroesse: am Handy ist der Container die ganze Seite (100dvh in telefon.css), am Computer die
   Innenflaeche des gezeichneten Telefons. Rahmen, Bildschirmgroessen und Karte stehen in telefon.css. */
.chat { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; background: var(--background); color: var(--foreground); position: relative; }

/* Kopfzeile */
.chat-kopf { flex: none; display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; padding-top: calc(.5rem + env(safe-area-inset-top)); border-bottom: 1px solid var(--border); background: var(--card); }
.chat-avatar { width: 2.5rem; height: 2.5rem; font-size: .875rem; }
.chat-titel { min-width: 0; }
.chat-name { margin: 0; font-size: 1rem; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; color: var(--foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-untertitel { margin: 0; font-size: .8125rem; color: var(--muted-foreground); display: flex; align-items: center; gap: .4rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statuspunkt { flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: var(--success-fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success-fg) 22%, transparent); }

/* Menue */
.chat-menue { position: relative; margin: 0 0 0 auto; }
.chat-menue > summary { list-style: none; margin: 0; }
.chat-menue > summary::-webkit-details-marker { display: none; }
.chat-menue-liste { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 20; width: min(22rem, calc(100vw - 1.5rem)); margin: 0; padding: .375rem; list-style: none; background: var(--popover); color: var(--popover-foreground); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.chat-menue-liste li { list-style: none; margin: 0; padding: .625rem .5rem; border-bottom: 1px solid var(--border); }
.chat-menue-liste li:last-child { border-bottom: 0; }
.chat-menue-liste a { display: inline-block; font-weight: 500; min-height: 1.5rem; }
.chat-menue-liste small { display: block; margin: .15rem 0 .4rem; color: var(--muted-foreground); font-size: .8125rem; line-height: 1.4; }
.chat-menue-liste form { margin: 0; }
.chat-menue-liste details { margin: 0 0 .5rem; }
.chat-menue-liste details summary { cursor: pointer; margin: 0; }
.chat-menue-liste button { margin: 0; min-height: var(--chat-ziel); width: 100%; }

/* Runde Knoepfe (Menue, Bueroklammer, Standort, Senden): Ghost-Icon-Buttons, Senden als Primary */
.chat .knopf-rund { flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--chat-ziel); height: var(--chat-ziel); min-height: 0; padding: 0; margin: 0; border: 0; border-radius: 50%; background: transparent; color: var(--foreground); cursor: pointer; box-shadow: none; transition: background-color var(--ease), color var(--ease); }
.chat .knopf-rund:hover { background: var(--accent); color: var(--accent-foreground); }
.chat .knopf-rund:disabled { opacity: .45; cursor: not-allowed; }
.chat .knopf-senden { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-sm); }
.chat .knopf-senden:hover:not(:disabled) { background: var(--primary-hover); color: var(--primary-foreground); }
.chat-foto:focus-within .knopf-rund { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Huelle, Nachrichtenbereich */
.chat-huelle { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-inhalt { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-verlauf { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .875rem .75rem; -webkit-overflow-scrolling: touch; }
#gespraech:focus { outline: none; }
ol.verlauf { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.blase { list-style: none; margin: 0; max-width: 85%; padding: .5rem .8rem; border-radius: var(--radius-xl); border: 1px solid transparent; overflow-wrap: anywhere; font-size: .9375rem; line-height: 1.45; }
.blase p { margin: 0 0 .3rem; }
.blase p:last-child { margin-bottom: 0; }
.blase-kopf { font-size: .75rem; color: var(--muted-foreground); }
.blase-kopf strong { font-weight: 600; }
/* der Typ "text" gibt auch dem Listenelement die Klasse blase-text: Zeilenumbrueche zaehlen nur im Absatz */
li.blase { white-space: normal; }
p.blase-text { white-space: pre-line; overflow-wrap: anywhere; font-size: .9375rem; line-height: 1.45; }
.blase-zeit { text-align: right; font-size: .6875rem; color: var(--muted-foreground); }
.blase-zeit time { opacity: .95; }
.blase-buerger { align-self: flex-end; background: var(--primary); color: var(--primary-foreground); border-bottom-right-radius: .25rem; }
.blase-buerger .blase-kopf { display: none; }
.blase-buerger .klein, .blase-buerger .blase-zeit { color: var(--primary-foreground-muted); }
.blase-buerger a { color: inherit; }
.blase-system, .blase-gemeinde { align-self: flex-start; background: var(--muted); color: var(--foreground); border-bottom-left-radius: .25rem; }
.blase-gemeinde { background: var(--card); border: 1px dashed var(--input); }
.blase-begruessung { max-width: 92%; }
.blase-fehler { align-self: flex-start; border: 1px solid color-mix(in srgb, var(--danger-fg) 35%, transparent); background: var(--danger-bg); color: var(--danger-fg); }
.blase-fehler .blase-kopf, .blase-fehler .klein, .blase-fehler .blase-zeit { color: var(--danger-fg); }
.blase-fehler .blase-text { color: var(--danger-fg); }
.blase-pending { opacity: .75; }
.blase em { font-style: normal; font-weight: 600; }
.blase .klein { font-size: .75rem; }
img.foto-vorschau { display: block; width: 100%; max-width: 16rem; height: auto; border-radius: var(--radius-lg); margin: .25rem 0; background: var(--card); border: 1px solid var(--border); }
.blase-standort .blase-text::before { content: "\1F4CD\00a0"; }

/* Tipp-Anzeige */
.blase-tippt { padding: .7rem .9rem; }
.tippt-warteschlange { display: block; margin-top: .3rem; font-size: .75rem; color: var(--muted-foreground); }
/* Denk-Punkte (Ticket 30): drei huepfende Punkte, versetzt. --phase setzt chat.js nach jedem Austausch aus der Uhr, damit die Bewegung
   beim Ersetzen des Fragments nicht von vorn beginnt. */
.punkte { --phase: 0ms; display: inline-flex; gap: .3rem; align-items: center; height: 1rem; }
.punkte i { width: .5rem; height: .5rem; border-radius: 50%; background: var(--muted-foreground); display: block; animation: ehda-punkt 1.2s infinite ease-in-out; animation-delay: var(--phase); }
.punkte i:nth-child(2) { animation-delay: calc(var(--phase) + .15s); }
.punkte i:nth-child(3) { animation-delay: calc(var(--phase) + .3s); }
@keyframes ehda-punkt { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-.3rem); } }
@keyframes ehda-puls { 0%, 100% { opacity: .35; } 50% { opacity: .9; } }

/* Status und Details unter dem Gespraech: Card */
.chat-status { margin: 0 0 .5rem; padding: .75rem .9rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); color: var(--card-foreground); box-shadow: var(--shadow-sm); font-size: .9375rem; }
.chat-status-klein { padding: .25rem .5rem; border: 0; background: transparent; box-shadow: none; font-size: .8125rem; color: var(--muted-foreground); }
.chat-status .statustext { font-size: 1rem; font-weight: 500; margin: 0 0 .4rem; }
.chat-status .klein { margin: 0 0 .4rem; }
.chat-status h3 { font-size: .75rem; margin: .9rem 0 .35rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; color: var(--muted-foreground); }
.chat-status dl.angaben { margin: 0 0 .4rem; font-size: .875rem; }
/* Erfolgsmeldung: der Vorgang ist freigegeben bzw. erledigt, das Gespraech ist beendet */
.chat-status-erfolg { border: 2px solid var(--success-fg); background: var(--success-bg); color: var(--success-fg); }
.chat-status-erfolg .statustext, .chat-status-erfolg .klein { color: var(--success-fg); }
.erfolg-kopf { display: flex; align-items: center; gap: .75rem; margin: 0 0 .6rem; padding: 0 0 .6rem; border-bottom: 1px solid color-mix(in srgb, var(--success-fg) 30%, transparent); }
.erfolg-symbol { flex: none; display: inline-flex; animation: ehda-erfolg .5s ease-out both; }
.erfolg-titel { margin: 0; font-size: 1.125rem; font-weight: 700; line-height: 1.25; }
.erfolg-untertitel { margin: .15rem 0 0; font-size: .875rem; }
@keyframes ehda-erfolg { 0% { opacity: 0; transform: scale(.4); } 70% { transform: scale(1.12); } 100% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .erfolg-symbol { animation: none; } }
.chat-details { margin: .5rem 0 0; }
.chat-details > summary { font-weight: 500; }

/* Eingabeleiste */
.chat-eingabe { flex: none; border-top: 1px solid var(--border); background: var(--card); padding: .5rem .6rem; padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); }
.chat-eingabe form { margin: 0; }
.chat-form { display: block; }
.chat-zeile { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .35rem; }
.chat-feld { position: relative; flex: 1 1 8rem; min-width: 0; }
.chat-feld textarea { display: block; margin: 0; width: 100%; min-height: var(--chat-ziel); max-height: 9.5rem; resize: none; padding: .6rem 3.4rem .6rem 1rem; border-radius: 1.4rem; line-height: 1.4; font-size: 1rem; overflow-y: hidden; }
.chat-feld textarea:disabled { opacity: .65; cursor: not-allowed; overflow-y: hidden; background: var(--muted); }
.zaehler { position: absolute; right: .9rem; bottom: .35rem; font-size: .6875rem; color: var(--muted-foreground); pointer-events: none; }
.chat-foto { display: contents; }
.chat-anhang { order: 20; flex: 1 1 100%; display: none; align-items: center; gap: .5rem; min-width: 0; }
.chat-anhang:has(.chat-dateiname:not(:empty)) { display: flex; }
.chat-dateiname { font-size: .8125rem; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.standort-fehler { color: var(--destructive-text) !important; font-weight: 600; white-space: normal; }
.chat-statuszeile { margin: .25rem .25rem 0; min-height: 0; flex: 1 1 100%; }
.chat-statuszeile:empty { display: none; }

/* Chips: Schnellantworten, Standort, Aktionen (Button outline, rund) */
.chat-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: 0 0 .5rem; }
.chat-standort { margin-bottom: .1rem; }
.chat-aktionen form, .chat-pruefung { margin: 0; display: contents; }
.chat-standortform { margin: 0 0 .25rem; }
.chat .chip { position: relative; display: inline-flex; align-items: center; gap: .35rem; min-height: var(--chat-ziel); margin: 0; padding: .3rem .9rem; width: auto; border: 1px solid var(--input); border-radius: 999px; background: var(--background); color: var(--foreground); font-size: .875rem; font-weight: 500; line-height: 1.2; text-decoration: none; cursor: pointer; box-shadow: var(--shadow-sm); text-align: left; transition: background-color var(--ease), color var(--ease), border-color var(--ease); }
.chat .chip:hover { background: var(--accent); color: var(--accent-foreground); }
.chat .chip-primaer { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.chat .chip-primaer:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-foreground); }
.chat .chip-aktion { border-style: dashed; color: var(--foreground); box-shadow: none; }
.chat .chip:disabled { opacity: .5; cursor: not-allowed; }
.chat .chip .symbol { width: 1.1rem; height: 1.1rem; }
.symbol { flex: none; }

.chat-noscript { margin: 0; padding: .4rem .75rem; }
.chat-fuss { flex: none; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .1rem .75rem; margin: 0; padding: .35rem .75rem; padding-bottom: calc(.35rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); font-size: .6875rem; line-height: 1.4; color: var(--muted-foreground); background: var(--background); }
.chat-fuss a { color: inherit; }

/* Dialog (Telegram-Hinweis auf kleinen Bildschirmen) */
.chat-dialog { padding: 0; }
.chat-dialog article { margin: 0; padding: 1.25rem; }
.chat-dialog h2 { font-size: 1.125rem; }
.chat-dialog img.qr { display: block; margin: 0 auto; background: #fff; padding: .25rem; border-radius: var(--radius-md); }
.chat-dialog footer { margin-top: 1rem; }
.chat-dialog footer form { margin: 0; }
.chat-dialog footer button { width: 100%; margin: 0; min-height: var(--chat-ziel); }

/* Schmale Bildschirme: Chips stehen in einer Reihe, die sich seitlich wischen laesst (spart Hoehe fuer das Gespraech) */
@media (max-width: 599px) {
  .chat .chat-eingabe .chat-chips { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: .15rem; scrollbar-width: none; }
  .chat .chat-eingabe .chat-chips > *, .chat .chat-eingabe .chat-chips .chip { flex: none; }
  .chat .chat-eingabe .chat-chips .chip { scroll-snap-align: start; white-space: nowrap; }
}
/* Schmale Bildschirme: Blasen bleiben bei hoechstens 85 %, die Leiste nutzt die Breite */
@media (max-width: 420px) {
  .chat-verlauf { padding: .6rem .5rem; }
  .chat-name { font-size: .9375rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  /* kein Huepfen: die Punkte stehen still und pulsieren nur sanft (Helligkeit) */
  .punkte i { opacity: .7; animation: ehda-puls 2.4s infinite ease-in-out !important; }
  .punkte i:nth-child(2) { animation-delay: calc(var(--phase) + .3s) !important; }
  .punkte i:nth-child(3) { animation-delay: calc(var(--phase) + .6s) !important; }
}
@media (forced-colors: active) {
  .blase, .chat .chip, .chat .knopf-rund { border: 1px solid CanvasText; }
  .punkte i { background: CanvasText; }
  .statuspunkt { background: Highlight; }
}

/* Selbstcheck (Ticket 33): Checklisten-Karte mit Auswahl je Punkt, im Stil der Chips */
.chat .checkliste { margin: 0 0 .6rem; }
.chat .checkliste-karte { border: 1px solid var(--border); border-radius: var(--radius-md); padding: .6rem .8rem; background: var(--card, var(--background)); }
.chat .checkliste-karte legend { font-weight: 600; padding: 0 .3rem; }
.chat .checkliste-punkte { margin: 0 0 .6rem; padding-left: 1.2rem; display: grid; gap: .6rem; }
.chat .checkliste-frage { display: block; margin-bottom: .3rem; overflow-wrap: anywhere; }
.chat .checkliste-wahl { display: flex; flex-wrap: wrap; gap: .4rem; }
.chat .checkliste-wahl .chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chat .checkliste-wahl .chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.chat .checkliste-wahl .chip:has(input:focus-visible) { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
