/* ===================================================================
   palais f. – Anfrage als Chat
   Wird nur auf der Anfrage-Seite geladen (pf/anfrage.php). Nutzt die
   Design-Tokens aus template.css; die Werte hinter dem Komma greifen nur,
   falls ein Token fehlt.
   =================================================================== */

[data-pf-anfrage] {
  --pf-chat-paper: var(--paper, #FFFFFF);
  --pf-chat-soft-bg: var(--paper-2, #F4F4F2);
  --pf-chat-ink: var(--ink, #211D18);
  /* kleiner Text: dunkler als --muted, damit der Kontrast auf Grau reicht */
  --pf-chat-soft: var(--ink-soft, #3A352D);
  --pf-chat-line: var(--line, rgba(33, 29, 24, .12));
  --pf-chat-edge: rgba(33, 29, 24, .5);
  --pf-chat-accent: var(--accent, #FFFF00);
  --pf-chat-err: #A3241C;
  /* Höhe der mitlaufenden Kopfzeile im gescrollten Zustand (template.css: --header-h) */
  --pf-chat-top: 72px;
  scroll-margin-top: calc(var(--pf-chat-top) + 12px);
}

.pf-chat-vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.pf-chat-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Rahmen ---------- */
.pf-chat-col { min-width: 0; }
.pf-chat {
  display: flex; flex-direction: column; min-width: 0;
  height: min(700px, calc(100vh - var(--pf-chat-top) - 48px)); min-height: 500px;
  background: var(--pf-chat-paper); color: var(--pf-chat-ink);
  border: 1px solid var(--pf-chat-line);
  font-family: var(--font, system-ui, sans-serif);
}
/* Start, Zusammenfassung und Bestätigung: Rahmen so hoch wie der Inhalt, die Seite scrollt */
.pf-chat.is-start, .pf-chat.is-open { height: auto; min-height: 0; }
.pf-chat.is-open .pf-chat__log { overflow: visible; }
.pf-chat[hidden], .pf-chat [hidden] { display: none !important; }
.pf-chat :focus-visible,
.pf-chat-fallback :focus-visible { outline: 3px solid var(--pf-chat-ink); outline-offset: 2px; }
.pf-chat__log:focus { outline: none; }

.pf-chat__head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--pf-chat-line);
}
.pf-chat__avatar { width: 44px; height: 44px; flex: 0 0 44px; object-fit: cover; object-position: center 22%; display: block; }
.pf-chat__headtext { min-width: 0; flex: 1; }
.pf-chat__title { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
.pf-chat__who { margin: 0; font-size: 13.5px; line-height: 1.35; color: var(--pf-chat-soft); }
.pf-chat__progress { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 0 0 auto; }
.pf-chat__count { font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--pf-chat-soft); font-variant-numeric: tabular-nums; }
.pf-chat__bar { display: block; width: 84px; height: 4px; background: var(--pf-chat-line); overflow: hidden; }
.pf-chat__bar i { display: block; height: 100%; background: var(--pf-chat-ink); transform-origin: left center; transform: scaleX(var(--pf-chat-p, 0)); transition: transform .4s ease; }

/* ---------- angeheftete Schritte ---------- */
.pf-chat__steps { overflow-x: auto; border-bottom: 1px solid var(--pf-chat-line); scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.pf-chat__steplist { display: flex; gap: 6px; list-style: none; margin: 0; padding: 10px 16px; width: max-content; }
.pf-chat__steplist li { margin: 0; padding: 0; }
.pf-chat-step {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  min-height: 44px; max-width: 190px; padding: 4px 10px;
  border: 1px solid var(--pf-chat-edge); background: transparent; color: var(--pf-chat-ink);
  font: inherit; text-align: left; border-radius: 0;
}
.pf-chat-step small { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; line-height: 1.4; color: var(--pf-chat-soft); }
.pf-chat-step span { font-size: 14px; line-height: 1.35; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.pf-chat-step { cursor: pointer; transition: background .15s ease; }
button.pf-chat-step small::after { content: " \270E"; letter-spacing: 0; }
button.pf-chat-step:hover { background: var(--pf-chat-accent); }
.pf-chat-step.is-now { border-style: dashed; }

/* ---------- Start: E-Mail zuerst ---------- */
.pf-chat__start { display: flex; flex-direction: column; gap: 22px; padding: 30px 24px 32px; }
.pf-chat__intro { margin: 0; font-size: 19px; line-height: 1.5; color: var(--pf-chat-soft); max-width: 44ch; }
.pf-chat__startform { display: flex; flex-direction: column; gap: 8px; }
.pf-chat__label { font-size: 14px; font-weight: 600; }
.pf-chat__row { display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.pf-chat__input {
  flex: 1 1 200px; min-width: 0; min-height: 52px; padding: 12px 14px;
  font: 400 16px/1.4 var(--font, system-ui, sans-serif); color: var(--pf-chat-ink);
  background: #fff; border: 1.5px solid var(--pf-chat-edge); border-radius: 0;
  -webkit-appearance: none; appearance: none;
}
.pf-chat__input::placeholder { color: #6B645A; opacity: 1; }
.pf-chat__input--long { resize: none; min-height: 68px; }
.pf-chat__input[aria-invalid="true"] { border-color: var(--pf-chat-err); }
.pf-chat .pf-btn { justify-content: center; min-height: 52px; padding: 0 24px; box-shadow: none; }
.pf-chat .pf-btn:hover { transform: none; }
.pf-chat .pf-btn:disabled { opacity: .55; cursor: default; }
.pf-chat__err { margin: 0; min-height: 1.4em; font-size: 14.5px; line-height: 1.4; color: var(--pf-chat-err); }
.pf-chat__err:empty { min-height: 0; }

/* ---------- Verlauf ---------- */
.pf-chat__log {
  position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px; padding: 18px 16px;
}
/* Nachrichten behalten ihre Höhe; gescrollt wird der Verlauf */
.pf-chat__log > * { flex: 0 0 auto; }
.pf-chat-msg {
  max-width: 86%; padding: 11px 15px; font-size: 16.5px; line-height: 1.45;
  overflow-wrap: anywhere; white-space: pre-line; animation: pf-chat-in .24s ease-out both;
}
.pf-chat-msg--bot { align-self: flex-start; background: var(--pf-chat-soft-bg); }
.pf-chat-msg--user { align-self: flex-end; background: var(--pf-chat-accent); font-weight: 500; }
.pf-chat-msg--big { font-size: 22px; font-weight: 600; letter-spacing: -.01em; background: var(--pf-chat-accent); }
.pf-chat-msg--err { box-shadow: inset 3px 0 0 var(--pf-chat-err); }
.pf-chat-typing { align-self: flex-start; display: flex; gap: 5px; padding: 15px 15px; background: var(--pf-chat-soft-bg); }
.pf-chat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--pf-chat-soft); animation: pf-chat-dot 1s infinite; }
.pf-chat-typing i:nth-child(2) { animation-delay: .15s; }
.pf-chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes pf-chat-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes pf-chat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.pf-chat-opts { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; animation: pf-chat-in .24s ease-out both; }
.pf-chat-opt {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 10px 16px;
  font: 500 16px/1.3 var(--font, system-ui, sans-serif); color: var(--pf-chat-ink); text-align: left;
  background: #fff; border: 1.5px solid var(--pf-chat-ink); border-radius: 0; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.pf-chat-opt:hover { background: var(--pf-chat-accent); }
.pf-chat-opt--soft { border-color: var(--pf-chat-edge); font-weight: 400; }
.pf-chat-opt:disabled { cursor: default; opacity: .45; }
.pf-chat-opt:disabled:hover { background: #fff; }
.pf-chat-opt__tip { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 3px 6px; background: var(--pf-chat-ink); color: #fff; }

/* ---------- Eingabezeile ---------- */
.pf-chat__composer { border-top: 1px solid var(--pf-chat-line); padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
.pf-chat__composertop { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 36px; }
.pf-chat__hint { font-size: 13.5px; line-height: 1.3; color: var(--pf-chat-soft); }
.pf-chat__back {
  flex: 0 0 auto; min-height: 36px; padding: 0 4px; background: none; border: 0; cursor: pointer;
  font: 600 13.5px/1 var(--font, system-ui, sans-serif); color: var(--pf-chat-ink);
  text-decoration: underline; text-underline-offset: 3px;
}
.pf-chat__back::before { content: "\2190\00a0"; }
.pf-chat__back:disabled { visibility: hidden; }
.pf-chat__composer .pf-chat__row { flex-wrap: nowrap; }
.pf-chat-opts--composer { margin-top: 10px; }
.pf-chat__composer .pf-btn { padding: 0 20px; }

/* ---------- Zusammenfassung ---------- */
.pf-chat-sum { align-self: stretch; border: 1.5px solid var(--pf-chat-ink); background: #fff; animation: pf-chat-in .24s ease-out both; }
.pf-chat-sum__title { margin: 0; padding: 16px 16px 10px; font-size: 20px; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
.pf-chat-sum__title:focus { outline: none; }
.pf-chat-sum__list { margin: 0; padding: 0 16px; }
.pf-chat-sum__row { display: grid; grid-template-columns: minmax(96px, 30%) 1fr auto; column-gap: 12px; align-items: center; border-top: 1px solid var(--pf-chat-line); min-height: 44px; }
.pf-chat.is-open .pf-chat-done { padding-bottom: 8px; }
.pf-chat-sum__row dt { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--pf-chat-soft); }
.pf-chat-sum__row dd { margin: 0; }
.pf-chat-sum__val { padding: 8px 0; font-size: 16px; line-height: 1.4; min-width: 0; overflow-wrap: anywhere; white-space: pre-line; }
.pf-chat-sum__edit {
  min-height: 44px; padding: 0 2px 0 8px; background: none; border: 0; cursor: pointer;
  font: 600 13.5px/1 var(--font, system-ui, sans-serif); color: var(--pf-chat-ink);
  text-decoration: underline; text-underline-offset: 3px;
}
.pf-chat-sum__edit:disabled { visibility: hidden; }
.pf-chat-sum__est { margin: 14px 16px 0; padding: 12px 14px; background: var(--pf-chat-soft-bg); box-shadow: inset 4px 0 0 var(--pf-chat-accent); font-size: 15.5px; line-height: 1.5; }
.pf-chat-sum__consent { display: flex; gap: 12px; align-items: flex-start; padding: 16px 16px 6px; font-size: 14.5px; line-height: 1.5; color: var(--pf-chat-soft); cursor: pointer; }
.pf-chat-sum__consent input { flex: 0 0 auto; width: 22px; height: 22px; margin: 0; accent-color: var(--pf-chat-ink); }
.pf-chat-sum__consent a { color: var(--pf-chat-ink); }
.pf-chat-sum .pf-chat__err { padding: 0 16px; }
.pf-chat-sum__send { display: flex; width: calc(100% - 32px); margin: 10px 16px 16px; }

/* ---------- Danach ---------- */
.pf-chat-done { align-self: flex-start; max-width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding-top: 6px; animation: pf-chat-in .24s ease-out both; }
.pf-chat-done p { margin: 0; font-size: 16px; line-height: 1.5; }
.pf-chat-done__links { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.pf-chat-done__links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--pf-chat-ink); font-weight: 600; text-underline-offset: 3px; }
.pf-chat-ext::after { content: "\00a0\2197"; }

/* ---------- Normales Formular (ohne JavaScript) und Meldung nach dessen Absenden ---------- */
.pf-chat-fallback[hidden] { display: none; }
.pf-chat-fallback__title { margin: 0 0 22px; font-size: clamp(26px, 3vw, 38px); font-weight: 500; line-height: 1.1; letter-spacing: -.02em; }
.pf-chat-fallback fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.pf-chat-fallback legend { padding: 0; margin-bottom: 9px; }
.pf-chat-fallback .pf-input { min-width: 0; width: 100%; padding: 14px 16px; border-color: var(--pf-chat-edge); }
.pf-chat-fallback .pf-radio { min-height: 44px; }
.pf-chat-fallback .pf-radio input { width: 20px; height: 20px; }
.pf-chat-fallback .pf-form__note { max-width: none; align-items: flex-start; }
.pf-chat-note { margin: 0 0 18px; padding: 14px 16px; background: var(--pf-chat-paper); box-shadow: inset 4px 0 0 var(--pf-chat-accent); font-size: 17px; line-height: 1.5; }
.pf-chat-note--err { box-shadow: inset 4px 0 0 var(--pf-chat-err); }

/* Links in der Janine-Box: gut treffbar */
.pf-chat-links a { display: inline-block; padding: 4px 0; }

/* ---------- Breiten ---------- */
@media (min-width: 1025px) {
  /* Chat bleibt beim Scrollen neben den Schritten stehen */
  .pf-chat-layout > .pf-chat-col { position: sticky; top: calc(var(--pf-chat-top) + 24px); }
  /* Die Karte kann höher sein als das Fenster: dann nicht festhalten */
  .pf-chat-layout > .pf-chat-col.is-open { position: static; }
}
@media (max-width: 860px) {
  /* Handy: erst der Chat, dann die Schritte und die Janine-Box */
  .pf-chat-layout > .pf-chat-col { order: -1; }
  [data-pf-anfrage] { --pf-chat-top: 62px; }
  .pf-chat { height: min(680px, calc(100svh - var(--pf-chat-top) - 20px)); min-height: 420px; }
  .pf-chat.is-keyboard:not(.is-start):not(.is-open) { height: calc(var(--pf-chat-vh, 100svh) - var(--pf-chat-top) - 12px); min-height: 0; }
  /* Die feste Leiste „Anrufen / Anfragen" würde das Eingabefeld verdecken; Telefon steht in der Janine-Box */
  body.pf-page--anfrage .seo-mbar { display: none !important; }
  .pf-chat.is-keyboard .pf-chat__head,
  .pf-chat.is-keyboard .pf-chat__steps { display: none; }
  .pf-chat-msg { max-width: 92%; }
  .pf-chat__start { padding: 22px 18px 24px; }
  .pf-chat__intro { font-size: 17.5px; }
  .pf-chat__startform .pf-btn { flex: 1 1 100%; }
  .pf-chat-opts { align-self: stretch; }
  .pf-chat-opt { flex: 1 1 calc(50% - 4px); }
  .pf-chat-sum__row { grid-template-columns: 1fr auto; }
  .pf-chat-sum__row dt { grid-column: 1; grid-row: 1; padding-top: 9px; }
  .pf-chat-sum__val { grid-column: 1; grid-row: 2; padding: 1px 0 8px; }
  .pf-chat-sum__act { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
}
@media (max-width: 400px) {
  .pf-chat__composer .pf-btn { padding: 0 14px; }
  .pf-chat__bar { width: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .pf-chat-msg, .pf-chat-opts, .pf-chat-sum, .pf-chat-done { animation: none; }
  .pf-chat-typing i { animation: none; opacity: .6; }
  .pf-chat__bar i, .pf-chat-opt, button.pf-chat-step { transition: none; }
}
