/* Agente IA Chat — estilos do widget. Tudo isolado em #psac-root para não brigar com o tema/Elementor. */

#psac-root {
  --psac-primary: #1D4ED8;
  --psac-on-primary: #FFFFFF;
  --psac-bg: #F4F6FA;
  --psac-agent-bg: #FFFFFF;
  --psac-agent-text: #1B2230;
  --psac-user-bg: #1D4ED8;
  --psac-user-text: #FFFFFF;
  --psac-border: #DDE2EC;
  --psac-radius: 20px;
  --psac-shadow: 0 16px 48px rgba(16, 24, 40, .20), 0 2px 8px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 99999;
  color: var(--psac-agent-text);
}
#psac-root.psac-pos-right { right: calc(20px + env(safe-area-inset-right, 0px)); }
#psac-root.psac-pos-left { left: calc(20px + env(safe-area-inset-left, 0px)); }

#psac-root *, #psac-root *::before, #psac-root *::after { box-sizing: border-box; }
#psac-root button, #psac-root input, #psac-root textarea { font-family: inherit; font-size: 16px; line-height: 1.4; margin: 0; letter-spacing: normal; text-transform: none; }
#psac-root button { cursor: pointer; -webkit-appearance: none; appearance: none; }
#psac-root svg { display: block; flex: none; }

/* foco visível */
#psac-root button:focus-visible, #psac-root input:focus-visible, #psac-root textarea:focus-visible, #psac-root a:focus-visible {
  outline: 3px solid var(--psac-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, .85);
}

/* ---------- botão flutuante ---------- */
#psac-root .psac-launcher {
  width: 64px; height: 64px; padding: 0; border: 0; border-radius: 50%;
  background: var(--psac-primary); color: var(--psac-on-primary);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .28), 0 0 0 4px #fff;
  transition: transform .2s ease, box-shadow .2s ease;
}
#psac-root .psac-launcher:hover { transform: scale(1.06); background: var(--psac-primary); }
/* animação discreta: pulsação suave + bolinha verde de "online" */
#psac-root .psac-launcher { overflow: visible; position: relative; animation: psac-pulse 2.8s ease-out infinite; }
#psac-root .psac-launcher img { border-radius: 50%; }
#psac-root .psac-launcher::after {
  content: ""; position: absolute; top: 1px; right: 1px; width: 16px; height: 16px; border-radius: 50%;
  background: #22C55E; border: 3px solid #fff; box-sizing: border-box; pointer-events: none;
  animation: psac-online 2.2s ease-out infinite;
}
#psac-root.psac-preview .psac-launcher::after { display: none; }

#psac-root .psac-launcher img { width: 100%; height: 100%; object-fit: cover; display: block; }
#psac-root .psac-launcher .psac-ico { width: 28px; height: 28px; }
#psac-root.psac-is-open .psac-launcher { display: none; }

/* ---------- painel ---------- */
#psac-root .psac-panel {
  position: absolute; bottom: 0;
  width: 392px; max-width: calc(100vw - 24px);
  height: min(680px, calc(100vh - 40px)); height: min(680px, calc(100dvh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--psac-bg); border: 1px solid var(--psac-border); border-radius: var(--psac-radius);
  box-shadow: var(--psac-shadow);
  opacity: 0; visibility: hidden; transform: translateY(12px) scale(.98); transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s ease, visibility 0s linear .22s;
}
#psac-root.psac-pos-right .psac-panel { right: 0; }
#psac-root.psac-pos-left .psac-panel { left: 0; transform-origin: bottom left; }
#psac-root .psac-panel.psac-open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

/* topo */
#psac-root .psac-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px; flex: none;
  background: var(--psac-primary); background: linear-gradient(135deg, var(--psac-primary) 0%, color-mix(in srgb, var(--psac-primary) 78%, #000) 100%);
  color: var(--psac-on-primary);
}
#psac-root .psac-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .18); border: 2px solid rgba(255, 255, 255, .55); color: var(--psac-on-primary);
}
#psac-root .psac-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
#psac-root .psac-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#psac-root .psac-name { font-weight: 700; font-size: 16px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--psac-on-primary); }
#psac-root .psac-status { font-size: 13px; line-height: 1.3; opacity: .92; display: flex; align-items: center; gap: 6px; color: var(--psac-on-primary); }
#psac-root .psac-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #34D399; box-shadow: 0 0 0 2px rgba(255, 255, 255, .45); }
#psac-root .psac-iconbtn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; flex: none; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--psac-on-primary); transition: background .15s ease;
}
#psac-root .psac-iconbtn:hover { background: rgba(255, 255, 255, .18); color: var(--psac-on-primary); }
#psac-root .psac-iconbtn .psac-ico { width: 20px; height: 20px; }

