#chatbot-fab {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: transparent;
  color: #fff;
  border: none;
  border-radius: 0;
  width: 110px;
  height: 110px;
  padding: 0;
  box-shadow: none;
  cursor: pointer;
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  outline: none;
}

#chatbot-fab img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

#chatbot-fab:hover {
  transform: scale(1.08);
}

#chatbot-fab:active {
  transform: scale(0.95);
}

#chatbot-fab:focus {
  outline: none;
}

/* ==========================================
   JANELA DO CHAT
   ========================================== */
#chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 500px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Animação Fluida "Crescendo" */
  opacity: 0;
  visibility: hidden;
  transform-origin: bottom right;
  transform: scale(0) translateY(20px);
  transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
  /* curve suave */
  pointer-events: none;
}

#chatbot-window.visible {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* ==========================================
   ANIMAÇÕES
   ========================================== */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing {

  0%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* ==========================================
   HEADER DO CHAT
   ========================================== */
.chatbot-header {
  background: rgba(0, 90, 146, 0.9);
  /* Transparência para glassmorphism */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 16px 16px 0 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-font-controls {
  display: flex;
  gap: 2px;
  background: rgba(0, 0, 0, 0.2);
  padding: 2px;
  border-radius: 6px;
}

.chatbot-font-controls button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.9);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.2s;
}

.chatbot-font-controls button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.chatbot-action-controls {
  display: flex;
  align-items: center;
}

.chatbot-header-title {
  font-weight: 600;
  font-size: 0.85em;
  letter-spacing: 0.3px;
}

.chatbot-header-status {
  font-size: 0.75em;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-header-status::before {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  background-color: #4cd964;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(76, 217, 100, 0.6);
}

#chatbot-new-chat {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  font-size: 1em;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 12px;
}

#chatbot-new-chat:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.2);
}

#chatbot-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  font-size: 1.25em;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
}

#chatbot-close:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: rotate(90deg);
}

/* ==========================================
   ÁREA DE MENSAGENS
   ========================================== */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8f9fa;
  scroll-behavior: smooth;
}

#chatbot-messages::-webkit-scrollbar,
#chatbot-input::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chatbot-input::-webkit-scrollbar-track {
  background: transparent;
  margin-top: 12px;
  margin-bottom: 12px;
}

#chatbot-messages::-webkit-scrollbar-thumb,
#chatbot-input::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

#chatbot-messages::-webkit-scrollbar-thumb:hover,
#chatbot-input::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* ==========================================
   MENSAGEM DE BOAS-VINDAS
   ========================================== */
.chatbot-welcome {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  animation: fadeIn 0.5s ease-out;
}

.chatbot-welcome-emoji {
  font-size: 48px;
  margin-bottom: 16px;
  display: inline-block;
  animation: wave 2s infinite;
  transform-origin: 70% 70%;
}

@keyframes wave {
  0% {
    transform: rotate(0.0deg)
  }

  10% {
    transform: rotate(14.0deg)
  }

  20% {
    transform: rotate(-8.0deg)
  }

  30% {
    transform: rotate(14.0deg)
  }

  40% {
    transform: rotate(-4.0deg)
  }

  50% {
    transform: rotate(10.0deg)
  }

  60% {
    transform: rotate(0.0deg)
  }

  100% {
    transform: rotate(0.0deg)
  }
}

.chatbot-welcome-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 1.125em;

}

.chatbot-welcome-subtitle {
  font-size: 0.875em;
}

/* ==========================================
   BOLHAS DE MENSAGEM
   ========================================== */
.chatbot-message {
  display: flex;
  margin-bottom: 12px;
  animation: fadeIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.chatbot-message.user {
  justify-content: flex-end;
}

.chatbot-message.bot {
  justify-content: flex-start;
}

.chatbot-message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.875em;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  white-space: pre-wrap;
}

.chatbot-message.user .chatbot-message-bubble {
  background: #005a92;
  color: white;
  border-bottom-right-radius: 4px;
}

