/* ============================================================
   Audio Fast - widget de chat
   Branding: negro cálido + dorado, coherente con el sitio.
   ============================================================ */

.af-chat-root {
  --af-gold: #ffd700;
  --af-gold-2: #f0b400;
  --af-bg: #0a0603;
  --af-panel: #120c08;
  --af-panel-2: #1a110a;
  --af-line: rgba(255, 215, 0, 0.18);
  --af-line-soft: rgba(255, 215, 0, 0.09);
  --af-text: #f5ede3;
  --af-muted: #b9a996;
  --af-green: #25d366;
  --af-danger: #ff6b5b;
  --af-shadow: 0 26px 80px rgba(0, 0, 0, 0.65);
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10000;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--af-text);
  -webkit-font-smoothing: antialiased;
}

.af-chat-root *,
.af-chat-root *::before,
.af-chat-root *::after {
  box-sizing: border-box;
}

.af-chat-root [hidden] {
  display: none !important;
}

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

/* ---------- Botones flotantes ---------- */
.af-chat-fab-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.af-chat-wa-fab,
.af-chat-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
}

.af-chat-wa-fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #17281d;
  color: #4be383;
  border: 1px solid rgba(37, 211, 102, 0.45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.af-chat-wa-fab svg {
  width: 23px;
  height: 23px;
}

.af-chat-wa-fab:hover {
  transform: translateY(-2px) scale(1.04);
  background: #1d3525;
}

.af-chat-fab {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffe45c, var(--af-gold) 45%, var(--af-gold-2));
  color: #1a1208;
  box-shadow: 0 12px 34px rgba(255, 215, 0, 0.28), 0 4px 14px rgba(0, 0, 0, 0.55);
}

.af-chat-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 18px 46px rgba(255, 215, 0, 0.36), 0 6px 18px rgba(0, 0, 0, 0.55);
}

.af-chat-fab svg {
  width: 28px;
  height: 28px;
}

.af-chat-fab .af-icon-close {
  display: none;
}

.af-chat-root.is-open .af-chat-fab .af-icon-chat {
  display: none;
}

.af-chat-root.is-open .af-chat-fab .af-icon-close {
  display: block;
}

.af-chat-root.is-open .af-chat-wa-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px) scale(0.9);
}

.af-chat-fab::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid rgba(255, 215, 0, 0.35);
  animation: afPulse 2.4s ease-out infinite;
  pointer-events: none;
}

.af-chat-root.is-open .af-chat-fab::after {
  display: none;
}

@keyframes afPulse {
  0% { transform: scale(0.96); opacity: 0.75; }
  70% { transform: scale(1.16); opacity: 0; }
  100% { transform: scale(1.16); opacity: 0; }
}

/* ---------- Panel ---------- */
.af-chat-panel {
  position: absolute;
  right: 0;
  bottom: 88px;
  width: 390px;
  height: min(640px, calc(100vh - 140px));
  height: min(640px, calc(100dvh - 140px));
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 85% 0%, rgba(255, 215, 0, 0.09), transparent 38%),
    linear-gradient(180deg, #130d08, var(--af-panel));
  border: 1px solid var(--af-line);
  border-radius: 22px;
  box-shadow: var(--af-shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(18px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.24s ease, transform 0.24s ease, visibility 0.24s ease;
}

.af-chat-root.is-open .af-chat-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ---------- Cabecera ---------- */
.af-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(36, 23, 12, 0.98), rgba(15, 9, 5, 0.98));
  border-bottom: 1px solid var(--af-line);
  position: relative;
  z-index: 2;
}

.af-chat-header::after {
  content: '';
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.5), transparent);
}

.af-chat-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.af-chat-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  border: 2px solid rgba(255, 215, 0, 0.75);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.af-chat-avatar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8d6a00;
  font-weight: 900;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
}

.af-chat-avatar img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.af-chat-brand-text {
  min-width: 0;
}

.af-chat-brand-text strong {
  display: block;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.af-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--af-muted);
  font-size: 0.68rem;
  letter-spacing: 0.2px;
}

.af-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--af-green);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.12);
  animation: afBlink 2.4s ease-in-out infinite;
}

