/*
 * NexIA — Widget de chat (NexScale Tech)
 * Convenção CSS: todas as classes prefixadas com `.nx-` (skill oop-conventions-nexscale).
 * Sem framework CSS — vanilla, dependência zero.
 */

.nx-chat-widget {
  --nx-color-primary: #23b5b5;
  --nx-color-primary-dark: #1c9191;
  --nx-color-bg: #ffffff;
  --nx-color-text: #1f2933;
  --nx-color-muted: #6b7280;
  --nx-color-border: #e5e7eb;
  --nx-color-bot-bubble: #f3f4f6;
  --nx-color-user-bubble: #23b5b5;
  --nx-radius: 14px;
  --nx-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  --nx-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  position: fixed;
  z-index: 999999;
  right: 20px;
  /* 200px para o botão flutuante e a janela de chat não taparem
     componentes fixos no fundo da página do site (T18 go-live, ajuste
     pedido em produção — subiu de 20 → 80 → 200px). Horizontal
     (right) mantém-se. */
  bottom: 200px;
  font-family: var(--nx-font);
  box-sizing: border-box;
}

.nx-chat-widget *,
.nx-chat-widget *::before,
.nx-chat-widget *::after {
  box-sizing: border-box;
}

/* --- Botão flutuante (CTA) ------------------------------------------- */

.nx-chat-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--nx-color-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--nx-shadow);
  transition: transform 0.15s ease, background 0.15s ease;
}

.nx-chat-bubble:hover {
  background: var(--nx-color-primary-dark);
  transform: translateY(-1px);
}

.nx-chat-bubble:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.nx-chat-bubble__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nx-chat-bubble__avatar {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.nx-chat-bubble__avatar svg {
  display: block;
  width: 100%;
  height: 100%;
}

.nx-chat-widget--open .nx-chat-bubble {
  display: none;
}

/* --- Janela de chat ---------------------------------------------------- */

.nx-chat-window {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 100px);
  background: var(--nx-color-bg);
  border-radius: var(--nx-radius);
  box-shadow: var(--nx-shadow);
  overflow: hidden;
  position: absolute;
  right: 0;
  bottom: 0;
}

.nx-chat-widget--open .nx-chat-window {
  display: flex;
}

.nx-chat-window__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nx-color-primary);
  color: #fff;
  padding: 14px 16px;
  flex-shrink: 0;
}

.nx-chat-window__header-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nx-chat-window__avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.nx-chat-window__avatar svg {
  display: block;
  width: 100%;
  height: 100%;
}

.nx-chat-window__title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.nx-chat-window__subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin: 2px 0 0;
}

.nx-chat-window__close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.nx-chat-window__close:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* --- Histórico de mensagens -------------------------------------------- */

.nx-chat-window__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
}

.nx-message {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.nx-message--bot {
  align-self: flex-start;
  background: var(--nx-color-bot-bubble);
  color: var(--nx-color-text);
  border-bottom-left-radius: 4px;
}

.nx-message--user {
  align-self: flex-end;
  background: var(--nx-color-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.nx-message--bot a {
  color: var(--nx-color-primary-dark);
  word-break: break-word;
}

.nx-message--bot strong {
  font-weight: 700;
}

.nx-message--error {
  align-self: center;
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
  text-align: center;
}

.nx-message--system {
  align-self: center;
  background: transparent;
  color: var(--nx-color-muted);
  font-size: 12px;
  text-align: center;
}

/* Indicador "a escrever" / streaming em curso */
.nx-typing-indicator {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 13px;
  border-radius: 12px;
  background: var(--nx-color-bot-bubble);
}

.nx-typing-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--nx-color-muted);
  animation: nx-typing-bounce 1.2s infinite ease-in-out;
}

.nx-typing-indicator__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.nx-typing-indicator__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes nx-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Input --------------------------------------------------------------*/

.nx-chat-window__input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--nx-color-border);
  background: var(--nx-color-bg);
  flex-shrink: 0;
}

.nx-chat-window__input {
  flex: 1;
  resize: none;
  border: 1px solid var(--nx-color-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  max-height: 100px;
  min-height: 40px;
  color: var(--nx-color-text);
}

.nx-chat-window__input:focus {
  outline: none;
  border-color: var(--nx-color-primary);
}

.nx-chat-window__send {
  background: var(--nx-color-primary);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nx-chat-window__send:disabled {
  background: var(--nx-color-border);
  cursor: not-allowed;
}

.nx-chat-window__send:hover:not(:disabled) {
  background: var(--nx-color-primary-dark);
}

/* --- Responsivo (mobile) ------------------------------------------------ */

@media (max-width: 480px) {
  .nx-chat-widget {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .nx-chat-window {
    width: 100%;
    height: calc(100vh - 96px);
    max-height: none;
    right: 0;
    left: 0;
  }

  .nx-chat-bubble {
    margin-left: auto;
  }
}
