/* MarkiMedia — Hilfe-Chat unten rechts (seit 19.09.2026, js/chat.js)
   ------------------------------------------------------------------
   Entwurf: wolke\CHAT-ENTWURF.md, Teil H. Eine eigene Datei statt eines
   Anhangs an stil.css: css-tote-regeln.mjs liest stil.css, und dort
   arbeiten andere Umbauten.

   Hell oder dunkel wie die Seite (seit 19.09.2026 mit Darkmode) — alle
   Farben aus den Token von css/farben.css. Schatten und Schleier nehmen
   --schatten (im Dunkeln schwarz), nicht --tint.

   STAPEL (z-index, vgl. stil.css und dreid.css)
     Sprungleiste 40 · Knopf 55 · Kopf 50 / Kopfbereich, Menue, Klappen 60 ·
     Handy-Kontomenue 69/70 · Handy-Blatt offen 75 · 3D-Fenster 150 ·
     Anmelden und Rechtstexte 170 · Grossansicht 200 · Meldungen 250.
   Der Knopf liegt also unter jedem Fenster: Ein offenes Menue, Kontomenue,
   Fenster oder die Grossansicht deckt ihn zu, ohne dass der Chat etwas tun
   muss (fensterFesthalten macht #chatHuelle dabei ausserdem inert). */

.chat {
  position: fixed; z-index: 55;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
}
/* Auf Finger-Geraeten, solange ein Feld ausserhalb des Chats den Fokus hat:
   Die Bildschirmtastatur schoebe den Knopf sonst ueber Formularfelder. */
.chat.chat-still { display: none !important; }

/* Ohne diese Zeile schluege `display: flex` weiter unten das `hidden` —
   die bekannte Falle der Seite. */
.chat-fenster[hidden], .chat-tippt[hidden], .chat-zaehler[hidden], .chat-schleier[hidden],
.chat-chips[hidden] {
  display: none !important;
}

.chat-vorlesen {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Knopf ── */
.chat-knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 20px 0 16px; border: 0; border-radius: 999px;
  background: var(--verlauf-knopf); color: #fff;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1;
  box-shadow: 0 12px 30px rgba(var(--schatten), .22);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.chat-knopf:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(var(--schatten), .26); }
.chat-knopf:focus-visible { outline: 3px solid var(--akzent); outline-offset: 3px; }
.chat-knopf svg { width: 22px; height: 22px; flex: none; }
.chat-knopf .chat-knopf-zu { display: none; }
.chat.offen .chat-knopf .chat-knopf-auf { display: none; }
.chat.offen .chat-knopf .chat-knopf-zu { display: block; }
/* Offen wird der Knopf rund und zeigt nur das Kreuz (Vorleser hoeren
   "Hilfe-Chat schliessen" aus aria-label). */
.chat.offen .chat-knopf { width: 52px; padding: 0; }
.chat.offen .chat-knopf-wort { display: none; }

/* ── Fenster (ab 641 px Breite und 501 px Hoehe: ueber dem Knopf, nicht
   modal). Seine Oberkante bleibt 20 px unter dem Kopfbereich: Hoehe =
   Fenster minus Kopf minus 104 px (20 Rand, 64 ueber dem Knopf, 20 Luft).
   Den Kopf misst chat.js beim Oeffnen (--chat-kopf, mit Vorstart-Balken);
   die Mindesthoehe von 260 px gibt nach, wenn weniger Platz ist — vorher
   schob sie das Fenster unter den Kopf (Gegenpruefung 18.09.2026). ── */
