/* ========== MENSAGENS ========== */
.message-wrapper {
  margin-bottom: 24px;
}

.message-wrapper.user {
  display: flex;
  justify-content: flex-end;
}

.message-wrapper.bot {
  display: flex;
  justify-content: flex-start;
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-inner {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-header {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  padding: 0 4px;
  transition: color 0.3s ease;
}

.message {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.6;
  word-wrap: break-word;
  transition: all 0.3s ease;
}

.message.user {
  background: var(--message-user-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.bot {
  background: var(--message-bot-bg);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Formatação Markdown nas mensagens */
.message.bot p {
  margin: 0 0 10px 0;
}

.message.bot p:last-child {
  margin-bottom: 0;
}

.message.bot ul,
.message.bot ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message.bot li {
  margin: 4px 0;
}

.message.bot a {
  color: var(--accent-primary);
  text-decoration: underline;
  font-weight: 500;
}

.message.bot a:hover {
  color: var(--accent-hover);
}

.message.bot code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 14px;
}

.message.bot pre {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border-color);
}

.message.bot pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* SQL Query Block */
.sql-query-block {
  margin-top: 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.sql-query-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  transition:
    background 0.15s,
    color 0.15s;
}

.sql-query-toggle:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.sql-query-toggle span {
  flex: 1;
}

.sql-chevron {
  transition: transform 0.2s;
}

.sql-query-block.open .sql-chevron {
  transform: rotate(180deg);
}

.sql-query-block.open .sql-query-toggle {
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

.sql-query-content {
  display: none;
  position: relative;
  background: var(--bg-secondary);
}

.sql-query-block.open .sql-query-content {
  display: block;
}

.sql-query-content pre {
  margin: 0;
  padding: 12px 14px;
  padding-top: 36px;
  background: transparent;
  border: none;
  border-radius: 0;
  overflow-x: auto;
}

.sql-query-content pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
  font-family: "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

.sql-copy-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

.sql-copy-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.typing-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.typing-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 1.25s ease-in-out infinite;
}

/* 🌞 LIGHT MODE */
body:not(.dark-theme) .typing-dot {
  background: #555;
}

/* 🌙 DARK MODE */
body.dark-theme .typing-dot {
  background: #ccc;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.75;
  }
  50% {
    transform: scale(1.6);
    opacity: 1;
  }
}

.message.bot {
  padding: 10px 14px;
  border-radius: 12px;
  display: inline-block;
  max-width: 95%;
  width: 100%;
  font-size: 12px;
}

/* 🌞 LIGHT  */
body:not(.dark-theme) .message.bot {
  background: #f1f1f1;
  color: #000;
}

/* 🌙 DARK */
body.dark-theme .message.bot {
  background: #2a2a2a;
  color: #fff;
}
/* ========== INPUT CONTAINER ========== */
.input-container {
  display: flex;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  padding: 24px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 10;
  transition: all 0.3s ease;
}

.input-action-row {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  gap: 10px;
}

.input-text-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.btn-new-chat {
  background: var(--accent-primary);
  color: white;
  border: none;
  justify-content: center;
  text-align: center;
  align-items: center;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 110px;
  height: 46px;
  flex-shrink: 0;
}

.btn-new-chat:hover {
  background: var(--accent-hover);
}

.input-wrapper {
  max-width: calc(100% - 126px);
  width: 100%;
  min-width: 300px;
}

.input-wrapper textarea {
  width: 100%;
}

.input-container.centered {
  position: absolute;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  border-top: none;
}

.input-container.fixed-bottom {
  position: sticky;
  bottom: 0;
  top: auto;
  transform: none;
}

.input-wrapper {
  max-width: 680px;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  border-radius: 12px;
  padding: 12px;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 6px 24px rgba(18, 82, 138, 0.35);
}

#messageInput {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
}

#messageInput::placeholder {
  color: var(--text-secondary);
}

.new-chat-wrapper {
  /* display: flex; */
  justify-content: center;
  margin-bottom: 8px;
  /* width: 100%; */
}

.btn-new-message {
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  font-weight: 600;
}

.btn-new-message:hover {
  background: var(--accent-hover);
}

.btn-new-message:hover {
  background: var(--bg-tertiary);
}

.message-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
}

.message-input::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.btn-send .send-icon {
  display: block;
  transition: opacity 0.2s ease;
}

.btn-send .lock-icon {
  display: none;
  transition: opacity 0.2s ease;
}

.btn-send:disabled .send-icon {
  display: none;
}

.btn-send:disabled .lock-icon {
  display: block;
  stroke: #ff6b6b;
  animation: lockPulse 1.5s ease-in-out infinite;
}

