.bfchat {
  --bf-y: #ffd400;
  --bf-ink: #080808;
  --bf-panel: #101010;
  --bf-line: #262626;
  --bf-text: #f2f1ec;
  --bf-muted: #9a9a94;
  position: fixed;
  right: 22px;
  bottom: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 1200;
  font-family: inherit;
}

/* ---------- Launcher ---------- */
.bfchat__launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px 14px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--bf-y);
  color: var(--bf-ink);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 18px 45px rgba(255, 212, 0, 0.28), 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.bfchat__launcher:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 22px 55px rgba(255, 212, 0, 0.35), 0 10px 26px rgba(0, 0, 0, 0.5); }
.bfchat__launcher:active { transform: translateY(-1px) scale(0.99); }
.bfchat__launcher-icon { display: grid; place-items: center; width: 26px; height: 26px; }
.bfchat__launcher-icon svg { width: 24px; height: 24px; }
.bfchat__launcher-ping {
  position: absolute; top: 6px; right: 6px; width: 11px; height: 11px;
  border-radius: 50%; background: #ff3b30; border: 2px solid var(--bf-y);
  animation: bfchatPing 2.4s ease-in-out infinite;
}
@keyframes bfchatPing { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.7; } }

body.bfchat-open .bfchat__launcher { transform: scale(0.92); opacity: 0; pointer-events: none; }

/* ---------- Panel ---------- */
.bfchat__panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 388px;
  max-width: calc(100vw - 28px);
  height: min(640px, calc(100vh - 44px));
  display: flex;
  flex-direction: column;
  background: var(--bf-panel);
  color: var(--bf-text);
  border: 1px solid var(--bf-line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  transform-origin: bottom right;
  animation: bfchatIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.bfchat__panel[hidden] { display: none; }
@keyframes bfchatIn { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: none; } }

