/* ===== Mada - MyLifePet Chatbot Widget ===== */

:root {
  --mlp-primary: #4CAF50;
  --mlp-primary-dark: #388E3C;
  --mlp-bg: #ffffff;
  --mlp-user-bubble: #4CAF50;
  --mlp-bot-bubble: #f1f5f1;
  --mlp-text: #333333;
  --mlp-text-light: #666666;
  --mlp-shadow: 0 8px 32px rgba(0,0,0,0.18);
  --mlp-radius: 18px;
}

#mlp-chat-wrapper {
  position: fixed !important;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
  right: calc(24px + env(safe-area-inset-right, 0px)) !important;
  left: auto !important;
  top: auto !important;
  z-index: 2147483600 !important; /* maior que praticamente qualquer plugin */
  font-family: 'Segoe UI', Arial, sans-serif;
  transform: none !important;
  filter: none !important;
}

/* Botão flutuante */
#mlp-toggle-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--mlp-primary);
  border: none;
  cursor: pointer;
  box-shadow: var(--mlp-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
  position: relative;
}

#mlp-toggle-btn:hover {
  background: var(--mlp-primary-dark);
  transform: scale(1.08);
}

#mlp-toggle-btn svg {
  width: 28px !important;
  height: 28px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  fill: white !important;
  display: block;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

#mlp-toggle-btn img.mlp-icon-chat {
  width: 72px !important;
  height: 72px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
}

#mlp-toggle-btn .mlp-icon-close {
  display: none;
}

#mlp-chat-wrapper.mlp-open #mlp-toggle-btn .mlp-icon-chat {
  display: none;
}

#mlp-chat-wrapper.mlp-open #mlp-toggle-btn .mlp-icon-close {
  display: block;
}

/* Badge de notificação */
#mlp-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #f44336;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

/* Janela do chat */
#mlp-chat-window {
  width: 360px;
  max-height: 540px;
  background: var(--mlp-bg);
  border-radius: var(--mlp-radius);
  box-shadow: var(--mlp-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 12px;
  animation: mlpSlideIn 0.25s ease;
  position: relative; /* âncora pro overlay do modo de voz */
}

@keyframes mlpSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#mlp-chat-wrapper.mlp-open #mlp-chat-window {
  display: flex;
}

/* Header */
#mlp-header {
  background: var(--mlp-primary);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#mlp-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}

#mlp-avatar img {
  width: 40px !important;
  height: 40px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
}

#mlp-header-info {
  flex: 1;
}

#mlp-header-name {
  color: white;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

#mlp-header-status {
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

#mlp-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #a5d6a7;
  border-radius: 50%;
  display: inline-block;
}

/* Área de mensagens */
#mlp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  scroll-behavior: smooth;
}

#mlp-messages::-webkit-scrollbar { width: 4px; }
#mlp-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Bolhas de mensagem */
.mlp-message {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 85%;
  animation: mlpFadeIn 0.2s ease;
}

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

.mlp-message.mlp-bot { align-self: flex-start; }
.mlp-message.mlp-user { align-self: flex-end; flex-direction: row-reverse; }

.mlp-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.mlp-bot .mlp-bubble {
  background: var(--mlp-bot-bubble);
  color: var(--mlp-text);
  border-bottom-left-radius: 4px;
}

.mlp-user .mlp-bubble {
  background: var(--mlp-user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}

/* Links dentro das bolhas */
.mlp-bubble a {
  color: inherit;
  text-decoration: underline;
}

/* Botões de ação (gatilhos do backend) */
.mlp-action-wrapper {
  display: flex;
  justify-content: center;
  margin: 4px 0;
  animation: mlpFadeIn 0.3s ease;
}

.mlp-action-btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
  text-align: center;
}

.mlp-action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.mlp-action-primary {
  background: var(--mlp-primary);
  color: white;
}

.mlp-action-primary:hover {
  background: var(--mlp-primary-dark);
}

.mlp-action-secondary {
  background: #25D366; /* verde WhatsApp */
  color: white;
}

.mlp-action-secondary:hover {
  background: #1da851;
}

/* Indicador de digitação */
.mlp-typing .mlp-bubble {
  padding: 12px 16px;
}

.mlp-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.mlp-typing-dots span {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: mlpDot 1.2s infinite;
}

.mlp-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.mlp-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mlpDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
#mlp-input-area {
  padding: 10px 12px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: white;
}

#mlp-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color 0.2s;
}

#mlp-input:focus { border-color: var(--mlp-primary); }

#mlp-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--mlp-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

#mlp-send-btn:hover { background: var(--mlp-primary-dark); }
#mlp-send-btn:active { transform: scale(0.92); }
#mlp-send-btn:disabled { background: #ccc; cursor: not-allowed; }

#mlp-send-btn svg {
  width: 18px !important;
  height: 18px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  fill: white !important;
  display: block;
  flex-shrink: 0;
}

/* Botão de microfone */
#mlp-mic-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #eef3ee;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

#mlp-mic-btn svg {
  width: 18px !important;
  height: 18px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  fill: var(--mlp-primary) !important;
  display: block;
  flex-shrink: 0;
}