@keyframes afBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.af-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.af-chat-header-wa {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(37, 211, 102, 0.12);
  border: 1px solid rgba(37, 211, 102, 0.4);
  color: #68f09a;
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
  transition: background 0.2s ease, transform 0.2s ease;
}

.af-chat-header-wa:hover {
  background: rgba(37, 211, 102, 0.2);
  transform: translateY(-1px);
}

.af-chat-header-wa svg {
  width: 15px;
  height: 15px;
}

.af-chat-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--af-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
}

.af-chat-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.af-chat-close svg {
  width: 19px;
  height: 19px;
}

/* ---------- Mensajes ---------- */
.af-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 215, 0, 0.28) transparent;
}

.af-chat-messages::-webkit-scrollbar {
  width: 7px;
}

.af-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 215, 0, 0.24);
  border-radius: 999px;
}

.af-chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 90%;
  animation: afMsgIn 0.2s ease both;
}

@keyframes afMsgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.af-chat-msg.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.af-chat-msg-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(255, 215, 0, 0.45);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.af-chat-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
}

.af-chat-msg-content {
  min-width: 0;
}

.af-chat-bubble {
  padding: 10px 13px;
  border-radius: 15px 15px 15px 5px;
  background: linear-gradient(160deg, #20150c, #170f08);
  border: 1px solid var(--af-line-soft);
  color: var(--af-text);
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.16);
}

.af-chat-msg.is-user .af-chat-bubble {
  border-radius: 15px 15px 5px 15px;
  background: linear-gradient(145deg, #ffe45c, var(--af-gold) 48%, #e9ab00);
  border-color: rgba(255, 215, 0, 0.55);
  color: #1b1206;
  font-weight: 600;
  box-shadow: 0 5px 18px rgba(255, 215, 0, 0.15);
}

.af-chat-time {
  display: block;
  margin-top: 4px;
  padding: 0 3px;
  color: #8c7c6b;
  font-size: 0.62rem;
  line-height: 1.2;
}

.af-chat-msg.is-user .af-chat-time {
  text-align: right;
}

/* Indicador de escritura */
.af-chat-typing .af-chat-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 11px 15px;
}

.af-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--af-gold);
  opacity: 0.45;
  animation: afTyping 1.1s ease-in-out infinite;
}

.af-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.af-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes afTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Respuestas rápidas ---------- */
.af-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 16px 10px;
}

.af-chat-quick:empty {
  display: none;
}

.af-chat-quick button {
  appearance: none;
  border: 1px solid rgba(255, 215, 0, 0.32);
  background: rgba(255, 215, 0, 0.06);
  color: #ffe27a;
  border-radius: 999px;
  padding: 7px 11px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.af-chat-quick button:hover {
  background: var(--af-gold);
  color: #1b1206;
  transform: translateY(-1px);
}

/* ---------- Formulario de mensaje ---------- */
.af-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 8px;
  border-top: 1px solid var(--af-line-soft);
  background: rgba(10, 6, 3, 0.62);
}

.af-chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 108px;
  resize: none;
  border: 1px solid rgba(255, 215, 0, 0.16);
  border-radius: 13px;
  background: #0c0704;
  color: var(--af-text);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 0.86rem;
  line-height: 1.35;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.af-chat-input::placeholder {
  color: #827263;
}

.af-chat-input:focus {
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.08);
}

.af-chat-send {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid rgba(255, 215, 0, 0.55);
  border-radius: 13px;
  background: linear-gradient(145deg, #ffe45c, var(--af-gold) 50%, #e3a900);
  color: #1a1208;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s ease, filter 0.18s ease, opacity 0.18s ease;
}

.af-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.af-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.af-chat-send svg {
  width: 19px;
  height: 19px;
}

.af-chat-disclaimer {
  padding: 0 16px 9px;
  color: #7f7061;
  font-size: 0.62rem;
  line-height: 1.3;
  text-align: center;
  background: rgba(10, 6, 3, 0.62);
}

/* ---------- Formulario de lead ---------- */
.af-chat-lead-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(3px);
}