.bfchat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #141414, #0c0c0c);
  border-bottom: 1px solid var(--bf-line);
}
.bfchat__avatar {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  border-radius: 13px; background: var(--bf-y); color: var(--bf-ink);
}
.bfchat__avatar svg { width: 22px; height: 22px; }
.bfchat__head-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.bfchat__head-text b { font-size: 15px; }
.bfchat__head-text span { font-size: 12px; color: var(--bf-muted); display: flex; align-items: center; gap: 6px; }
.bfchat__status { width: 7px; height: 7px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.bfchat__close {
  margin-left: auto; width: 34px; height: 34px; flex: none;
  display: grid; place-items: center; border-radius: 10px;
  background: transparent; border: 1px solid var(--bf-line); color: var(--bf-muted);
  cursor: pointer; transition: 0.18s;
}
.bfchat__close:hover { color: var(--bf-text); border-color: #444; }
.bfchat__close svg { width: 18px; height: 18px; }

/* ---------- Messages ---------- */
.bfchat__body {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.bfchat__body::-webkit-scrollbar { width: 8px; }
.bfchat__body::-webkit-scrollbar-thumb { background: #2c2c2c; border-radius: 8px; }

.bfchat__bubble {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: bfchatBubble 0.25s ease both;
}
@keyframes bfchatBubble { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bfchat__bubble--bot { align-self: flex-start; background: #1b1b1b; border: 1px solid var(--bf-line); border-bottom-left-radius: 5px; }
.bfchat__bubble--user { align-self: flex-end; background: var(--bf-y); color: var(--bf-ink); border-bottom-right-radius: 5px; font-weight: 500; }
.bfchat__bubble--error { background: #2a1414; border-color: #4a2020; color: #f2b8b8; }
.bfchat__bubble strong { font-weight: 700; }
.bfchat__bubble a { color: var(--bf-y); }
.bfchat__bubble--user a { color: #111; text-decoration: underline; }
.bfchat__bubble ul { margin: 6px 0 0; padding-left: 18px; }
.bfchat__bubble li { margin: 2px 0; }

.bfchat__suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.bfchat__chip {
  border: 1px solid var(--bf-line);
  background: transparent;
  color: var(--bf-text);
  font: inherit;
  font-size: 12.5px;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.18s;
  text-align: left;
}
.bfchat__chip:hover { border-color: var(--bf-y); color: var(--bf-y); }
.bfchat__suggestions[hidden] { display: none; }

/* ---------- Typing ---------- */
.bfchat__typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.bfchat__typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--bf-muted); animation: bfchatDot 1.3s infinite ease-in-out; }
.bfchat__typing i:nth-child(2) { animation-delay: 0.18s; }
.bfchat__typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes bfchatDot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Form ---------- */
.bfchat__form {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 12px 14px 8px; border-top: 1px solid var(--bf-line);
  background: #0c0c0c;
}
.bfchat__input {
  flex: 1; resize: none; max-height: 120px;
  padding: 12px 14px; border-radius: 14px;
  background: #161616; border: 1px solid var(--bf-line); color: var(--bf-text);
  font: inherit; font-size: 14px; line-height: 1.4;
}
.bfchat__input:focus { outline: none; border-color: var(--bf-y); }
.bfchat__input::placeholder { color: var(--bf-muted); }
.bfchat__send {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center; border: 0; border-radius: 13px;
  background: var(--bf-y); color: var(--bf-ink); cursor: pointer; transition: 0.18s;
}
.bfchat__send:hover { filter: brightness(1.05); transform: translateY(-1px); }
.bfchat__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.bfchat__send svg { width: 20px; height: 20px; }
.bfchat__note { margin: 0; padding: 0 16px 14px; font-size: 11px; color: var(--bf-muted); text-align: center; }

@media (max-width: 640px) {
  .bfchat { right: 14px; bottom: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .bfchat__launcher { padding: 13px; }
  .bfchat__launcher-label { display: none; }
  .bfchat__panel { left: 0; right: 0; bottom: 0; width: auto; height: 100vh; height: 100dvh; max-width: none; border-radius: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* ---------- Chat history divider ---------- */
.bfchat__divider {
  align-self: center;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bf-muted);
  padding: 2px 0 6px;
}

/* Respuestas con formato: párrafos, listas, énfasis, emojis y botones de acción */
.bfchat__bubble--bot { white-space: normal; }
.bfchat__bubble--user { white-space: pre-wrap; }
.bfchat__bubble p { margin: 0 0 8px; }
.bfchat__bubble p:last-child { margin-bottom: 0; }
.bfchat__bubble ul, .bfchat__bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bfchat__bubble li { margin: 3px 0; padding-left: 2px; }
.bfchat__bubble li::marker { color: var(--bf-y); }
.bfchat__bubble li.has-emoji { list-style: none; margin-left: -20px; padding-left: 0; }
.bfchat__bubble em { font-style: italic; color: #e8e8e8; }
.bfchat__bubble--user em { color: inherit; }
.bfchat__bubble .bfchat__h { font-weight: 700; color: var(--bf-y); letter-spacing: .02em; margin: 2px 0 6px; }
.bfchat__bubble hr { border: 0; border-top: 1px solid var(--bf-line); margin: 8px 0; }
.bfchat__bubble code { background: rgba(255,255,255,.08); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.bfchat__bubble .bfchat__cta-wrap { margin: 10px 0 2px; }
.bfchat__bubble a.bfchat__cta {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bf-y); color: #111; font-weight: 700; font-size: 13px;
  padding: 9px 14px; border-radius: 10px; text-decoration: none;
  transition: transform .2s, background .2s;
}
.bfchat__bubble a.bfchat__cta::after { content: "\2192"; }
.bfchat__bubble a.bfchat__cta:hover { background: #fff; transform: translateY(-1px); }
.bfchat__bubble { font-family: inherit, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }

/* ---------- Ajuste de márgenes y espaciados ---------- */
.bfchat__head { padding: 14px 16px; }
.bfchat__body { padding: 16px 14px 10px; gap: 10px; overscroll-behavior: contain; scroll-padding-bottom: 12px; }
.bfchat__bubble { max-width: 88%; padding: 10px 13px; }
.bfchat__suggestions { gap: 7px; margin-top: 4px; }
.bfchat__chip { padding: 7px 12px; }
.bfchat__form { align-items: center; gap: 8px; padding: 10px 12px 6px; }
.bfchat__input {
  min-height: 44px; padding: 11px 14px; line-height: 1.4; display: block;
  overflow: hidden; scrollbar-width: thin; scrollbar-color: #333 transparent;
}
.bfchat__send { width: 44px; height: 44px; align-self: flex-end; }
.bfchat__note { padding: 4px 16px 12px; font-size: 10.5px; line-height: 1.4; text-wrap: balance; }
@media (max-width: 640px) {
  .bfchat__body { padding: 14px 12px 8px; }
  .bfchat__input { font-size: 16px; }
  .bfchat__form { padding: 10px 12px 6px; }
  .bfchat__note { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}
