/* Chatbot Widget — Frauenarztpraxis im Medicum
 * Test-Deployment unter /test-bot-xk4q/
 * Farben aus Corporate: #F24147 Rot, #303940 Text, #f6f8fb Hintergrund
 */

:root {
  --fim-bot-red:    #F24147;
  --fim-bot-red-d:  #d8363c;
  --fim-bot-text:   #303940;
  --fim-bot-text-2: #3d4651;
  --fim-bot-bg:     #f6f8fb;
  --fim-bot-panel:  #ffffff;
  --fim-bot-line:   #e5e8ed;
  --fim-bot-shadow: 0 16px 48px rgba(40, 50, 65, 0.22);
  --fim-bot-radius: 18px;
  --fim-bot-font:   'Source Sans Pro', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.fim-bot, .fim-bot * { box-sizing: border-box; }
.fim-bot { font-family: var(--fim-bot-font); }

/* ===== Floating launcher (Avatar) ===== */
.fim-bot-launcher {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 72px;
  height: 72px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  z-index: 999998;
  animation: fimFloat 4s ease-in-out infinite;
  filter: drop-shadow(0 6px 12px rgba(242, 65, 71, 0.35));
  transition: transform .2s ease;
}
.fim-bot-launcher:hover { transform: scale(1.08); }
.fim-bot-launcher:active { transform: scale(0.95); }
.fim-bot-launcher:focus-visible {
  outline: 3px solid var(--fim-bot-red);
  outline-offset: 4px;
  border-radius: 50%;
}

.fim-bot-launcher svg { width: 100%; height: 100%; display: block; }

@keyframes fimFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

/* Cookie-Banner-Pulse: wenn User Bot anklickt obwohl Banner noch offen ist,
   wird der Banner kurz hervorgehoben — als sanftes "Hier zuerst entscheiden!" */
.consent-overlay.is-pulsing,
.consent-overlay.is-pulsing .consent-modal {
  animation: fimConsentNudge 1.5s ease-out;
}
@keyframes fimConsentNudge {
  0%, 100% { transform: scale(1); }
  20%      { transform: scale(1.025); box-shadow: 0 0 0 6px rgba(242, 65, 71, 0.25); }
  40%      { transform: scale(0.99); }
  60%      { transform: scale(1.015); }
}

/* Bubble fade-out (smooth disappearance after inactivity) */
.fim-bot-bubble[hidden] {
  display: block !important;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
  visibility: hidden;
}
.fim-bot-bubble:not([hidden]) {
  transition: opacity 0.4s ease-in, transform 0.4s ease-in;
}

/* Glow-Pulse als "Lebenszeichen" — laeuft ~1.5s wenn Bubble weg ist */
.fim-bot-launcher.is-glowing {
  animation: fimFloat 4s ease-in-out infinite, fimGlowPulse 1.5s ease-out;
}
@keyframes fimGlowPulse {
  0%   { box-shadow: 0 6px 12px rgba(242, 65, 71, 0.35); }
  35%  { box-shadow: 0 6px 24px rgba(242, 65, 71, 0.65), 0 0 0 10px rgba(242, 65, 71, 0.18); }
  100% { box-shadow: 0 6px 12px rgba(242, 65, 71, 0.35); }
}

/* ===== Avatar-Stack (5 WebP-Frames gestapelt, einer aktiv via .is-active) ===== */
.fim-bot-avatar-stack {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
}
.fim-bot-avatar-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 0.08s ease-in-out;
  pointer-events: none;
  user-select: none;
}
.fim-bot-avatar-frame.is-active {
  opacity: 1;
}
/* Instant-Switch (kein Cross-Fade) — wird vom JS beim Blinzeln aktiviert,
   damit nicht beide Frames zur Mitte halb-transparent werden. */
.fim-bot-avatar-stack.no-fade .fim-bot-avatar-frame {
  transition: none;
}