.chatbot-message.bot .chatbot-message-bubble {
  background: white;
  color: #333;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ==========================================
   INDICADOR DE DIGITAÇÃO
   ========================================== */
.chatbot-typing-indicator {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
  animation: fadeIn 0.3s ease;
}

.chatbot-typing-bubble {
  background: white;
  padding: 12px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  height: 40px;
}

.chatbot-typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #005a92;
  border-radius: 50%;
  margin: 0 2px;
  animation: typing 1.4s infinite ease-in-out;
  opacity: 0.6;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Texto "Pensando..." */
.chatbot-typing-text {
  margin-right: 8px;
  font-size: 0.9em;
  color: #666;
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}

/* ==========================================
   ÁREA DE INPUT
   ========================================== */
.chatbot-input-area {
  padding: 16px;
  background: white;
  border-top: 1px solid #f0f0f0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  /* Align to bottom so button stays aligned with input bottom if it grows */
}

.chatbot-input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

#chatbot-char-counter {
  position: absolute;
  bottom: 5px;
  right: 10px;
  font-size: 10px;
  color: #999;
  font-weight: 500;
  transition: color 0.2s;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.8);
  padding: 2px 4px;
  border-radius: 4px;
}

#chatbot-char-counter.limit-reached {
  color: #dc3545;
  font-weight: bold;
}

#chatbot-input {
  flex: 1;
  padding: 12px 16px 20px 16px;
  /* Extra bottom padding for counter */
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 0.875em;
  outline: none;
  transition: all 0.2s ease;
  font-family: inherit;
  background: #f8f9fa;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.4;
  overflow-y: hidden;
}

#chatbot-input:focus {
  border-color: #005a92;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0, 90, 146, 0.1);
}

#chatbot-input:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
  opacity: 0.7;
}

#chatbot-send {
  background: #005a92;
  color: white;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1em;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 90, 146, 0.3);
}

#chatbot-send:hover {
  transform: scale(1.05);
  background: #004080;
  box-shadow: 0 4px 12px rgba(0, 90, 146, 0.4);
}

#chatbot-send:active {
  transform: scale(0.95);
}

#chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ==========================================
   ESTILOS PARA MARKDOWN (Compatíveis com tema)
   ========================================== */
#chatbot-messages pre {
  background: #2d2d2d;
  color: #ccc;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

#chatbot-messages code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
  color: #d63384;
}

#chatbot-messages pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

#chatbot-messages h1,
#chatbot-messages h2,
#chatbot-messages h3 {
  margin: 12px 0 6px 0;
  font-weight: 700;
  color: #004080;
}

#chatbot-messages h1 {
  font-size: 1.4em;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
}

#chatbot-messages h2 {
  font-size: 1.25em;
}

#chatbot-messages h3 {
  font-size: 1.1em;
}

#chatbot-messages p {
  margin: 0 0 8px 0;
}

#chatbot-messages ul,
#chatbot-messages ol {
  margin: 6px 0;
  padding-left: 24px;
}

#chatbot-messages li {
  margin-bottom: 4px;
}

#chatbot-messages a {
  color: #005a92;
  text-decoration: underline;
}

#chatbot-messages blockquote {
  border-left: 3px solid #005a92;
  margin: 8px 0;
  padding-left: 12px;
  color: #555;
  font-style: italic;
}

/* ==========================================
   RESPONSIVIDADE E POLIMENTO FINAL
   ========================================== */
@media (max-width: 768px) {
  #chatbot-window {
    width: 400px;
    /* Largura fixa ideal para tablets */
    max-width: calc(100% - 32px);
    /* Fallback de margem */
    height: 600px;
    max-height: calc(100% - 100px);
    right: 16px;
    bottom: 90px;
    border-radius: 16px;
  }
}

@media (max-width: 480px) {
  #chatbot-window {
    width: 100% !important;
    height: 100% !important;
    /* Fullscreen total */
    min-height: 100dvh;
    /* Dynamic viewport height para mobile moderno */
    max-height: none;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 0;
    transform-origin: bottom right;
  }

  /* Ajuste da animação para mobile - vem de baixo ocupando tudo */
  @keyframes slideIn {
    from {
      opacity: 0;
      transform: translateY(100%);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Sobrescreve transform original para mobile */
  #chatbot-window {
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s;
  }

  #chatbot-window.visible {
    transform: translateY(0);
  }

  .chatbot-header {
    border-radius: 0;
    padding-top: max(16px, env(safe-area-inset-top));
    /* Área segura topo iPhone X+ */
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 16px;
  }

  #chatbot-fab {
    /* Oculta o FAB quando o chat está aberto (visualmente coberto, mas z-index menor garante) */
    z-index: 9000;
    bottom: 16px;
    right: 16px;
  }

  /* Garante que o chat fique por cima de tudo no mobile */
  #chatbot-window {
    z-index: 10001;
  }

  #chatbot-input-area {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    /* Área segura baixo iPhone X+ */
  }

  #chatbot-input {
    font-size: 16px !important;
    /* Evita zoom automático no iOS */
  }

  /* Melhoria nos alvos de toque */
  #chatbot-send {
    width: 48px;
    height: 48px;
  }

  #chatbot-close {
    width: 40px;
    height: 40px;
    font-size: 24px;
    background: transparent;
  }
}

