/* =========================================
   CNF AI SEARCH — Chat Widget Styles
   Identidade: Portal CNF (vermelho #1a3a5c)
   Fonte: Oxygen (mesma do player)
========================================= */

@import url('https://fonts.googleapis.com/css2?family=Oxygen:wght@300;400;700&display=swap');

/* ---- Reset local ---- */
#cnf-ai-root,
#cnf-ai-root * {
  box-sizing: border-box;
  font-family: 'Oxygen', Arial, sans-serif;
}

/* =========================================
   FAB — Botão flutuante
========================================= */
#cnf-ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1a3a5c;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(198,40,40,.45);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

#cnf-ai-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 22px rgba(198,40,40,.55);
  background: #b71c1c;
}

#cnf-ai-fab:active {
  transform: scale(0.94);
}

#cnf-ai-fab svg {
  width: 24px;
  height: 24px;
}

/* Badge de notificação (opcional, JS pode ativar) */
#cnf-ai-fab.has-badge::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #1a3a5c;
  border-radius: 50%;
}

/* =========================================
   PAINEL DO CHAT
========================================= */
#cnf-ai-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 999997;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Animação de entrada */
  transform-origin: bottom right;
  transform: scale(0.92) translateY(12px);
  opacity: 0;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
  pointer-events: none;
}

#cnf-ai-panel:not([hidden]) {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Hack: [hidden] bloqueia a transição; usamos classe */
#cnf-ai-panel.cbn-visible {
  display: flex !important;
}

/* =========================================
   HEADER
========================================= */
#cnf-ai-header {
  background: #1a3a5c;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.cnf-ai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cnf-ai-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #fff;
  padding: 2px;
  object-fit: contain;
}

.cnf-ai-title {
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}

.cnf-ai-subtitle {
  color: rgba(255,255,255,.75);
  font-size: 11px;
  font-weight: 400;
}

#cnf-ai-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.85);
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: color .15s, background .15s;
}

#cnf-ai-close svg {
  width: 18px;
  height: 18px;
}

#cnf-ai-close:hover {
  color: #fff;
  background: rgba(255,255,255,.15);
}

/* =========================================
   ÁREA DE MENSAGENS
========================================= */
#cnf-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar discreta */
#cnf-ai-messages::-webkit-scrollbar { width: 4px; }
#cnf-ai-messages::-webkit-scrollbar-track { background: transparent; }
#cnf-ai-messages::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }

/* ---- Mensagem genérica ---- */
.cbn-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: cbn-fadein .25s ease;
}

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

.cbn-msg-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 90%;
  word-break: break-word;
}

/* ---- Usuário ---- */
.cbn-msg.cbn-user {
  align-items: flex-end;
}

.cbn-msg.cbn-user .cbn-msg-bubble {
  background: #1a3a5c;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ---- IA ---- */
.cbn-msg.cbn-ai {
  align-items: flex-start;
}

.cbn-msg.cbn-ai .cbn-msg-bubble {
  background: #f5f5f5;
  color: #222;
  border-bottom-left-radius: 4px;
}

/* Links dentro da resposta da IA */
.cbn-msg.cbn-ai .cbn-msg-bubble a {
  color: #1a3a5c;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(198,40,40,.3);
  transition: border-color .15s;
}

.cbn-msg.cbn-ai .cbn-msg-bubble a:hover {
  border-color: #1a3a5c;
}

/* ---- Cards de artigos ---- */
.cbn-articles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.cbn-article-card {
  background: #fff;
  border: 1.5px solid #e8e8e8;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  transition: border-color .15s, box-shadow .15s;
}

.cbn-article-card:hover {
  border-color: #1a3a5c;
  box-shadow: 0 2px 8px rgba(198,40,40,.1);
}

.cbn-article-card a {
  color: #222;
  text-decoration: none;
  font-weight: 700;
  line-height: 1.35;
  display: block;
}

.cbn-article-card a:hover { color: #1a3a5c; }

.cbn-article-meta {
  color: #888;
  font-size: 11px;
  margin-top: 2px;
}

/* ---- Typing indicator ---- */
.cbn-typing .cbn-msg-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
}

.cbn-dot {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: cbn-bounce .9s infinite ease-in-out;
}

.cbn-dot:nth-child(2) { animation-delay: .15s; }
.cbn-dot:nth-child(3) { animation-delay: .30s; }

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

/* ---- Mensagem de erro ---- */
.cbn-msg-error .cbn-msg-bubble {
  background: #fff3f3;
  border: 1px solid #ffcdd2;
  color: #1a3a5c;
  font-size: 13px;
}

/* ---- Mensagem de boas-vindas ---- */
.cbn-welcome {
  text-align: center;
  padding: 20px 10px 10px;
  color: #555;
  font-size: 13px;
}

.cbn-welcome strong {
  display: block;
  color: #1a3a5c;
  font-size: 15px;
  margin-bottom: 6px;
}

.cbn-welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
}