.af-chat-lead-card {
  width: 100%;
  max-height: calc(100% - 8px);
  overflow-y: auto;
  background: linear-gradient(180deg, #1b120b, #0f0905);
  border: 1px solid rgba(255, 215, 0, 0.28);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.af-chat-lead-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.af-chat-lead-head h3 {
  margin: 0;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}

.af-chat-lead-head p {
  margin: 4px 0 0;
  color: var(--af-muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.af-chat-lead-close {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--af-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.af-chat-lead-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.11);
}

.af-chat-lead-close svg {
  width: 17px;
  height: 17px;
}

.af-chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.af-chat-lead-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #d9cbbd;
  font-size: 0.72rem;
  font-weight: 600;
}

.af-chat-lead-form input,
.af-chat-lead-form textarea {
  width: 100%;
  border: 1px solid rgba(255, 215, 0, 0.16);
  border-radius: 10px;
  background: #0b0704;
  color: var(--af-text);
  padding: 9px 10px;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.35;
  outline: none;
}

.af-chat-lead-form textarea {
  resize: vertical;
  min-height: 54px;
  max-height: 120px;
}

.af-chat-lead-form input:focus,
.af-chat-lead-form textarea:focus {
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.07);
}

.af-chat-consent {
  flex-direction: row !important;
  align-items: flex-start;
  gap: 8px !important;
  color: #a99a8a !important;
  font-size: 0.68rem !important;
  font-weight: 500 !important;
  line-height: 1.35;
}

.af-chat-consent input {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin: 1px 0 0;
  accent-color: var(--af-gold);
}

.af-chat-lead-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 107, 91, 0.1);
  border: 1px solid rgba(255, 107, 91, 0.3);
  color: #ff9a8e;
  font-size: 0.72rem;
  line-height: 1.35;
}

.af-chat-lead-submit {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 215, 0, 0.6);
  border-radius: 11px;
  background: linear-gradient(145deg, #ffe45c, var(--af-gold) 50%, #e3a900);
  color: #1a1208;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  transition: filter 0.18s ease, opacity 0.18s ease;
}

.af-chat-lead-submit:hover:not(:disabled) {
  filter: brightness(1.06);
}

.af-chat-lead-submit:disabled {
  opacity: 0.55;
  cursor: wait;
}

.af-chat-lead-wa {
  display: block;
  margin-top: 2px;
  color: #68f09a;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
}

.af-chat-lead-wa:hover {
  text-decoration: underline;
}

/* ---------- Foco accesible ---------- */
.af-chat-root button:focus-visible,
.af-chat-root a:focus-visible,
.af-chat-root input:focus-visible,
.af-chat-root textarea:focus-visible {
  outline: 2px solid var(--af-gold);
  outline-offset: 2px;
}

/* ---------- Móvil ---------- */
@media (max-width: 520px) {
  .af-chat-root {
    right: 16px;
    bottom: 16px;
  }

  .af-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    max-height: none;
    border-radius: 0;
    border: 0;
    transform-origin: center bottom;
  }

  .af-chat-header {
    padding-top: calc(13px + env(safe-area-inset-top));
    padding-left: 14px;
    padding-right: 14px;
  }

  .af-chat-header-wa span {
    display: none;
  }

  .af-chat-header-wa {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .af-chat-messages {
    padding-left: 14px;
    padding-right: 14px;
  }

  .af-chat-quick {
    padding-left: 14px;
    padding-right: 14px;
  }

  .af-chat-disclaimer {
    padding-bottom: calc(9px + env(safe-area-inset-bottom));
  }

  .af-chat-root.is-open .af-chat-fab-group {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
  }

  .af-chat-lead-overlay {
    align-items: stretch;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .af-chat-lead-card {
    max-height: 100%;
    border-radius: 16px;
  }

  body.af-chat-lock {
    overflow: hidden;
  }
}

@media (min-width: 521px) {
  .af-chat-lead-overlay {
    align-items: center;
  }

  .af-chat-lead-card {
    max-height: calc(100% - 12px);
  }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  .af-chat-root *,
  .af-chat-root *::before,
  .af-chat-root *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