/* ==========================================
   MODO ALTO CONTRASTE (Dark Mode)
   ========================================== */

/* FAB Button - Contraste */
body.high-contrast #chatbot-fab,
.high-contrast #chatbot-fab {
  /* SVG já tem cores próprias, apenas mantém transparente */
  background: transparent;
}

body.high-contrast #chatbot-fab:hover,
.high-contrast #chatbot-fab:hover {
  background: transparent;
}

/* Janela do Chat - Contraste */
body.high-contrast #chatbot-window,
.high-contrast #chatbot-window {
  background: #1a1a1a;
  border: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Header - Contraste */
body.high-contrast .chatbot-header,
.high-contrast .chatbot-header {
  background: rgba(26, 26, 26, 0.95);
  border-bottom: 1px solid #333;
  /* Sutil em vez de amarelo/branco gritante */
}

body.high-contrast .chatbot-header-title,
.high-contrast .chatbot-header-title {
  color: #ffff00;
}


/* Font Controls - Contraste */
body.high-contrast .chatbot-font-controls button,
.high-contrast .chatbot-font-controls button {
  color: #ffff00;
}

body.high-contrast .chatbot-font-controls button:hover,
.high-contrast .chatbot-font-controls button:hover {
  background: rgba(255, 255, 0, 0.2);
}

body.high-contrast .chatbot-header-status,
.high-contrast .chatbot-header-status {
  color: #cccc00;
}

body.high-contrast #chatbot-close,
.high-contrast #chatbot-close {
  background: rgba(255, 255, 0, 0.1);
  color: #ffff00;
}

body.high-contrast #chatbot-close:hover,
.high-contrast #chatbot-close:hover {
  background: rgba(255, 255, 0, 0.25);
}

/* Área de Mensagens - Contraste */
body.high-contrast #chatbot-messages,
.high-contrast #chatbot-messages {
  background: #0d0d0d;
}

body.high-contrast #chatbot-messages::-webkit-scrollbar-track,
.high-contrast #chatbot-messages::-webkit-scrollbar-track {
  background: #1a1a1a;
}

body.high-contrast #chatbot-messages::-webkit-scrollbar-thumb,
.high-contrast #chatbot-messages::-webkit-scrollbar-thumb {
  background: #ffff00;
}

/* Mensagem de Boas-Vindas - Contraste */
body.high-contrast .chatbot-welcome,
.high-contrast .chatbot-welcome {
  color: #cccccc;
}

body.high-contrast .chatbot-welcome-title,
.high-contrast .chatbot-welcome-title {
  color: #ffff00;
}

/* Bolhas de Mensagem - Contraste */
body.high-contrast .chatbot-message.user .chatbot-message-bubble,
.high-contrast .chatbot-message.user .chatbot-message-bubble {
  background: #333300;
  color: #ffff00;
  border: 1px solid #ffff00;
}

body.high-contrast .chatbot-message.bot .chatbot-message-bubble,
.high-contrast .chatbot-message.bot .chatbot-message-bubble {
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid #444444;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Indicador de Digitação - Contraste */
body.high-contrast .chatbot-typing-bubble,
.high-contrast .chatbot-typing-bubble {
  background: #1a1a1a;
  border: 1px solid #444444;
}

body.high-contrast .chatbot-typing-dot,
.high-contrast .chatbot-typing-dot {
  background: #ffff00;
}

body.high-contrast .chatbot-typing-text,
.high-contrast .chatbot-typing-text {
  color: #ccc;
}

/* Área de Input - Contraste */
body.high-contrast .chatbot-input-area,
.high-contrast .chatbot-input-area {
  background: #1a1a1a;
  border-top: 1px solid #ffff00;
}

body.high-contrast #chatbot-input,
.high-contrast #chatbot-input {
  background: #0d0d0d;
  border: 1px solid #666666;
  color: #ffffff;
}

