/* Cortexion — Anfrage-Chat (partials/components/inquiry-chat.php)
   Schwarzer Auslöser wie der Primary-Button, weißes Fenster mit der
   Cyan-Hairline der Fußzeile als Markenmotiv. Cyan bleibt dosiert:
   Signet, Hairline, Marker und Fokus. */

.ichat {
  --ichat-gap: 1rem;
  --ichat-offset: 0rem;
}

@media (min-width: 640px) {
  .ichat { --ichat-gap: 1.5rem; }
}

/* Mitlaufender Buchen-Knopf auf /ihr-entwurf: Chat-Auslöser darüber setzen */
body:has(.offer-sticky.is-visible) .ichat { --ichat-offset: 5rem; }

/* --- Auslöser ----------------------------------------------------------- */

.ichat-launcher {
  position: fixed;
  right: var(--ichat-gap);
  bottom: calc(var(--ichat-gap) + var(--ichat-offset) + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  display: none;
  align-items: center;
  gap: 0.625rem;
  min-height: 3rem;
  padding: 0.5rem 1.125rem 0.5rem 0.5rem;
  border: 0;
  border-radius: 9999px;
  background-color: #0a0b14;
  color: #ffffff;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.12),
    0 2px 6px 0 rgba(15, 23, 42, 0.14),
    0 14px 36px -10px rgba(15, 23, 42, 0.45);
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.25s ease, bottom 0.25s ease-out;
}

html.js .ichat-launcher { display: inline-flex; }

/* Solange der Cookie-Hinweis offen ist, hat er Vorrang am unteren Rand */
body:has(#cookie-banner:not(.hidden)) .ichat-launcher { display: none; }

.ichat-launcher:hover {
  background-color: #1a1c2e;
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.16),
    0 2px 6px 0 rgba(15, 23, 42, 0.14),
    0 18px 40px -10px rgba(15, 23, 42, 0.5),
    0 0 60px -12px var(--brand-glow);
}

.ichat-launcher:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 3px; }

.ichat-launcher-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  background-color: rgba(255, 255, 255, 0.1);
}

.ichat-launcher-icon svg { width: 1.125rem; height: 1.125rem; }

/* Markenpunkt: kleiner Cyan-Marker am Symbol */
.ichat-launcher-icon::after {
  content: "";
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background-color: var(--brand-500);
  box-shadow: 0 0 0 2px #0a0b14;
}

/* --- Fenster -------------------------------------------------------------- */

.ichat-panel {
  position: fixed;
  inset: 0;
  z-index: 46;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background-color: #ffffff;
  color: #2c2e44;
  overflow: hidden;
  overflow: clip;
}

.ichat-panel[hidden] { display: none; }

.ichat-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background-image: linear-gradient(90deg, transparent, var(--brand-500), transparent);
  pointer-events: none;
}

@media (max-width: 639px) {
  .ichat.is-open .ichat-launcher { display: none; }
  html.ichat-open { overflow: hidden; }
}

@media (min-width: 640px) {
  .ichat-panel {
    inset: auto var(--ichat-gap) calc(var(--ichat-gap) + var(--ichat-offset) + 3.75rem) auto;
    width: min(25rem, calc(100vw - 2 * var(--ichat-gap)));
    height: min(38rem, calc(100vh - 7.5rem));
    height: min(38rem, calc(100dvh - 7.5rem - var(--ichat-offset)));
    border: 1px solid var(--border-hairline);
    border-radius: 1.25rem;
    box-shadow:
      0 1px 2px 0 rgba(15, 23, 42, 0.06),
      0 24px 60px -18px rgba(15, 23, 42, 0.35);
  }
}

.ichat-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.75rem 0.875rem 1rem;
  border-bottom: 1px solid var(--border-hairline);
}

.ichat-avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  background-color: #0a0b14;
  color: var(--brand-400);
}

.ichat-avatar-mark { width: 1.25rem; height: 1.25rem; }

.ichat-head-text { flex: 1; min-width: 0; }

.ichat-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: #0a0b14;
}

.ichat-progress {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
  color: #6b6e85;
}

.ichat-close {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 0.625rem;
  background: transparent;
  color: #4a4d63;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.ichat-close:hover { background-color: rgba(15, 23, 42, 0.05); color: #0a0b14; }

.ichat-close svg { width: 1.25rem; height: 1.25rem; }

/* --- Gesprächsverlauf ------------------------------------------------------ */

.ichat-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin: 0;
  padding: 1rem;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--bg-base);
}

