/* chat.css – Version 20261113e (Paket 1234, Agent «daten»)
   Chat-Knopf unten rechts und Chat-Fenster (<dialog class="chat-fenster">) aus assets/js/chat.js.
   Der Knopf erscheint nur, wenn /api/chat/status aktiv:true liefert. Farben ueber die Bereichs-Variablen;
   Schrift auf dem Knopf dunkel (#020822) auf der Akzentfarbe (>= 4.5:1 in allen fuenf Bereichen).
   Mobil (< 640 px) fuellt das Fenster den Bildschirm. Kontrastmodus, Druck und reduzierte Bewegung am Ende. */

/* ---------- Knopf ---------- */
.chat-knopf {
  position: fixed; z-index: 97;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 20px 0 16px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: linear-gradient(135deg, var(--akzent), var(--akzent-2));
  color: var(--dz-ink, #020822); font: inherit; font-weight: 800; font-size: 1rem; line-height: 1;
  box-shadow: 0 14px 34px -12px rgb(var(--akzent-rgb) / 0.75), 0 2px 10px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s var(--ease, ease), box-shadow 0.2s ease;
}
.chat-knopf:hover { transform: translateY(-2px); }
.chat-knopf:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px #020822; }
.chat-knopf-ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-knopf-zahl {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: #fff; color: #020822; font-size: 0.78rem; font-variant-numeric: tabular-nums;
}
/* mobiles Menue offen (site.js setzt html.menu-open): Knopf weg, damit er nicht in die Fokusfolge geraet */
html.menu-open .chat-knopf { display: none; }
/* Knopf sichtbar (chat.js setzt html[data-chat="an"]): fokussierte Elemente nicht darunter verstecken (WCAG 2.4.11).
   Nur wenn die Seite selbst nichts Groesseres braucht (Umzugsrechner setzt 160 px, site.css). */
html[data-chat="an"]:not(:has(.tz-rechner)) { scroll-padding-bottom: 84px; }
/* Am Seitenende hilft scroll-padding nicht (die Seite scrollt nicht weiter): Fuss unten um die Knopfhoehe
   verlaengern, damit der Link «English»/«Deutsch» unten rechts nicht unter dem Knopf liegt (WCAG 2.4.11) */
html[data-chat="an"] .site-footer { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
/* Integration 20261113e (Wunsch «formulare»): Hinweis «Empfehlungscode übernommen» (site.css §50, unten links,
   bis 420 px breit) ueberschneidet sich auf schmalen Bildschirmen mit dem Knopf (z-index 97) -> Hinweis darueber */
@media (max-width: 599px) {
  html[data-chat="an"] .empf-hinweis { bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 64px); }
}
/* Umzugsrechner (< 1100 px): klebender Ergebnis-Balken unten (bei 320 px rund 130 px hoch) -> Knopf darueber,
   damit er den Preis nicht verdeckt; Fokus auch nicht hinter dem Knopf (scroll-padding, WCAG 2.4.11) */
@media (max-width: 1099px) {
  html:has(.tz-rechner) .chat-knopf { bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 150px); }
  html[data-chat="an"]:has(.tz-rechner) { scroll-padding-bottom: 230px; }
  html[data-chat="an"]:has(.tz-rechner) .site-footer { padding-bottom: calc(230px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Fenster ---------- */
.chat-fenster {
  position: fixed; inset: auto max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) auto;
  width: min(420px, calc(100vw - 32px)); height: min(660px, calc(100vh - 32px)); height: min(660px, calc(100dvh - 32px));
  max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden;
  border: 1px solid rgb(var(--akzent-rgb) / 0.55); border-radius: var(--r-lg, 26px);
  background: #050d33; color: var(--ink, #eef2ff);
  box-shadow: var(--shadow, 0 30px 80px -24px rgba(0, 0, 0, 0.7));
}
.chat-fenster[open] { display: flex; }
.chat-fenster::backdrop { background: rgba(1, 5, 22, 0.55); }
.chat-rahmen { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; }
.chat-kopf {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex: none;
  padding: 16px 12px 14px 20px; border-bottom: 1px solid var(--line, rgba(255, 255, 255, 0.1));
  background: linear-gradient(160deg, rgb(var(--akzent-rgb) / 0.16), transparent 70%);
}
.chat-kopf-text { min-width: 0; }
.chat-titel { margin: 0; color: #fff; font-size: 1.15rem; letter-spacing: -0.01em; }
.chat-intro { margin: 4px 0 0; color: var(--akzent-text, #a9c1ff); font-size: 0.92rem; font-weight: 700; }
.chat-zu {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.chat-zu:hover { background: rgba(255, 255, 255, 0.08); }
.chat-zu:focus-visible { outline: 3px solid var(--fokus, #a9c1ff); outline-offset: -3px; }
.chat-koerper {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  /* max-content: sonst schrumpft das Raster bei vollem Verlauf Zeilen mit fester min-height (Statusmeldung) */
  display: grid; grid-auto-rows: max-content; align-content: start; gap: 14px; padding: 16px 20px;
}
.chat-koerper > * { margin: 0; min-width: 0; }
.chat-koerper:focus-visible { outline: 3px solid var(--fokus, #a9c1ff); outline-offset: -3px; }
.chat-hinweis {
  padding: 12px 14px; border-radius: 12px; border: 1px solid rgb(var(--dz-warn-rgb, 255 208 96) / 0.55);
  background: rgb(var(--dz-warn-rgb, 255 208 96) / 0.1); color: #fff; font-size: 0.92rem; line-height: 1.5;
}
.chat-hinweis strong { color: var(--dz-warn, #ffd060); }
.chat-start-form { gap: 16px; }
.chat-start-form .check a { padding-block: 3px; }
.chat-start-form .actions { margin-top: 0; }
.chat-leer { color: var(--muted, #b3bddc); }

/* ---------- Verlauf ---------- */
.chat-verlauf { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.chat-nachricht {
  max-width: 88%; padding: 10px 14px; border-radius: 16px;
  border: 1px solid var(--line-2, rgba(255, 255, 255, 0.18)); background: rgba(255, 255, 255, 0.05);
}
.chat-nachricht > * { margin: 0; }
.chat-nachricht[data-von="besucher"] {
  justify-self: end; border-color: rgb(var(--akzent-rgb) / 0.6); background: rgb(var(--akzent-rgb) / 0.16);
  border-bottom-right-radius: 4px;
}
.chat-nachricht[data-von="team"] { justify-self: start; border-bottom-left-radius: 4px; }
.chat-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-bottom: 4px; color: var(--dim, #9aa6cf); font-size: 0.8rem; }
.chat-wer { color: #fff; font-weight: 700; }
.chat-text { color: var(--ink, #eef2ff); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }

/* ---------- Eingabe und Ende ---------- */
.chat-fuss { flex: none; padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line, rgba(255, 255, 255, 0.1)); background: rgba(3, 9, 36, 0.9); }
.chat-fuss > * { margin: 0; }
.chat-eingabe { gap: 10px; }
.chat-eingabe textarea { min-height: 76px; max-height: 30vh; resize: vertical; }
.chat-aktionen, .chat-bestaetigen .actions { margin-top: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chat-aktionen .btn, .chat-bestaetigen .btn { min-height: 44px; }
.chat-bestaetigen { display: grid; gap: 8px; }
.chat-bestaetigen > p { margin: 0; color: #fff; font-weight: 700; }
.chat-ende { display: grid; gap: 10px; }
.chat-ende > * { margin: 0; }
.chat-ende-text { color: #fff; font-weight: 700; }
.chat-ende .actions { margin-top: 0; }
.chat-zu-hinweis { margin-top: 8px !important; color: var(--dim, #9aa6cf); font-size: 0.8rem; }

/* ---------- Telefon: Vollbild ---------- */
@media (max-width: 639px) {
  .chat-knopf { min-height: 50px; padding: 0 18px 0 14px; }
  .chat-fenster {
    inset: 0; width: 100%; height: 100%; max-width: 100%; max-height: 100%;
    border: 0; border-radius: 0;
  }
  .chat-koerper { padding: 14px 16px; }
  .chat-fuss { padding-left: 16px; padding-right: 16px; }
  .chat-kopf { padding-left: 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .chat-nachricht { max-width: 94%; }
}

/* ---------- Bewegung, Kontrast, Druck ---------- */
@media (prefers-reduced-motion: reduce) {
  .chat-knopf { transition: none; }
  .chat-knopf:hover { transform: none; }
}
@media (prefers-contrast: more) {
  .chat-nachricht, .chat-fenster { border-color: rgba(255, 255, 255, 0.8); }
  .chat-meta, .chat-zu-hinweis { color: var(--muted, #b3bddc); }
}
@media (forced-colors: active) {
  .chat-knopf { border: 2px solid ButtonText; background: ButtonFace; color: ButtonText; forced-color-adjust: none; }
  .chat-knopf-zahl { border: 1px solid ButtonText; background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .chat-fenster, .chat-nachricht, .chat-hinweis { border: 1px solid CanvasText; }
  .chat-nachricht[data-von="besucher"] { border-width: 2px; }
}
@media print {
  .chat-knopf, .chat-fenster { display: none !important; }
}