.chat-fenster {
  position: absolute; right: 0; bottom: 64px;
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 40px));
  height: min(540px, calc(100vh - var(--chat-kopf, var(--kopf-hoehe, 110px)) - 104px));
  height: min(540px, calc(100dvh - var(--chat-kopf, var(--kopf-hoehe, 110px)) - 104px));
  min-height: min(260px, calc(100vh - var(--chat-kopf, var(--kopf-hoehe, 110px)) - 104px));
  min-height: min(260px, calc(100dvh - var(--chat-kopf, var(--kopf-hoehe, 110px)) - 104px));
  padding: 0;                       /* stil.css gibt jeder <section> 60–100 px */
  background: var(--karte); color: var(--text);
  border: 1px solid var(--rand); border-radius: var(--rundung);
  box-shadow: 0 24px 60px rgba(var(--schatten), .22);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-auf .18s ease-out;
}
.chat-fenster.geht { animation: chat-zu .14s ease-in forwards; }
@keyframes chat-auf { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes chat-zu { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.96); } }

.chat-schleier { display: none; }

.chat-kopf {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px 11px 18px; border-bottom: 1px solid var(--rand);
  background: var(--flaeche);
}
.chat-titel { flex: 1 1 auto; margin: 0; font-size: 16px; font-weight: 700; letter-spacing: 0; }
/* Den Titel fokussiert nur chat.js (am Handy beim Oeffnen) — er ist kein
   Bedienelement, ein Rahmen darum saehe aus wie ein Eingabefeld. */
.chat-titel:focus, .chat-titel:focus-visible { outline: none; }
.chat-neu, .chat-zu {
  flex: none; border: 1px solid var(--rand); background: var(--karte); color: var(--leise);
  font-family: inherit; cursor: pointer;
}
.chat-neu { height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.chat-zu { width: 34px; height: 34px; border-radius: 10px; font-size: 20px; line-height: 1; }
.chat-neu:hover, .chat-zu:hover { border-color: var(--randstark); color: var(--text); }
.chat-neu:focus-visible, .chat-zu:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }

/* ── Verlauf ── */
.chat-verlauf {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 16px 10px;
}
.chat-verlauf:focus-visible { outline: 2px solid var(--akzent); outline-offset: -2px; }
.chat-gruss, .chat-nachricht {
  max-width: 90%; margin: 0; padding: 10px 13px;
  font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere;
}
.chat-gruss, .chat-nachricht.hilfe {
  align-self: flex-start;
  background: var(--flaeche); border: 1px solid var(--rand); color: var(--text);
  border-radius: 14px 14px 14px 4px;
}
.chat-nachricht.nutzer {
  align-self: flex-end;
  background: var(--verlauf-knopf); color: #fff;
  border-radius: 14px 14px 4px 14px;
}
.chat-nachricht.fehler { background: var(--fehler-flaeche); border-color: var(--fehler-rand); }
.chat-nachricht p { margin: 0; white-space: pre-line; }
.chat-nachricht p + p { margin-top: 8px; }
.chat-nachricht.hilfe p a { color: var(--akzent); }
.chat-marke {
  display: block; margin-bottom: 4px;
  font-size: 11.5px; font-weight: 600; color: var(--leise);
}

.chat-chips, .chat-links { display: flex; flex-wrap: wrap; gap: 7px; }
.chat-links { margin-top: 10px; }
.chat-chip, .chat-link {
  display: inline-flex; align-items: center; min-height: 36px; max-width: 100%;
  padding: 6px 13px; border: 1px solid var(--randstark); border-radius: 999px;
  background: var(--karte); color: var(--akzent);
  font-family: inherit; font-size: 13px; font-weight: 600; line-height: 1.3;
  text-align: left; text-decoration: none; cursor: pointer;
}
.chat-chip:hover, .chat-link:hover { border-color: var(--akzent); background: rgba(var(--akzent-rgb), .05); }
.chat-chip:focus-visible, .chat-link:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }
.chat-chip:disabled { opacity: .5; cursor: default; }

