/* ═══════════════════════════════════════════════════════════════════
   CHATBOT FLOATING WIDGET — chatbot.css
   Namespace: .cbot-*  |  Consome tokens de tokens.css
   ═══════════════════════════════════════════════════════════════════ */


/* ── FAB (Floating Action Button) ─────────────────────────────────── */

.cbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9010;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform var(--transition-base),
    box-shadow var(--transition-base);
}

.cbot-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.55);
}

.cbot-fab:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 3px;
}

.cbot-fab svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Troca de ícone via classe */
.cbot-fab .icon-close  { display: none; }
.cbot-fab.is-open .icon-chat  { display: none; }
.cbot-fab.is-open .icon-close { display: block; }

/* Badge de notificação */
.cbot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  font-family: var(--font-family-base);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-bg);
  animation: cbot-pulse 2s ease-in-out 3;
}

.cbot-badge[hidden] { display: none; }

@keyframes cbot-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.25); }
}


/* ── PAINEL ────────────────────────────────────────────────────────── */

.cbot-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9009;
  width: 380px;
  max-height: 560px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow:
    0 24px 56px rgba(0, 0, 0, 0.18),
    0 4px 16px  rgba(0, 0, 0, 0.10);
  overflow: hidden;

  /* Estado fechado */
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition:
    opacity    var(--transition-slow),
    transform  var(--transition-slow),
    width      var(--transition-slow),
    max-height var(--transition-slow);
}

.cbot-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

@media (max-width: 480px) {
  .cbot-panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 80px;
  }
  .cbot-fab {
    right: 16px;
    bottom: 16px;
  }
}


/* ── HEADER ────────────────────────────────────────────────────────── */

.cbot-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px var(--space-4);
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
  flex-shrink: 0;
}

.cbot-header__icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cbot-header__icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cbot-header__info { flex: 1; min-width: 0; }

.cbot-header__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: #fff;
  line-height: 1.25;
  margin: 0;
}

.cbot-header__subtitle {
  font-size: var(--font-size-xs);
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.25;
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Dot "online" */
.cbot-header__subtitle::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
}

.cbot-header__actions {
  display: flex;
  gap: 4px;
}

.cbot-header__btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.cbot-header__btn:hover { background: rgba(255, 255, 255, 0.22); }

.cbot-header__btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}


/* ── MENSAGENS ─────────────────────────────────────────────────────── */

.cbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.cbot-messages::-webkit-scrollbar        { width: 4px; }
.cbot-messages::-webkit-scrollbar-track  { background: transparent; }
.cbot-messages::-webkit-scrollbar-thumb  {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.cbot-msg {
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: cbot-fadein 0.22s ease-out;
}

@keyframes cbot-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cbot-msg--bot  { align-self: flex-start; }
.cbot-msg--user { align-self: flex-end;   }

.cbot-msg__bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  word-break: break-word;
}

.cbot-msg--bot .cbot-msg__bubble {
  background: var(--color-hover-bg);
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--radius-xs);
}

.cbot-msg--user .cbot-msg__bubble {
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: var(--radius-xs);
}

/* Markdown inline */
.cbot-msg__bubble strong { font-weight: var(--font-weight-bold); }
.cbot-msg__bubble em     { font-style: italic; }
.cbot-msg__bubble code {
  font-family: var(--font-family-mono);
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 4px;
  border-radius: var(--radius-xs);
}

[data-theme="dark"] .cbot-msg__bubble code {
  background: rgba(255, 255, 255, 0.1);
}

/* Meta (cache / tipo execução) */
.cbot-msg__meta {
  font-size: 10px;
  color: var(--color-text-tertiary);
  padding: 0 2px;
}

.cbot-msg--user .cbot-msg__meta { text-align: right; }

/* Botão "Abrir análise completa" */
.cbot-msg__action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-family-base);
  text-decoration: none;
  border: 1px solid rgba(37, 99, 235, 0.22);
  cursor: pointer;
  transition: background var(--transition-fast);
  align-self: flex-start;
}

.cbot-msg__action:hover {
  background: rgba(37, 99, 235, 0.18);
  text-decoration: none;
}

.cbot-msg__action svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  flex-shrink: 0;
}

[data-theme="dark"] .cbot-msg__action {
  color: #93c5fd;
  background: rgba(147, 197, 253, 0.1);
  border-color: rgba(147, 197, 253, 0.2);
}


/* ── LOADING DOTS ──────────────────────────────────────────────────── */

.cbot-msg--loading .cbot-msg__bubble {
  display: flex;
  align-items: center;
  padding: 12px 16px;
}

.cbot-dots {
  display: flex;
  gap: 4px;
}

.cbot-dots span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-tertiary);
  animation: cbot-bounce 1.2s ease-in-out infinite;
}

.cbot-dots span:nth-child(2) { animation-delay: 0.2s; }
.cbot-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cbot-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1;   }
}


/* ── CHIPS DE SUGESTÃO ─────────────────────────────────────────────── */

.cbot-chips {
  padding: 0 var(--space-4) var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.cbot-chip {
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-family: var(--font-family-base);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color var(--transition-fast),
    color        var(--transition-fast),
    background   var(--transition-fast);
}

.cbot-chip:hover {
  border-color: #2563eb;
  color: #2563eb;
  background: rgba(37, 99, 235, 0.06);
}

[data-theme="dark"] .cbot-chip:hover {
  border-color: #93c5fd;
  color: #93c5fd;
  background: rgba(147, 197, 253, 0.08);
}


/* ── FOOTER / INPUT ────────────────────────────────────────────────── */

.cbot-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.cbot-input {
  flex: 1;
  padding: 9px 13px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-family: var(--font-family-base);
  outline: none;
  transition:
    border-color var(--transition-fast),
    box-shadow   var(--transition-fast);
}

.cbot-input::placeholder { color: var(--color-text-tertiary); }

.cbot-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.cbot-send {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background  var(--transition-fast),
    transform   var(--transition-fast);
}

.cbot-send:hover    { background: #1d4ed8; transform: scale(1.06); }
.cbot-send:disabled { background: var(--color-border); cursor: not-allowed; transform: none; }

.cbot-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hint de atalho de teclado */
.cbot-shortcut-hint {
  text-align: center;
  font-size: 10px;
  color: var(--color-text-tertiary);
  padding: 0 var(--space-4) var(--space-2);
  flex-shrink: 0;
  font-family: var(--font-family-base);
}


/* ── ESTADO MAXIMIZADO ─────────────────────────────────────────────── */

.cbot-panel.is-maximized {
  width: min(600px, calc(100vw - 48px));
  max-height: min(78vh, 720px);
}

@media (max-width: 640px) {
  .cbot-panel.is-maximized {
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 85vh;
  }
}

/* Toggle de ícone do botão maximizar/restaurar */
.cbot-header__btn--max .icon-restore            { display: none; }
.cbot-panel.is-maximized .cbot-header__btn--max .icon-restore  { display: block; }
.cbot-panel.is-maximized .cbot-header__btn--max .icon-maximize { display: none; }