.cbn-chip {
  background: #fff0f0;
  border: 1.5px solid #ffcdd2;
  color: #1a3a5c;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}

.cbn-chip:hover {
  background: #1a3a5c;
  color: #fff;
  border-color: #1a3a5c;
}

/* =========================================
   INPUT AREA
========================================= */
#cnf-ai-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}

#cnf-ai-input {
  flex: 1;
  border: 1.5px solid #e0e0e0;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: 'Oxygen', Arial, sans-serif;
  outline: none;
  background: #fafafa;
  transition: border-color .15s, background .15s;
  color: #222;
}

#cnf-ai-input:focus {
  border-color: #1a3a5c;
  background: #fff;
}

#cnf-ai-input::placeholder { color: #bbb; }

#cnf-ai-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #1a3a5c;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

#cnf-ai-send svg {
  width: 17px;
  height: 17px;
}

#cnf-ai-send:hover  { background: #b71c1c; }
#cnf-ai-send:active { transform: scale(.9); }
#cnf-ai-send:disabled { background: #e0e0e0; cursor: not-allowed; }

/* =========================================
   FOOTER
========================================= */
#cnf-ai-footer {
  text-align: center;
  font-size: 10.5px;
  color: #bbb;
  padding: 6px 14px 10px;
  flex-shrink: 0;
}

/* =========================================
   RESPONSIVO
========================================= */
@media (max-width: 400px) {
  #cnf-ai-panel {
    right: 12px;
    bottom: 80px;
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    border-radius: 14px;
  }

  #cnf-ai-fab {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }
}

/* =========================================
   SHORTCODE & SIDEBAR WIDGET
   Compartilham classes .cbn-sc-*
========================================= */
.cbn-shortcode-wrap,
.cbn-sidebar-widget {
  font-family: inherit;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0,0,0,.1);
  border: 1px solid #e8e8e8;
  background: #fff;
  margin: 1.5em 0;
}

.cbn-sc-header {
  background: #1a3a5c;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cbn-sc-messages {
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: #fff;
}

.cbn-sc-messages::-webkit-scrollbar { width: 4px; }
.cbn-sc-messages::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }

.cbn-sc-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #f0f0f0;
  background: #fff;
}

.cbn-sc-input {
  flex: 1;
  border: 1.5px solid #e0e0e0;
  border-radius: 22px;
  padding: 8px 14px;
  font-size: 13.5px;
  outline: none;
  background: #fafafa;
  transition: border-color .15s;
  color: #222;
}

.cbn-sc-input:focus { border-color: #1a3a5c; background: #fff; }
.cbn-sc-input::placeholder { color: #bbb; }

.cbn-sc-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1a3a5c;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.cbn-sc-send svg { width: 15px; height: 15px; }
.cbn-sc-send:hover  { background: #b71c1c; }
.cbn-sc-send:active { transform: scale(.9); }
.cbn-sc-send:disabled { background: #e0e0e0; cursor: not-allowed; }

.cbn-sc-footer {
  text-align: center;
  font-size: 10.5px;
  color: #bbb;
  padding: 5px 14px 9px;
  background: #fff;
}

/* =========================================
   POP-UP DE INTENÇÃO DE SAÍDA
========================================= */
#cbn-exit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: cbn-fadein .2s ease;
}

#cbn-exit-popup {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,.22);
  width: 400px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  animation: cbn-slidein .22s cubic-bezier(.34,1.56,.64,1);
}

@keyframes cbn-slidein {
  from { transform: translateY(20px) scale(.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}

#cbn-exit-popup .cbn-ep-header {
  background: #1a3a5c;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#cbn-exit-popup .cbn-ep-title {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

#cbn-exit-popup .cbn-ep-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: 2px;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
}

#cbn-exit-popup .cbn-ep-close:hover { color: #fff; }

#cbn-exit-popup .cbn-ep-body {
  padding: 20px;
}

#cbn-exit-popup .cbn-ep-msg {
  font-size: 14px;
  color: #444;
  margin-bottom: 14px;
  line-height: 1.5;
}

#cbn-exit-popup .cbn-ep-input-row {
  display: flex;
  gap: 8px;
}