body.high-contrast #chatbot-input:focus,
.high-contrast #chatbot-input:focus {
  border-color: #ffff00;
  background: #1a1a1a;
  box-shadow: 0 0 0 3px rgba(255, 255, 0, 0.2);
}

body.high-contrast #chatbot-input::placeholder,
.high-contrast #chatbot-input::placeholder {
  color: #888888;
}

body.high-contrast #chatbot-send,
.high-contrast #chatbot-send {
  background: #ffff00;
  color: #000000;
  box-shadow: 0 2px 6px rgba(255, 255, 0, 0.3);
}

body.high-contrast #chatbot-send:hover,
.high-contrast #chatbot-send:hover {
  background: #cccc00;
  box-shadow: 0 4px 12px rgba(255, 255, 0, 0.4);
}

body.high-contrast #chatbot-send:disabled,
.high-contrast #chatbot-send:disabled {
  background: #444444;
  color: #888888;
}

/* Markdown no Contraste */
body.high-contrast #chatbot-messages pre,
.high-contrast #chatbot-messages pre {
  background: #0d0d0d;
  border: 1px solid #444444;
}

body.high-contrast #chatbot-messages code,
.high-contrast #chatbot-messages code {
  background: rgba(255, 255, 0, 0.1);
  color: #ffff00;
}

body.high-contrast #chatbot-messages h1,
body.high-contrast #chatbot-messages h2,
body.high-contrast #chatbot-messages h3,
.high-contrast #chatbot-messages h1,
.high-contrast #chatbot-messages h2,
.high-contrast #chatbot-messages h3 {
  color: #ffff00;
}

body.high-contrast #chatbot-messages h1,
.high-contrast #chatbot-messages h1 {
  border-bottom-color: #444444;
}

body.high-contrast #chatbot-messages a,
.high-contrast #chatbot-messages a {
  color: #ffff00;
}

body.high-contrast #chatbot-messages blockquote,
.high-contrast #chatbot-messages blockquote {
  border-left-color: #ffff00;
  color: #cccccc;
}

/* Mensagens de Erro - Contraste */
body.high-contrast .chatbot-error-message,
.high-contrast .chatbot-error-message {
  background: #330000;
  border-color: #ff6666;
  color: #ff9999;
}

body.high-contrast .chatbot-retry-btn,
.high-contrast .chatbot-retry-btn {
  background: #ffff00;
  color: #000000;
}

body.high-contrast .chatbot-retry-btn:hover,
.high-contrast .chatbot-retry-btn:hover {
  background: #cccc00;
}

/* ==========================================
   ESTILOS PARA MENSAGENS DE ERRO
   ========================================== */
.chatbot-error-message {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbot-retry-btn {
  align-self: flex-start;
  background: #005a92;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(0, 90, 146, 0.3);
}

.chatbot-retry-btn:hover {
  background: #004080;
  transform: scale(1.02);
}

.chatbot-retry-btn:active {
  transform: scale(0.98);
}

/* Botão de Limpar Conversa */
.chatbot-clear-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  margin-right: 8px;
}

.chatbot-clear-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

body.high-contrast .chatbot-clear-btn,
.high-contrast .chatbot-clear-btn {
  background: rgba(255, 255, 0, 0.1);
  color: #ffff00;
  border-radius: 4px;
  /* Ensure consistency */
}

body.high-contrast .chatbot-clear-btn:hover,
.high-contrast .chatbot-clear-btn:hover {
  background: rgba(255, 255, 0, 0.25);
  color: #ffff00;
}

body.high-contrast #chatbot-new-chat svg,
body.high-contrast #chatbot-new-chat svg path,
body.high-contrast #chatbot-new-chat svg line,
.high-contrast #chatbot-new-chat svg,
.high-contrast #chatbot-new-chat svg path,
.high-contrast #chatbot-new-chat svg line {
  stroke: #ffff00 !important;
  color: #ffff00 !important;
  fill: none !important;
}