/* =========================================================================
   DCX ASSISTANT · UI (Fase 1)
   -------------------------------------------------------------------------
   CSS 100% escopado sob o prefixo .dcx- (zero seletores globais, zero
   !important). Os tokens --dcx-* são aplicados pelo motor a partir da
   config — que referencia as variáveis do PRÓPRIO site, então o assistente
   acompanha o tema claro/escuro automaticamente. Fallbacks = hex reais do
   tema escuro (auditoria do Passo 0).
   ========================================================================= */

/* ---- Escopo: reset e herança explícita (nada entra/sai por acidente) ---- */
.dcx-root,
.dcx-root *,
.dcx-root *::before,
.dcx-root *::after { box-sizing: border-box; margin: 0; padding: 0; }

.dcx-root {
  --dcx-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dcx-radius: 16px;
  --dcx-radius-lg: 22px;
  font-family: var(--dcx-font-b, "Manrope", system-ui, -apple-system, sans-serif);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--dcx-text, #f2eee5);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
.dcx-root button,
.dcx-root input { font: inherit; color: inherit; }
.dcx-root :focus-visible { outline: 2px solid var(--dcx-accent, #d7b978); outline-offset: 2px; }

/* Utilitário: visível só para leitores de tela. */
.dcx-vh {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* =========================================================================
   FAB — botão flutuante (entrada única, sem pulso contínuo)
   ========================================================================= */
.dcx-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: var(--dcx-z, 90);
  display: inline-flex; align-items: center; gap: 0.55rem;
  min-height: 52px; padding: 0.55rem 1.05rem 0.55rem 0.6rem;
  border: 1px solid color-mix(in oklab, var(--dcx-accent, #d7b978) 42%, transparent);
  border-radius: 999px;
  background: linear-gradient(160deg, var(--dcx-surface, #11293f), var(--dcx-surface2, #0e2236));
  color: var(--dcx-heading, #f7f3ea);
  font-weight: 600; font-size: 0.94rem;
  box-shadow: 0 14px 36px rgba(4, 12, 22, 0.4);
  cursor: pointer;
  transition: transform 0.25s var(--dcx-ease), box-shadow 0.25s var(--dcx-ease), opacity 0.25s var(--dcx-ease);
}
.dcx-fab.dcx-in { animation: dcx-rise 0.6s var(--dcx-ease) 0.12s backwards; }
.dcx-fab:hover { transform: translateY(-2px); box-shadow: 0 18px 44px rgba(4, 12, 22, 0.48); }
.dcx-fab__ic {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%;
  background: color-mix(in oklab, var(--dcx-accent, #d7b978) 16%, transparent);
  color: var(--dcx-accent, #d7b978);
}
.dcx-fab__ic svg { width: 19px; height: 19px; }
.dcx-fab__tx { white-space: nowrap; }
.dcx-root[data-open] .dcx-fab { opacity: 0; pointer-events: none; transform: translateY(10px) scale(0.96); }

/* =========================================================================
   PAINEL — cartão de conversa (glass sutil, cara de app)
   ========================================================================= */
.dcx-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: calc(var(--dcx-z, 90) + 20);
  display: flex; flex-direction: column;
  width: min(386px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 88px));
  background: color-mix(in oklab, var(--dcx-surface, #11293f) 90%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.12);
  backdrop-filter: blur(16px) saturate(1.12);
  border: 1px solid color-mix(in oklab, var(--dcx-accent, #d7b978) 24%, var(--dcx-border, rgba(242, 238, 229, 0.12)));
  border-radius: var(--dcx-radius-lg);
  box-shadow: 0 32px 90px rgba(3, 10, 20, 0.55);
  overflow: hidden;
  overscroll-behavior: contain;
}
.dcx-panel[hidden] { display: none; }
.dcx-panel.dcx-in { animation: dcx-pop 0.42s var(--dcx-ease) backwards; }

/* ---- Cabeçalho ---- */
.dcx-head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.85rem 0.85rem 0.85rem 1rem;
  border-bottom: 1px solid var(--dcx-border, rgba(242, 238, 229, 0.12));
  background: linear-gradient(180deg, color-mix(in oklab, var(--dcx-surface2, #0e2236) 72%, transparent), transparent);
}
.dcx-ava {
  position: relative; flex: 0 0 auto;
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--dcx-surface2, #0e2236);
  box-shadow:
    0 0 0 1px color-mix(in oklab, var(--dcx-accent, #d7b978) 55%, transparent),
    0 0 0 4px color-mix(in oklab, var(--dcx-accent, #d7b978) 12%, transparent);
  overflow: hidden;
}
.dcx-ava img { width: 78%; height: 78%; object-fit: contain; }
.dcx-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dcx-name {
  font-family: var(--dcx-font-h, "Fraunces", Georgia, serif);
  font-weight: 600; font-size: 1.06rem; line-height: 1.2;
  color: var(--dcx-heading, #f7f3ea);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dcx-status {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.74rem; color: var(--dcx-muted, rgba(242, 238, 229, 0.66));
}
.dcx-status i {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: var(--dcx-accent, #d7b978);
  animation: dcx-beat 2.8s ease-in-out infinite;
}
.dcx-close {
  margin-left: auto; flex: 0 0 auto;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 12px;
  background: transparent;
  color: var(--dcx-muted, rgba(242, 238, 229, 0.66));
  cursor: pointer;
  transition: background 0.2s var(--dcx-ease), color 0.2s var(--dcx-ease);
}
.dcx-close:hover { background: color-mix(in oklab, var(--dcx-text, #f2eee5) 8%, transparent); color: var(--dcx-heading, #f7f3ea); }
.dcx-close svg { width: 18px; height: 18px; }

/* ---- Log de mensagens ---- */
.dcx-log {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 0.55rem;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in oklab, var(--dcx-text, #f2eee5) 22%, transparent) transparent;
}
.dcx-log::-webkit-scrollbar { width: 6px; }
.dcx-log::-webkit-scrollbar-track { background: transparent; }
.dcx-log::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in oklab, var(--dcx-text, #f2eee5) 22%, transparent);
}

.dcx-msg {
  max-width: 86%;
  padding: 0.62rem 0.85rem;
  border-radius: var(--dcx-radius);
  font-size: 0.95rem; line-height: 1.5;
  overflow-wrap: break-word; white-space: pre-line;
}
.dcx-msg.dcx-anim { animation: dcx-msg 0.35s var(--dcx-ease) backwards; }
.dcx-msg--bot {
  align-self: flex-start;
  background: var(--dcx-surface2, #0e2236);
  border: 1px solid var(--dcx-border, rgba(242, 238, 229, 0.12));
  border-bottom-left-radius: 6px;
  color: var(--dcx-text, #f2eee5);
}
.dcx-msg--user {
  align-self: flex-end;
  background: linear-gradient(160deg, var(--dcx-primary, #1763c4), color-mix(in oklab, var(--dcx-primary, #1763c4) 74%, #06264d));
  border-bottom-right-radius: 6px;
  color: #ffffff;
}

/* Indicador de digitação (3 pontos). */
.dcx-typing { display: inline-flex; align-items: center; gap: 5px; padding: 0.78rem 0.9rem; }
.dcx-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--dcx-muted, rgba(242, 238, 229, 0.66));
  animation: dcx-dot 1.05s ease-in-out infinite;
}
.dcx-typing i:nth-child(2) { animation-delay: 0.14s; }
.dcx-typing i:nth-child(3) { animation-delay: 0.28s; }

/* Ações contextuais (botões após uma resposta). */
.dcx-actions {
  align-self: flex-start;
  display: flex; flex-wrap: wrap; gap: 0.45rem;
  max-width: 92%;
}
.dcx-actions.dcx-anim { animation: dcx-msg 0.35s var(--dcx-ease) 0.05s backwards; }
.dcx-act {
  display: inline-flex; align-items: center; gap: 0.45rem;
  min-height: 44px; padding: 0.5rem 0.95rem;
  border: 1px solid color-mix(in oklab, var(--dcx-accent, #d7b978) 45%, transparent);
  border-radius: 999px;
  background: color-mix(in oklab, var(--dcx-accent, #d7b978) 10%, transparent);
  color: var(--dcx-heading, #f7f3ea);
  font-size: 0.88rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
  transition: transform 0.2s var(--dcx-ease), background 0.2s var(--dcx-ease);
}
.dcx-act:hover { transform: translateY(-1px); background: color-mix(in oklab, var(--dcx-accent, #d7b978) 18%, transparent); }
.dcx-act svg { width: 16px; height: 16px; flex: 0 0 auto; }
.dcx-act--primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--dcx-accent, #d7b978), color-mix(in oklab, var(--dcx-accent, #d7b978) 68%, #f4e3b8));
  color: #0b1f33;
}
.dcx-act--primary:hover { background: linear-gradient(135deg, color-mix(in oklab, var(--dcx-accent, #d7b978) 88%, #ffffff), var(--dcx-accent, #d7b978)); }

/* ---- Perguntas rápidas (chips com rolagem horizontal) ---- */
.dcx-quick {
  display: flex; gap: 0.45rem;
  padding: 0.4rem 1rem 0.55rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.dcx-quick::-webkit-scrollbar { display: none; }
.dcx-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0.5rem 0.85rem;
  border: 1px solid var(--dcx-border, rgba(242, 238, 229, 0.12));
  border-radius: 999px;
  background: color-mix(in oklab, var(--dcx-text, #f2eee5) 5%, transparent);
  color: var(--dcx-text, #f2eee5);
  font-size: 0.86rem; font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s var(--dcx-ease), color 0.2s var(--dcx-ease), background 0.2s var(--dcx-ease);
}
.dcx-chip:hover {
  border-color: color-mix(in oklab, var(--dcx-accent, #d7b978) 55%, transparent);
  background: color-mix(in oklab, var(--dcx-accent, #d7b978) 10%, transparent);
  color: var(--dcx-heading, #f7f3ea);
}

/* ---- Composição ---- */
.dcx-compose {
  display: flex; gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--dcx-border, rgba(242, 238, 229, 0.12));
}
.dcx-input {
  flex: 1; min-width: 0; min-height: 46px;
  padding: 0.6rem 0.95rem;
  border: 1px solid var(--dcx-border, rgba(242, 238, 229, 0.12));
  border-radius: 999px;
  background: var(--dcx-surface2, #0e2236);
  color: var(--dcx-text, #f2eee5);
  font-size: 0.95rem;
}
.dcx-input::placeholder { color: var(--dcx-muted, rgba(242, 238, 229, 0.66)); }
.dcx-input:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--dcx-accent, #d7b978) 70%, transparent);
  outline-offset: 1px;
  border-color: transparent;
}
.dcx-send {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--dcx-accent, #d7b978), color-mix(in oklab, var(--dcx-accent, #d7b978) 72%, #a9853f));
  color: #0b1f33;
  cursor: pointer;
  transition: transform 0.2s var(--dcx-ease), opacity 0.2s var(--dcx-ease);
}
.dcx-send:hover { transform: translateY(-1px); }
.dcx-send:disabled { opacity: 0.55; cursor: default; transform: none; }
.dcx-send svg { width: 19px; height: 19px; }

/* ---- Nota de privacidade ---- */
.dcx-note {
  padding: 0 1.1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.72rem; line-height: 1.45;
  color: var(--dcx-muted, rgba(242, 238, 229, 0.66));
  text-align: center;
}

/* =========================================================================
   MOBILE — folha em tela cheia; teclado nunca cobre o campo
   (o motor injeta --dcx-vvh via visualViewport)
   ========================================================================= */
@media (max-width: 719px) {
  .dcx-panel {
    inset: 0;
    width: auto;
    height: var(--dcx-vvh, 100dvh);
    border-radius: 0;
    border: 0;
  }
}

/* =========================================================================
   ANIMAÇÕES
   ========================================================================= */
@keyframes dcx-rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes dcx-pop { from { opacity: 0; transform: translateY(14px) scale(0.985); } }
@keyframes dcx-msg { from { opacity: 0; transform: translateY(7px); } }
@keyframes dcx-dot {
  0%, 100% { opacity: 0.35; transform: none; }
  50% { opacity: 1; transform: translateY(-3px); }
}
@keyframes dcx-beat {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--dcx-accent, #d7b978) 45%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; }
}

/* Reduced motion: sem animações decorativas; tudo continua utilizável. */
@media (prefers-reduced-motion: reduce) {
  .dcx-fab.dcx-in,
  .dcx-panel.dcx-in,
  .dcx-msg.dcx-anim,
  .dcx-actions.dcx-anim,
  .dcx-typing i,
  .dcx-status i { animation: none; }
  .dcx-fab,
  .dcx-chip,
  .dcx-act,
  .dcx-close,
  .dcx-send { transition: none; }
  .dcx-log { scroll-behavior: auto; }
}