/* State-Animationen — sanft, nicht aufdringlich. data-bot-state auf .fim-bot Root. */
@keyframes fimIdleBreathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.025); }
}
@keyframes fimThinkingWobble {
  0%, 100% { transform: rotate(-2.2deg); }
  50%      { transform: rotate(2.2deg); }
}
@keyframes fimSpeakingBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.5px); }
}
@keyframes fimHappyHop {
  0%   { transform: translateY(0) scale(1); }
  35%  { transform: translateY(-5px) scale(1.06); }
  70%  { transform: translateY(0) scale(1); }
  100% { transform: translateY(0) scale(1); }
}
[data-bot-state="idle"] .fim-bot-avatar-stack {
  animation: fimIdleBreathe 4.2s ease-in-out infinite;
  transform-origin: 50% 90%;
}
[data-bot-state="thinking"] .fim-bot-avatar-stack {
  animation: fimThinkingWobble 1.4s ease-in-out infinite;
  transform-origin: 50% 95%;
}
[data-bot-state="speaking"] .fim-bot-avatar-stack {
  animation: fimSpeakingBounce 0.42s ease-in-out infinite;
}
[data-bot-state="happy"] .fim-bot-avatar-stack {
  animation: fimHappyHop 0.7s ease-out;
  transform-origin: 50% 90%;
}

/* Notification-Dot ueber dem Avatar */
.fim-bot-dot {
  position: absolute;
  top: 0; right: 0;
  width: 18px; height: 18px;
  background: #fff;
  color: var(--fim-bot-red);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  opacity: 0;
  transform: scale(0);
  transition: opacity .3s, transform .3s cubic-bezier(.34,1.56,.64,1);
}
.fim-bot-launcher[data-unread="1"] .fim-bot-dot {
  opacity: 1;
  transform: scale(1);
}

/* ===== Auto-Bubble (Begruessung nach 10s) ===== */
.fim-bot-bubble {
  position: fixed;
  bottom: 105px;
  right: 22px;
  max-width: 260px;
  padding: 14px 18px;
  background: var(--fim-bot-panel);
  color: var(--fim-bot-text);
  border-radius: 14px;
  box-shadow: var(--fim-bot-shadow);
  font-family: var(--fim-bot-font);
  font-size: 15px;
  line-height: 1.4;
  z-index: 999997;
  cursor: pointer;
  animation: fimBubbleIn .4s cubic-bezier(.34,1.56,.64,1);
}
.fim-bot-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 30px;
  width: 16px; height: 16px;
  background: var(--fim-bot-panel);
  transform: rotate(45deg);
  box-shadow: 3px 3px 6px rgba(40,50,65,0.08);
}
.fim-bot-bubble-close {
  position: absolute;
  top: 6px; right: 6px;
  background: none; border: none;
  color: var(--fim-bot-text);
  opacity: 0.5;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.fim-bot-bubble-close:hover { opacity: 1; }
.fim-bot-bubble[hidden] { display: none; }
@keyframes fimBubbleIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Chatfenster ===== */
.fim-bot-panel {
  position: fixed;
  bottom: 110px;
  right: 22px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 130px);
  background: var(--fim-bot-bg);
  border-radius: var(--fim-bot-radius);
  box-shadow: var(--fim-bot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  font-family: var(--fim-bot-font);
  color: var(--fim-bot-text);
  animation: fimPanelIn .3s cubic-bezier(.34,1.56,.64,1);
}
.fim-bot-panel[hidden] { display: none; }
@keyframes fimPanelIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fim-bot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--fim-bot-text);
  color: #fff;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.fim-bot-header-avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  background: #fff;
  border-radius: 50%;
  padding: 2px;
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.fim-bot-header-text { flex: 1; min-width: 0; }
.fim-bot-header-title { font-size: 15px; font-weight: 600; line-height: 1.2; letter-spacing: 0.01em; }
.fim-bot-header-sub { font-size: 11.5px; opacity: 0.7; line-height: 1.3; }
.fim-bot-header-close {
  background: none; border: none;
  color: #fff; font-size: 24px; line-height: 1;
  cursor: pointer;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 10px;
  flex-shrink: 0;
}
.fim-bot-header-close:hover { background: rgba(255,255,255,0.12); }
.fim-bot-header-close:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }

