/* AP Chatbot – Markendesign (Tinte / Creme / Terracotta) */
#apbot-root {
  --apbot-ink: #1A1410;
  --apbot-cream: #FBF7F0;
  --apbot-rose: #C9907E;
  --apbot-rose-light: #E8C4B8;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: inherit;
}

/* Wichtig: schlägt die display-Regeln unten, damit [hidden] wirklich versteckt.
   Ohne das bliebe das Chatfenster dauerhaft offen. */
#apbot-root [hidden] { display: none !important; }

/* Startknopf */
.apbot-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--apbot-ink);
  color: var(--apbot-cream);
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 28px -8px rgba(26, 20, 16, 0.55);
  transition: transform 0.18s ease, background 0.18s ease;
}
.apbot-btn:hover { background: var(--apbot-rose); transform: translateY(-2px); }
.apbot-btn:focus-visible { outline: 3px solid var(--apbot-rose); outline-offset: 3px; }
.apbot-btn__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--apbot-rose-light);
  flex: 0 0 auto;
}

/* Fenster */
.apbot-panel {
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  /* --apbot-vh wird per JS auf die tatsächlich sichtbare Höhe gesetzt
     (schrumpft mit der Tastatur). dvh als Fallback, vh als letzte Reserve. */
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  max-height: calc(var(--apbot-vh, 100dvh) - 96px);
  background: var(--apbot-cream);
  border-radius: 14px;
  box-shadow: 0 24px 60px -16px rgba(26, 20, 16, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.apbot-kopf {
  background: var(--apbot-ink);
  color: var(--apbot-cream);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}
.apbot-kopf__titel { font-weight: 600; font-size: 1rem; }
.apbot-zu {
  background: none; border: none; color: var(--apbot-cream);
  font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0 4px;
}
.apbot-zu:hover { color: var(--apbot-rose); }
.apbot-zu:focus-visible { outline: 2px solid var(--apbot-rose); }

/* Verlauf */
.apbot-verlauf {
  flex: 1 1 auto;
  /* Ohne min-height:0 weigert sich ein scrollbarer Flex-Bereich zu schrumpfen
     und drückt Kopf und Eingabe aus dem Bild. */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.apbot-msg {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.93rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.apbot-msg--bot { background: #fff; color: var(--apbot-ink); align-self: flex-start; border-bottom-left-radius: 4px; }
.apbot-msg--ich { background: var(--apbot-rose); color: var(--apbot-ink); align-self: flex-end; border-bottom-right-radius: 4px; }

/* Tipp-Animation */
.apbot-tippt { display: flex; gap: 4px; align-items: center; }
.apbot-tippt span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--apbot-rose);
  animation: apbot-blink 1.3s infinite ease-in-out;
}
.apbot-tippt span:nth-child(2) { animation-delay: 0.18s; }
.apbot-tippt span:nth-child(3) { animation-delay: 0.36s; }
@keyframes apbot-blink { 0%, 80%, 100% { opacity: 0.28; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .apbot-tippt span { animation: none; opacity: 0.6; }
  .apbot-btn { transition: none; }
}

/* Dezentes Angebot: erst auf Klick kommt das Mailformular */
.apbot-anbieten {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: #8a7d72;
  padding: 2px 4px;
}
.apbot-anbieten__btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--apbot-rose);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.apbot-anbieten__btn:hover { color: var(--apbot-ink); }
.apbot-anbieten__btn:focus-visible { outline: 2px solid var(--apbot-rose); outline-offset: 2px; }

/* Eskalation */
.apbot-eskal {
  background: #fff;
  border: 1px solid var(--apbot-rose-light);
  border-radius: 12px;
  padding: 13px 14px;
  align-self: stretch;
}
.apbot-eskal p { margin: 0 0 9px; font-size: 0.9rem; line-height: 1.4; }
.apbot-eskal__form { display: flex; gap: 7px; }

/* Eingabe */
.apbot-fuss { flex: 0 0 auto; padding: 12px 14px 10px; border-top: 1px solid var(--apbot-rose-light); }
.apbot-form { display: flex; gap: 7px; }
.apbot-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid #d8d2c8;
  border-radius: 8px;
  font-size: 0.93rem;
  font-family: inherit;
  background: #fff;
  color: var(--apbot-ink);
}
.apbot-input:focus { outline: none; border-color: var(--apbot-rose); box-shadow: 0 0 0 3px rgba(201, 144, 126, 0.2); }
.apbot-send {
  flex: 0 0 auto;
  background: var(--apbot-ink);
  color: var(--apbot-cream);
  border: none;
  border-radius: 8px;
  padding: 11px 17px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.apbot-send:hover:not(:disabled) { background: var(--apbot-rose); }
.apbot-send:disabled { opacity: 0.5; cursor: default; }
.apbot-send:focus-visible { outline: 2px solid var(--apbot-rose); outline-offset: 2px; }

.apbot-hinweis { margin: 8px 0 0; font-size: 0.72rem; color: #8a7d72; line-height: 1.4; }
.apbot-hinweis a { color: var(--apbot-rose); }

.apbot-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; }

@media (max-width: 480px) {
  #apbot-root { right: 12px; bottom: 12px; left: 12px; }
  .apbot-panel {
    width: auto;
    max-width: none;
    /* Fenster passt sich der sichtbaren Höhe an – auch bei offener Tastatur */
    height: calc(100vh - 84px);
    height: calc(100dvh - 84px);
    height: calc(var(--apbot-vh, 100dvh) - 84px);
    max-height: calc(var(--apbot-vh, 100dvh) - 84px);
    min-height: 260px;
  }
  .apbot-btn { float: right; }
  .apbot-verlauf { padding: 12px; gap: 8px; }
  .apbot-msg { max-width: 90%; font-size: 0.9rem; padding: 10px 12px; }
  .apbot-fuss { padding: 10px 12px 8px; }
  .apbot-hinweis { font-size: 0.68rem; margin-top: 6px; }
  .apbot-kopf { padding: 11px 14px; }
}