/* ── Tipp-Anzeige ── */
.chat-tippt { display: flex; align-items: center; gap: 5px; padding: 2px 22px 8px; }
.chat-punkt {
  width: 6px; height: 6px; border-radius: 50%; background: var(--leise); opacity: .3;
  animation: chat-punkt 1s ease-in-out infinite;
}
.chat-punkt:nth-of-type(3) { animation-delay: .15s; }
.chat-punkt:nth-of-type(4) { animation-delay: .3s; }
@keyframes chat-punkt {
  0%, 80%, 100% { opacity: .3; transform: none; }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ── Eingabe ── */
.chat-formular {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  padding: 10px 12px 4px; border-top: 1px solid var(--rand);
}
.chat-formular textarea {
  flex: 1 1 0; min-width: 0; min-height: 44px; max-height: 118px;
  padding: 10px 12px; resize: none; overflow-y: auto;
  border: 1px solid var(--feldrand); border-radius: 12px;
  background: var(--karte); color: var(--text);
  font-family: inherit; font-size: 16px; line-height: 1.45;   /* 16 px: kein Zoom unter iOS */
}
.chat-formular textarea::placeholder { color: var(--leise); opacity: .8; }
.chat-formular textarea:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
.chat-senden {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--verlauf-knopf); color: #fff; cursor: pointer;
}
.chat-senden svg { width: 20px; height: 20px; }
.chat-senden:disabled { opacity: .45; cursor: default; }
.chat-senden:focus-visible { outline: 3px solid var(--akzent); outline-offset: 2px; }
.chat-zaehler { flex: 1 0 100%; font-size: 12px; color: var(--leise); }
.chat-zaehler.voll { color: var(--fehler); }

.chat-hinweis { margin: 0; padding: 4px 16px 12px; font-size: 12px; line-height: 1.45; color: var(--leise); }
.chat-hinweis a { color: var(--leise); text-decoration: underline; }
.chat-hinweis a:hover { color: var(--akzent); }

/* Die Fussleiste bekommt unten Luft: Der Knopf steht 20 px ueber dem Rand
   und ist 52 px hoch, dazu 8 px Abstand. Am Seitenende liegt er so auf
   leerem Grund UNTER dem Pfeil "Nach oben", statt ihn zu verdecken. Kein
   Beobachter, kein Springen. body.mitchat setzt chat.js nur, wenn der Knopf
   da ist. */
body.mitchat .fussleiste { padding-bottom: calc(16px + 80px + env(safe-area-inset-bottom, 0px)); }

/* ── Handy: rund, das Fenster als Blatt von unten, modal ──
   Auch bei wenig Hoehe (Handy quer, seit der Gegenpruefung vom 18.09.2026):
   Unter 500 px schob die Mindesthoehe von 260 px das Seitenfenster unter
   den klebenden Kopfbereich (z-index 60), und ein Tipp auf das × traf den
   Menueknopf der Seite. Dieselbe Abfrage steht in js/chat.js (schmal). */
@media (max-width: 640px), (max-height: 500px) {
  .chat-knopf { width: 52px; padding: 0; }
  .chat-knopf-wort {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
  }
  .chat.offen { z-index: 75; }
  .chat.offen .chat-knopf { visibility: hidden; }
  .chat-schleier {
    display: block; position: fixed; inset: 0;
    background: rgba(var(--schatten), .42);
  }
  .chat-fenster {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto;
    height: min(88vh, 640px); height: min(88dvh, 640px); min-height: 0;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform-origin: bottom center;
    animation-name: chat-hoch;
  }
  .chat-fenster.geht { animation-name: chat-runter; }
  .chat-chip, .chat-link { min-height: 44px; }
  .chat-gruss, .chat-nachricht { max-width: 94%; }
}
@keyframes chat-hoch { from { opacity: .4; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes chat-runter { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(40px); } }

body.chat-offen { overflow: hidden; }

/* Wer Bewegung nicht mag, bekommt keine — die globale Regel in stil.css
   deckt das ab, hier trotzdem ausdruecklich: Die Punkte stehen still. */
@media (prefers-reduced-motion: reduce) {
  .chat-fenster, .chat-fenster.geht, .chat-punkt { animation: none; }
  .chat-punkt { opacity: .6; }
  .chat-knopf { transition: none; }
  .chat-knopf:hover { transform: none; }
}

@media print { .chat { display: none; } }