#cbn-exit-popup .cbn-ep-input {
  flex: 1;
  border: 1.5px solid #e0e0e0;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s;
}

#cbn-exit-popup .cbn-ep-input:focus { border-color: #1a3a5c; }

#cbn-exit-popup .cbn-ep-submit {
  background: #1a3a5c;
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

#cbn-exit-popup .cbn-ep-submit:hover { background: #b71c1c; }

#cbn-exit-popup .cbn-ep-response {
  margin-top: 14px;
  display: none;
  flex-direction: column;
  gap: 8px;
}

/* =========================================
   BOTÃO DE VOZ
========================================= */
.cbn-voice-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.5);
  color: rgba(255,255,255,.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s, transform .1s;
}

#cnf-ai-input-area .cbn-voice-btn {
  border-color: #e0e0e0;
  color: #888;
}

.cbn-voice-btn svg { width: 16px; height: 16px; }
.cbn-voice-btn:hover { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.8); }
#cnf-ai-input-area .cbn-voice-btn:hover { background: #f5f5f5; border-color: #1a3a5c; color: #1a3a5c; }
.cbn-voice-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Animação de gravação ativa */
.cbn-voice-btn.cbn-voice-active {
  background: #1a3a5c !important;
  border-color: #1a3a5c !important;
  color: #fff !important;
  animation: cbn-voice-pulse 1s infinite;
}

@keyframes cbn-voice-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(198,40,40,.4); }
  50%      { box-shadow: 0 0 0 6px rgba(198,40,40,0); }
}

/* =========================================
   CURSOR DE STREAMING (texto aparecendo)
========================================= */
.cbn-streaming::after {
  content: '▋';
  display: inline-block;
  animation: cbn-blink .7s step-end infinite;
  color: #1a3a5c;
  margin-left: 2px;
  font-size: 14px;
}

@keyframes cbn-blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* CTA Bubble above FAB */
#cnf-ai-cta {
  position: fixed;
  z-index: 999997;
  max-width: 220px;
  background: #fff;
  color: #1a3a5c;
  border: 1px solid #e0e0e0;
  border-radius: 12px 12px 4px 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}
#cnf-ai-cta.cnf-cta-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}
#cnf-ai-cta::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 18px;
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 0 solid transparent;
  border-top: 7px solid #fff;
}
#cnf-ai-cta .cnf-cta-close {
  position: absolute;
  top: 4px; right: 6px;
  font-size: 14px;
  cursor: pointer;
  opacity: .5;
  line-height: 1;
  background: none;
  border: none;
  color: inherit;
  padding: 0;
}
#cnf-ai-cta .cnf-cta-close:hover { opacity: 1; }

/* FAB pill style */
#cnf-ai-fab.cnf-fab-pill {
  width: auto;
  border-radius: 28px;
  padding: 0 20px;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

/* FAB pulse animation */
@keyframes cnf-pulse {
  0%,100% { box-shadow: 0 4px 16px rgba(26,58,92,.4), 0 0 0 0 rgba(26,58,92,.35); }
  50%      { box-shadow: 0 4px 16px rgba(26,58,92,.4), 0 0 0 10px rgba(26,58,92,0); }
}
#cnf-ai-fab.cnf-fab-pulse {
  animation: cnf-pulse 2s ease-in-out infinite;
}

/* Positioning helpers */
#cnf-ai-fab.cnf-pos-right { right: 24px; left: auto; }
#cnf-ai-fab.cnf-pos-left  { left: 24px; right: auto; }
#cnf-ai-cta.cnf-pos-right { right: 24px; left: auto; }
#cnf-ai-cta.cnf-pos-left  { left: 24px; right: auto; }
#cnf-ai-cta.cnf-pos-left::after { right: auto; left: 18px; }