/* conversa */
#psac-root .psac-log {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
#psac-root .psac-row-msg { display: flex; max-width: 100%; animation: psac-in .22s ease both; }
#psac-root .psac-row-msg.psac-user { justify-content: flex-end; }
#psac-root .psac-bubble {
  max-width: 88%; padding: 11px 14px; font-size: 15px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
  background: var(--psac-agent-bg); color: var(--psac-agent-text);
  border: 1px solid var(--psac-border); border-radius: 18px 18px 18px 6px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04); white-space: pre-line;
}
#psac-root .psac-user .psac-bubble {
  background: var(--psac-user-bg); color: var(--psac-user-text); border-color: transparent; border-radius: 18px 18px 6px 18px;
}
#psac-root .psac-bubble.psac-wide { width: 100%; max-width: 100%; }

/* ver detalhes */
#psac-root .psac-more {
  margin-top: 8px; padding: 6px 0; min-height: 32px; border: 0; background: none; color: var(--psac-primary);
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px;
}
#psac-root .psac-more:hover { background: none; color: var(--psac-primary); text-decoration: underline; }
#psac-root .psac-more .psac-ico { width: 16px; height: 16px; transition: transform .2s ease; }
#psac-root .psac-more[aria-expanded="true"] .psac-ico { transform: rotate(180deg); }
#psac-root .psac-full { margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--psac-border); font-size: 14.5px; white-space: pre-line; }

/* botões de ação */
#psac-root .psac-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; white-space: normal; }
#psac-root .psac-act {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1.5px solid var(--psac-primary); border-radius: 12px; text-align: left; text-decoration: none;
  background: var(--psac-agent-bg); color: var(--psac-primary); font-size: 15px; font-weight: 600; line-height: 1.25;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
#psac-root .psac-act:hover { background: color-mix(in srgb, var(--psac-primary) 8%, var(--psac-agent-bg)); color: var(--psac-primary); text-decoration: none; }
#psac-root .psac-act:active { transform: scale(.985); }
#psac-root .psac-act .psac-ico { width: 20px; height: 20px; }
#psac-root .psac-act.psac-primary { background: var(--psac-primary); color: var(--psac-on-primary); box-shadow: 0 4px 12px color-mix(in srgb, var(--psac-primary) 35%, transparent); }
#psac-root .psac-act.psac-primary:hover { background: color-mix(in srgb, var(--psac-primary) 88%, #000); color: var(--psac-on-primary); }
#psac-root .psac-act.psac-quiet { border-color: var(--psac-border); color: var(--psac-agent-text); font-weight: 500; }
#psac-root .psac-act.psac-quiet:hover { background: var(--psac-bg); color: var(--psac-agent-text); }

/* sugestões rápidas */
#psac-root .psac-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 14px 10px; }
#psac-root .psac-chip {
  min-height: 40px; padding: 8px 14px; border: 1.5px solid var(--psac-border); border-radius: 999px;
  background: var(--psac-agent-bg); color: var(--psac-agent-text); font-size: 14px; font-weight: 500; text-align: left;
  transition: border-color .15s ease, color .15s ease;
}
#psac-root .psac-chip:hover { border-color: var(--psac-primary); color: var(--psac-primary); background: var(--psac-agent-bg); }

/* digitando */
#psac-root .psac-typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
#psac-root .psac-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--psac-primary); opacity: .35; animation: psac-dot 1.1s infinite ease-in-out; }
#psac-root .psac-typing i:nth-child(2) { animation-delay: .15s; }
#psac-root .psac-typing i:nth-child(3) { animation-delay: .3s; }

/* formulário de e-mail dentro do chat */
#psac-root .psac-mailform { display: flex; flex-direction: column; gap: 10px; white-space: normal; }
#psac-root .psac-mailform label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; font-weight: 600; color: var(--psac-agent-text); }
#psac-root .psac-mailform input, #psac-root .psac-mailform textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1.5px solid var(--psac-border); border-radius: 10px;
  background: #fff; color: #111827; font-weight: 400; box-shadow: none;
}
#psac-root .psac-mailform textarea { min-height: 96px; resize: vertical; }
#psac-root .psac-mailform input:focus, #psac-root .psac-mailform textarea:focus { border-color: var(--psac-primary); }
#psac-root .psac-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }
#psac-root .psac-formerr { color: #B42318; font-size: 13.5px; font-weight: 600; margin: 0; }
#psac-root .psac-formrow { display: flex; gap: 8px; }
#psac-root .psac-formrow .psac-act { justify-content: center; }
#psac-root .psac-formrow .psac-act:first-child { flex: 1; }

