#chat-toggle {
  position: fixed;
  bottom: 80px;
  right: 30px;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background: #dd6130;
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
}

#chat-widget {
  position: fixed;
  bottom: 150px;
  right: 20px;
  width: 380px;
  height: 420px;
  background: rgb(81,82,83);
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
}

#chat-header {
  background: #dd6130;
  color: white;
  padding: 12px;
  display: flex;
  justify-content: space-between;
}

#chat-header button {
  background: transparent;
  border: transparent;
  border-radius: 0%;
  cursor: pointer;
}

#mensagem:disabled::placeholder {
  color: white;
  opacity: 0.7;
}

#chat-messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  font-size: 14px;
  color: black;
}

#chat-input {
  display: flex;
  border-top: 1px solid #ddd;
}

#chat-input input {
  flex: 1;
  border: none;
  padding: 10px;
}

.chat-msg {
  display: flex;
  align-items: flex-start;
  margin: 8px 0;
  gap: 8px;
}

.chat-msg.user {
  flex-direction: row-reverse;
}

.chat-msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.chat-msg .bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
}

.chat-msg.user .bubble {
  background-color: #dcf8c6;
  text-align: right;
}

.chat-msg.bot .bubble {
  background-color: #f1f1f1;
  text-align: left;
}


.chat-languages {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px 40px;
}

/* .lang-btn {
  padding: 6px 12px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background-color: #b22334;
  color: white;
  font-weight: bold;
  font-size: 13px;
}

.lang-btn:hover {
  opacity: 0.85;
} */


.typing .dots::after {
  content: '.';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  33%  { content: ' .'; }
  66%  { content: ' ..'; }
  100% { content: ' ...'; }
}


.chat-languages-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 3 botões por linha */
  gap: 8px; /* espaço entre botões */
  margin-top: 10px;
}

.lang-btn {
  padding: 6px 12px;
  cursor: pointer;
  border: none;
  border-radius: 4px;
  background-color: #444;
  color: white;
  font-weight: bold;
  transition: background-color 0.2s;
}

.lang-btn:hover {
  background-color: #666;
}

#mensagem {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: none; /* Impede redimensionamento manual */
  overflow-y: hidden; /* Esconde scroll inicialmente */
  min-height: 40px; /* Altura mínima de uma linha */
  max-height: 120px; /* Altura máxima de ~5 linhas */
  line-height: 1.4;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#mensagem:focus {
  outline: none;
  border-color: #444;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

#mensagem::placeholder {
  color: #999;
}

/* Estilo para quando tem scroll */
#mensagem.scrollable {
  overflow-y: auto;
}

/* Custom scrollbar */
#mensagem::-webkit-scrollbar {
  width: 6px;
}

#mensagem::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#mensagem::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

#mensagem::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* Botão de enviar */
#enviar {
  font-size: 12px;
  background: #dd6130;
  color: white;
  border: none;
  border-radius: 30%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0; /* Impede que o botão encolha */
}

#enviar:hover {
  background: #444;
}

#enviar:active {
  transform: scale(0.95);
}


@media (max-width: 768px) {

  #chat-widget {
    position: fixed;
    width: calc(100vw - 40px); /* Ocupa quase toda a largura */
    max-width: 400px; /* Limite máximo */
    height: 70vh; /* Altura relativa à tela */
    max-height: 600px;
    bottom: 100px;
    right: 20px;
    left: 20px; /* Centraliza horizontalmente */
    margin: 0 auto; /* Centraliza se a largura for menor */
    z-index: 10000; /* Garante que fique acima de outros elementos */
  }

  /* Botão de toggle - maior para fácil toque */
  #chat-toggle {
    width: 60px;
    height: 60px;
    bottom: 25px;
    right: 25px;
    font-size: 28px;
    z-index: 9999;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  }

  /* Área de mensagens - mais espaço */
  #chat-messages {
    padding: 15px 12px;
    font-size: 15px; /* Texto um pouco maior */
  }

  /* Bolhas de mensagem - ajuste para mobile */
  .chat-msg .bubble {
    max-width: 80%; /* Mais largura para menos quebra */
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.5;
  }

  /* Avatar menor para economizar espaço */
  .chat-msg .avatar {
    width: 30px;
    height: 30px;
  }

  /* Grid de idiomas - 2 colunas em mobile menor */
  .chat-languages-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin: 10px 0 15px 40px;
  }

  .lang-btn {
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 6px;
  }

  /* Área de entrada - mais alta para toque fácil */
  #chat-input {
    padding: 10px;
    gap: 10px;
  }

  #mensagem {
    min-height: 44px; /* Altura mínima para toque (acessibilidade) */
    font-size: 16px; /* Tamanho padrão de input mobile */
    padding: 12px 16px;
    border-radius: 12px;
  }

  /* Botão de enviar - maior para toque */
  #enviar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 14px;
  }

  /* Header com toque mais fácil */
  #chat-header {
    padding: 16px 12px;
  }

  #chat-header button {
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  #chat-widget {
    width: calc(100vw - 30px);
    left: 15px;
    right: 15px;
    height: 65vh;
    bottom: 90px;
    z-index: 9999;
  }

  #chat-toggle {
    width: 55px;
    height: 55px;
    bottom: 20px;
    right: 20px;
  }

  .chat-languages-grid {
    grid-template-columns: 1fr; /* 1 coluna em telas muito pequenas */
  }

  .chat-msg .bubble {
    max-width: 85%;
  }

  /* Ajuste para modo paisagem em mobile */
  @media (max-height: 500px) and (orientation: landscape) {
    #chat-widget {
      height: 80vh;
      max-height: 300px;
      bottom: 80px;
    }
  }
}

@media (hover: none) and (pointer: coarse) {
  /* Estilos específicos para dispositivos com toque */
  .lang-btn,
  #enviar,
  #chat-toggle,
  #chat-header button {
    min-height: 44px; /* Tamanho mínimo recomendado para toque */
  }

  /* Remove hover effects em dispositivos touch */
  .lang-btn:hover,
  #enviar:hover,
  #chat-toggle:hover {
    transform: none;
  }

  /* Feedback visual ao tocar */
  .lang-btn:active,
  #enviar:active,
  #chat-toggle:active {
    opacity: 0.8;
    transform: scale(0.98);
  }

  /* Melhora a área de scroll das mensagens */
  #chat-messages {
    -webkit-overflow-scrolling: touch; /* Scroll suave no iOS */
    scroll-behavior: smooth;
  }
}

@media (prefers-color-scheme: dark) {
  #chat-widget {
    background: #2d2d2d;
    border: 1px solid #444;
  }

  #chat-input input,
  #mensagem {
    background: #333;
    color: #fff;
    border-color: #555;
  }

  .chat-msg.bot .bubble {
    background-color: #3a3a3a;
    color: #fff;
  }

  .chat-msg.user .bubble {
    background-color: #1a5a1a;
    color: #fff;
  }

  .lang-btn {
    background-color: #555;
  }

  .lang-btn:hover {
    background-color: #777;
  }
}

#chat-widget.mobile-open {
  animation: slideUpMobile 0.3s ease-out;
}

@keyframes slideUpMobile {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@supports (-webkit-touch-callout: none) {
  #chat-widget {
    /* Ajuste para safe areas no iOS */
    bottom: calc(100px + env(safe-area-inset-bottom));
  }

  #chat-toggle {
    bottom: calc(25px + env(safe-area-inset-bottom));
  }

  #mensagem {
    font-size: 16px; /* Previne zoom no iOS */
  }
}