.ichat-msg {
  position: relative;
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.ichat-msg-bot {
  align-self: flex-start;
  border: 1px solid var(--border-hairline);
  border-bottom-left-radius: 0.375rem;
  background-color: #ffffff;
  color: #2c2e44;
}

.ichat-msg-bot a {
  color: var(--brand-700);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}

.ichat-msg-bot a:hover { color: var(--brand-800); }

.ichat-msg-user {
  align-self: flex-end;
  border-bottom-right-radius: 0.375rem;
  background-color: #0a0b14;
  color: #ffffff;
}

.ichat-msg-user.is-empty {
  background-color: var(--accent-100);
  color: #4a4d63;
}

.ichat-msg-success {
  border-color: var(--brand-border);
  background-color: var(--brand-50);
  color: #0a0b14;
}

.ichat-msg.is-new {
  animation: ichat-in 0.28s ease-out;
}

@keyframes ichat-in { from { transform: translateY(6px); opacity: 0.4; } to { transform: none; opacity: 1; } }

/* Zusammenfassung vor dem Absenden */
.ichat-summary { width: 88%; white-space: normal; }

.ichat-summary dl { margin: 0; }

.ichat-summary-row {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-hairline);
}

.ichat-summary-row:first-child { border-top: 0; padding-top: 0; }

.ichat-summary dt {
  grid-column: 1;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b6e85;
}

.ichat-summary dd {
  grid-column: 1;
  margin: 0.125rem 0 0;
  color: #0a0b14;
  white-space: pre-line;
}

.ichat-summary dd.is-empty { color: #6b6e85; }

.ichat-edit {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  min-height: 2.25rem;
  padding: 0 0.5rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--brand-700);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.ichat-edit:hover { color: var(--brand-800); background-color: var(--brand-tint); }

/* --- Eingabebereich -------------------------------------------------------- */

.ichat-composer {
  padding: 0.875rem 1rem 0.75rem;
  border-top: 1px solid var(--border-hairline);
  background-color: #ffffff;
}

.ichat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.ichat-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #2c2e44;
}

.ichat-optional { font-weight: 400; color: #6b6e85; }

/* 16 px verhindert das automatische Hineinzoomen auf iOS */
.ichat .ichat-input { font-size: 1rem; padding: 0.625rem 0.875rem; }

.ichat textarea.ichat-input {
  min-height: 5.5rem;
  max-height: 10rem;
  resize: vertical;
}

.ichat .ichat-input[aria-invalid="true"] { border-color: #b42318; }

.ichat-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.ichat-option {
  min-height: 2.75rem;
  padding: 0.5rem 0.9375rem;
  border: 1px solid var(--border-soft);
  border-radius: 9999px;
  background-color: #ffffff;
  color: #0a0b14;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.ichat-option:hover { border-color: var(--brand-400); background-color: var(--brand-50); }

.ichat-option[aria-pressed="true"] { border-color: #0a0b14; box-shadow: inset 0 0 0 1px #0a0b14; }

.ichat-consent {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #2c2e44;
}

.ichat-consent input {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.125rem;
  accent-color: #0a0b14;
}

.ichat-consent a {
  color: var(--brand-700);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ichat-error {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #b42318;
}

.ichat-error:not(:empty) { margin-top: 0.5rem; }

.ichat-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.ichat-actions-main {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.ichat-back,
.ichat-skip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.75rem;
  padding: 0 0.625rem;
  border: 0;
  border-radius: 0.625rem;
  background: transparent;
  color: #4a4d63;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.ichat-back:hover,
.ichat-skip:hover { background-color: rgba(15, 23, 42, 0.05); color: #0a0b14; }

.ichat-back svg { width: 1rem; height: 1rem; }

.ichat-back[hidden],
.ichat-skip[hidden],
.ichat-actions [hidden] { display: none; }

.ichat-next { min-height: 2.75rem; }

.ichat-next:disabled { cursor: progress; opacity: 0.7; transform: none; }

.ichat-note {
  margin: 0;
  padding: 0 1rem calc(0.875rem + env(safe-area-inset-bottom, 0px));
  background-color: #ffffff;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #6b6e85;
}

.ichat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .ichat-launcher,
  .ichat-option,
  .ichat-close { transition: none; }
  .ichat-msg.is-new { animation: none; }
  .ichat-launcher:hover { transform: none; }
}