#mlp-mic-btn:hover { background: #e0eae0; }
#mlp-mic-btn:active { transform: scale(0.92); }

/* Estado gravando: vermelho pulsante */
#mlp-mic-btn.mlp-recording {
  background: #f44336;
}

#mlp-mic-btn.mlp-recording svg {
  fill: white !important;
}

#mlp-mic-btn.mlp-recording::after {
  content: '';
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #f44336;
  animation: mlpPulse 1.2s ease-out infinite;
}

@keyframes mlpPulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Footer do chat */
#mlp-footer {
  text-align: center;
  font-size: 11px;
  color: #bbb;
  padding: 6px 0 8px;
  background: white;
}

/* Responsivo mobile */
@media (max-width: 480px) {
  #mlp-chat-wrapper {
    right: calc(28px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
  }
  /* Bolinha maior no mobile (mais "tocável" e visível) */
  #mlp-toggle-btn {
    width: 84px !important;
    height: 84px !important;
  }
  #mlp-toggle-btn img.mlp-icon-chat {
    width: 84px !important;
    height: 84px !important;
  }
  /* Quando o chat ABRE em mobile: dimensiona o chat-window via vw/vh, SEM
     position:fixed. Isso evita o bug do Elementor que quebra position:fixed
     em Android — o chat passa a ser posicionado relativo ao wrapper, que
     por sua vez é colocado corretamente pelo JS de fallback no canto.
     Resultado: o balão sempre fica dentro do viewport, ocupando ~92vw × 70vh */
  #mlp-chat-wrapper.mlp-open #mlp-chat-window {
    position: relative !important;
    width: 92vw !important;
    height: 70vh !important;
    max-width: none !important;
    max-height: 70vh !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    margin-bottom: 12px !important;
  }
}

/* ===================================================================
   MODO DE VOZ (estilo ChatGPT) — tela limpa que cobre o chat
   =================================================================== */

#mlp-voice-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  background: linear-gradient(165deg, #4CAF50 0%, #2e7d32 100%);
  border-radius: var(--mlp-radius);
  animation: mlpFadeIn 0.25s ease;
}

/* Ativa o overlay quando o modo voz está ligado */
#mlp-chat-wrapper.mlp-voice-on #mlp-voice-overlay {
  display: flex;
}

/* O orb da Mada (avatar com anéis pulsantes) */
#mlp-voice-orb {
  position: relative;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#mlp-voice-orb img {
  width: 116px !important;
  height: 116px !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0 !important;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255, 255, 255, 0.9);
  position: relative;
  z-index: 2;
  transition: transform 0.2s;
  display: block;
  flex-shrink: 0;
}

/* Anéis pulsantes ao redor do avatar */
#mlp-voice-orb .mlp-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  opacity: 0;
}

/* ── Estado: OUVINDO — anéis expandem continuamente ── */
.mlp-vstate-listening #mlp-voice-orb .mlp-ring {
  animation: mlpPulseRing 2.1s ease-out infinite;
}
.mlp-vstate-listening #mlp-voice-orb .mlp-ring:nth-child(2) { animation-delay: 0.7s; }
.mlp-vstate-listening #mlp-voice-orb .mlp-ring:nth-child(3) { animation-delay: 1.4s; }

@keyframes mlpPulseRing {
  0%   { transform: scale(0.85); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ── Estado: PENSANDO — avatar levemente apagado + giro ── */
.mlp-vstate-thinking #mlp-voice-orb img {
  filter: brightness(0.8);
}
.mlp-vstate-thinking #mlp-voice-orb .mlp-ring:nth-child(1) {
  opacity: 1;
  border-color: transparent;
  border-top-color: rgba(255, 255, 255, 0.9);
  animation: mlpSpin 0.9s linear infinite;
}

@keyframes mlpSpin {
  to { transform: rotate(360deg); }
}

/* ── Estado: FALANDO — avatar pulsa ── */
.mlp-vstate-speaking #mlp-voice-orb img {
  animation: mlpSpeakPulse 0.9s ease-in-out infinite;
}
.mlp-vstate-speaking #mlp-voice-orb .mlp-ring:nth-child(1),
.mlp-vstate-speaking #mlp-voice-orb .mlp-ring:nth-child(2) {
  animation: mlpPulseRing 1.6s ease-out infinite;
}
.mlp-vstate-speaking #mlp-voice-orb .mlp-ring:nth-child(2) { animation-delay: 0.8s; }

@keyframes mlpSpeakPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* Textos do overlay */
#mlp-voice-status {
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.2px;
}

#mlp-voice-hint {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-align: center;
  min-height: 16px;
}

/* Botão de encerrar a conversa por voz */
#mlp-voice-end {
  margin-top: 6px;
  padding: 12px 26px;
  border: none;
  border-radius: 24px;
  background: #fff;
  color: #2e7d32;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s, background 0.15s;
}

#mlp-voice-end:hover {
  transform: translateY(-1px);
  background: #f0f0f0;
}

#mlp-voice-end:active {
  transform: scale(0.96);
}
