/* Painel de chat com IA (coluna à direita do dashboard). Usado por index_v2.html. */

.chat-panel {
  width: 340px;
  flex-shrink: 0;
  align-self: flex-start;
  position: sticky;
  top: 16px;
  height: min(640px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #ffffff 0%, #f7f5f2 100%);
  border: 1px solid rgba(12, 42, 55, 0.08);
  border-radius: 20px;
  box-shadow: 0 18px 32px rgba(12, 42, 55, 0.07);
  overflow: hidden;
}

.chat-panel[hidden] {
  display: none;
}

/* ---------- Cabeçalho ---------- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--ink);
  border-bottom: 1px solid var(--ink-line);
  color: var(--ink-text);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-header-title strong {
  display: block;
  font-size: 0.9rem;
  color: var(--champagne-soft);
}

.chat-header-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-text-muted);
}

.chat-status-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #4cc38a;
  box-shadow: 0 0 0 3px rgba(76, 195, 138, 0.2);
}

.chat-status-dot.is-busy {
  background: var(--champagne);
  box-shadow: 0 0 0 3px rgba(217, 182, 107, 0.25);
}

.chat-status-dot.is-error {
  background: #e5645a;
  box-shadow: 0 0 0 3px rgba(229, 100, 90, 0.25);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-text);
  cursor: pointer;
  transition: background 0.15s ease;
}

.chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-icon-btn svg,
.chat-send svg,
.chat-launcher svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Mensagens ---------- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--champagne) 0%, var(--champagne-soft) 100%);
  color: var(--petroleum-deep);
  border-bottom-right-radius: 4px;
}

.chat-msg--assistant {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--card-text);
  border-bottom-left-radius: 4px;
}

.chat-msg--system {
  align-self: center;
  max-width: 100%;
  background: rgba(12, 42, 55, 0.05);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.chat-msg--error {
  align-self: center;
  max-width: 100%;
  background: rgba(229, 100, 90, 0.1);
  border: 1px solid rgba(229, 100, 90, 0.35);
  color: #9b2c24;
  font-size: 0.82rem;
}

.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-blink 1.2s infinite ease-in-out;
}

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

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

@keyframes chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

/* ---------- Entrada ---------- */

.chat-voice-btn {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
  color: var(--card-text);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: normal;
}

.chat-voice-btn:focus-visible {
  outline: 2px solid var(--champagne);
  outline-offset: 2px;
}

.chat-voice-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-voice-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-voice-icon.is-spinning {
  animation: chat-voice-spin 0.9s linear infinite;
}

@keyframes chat-voice-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-voice-icon.is-spinning {
    animation-duration: 3s;
  }
}

.chat-listen {
  margin-top: 8px;
  padding: 6px 10px;
  color: var(--muted);
}

.chat-listen:hover:not(:disabled) {
  color: var(--card-text);
}

.chat-mic {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-mic[aria-pressed="true"] {
  border-color: #9b2c24;
  color: #9b2c24;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px 6px;
  border-top: 1px solid var(--line);
}

.chat-input {
  min-width: 0;
  flex: 1;
  resize: none;
  max-height: 110px;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--card-text);
}

.chat-input:focus {
  outline: 2px solid rgba(217, 182, 107, 0.6);
  outline-offset: 1px;
}

.chat-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--champagne) 0%, var(--champagne-soft) 100%);
  color: var(--petroleum-deep);
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-disclaimer {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Lançador (aparece com o painel recolhido) ---------- */

.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: var(--champagne-soft);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(12, 42, 55, 0.3);
}

.chat-launcher.is-visible {
  display: inline-flex;
}

/* ---------- Responsivo: no mobile o painel vira uma janela fixa no canto ---------- */

@media (max-width: 900px) {
  .chat-panel {
    position: fixed;
    right: 12px;
    bottom: 12px;
    top: auto;
    z-index: 60;
    width: min(380px, calc(100% - 24px));
    height: min(70vh, 560px);
  }
}