/* campo de digitar */
#psac-root .psac-form { display: flex; gap: 8px; padding: 10px 12px 6px; background: var(--psac-agent-bg); border-top: 1px solid var(--psac-border); flex: none; margin: 0; }
#psac-root .psac-input {
  flex: 1; min-width: 0; min-height: 48px; padding: 10px 16px; border: 1.5px solid var(--psac-border); border-radius: 999px;
  background: var(--psac-bg); color: var(--psac-agent-text); box-shadow: none;
}
#psac-root .psac-input::placeholder { color: #6B7280; opacity: 1; }
#psac-root .psac-input:focus { border-color: var(--psac-primary); background: #fff; }
#psac-root .psac-send {
  width: 48px; height: 48px; border: 0; border-radius: 50%; padding: 0; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--psac-primary); color: var(--psac-on-primary); transition: transform .1s ease, opacity .15s ease;
}
#psac-root .psac-send:hover { background: color-mix(in srgb, var(--psac-primary) 88%, #000); color: var(--psac-on-primary); }
#psac-root .psac-send:disabled { opacity: .5; cursor: not-allowed; }
#psac-root .psac-note { margin: 0; padding: 4px 14px 10px; font-size: 12px; line-height: 1.35; color: #5B6475; text-align: center; background: var(--psac-agent-bg); flex: none; }

#psac-root .psac-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes psac-pulse {
  0% { box-shadow: 0 10px 28px rgba(16, 24, 40, .28), 0 0 0 4px #fff, 0 0 0 4px color-mix(in srgb, var(--psac-primary) 40%, transparent); }
  70%, 100% { box-shadow: 0 10px 28px rgba(16, 24, 40, .28), 0 0 0 4px #fff, 0 0 0 24px color-mix(in srgb, var(--psac-primary) 0%, transparent); }
}
@keyframes psac-online { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); } 70%, 100% { box-shadow: 0 0 0 9px rgba(34, 197, 94, 0); } }
@keyframes psac-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes psac-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: 1; } }

/* celular: tela cheia */
@media (max-width: 520px) {
  #psac-root.psac-is-open { bottom: 0; right: 0; left: 0; top: 0; }
  /* chat aberto fica por cima de tudo (ex.: bolinha de cookies) */
  #psac-root.psac-is-open { z-index: 2147483647; }
  /* camada superior do navegador (Popover API): zera o estilo padrão do popover */
  #psac-root[popover] { margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; width: auto; height: auto; max-width: none; max-height: none; inset: 0; color: var(--psac-agent-text); }
  /* bolinha/controlador da AdOpt (e variações) some enquanto o chat está aberto no celular */
  body.psac-chat-open > [id*="adopt" i], body.psac-chat-open > [class*="adopt" i],
  body.psac-chat-open > [id*="goadopt" i], body.psac-chat-open > [class*="goadopt" i],
  html.psac-chat-open > [id*="adopt" i], html.psac-chat-open > [class*="adopt" i] { display: none !important; }
  body.psac-chat-open .cky-btn-revisit-wrapper,
  body.psac-chat-open #cmplz-manage-consent, body.psac-chat-open .cmplz-manage-consent,
  body.psac-chat-open #cookie-law-info-again, body.psac-chat-open #CookiebotWidget,
  body.psac-chat-open #termly-code-snippet-support, body.psac-chat-open #moove_gdpr_save_popup_settings_button { display: none !important; }
  #psac-root .psac-panel {
    position: fixed; inset: 0; width: 100%; max-width: none; height: 100vh; height: 100dvh; border-radius: 0; border: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }
  #psac-root .psac-form { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
}

/* pré-visualização no painel do WordPress */
#psac-root.psac-preview { position: static; font-size: 16px; }
#psac-root.psac-preview .psac-panel { position: relative; width: 100%; max-width: 380px; height: auto; max-height: none; margin: 0 auto; opacity: 1; visibility: visible; transform: none; }
#psac-root.psac-preview .psac-log { overflow: visible; }
#psac-root.psac-preview .psac-row-msg { animation: none; }

@media (prefers-reduced-motion: reduce) {
  #psac-root *, #psac-root *::before, #psac-root *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