/* Sprach-Pill: DE | EN | ES als kleine Toggle-Group im Header */
.fim-bot-lang-pill {
  display: inline-flex;
  background: rgba(255,255,255,0.10);
  border-radius: 999px;
  padding: 2px;
  flex-shrink: 0;
}
.fim-bot-lang-btn {
  background: none; border: none;
  color: rgba(255,255,255,0.65);
  font-family: inherit;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em;
  padding: 4px 9px; min-width: 28px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fim-bot-lang-btn:hover { color: #fff; }
.fim-bot-lang-btn.is-active {
  background: #fff;
  color: var(--fim-bot-text);
}

/* ===== Messages ===== */
.fim-bot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.fim-bot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: fimMsgIn .25s ease-out;
}
@keyframes fimMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fim-bot-msg-bot {
  align-self: flex-start;
  background: var(--fim-bot-panel);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(40,50,65,0.06);
}
.fim-bot-msg-user {
  align-self: flex-end;
  background: var(--fim-bot-text-2);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.fim-bot-msg a {
  color: var(--fim-bot-red);
  text-decoration: underline;
  word-break: break-all;
}
.fim-bot-msg-user a { color: #fff; }
.fim-bot-msg strong { font-weight: 700; }

/* Bubble-Timestamp (HH:MM) am unteren Bubble-Rand, rechts ausgerichtet —
   WhatsApp-Style. Klein, dezent, nicht selektierbar. */
.fim-bot-msg-time {
  font-size: 10.5px;
  line-height: 1;
  color: #94a0ad;
  margin-top: 6px;
  text-align: right;
  user-select: none;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.fim-bot-msg-user .fim-bot-msg-time {
  color: rgba(255, 255, 255, 0.7);
}
.fim-bot-followup .fim-bot-msg-time { display: none; }
.fim-bot-typing-wrap .fim-bot-msg-time { display: none; }

/* Last-Update-Stamp neben/unter Disclaimer — dezent, schafft Vertrauen */
.fim-bot-stamp {
  display: block;
  font-size: 10px;
  opacity: 0.55;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* Notfall-Hinweis im Footer — dezent dunkelrot, klein, nicht ablenkend (Healthcare-Compliance) */
.fim-bot-emergency {
  display: block;
  font-size: 11px;
  color: #8B1A1F;
  margin-top: 4px;
  letter-spacing: 0.01em;
}
.fim-bot-emergency a {
  color: #8B1A1F;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted rgba(139, 26, 31, 0.4);
}
.fim-bot-emergency a:hover { border-bottom-style: solid; }

/* Mini-Gynnie als Smiley-Ersatz im Typing-Indicator */
.fim-bot-typing-avatar {
  width: 24px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 4px;
  flex-shrink: 0;
}

/* Follow-up Bubble: dezenter, kleiner, kursiv — "Noch Fragen?" nach jeder Bot-Antwort */
.fim-bot-followup {
  font-size: 13px;
  font-style: italic;
  opacity: 0.8;
  padding: 8px 12px;
  margin-top: 4px;
}

/* App-Block (App-Icon + Apple-Download-Badge + QR-Code) bei Bot-Antwort mit App-Link.
   Mike-Vorgabe 24.04.2026: visuelle "Leerzeile" zwischen Info-Block und Kontakt-Block —
   Border-Top entfernt, dafuer mehr margin-top als optische Trennung. */
.fim-bot-app-block {
  margin-top: 18px;
  padding-top: 0;
  border-top: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  justify-items: center;
}
/* Compact-Variante fuer Folge-Erwaehnungen der App im selben Chat:
   nur Apple-Badge, kein Icon, kein QR — App ist bekannt, dezenter Hinweis reicht. */
.fim-bot-app-block.is-compact {
  grid-template-columns: 1fr;
  justify-items: start;
  margin-top: 16px;
}
.fim-bot-app-block.is-compact .fim-bot-app-icon-link,
.fim-bot-app-block.is-compact .fim-bot-qr-wrap {
  display: none;
}
.fim-bot-app-icon-link,
.fim-bot-app-badge-link {
  display: inline-block;
  line-height: 0;
  text-decoration: none;
  border: 0;
}
.fim-bot-app-icon {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  display: block;
  box-shadow: 0 1px 3px rgba(40, 50, 65, 0.12);
}
.fim-bot-app-badge {
  height: 42px;
  width: auto;
  display: block;
}
/* Standalone QR (Legacy + innerhalb des App-Blocks) */
.fim-bot-qr-wrap {
  text-align: center;
}
.fim-bot-app-block .fim-bot-qr-wrap {
  margin: 0;
  padding: 0;
  border: 0;
}
.fim-bot-qr {
  display: inline-block;
  width: 100px;
  height: 100px;
  background: #fff;
  padding: 5px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(40, 50, 65, 0.08);
}
.fim-bot-qr-caption {
  font-size: 11px;
  color: #6a7280;
  margin-top: 4px;
  line-height: 1.3;
}
/* Mobile: QR-Code raus (User scannt nicht eigenes Display), Apple-Badge dominiert */
@media (max-width: 480px) {
  .fim-bot-app-block {
    grid-template-columns: auto 1fr;
    gap: 12px;
  }
  .fim-bot-app-block .fim-bot-qr-wrap {
    display: none;
  }
  .fim-bot-app-badge {
    height: 50px;
  }
}

/* Typing indicator */
.fim-bot-typing-wrap {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
}
.fim-bot-typing-label {
  font-style: italic;
  opacity: 0.85;
}
.fim-bot-typing {
  display: inline-flex; gap: 4px;
}
.fim-bot-typing span {
  width: 7px; height: 7px;
  background: var(--fim-bot-text);
  opacity: 0.4;
  border-radius: 50%;
  animation: fimDot 1.2s infinite;
}
.fim-bot-typing span:nth-child(2) { animation-delay: .15s; }
.fim-bot-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes fimDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ===== Start-Kacheln ===== */
.fim-bot-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.fim-bot-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--fim-bot-panel);
  border: 1px solid var(--fim-bot-line);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fim-bot-text);
  text-align: left;
  transition: background .15s, border-color .15s, transform .15s;
}
.fim-bot-tile:hover {
  background: #fff;
  border-color: var(--fim-bot-red);
  transform: translateY(-1px);
}
.fim-bot-tile:active { transform: translateY(0); }
.fim-bot-tile[hidden] { display: none; }
.fim-bot-tile-icon {
  flex-shrink: 0;
  width: 18px; height: 18px;
  color: var(--fim-bot-red);
}

/* ===== Input ===== */
.fim-bot-input-wrap {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  background: var(--fim-bot-panel);
  border-top: 1px solid var(--fim-bot-line);
  flex-shrink: 0;
}
.fim-bot-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--fim-bot-line);
  border-radius: 22px;
  font-family: inherit;
  font-size: 15px;
  color: var(--fim-bot-text);
  background: var(--fim-bot-bg);
  outline: none;
  transition: border-color .15s;
}
.fim-bot-input:focus { border-color: var(--fim-bot-red); }
.fim-bot-input::placeholder { color: #9aa2ad; }

.fim-bot-send {
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: var(--fim-bot-red);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, transform .1s;
}
.fim-bot-send:hover { background: var(--fim-bot-red-d); }
.fim-bot-send:active { transform: scale(0.92); }
.fim-bot-send:disabled { opacity: 0.5; cursor: not-allowed; }
.fim-bot-send svg { width: 18px; height: 18px; }

.fim-bot-disclaimer {
  font-size: 11px;
  line-height: 1.35;
  color: #7a828e;
  padding: 6px 16px 10px;
  text-align: center;
  background: var(--fim-bot-panel);
}

/* ===== Mobile ===== */
@media (max-width: 520px) {
  .fim-bot-launcher {
    width: 62px; height: 62px; bottom: 14px; right: 14px;
    z-index: 1000001; /* ueber Panel → Toggle-Tap immer erreichbar */
  }
  .fim-bot-bubble { bottom: 86px; right: 14px; max-width: calc(100vw - 76px); }
  .fim-bot-panel {
    right: 0; bottom: 0; top: 0; left: 0;
    width: 100%; height: 100%;
    max-height: 100%;
    border-radius: 0;
    /* iOS-Notch / Safari-URL-Bar kompensieren */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* Close-X gross + sichtbar abgesetzt (Apple HIG: mind. 44x44) */
  .fim-bot-header-close {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    font-size: 26px;
    background: rgba(255,255,255,0.18);
    border-radius: 50%;
  }
  .fim-bot-header-close:hover,
  .fim-bot-header-close:active { background: rgba(255,255,255,0.3); }
  /* Platz fuer den schwebenden Launcher in der Messages-Liste unten lassen,
     damit er keine Bubble verdeckt */
  .fim-bot-input-wrap { padding-right: 88px; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .fim-bot-launcher { animation: none; }
  .fim-bot-launcher svg .pupil { animation: none; }
  .fim-bot-avatar-stack,
  [data-bot-state] .fim-bot-avatar-stack { animation: none !important; }
  .fim-bot-avatar-frame { transition: none; }
  .fim-bot-bubble,
  .fim-bot-panel,
  .fim-bot-msg { animation: none; }
}