@keyframes lockPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  background: var(--bg-tertiary);
  cursor: not-allowed;
  opacity: 0.9;
}

.btn-send:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-send.generating {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  opacity: 1;
}

.btn-send.generating .send-icon {
  display: none;
}

.btn-send.generating .lock-icon {
  display: none;
}

.btn-send.generating .stop-gen-icon {
  display: block !important;
  color: var(--text-primary);
}

.btn-send.generating:hover {
  background: var(--bg-secondary);
}

/* ========== COPY BUTTON ========== */
.msg-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 4px;
  right: -44px;
  opacity: 1;
}

.message.bot {
  position: relative;
  width: 100%;
  max-width: 920px;
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.5;
  word-wrap: break-word;
  margin-bottom: 8px;
}

.message.user {
  width: 100%;
  max-width: 920px;
  padding: 14px 18px;
  background: var(--message-user-bg);
  color: #fff;
  border-radius: 16px;
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 8px;
}

.btn-copy {
  width: 36px;
  height: 36px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}

.btn-copy svg {
  display: block;
  flex-shrink: 0;
}

.btn-copy:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
}

.btn-copy:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.btn-copy:focus-visible {
  outline: none;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.btn-copy.copied {
  background: var(--bg-secondary);
  border-color: #22c55e;
  color: #22c55e;
}

/* ========== AUDIO RECORD BUTTON ========== */
/* ========== AUDIO RECORDING UI (estilo WhatsApp) ========== */

/* Barra de gravação – flex item dentro do input-wrapper */
.audio-rec-bar {
  display: none;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

/* Mostrar barra + esconder textarea e btn-send durante gravação */
.input-wrapper.is-recording .audio-rec-bar {
  display: flex;
}
.input-wrapper.is-recording #messageInput {
  display: none;
}
.input-wrapper.is-recording .btn-send {
  display: none;
}

/* Cancelar (lixeira): visível só no mode bloqueado */
.audio-rec-cancel {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--error-color, #ef4444);
  padding: 6px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.audio-rec-cancel:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Dica de deslizar: visível ANTES de bloquear */
.audio-rec-slide {
  display: none;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  flex: 1;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  transition:
    opacity 0.2s ease,
    transform 0.15s ease;
}

/* Dot + timer */
.audio-rec-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.audio-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  animation: recDotBlink 1s ease-in-out infinite;
}
@keyframes recDotBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.15;
  }
}
.audio-rec-time {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

/* Não-bloqueado: cancelar escondido, slide visível */
.input-wrapper.is-recording:not(.is-locked) .audio-rec-cancel {
  display: none;
}
.input-wrapper.is-recording:not(.is-locked) .audio-rec-slide {
  display: flex;
}

/* Bloqueado: slide escondido, cancelar visível */
.input-wrapper.is-locked .audio-rec-slide {
  display: none;
}
.input-wrapper.is-locked .audio-rec-cancel {
  display: flex;
}

/* Cadeado flutuante acima do botão mic */
.audio-lock-hint {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 55px; /* posição aproximada acima do btn-audio */
  width: 34px;
  height: 34px;
  background: var(--accent-primary);
  color: white;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  z-index: 20;
  transition:
    transform 0.15s ease,
    background 0.2s ease;
  user-select: none;
}
.audio-lock-hint:hover {
  transform: scale(1.1);
}
.audio-lock-hint.is-locked-state {
  background: #25d366;
}
.input-wrapper.is-recording:not(.is-locked) .audio-lock-hint {
  display: flex;
}

/* Botão enviar áudio (modo bloqueado) */
.audio-rec-send-btn {
  display: none;
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  transition:
    background 0.2s ease,
    transform 0.1s ease;
}
.audio-rec-send-btn:hover {
  background: var(--accent-hover);
}
.audio-rec-send-btn:active {
  transform: scale(0.95);
}

/* No modo bloqueado: esconder mic, mostrar send */
.input-wrapper.is-locked #btnGravar {
  display: none;
}
.input-wrapper.is-locked .audio-rec-send-btn {
  display: flex;
}

.btn-audio {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.btn-audio:hover {
  color: var(--accent-primary);
  background: var(--bg-tertiary);
}

.btn-audio.recording {
  color: #ff4444;
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

.btn-audio:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Input Disclaimer */
.input-disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 16px 0 130px;
  line-height: 1.4;
  max-width: 768px;
  margin: 8px auto 0 auto;
  width: 100%;
  order: 2;
}

.send-btn {
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:disabled {
  background: var(--bg-tertiary);
  cursor: not-allowed;
}

.send-btn:active:not(:disabled) {
  transform: scale(0.98);
}

