/* Pomelo · chat da Cléo (partials/chat.njk, js/chat.js). Só nas páginas com o chat (base.njk).
   Visual v1.2 do protótipo widget-chat (aprovado em 11/11): robô h01 e painel em vidro claro. Lançador em pílula
   de vidro, painel com o robô espiando de trás da borda de cima, chips em pílula, progresso de 1 a 5, um scroll só.
   No celular (abaixo de 480 px), folha inferior. Cores e fontes só dos tokens do site.css (paleta oficial). */

/* A base do robô h01 (gomos, olhos, folhas, estados) fica no css/paginas.css ("Robô h01"), que carrega em toda página:
   o robô também aparece no rodapé, inclusive nas páginas sem o chat. */

/* ============================================================
   Robô no widget: corpo opaco, só a sombra de contato
   ============================================================ */
.ch-ag { position: relative; display: inline-block; flex: none; }
.ch-ag .pm-agente { width: 100%; height: 100%; }

/* ============================================================
   Lançador: pílula de vidro claro
   ============================================================ */
.ch { display: none; }
.js .ch { display: block; position: fixed; right: 24px; bottom: 24px; z-index: 85; font-family: var(--f-ui); color: var(--t1); -webkit-font-smoothing: antialiased; }
.js .ch[hidden], .cs-aberto .ch { display: none; }
/* Menu do celular aberto: o lançador sai da frente (cobria os últimos links do painel). */
body:has(.gn-mob[open]) .ch { display: none; }
.ch *, .ch *::before, .ch *::after { box-sizing: border-box; }
.ch [hidden] { display: none !important; }
.ch-botao {
  display: inline-flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 20px 8px 10px;
  border-radius: 9999px; border: 1px solid rgb(255 255 255 / .7); background: rgb(247 248 243 / .55);
  -webkit-backdrop-filter: blur(22px) saturate(150%); backdrop-filter: blur(22px) saturate(150%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .9), 0 18px 40px -14px rgb(46 59 44 / .35), 0 1px 2px rgb(46 59 44 / .08);
  color: var(--casca); font: inherit; text-align: left; cursor: pointer;
  transition: transform 220ms var(--out), box-shadow 220ms var(--out), border-color 220ms ease;
}
.ch-botao:hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 rgb(255 255 255 / .9), 0 22px 44px -14px rgb(46 59 44 / .4), 0 1px 2px rgb(46 59 44 / .08); }
.ch-botao:focus-visible { outline: 2px solid var(--casca); outline-offset: 3px; }
/* as folhas passam ~9 px do quadrado de 34 px: o robô desce para caber na pílula */
.ch-botao .ch-ag { width: 34px; height: 34px; margin-top: 7px; filter: drop-shadow(0 1px 2px rgb(36 48 35 / .22)); }
.ch-botao-txt { display: grid; line-height: 1.15; }
.ch-botao-txt strong { font-weight: 600; font-size: 15px; letter-spacing: .005em; }
.ch-botao-txt small { margin-top: 2px; font-size: 12px; color: var(--t1); }
.ch-on .ch-botao { display: none; }
/* espiar: no hover o robô sobe mais 2 px e abre as folhas (ouvindo); os olhos vão para o texto (js/chat.js) */
.ch-botao:hover .pm-robo { transform: translateY(-2px); }
/* precisa: brilho Polpa contido em volta da silhueta */
.ch-botao.ch-chama .ch-ag { animation: ch-chama 2.8s ease-in-out infinite; }
@keyframes ch-chama {
  0%, 100% { filter: drop-shadow(0 1px 2px rgb(36 48 35 / .22)) drop-shadow(0 0 4px rgb(232 144 140 / .7)); }
  50%      { filter: drop-shadow(0 1px 2px rgb(36 48 35 / .22)) drop-shadow(0 0 2px rgb(232 144 140 / .3)); }
}

/* ============================================================
   Painel: vidro claro (Área a 55%, blur 28 px, borda branca a 60%) com luz difusa interna
   que segue o estado do robô (data-ag no painel, posto pelo js/chat.js)
   ============================================================ */
.ch-painel {
  --luz-a: var(--pomelo); --luz-b: var(--flor); --luz-op: .30;
  position: fixed; right: 24px; bottom: 24px; width: 380px; height: 600px;
  max-height: calc(100vh - 124px); max-height: calc(100dvh - 124px);
  display: flex; flex-direction: column; color: var(--t1);
  background: rgb(247 248 243 / .55);
  -webkit-backdrop-filter: blur(28px) saturate(150%); backdrop-filter: blur(28px) saturate(150%);
  border: 1px solid rgb(255 255 255 / .6); border-radius: 28px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .9), inset 0 0 0 1px rgb(255 255 255 / .2),
              0 40px 80px -24px rgb(46 59 44 / .35), 0 12px 32px -12px rgb(46 59 44 / .18);
  transform-origin: bottom right; animation: ch-abre 260ms var(--out) both;
}
/* sem backdrop-filter: fundo sólido claro */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ch-painel { background: rgb(247 248 243 / .97); }
  .ch-botao { background: rgb(247 248 243 / .96); }
}
.ch-painel:focus { outline: none; }
@keyframes ch-abre { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
/* reflexo diagonal no topo, por cima da luz e por baixo do conteúdo */
.ch-painel::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  background: linear-gradient(155deg, rgb(255 255 255 / .45) 0%, rgb(255 255 255 / .12) 24%, rgb(255 255 255 / 0) 44%);
}
/* a luz difusa: três manchas (gradiente radial, sem filter) que derivam devagar e trocam de cor com o estado */
.ch-luz { position: absolute; inset: 0; z-index: 0; overflow: hidden; border-radius: inherit; pointer-events: none; }
.ch-luz i {
  position: absolute; display: block; border-radius: 50%; opacity: var(--luz-op);
  background: radial-gradient(closest-side, currentColor, rgb(255 255 255 / 0));
  transition: color 800ms ease, opacity 800ms ease;
}
.ch-luz i:nth-child(1) { width: 420px; height: 380px; left: -150px; top: 2%; color: var(--luz-a); animation: ch-deriva-a 22s ease-in-out infinite alternate; }
.ch-luz i:nth-child(2) { width: 400px; height: 400px; right: -170px; top: 36%; color: var(--luz-b); animation: ch-deriva-b 26s ease-in-out infinite alternate; }
.ch-luz i:nth-child(3) { width: 340px; height: 300px; left: 20%; bottom: -140px; color: var(--luz-a); opacity: calc(var(--luz-op) * .7); animation: ch-deriva-c 30s ease-in-out infinite alternate; }
@keyframes ch-deriva-a { to { transform: translate(70px, 60px) scale(1.12); } }
@keyframes ch-deriva-b { to { transform: translate(-60px, -80px) scale(.92); } }
@keyframes ch-deriva-c { to { transform: translate(-50px, -40px) scale(1.15); } }
.ch-painel[data-ag="pensando"] { --luz-op: .48; }
.ch-painel[data-ag="ouvindo"]  { --luz-op: .38; }
.ch-painel[data-ag="feito"]    { --luz-a: var(--flor); --luz-b: #F9CFCB; --luz-op: .5; }
.ch-painel[data-ag="precisa"]  { --luz-a: var(--polpa); --luz-b: var(--polpa); --luz-op: .34; }
.ch-topo, .ch-progresso, .ch-rolo { position: relative; z-index: 2; }

/* o robô espiando: fica atrás da borda de cima, recortado por ela (janela com overflow hidden apoiada na borda;
   os entalhes de baixo ficam escondidos). Robô de 72 px: 20 px de folhas e 55 px de corpo visíveis. */
.ch-espia { position: absolute; bottom: 100%; left: 22px; z-index: 3; width: 88px; height: 76px; overflow: hidden; pointer-events: none; }
.ch-espia .ch-ag { position: absolute; left: 8px; top: 20px; width: 72px; height: 72px; filter: drop-shadow(0 6px 6px rgb(36 48 35 / .22)); }
.ch-painel:not([hidden]) .ch-espia .ch-ag { animation: ch-espia-sobe 500ms cubic-bezier(.33, 1, .68, 1) 120ms both; }
@keyframes ch-espia-sobe { from { transform: translateY(60%); } to { transform: none; } }
/* sombra curta na borda, logo abaixo do robô, para ele ler atrás do vidro */
.ch-espia-chao {
  position: absolute; left: 32px; top: 0; z-index: 3; width: 76px; height: 12px; pointer-events: none;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  background: radial-gradient(50% 100% at 50% 0, rgb(36 48 35 / .16), rgb(36 48 35 / 0));
}

.ch-topo { display: flex; align-items: flex-start; gap: 12px; min-height: 52px; padding: 14px 12px 0 20px; }
.ch-id { flex: 1; min-width: 0; }
.ch-titulo { margin: 0; font: 300 24px/1.05 var(--f-disp); letter-spacing: -.01em; color: var(--casca); outline: none; }
.ch-sub { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font-size: 12px; color: var(--t1); }
.ch-online { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #6FA06A; box-shadow: 0 0 0 3px rgb(111 160 106 / .2); }
.ch-x { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--t1); cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.ch-x:hover { background: rgb(255 255 255 / .5); color: var(--casca); }
.ch-x:focus-visible { outline: 2px solid var(--casca); outline-offset: 0; }

/* progresso de 1 a 5 */
.ch-progresso { display: flex; align-items: center; gap: 10px; padding: 14px 20px 10px; border-bottom: 1px solid rgb(46 59 44 / .10); font-size: 12px; color: var(--t1); transition: opacity 300ms ease; }
.ch-progresso.ch-sem { opacity: 0; }
.ch-pontos { display: flex; gap: 5px; }
.ch-ponto { width: 18px; height: 4px; border-radius: 4px; background: rgb(46 59 44 / .12); transition: background-color 400ms ease; }
.ch-ponto.ch-feito { background: var(--pomelo); }
.ch-ponto.ch-atual { background: var(--casca); }

/* o único scroll: conversa e controles (sem rodapé: o último elemento é "Tenho uma dúvida" ou "Recomeçar") */
.ch-rolo {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 20px;
  border-radius: 0 0 28px 28px;
  scrollbar-width: thin; scrollbar-color: rgb(46 59 44 / .18) transparent; scroll-padding-bottom: 20px;
}
.ch-rolo::-webkit-scrollbar { width: 6px; }
.ch-rolo::-webkit-scrollbar-track { background: transparent; }
.ch-rolo::-webkit-scrollbar-thumb { background: rgb(46 59 44 / .18); border-radius: 6px; }
.ch-log { display: flex; flex-direction: column; gap: 8px; }
.ch-msg { max-width: 86%; padding: 10px 14px; border-radius: 20px; font-size: 14.5px; line-height: 1.45; overflow-wrap: anywhere; outline: none; animation: ch-entra 280ms var(--out) both; }
.ch-msg p { margin: 0; }
.ch-cleo { align-self: flex-start; background: rgb(255 255 255 / .55); border: 1px solid rgb(255 255 255 / .75); color: var(--casca); border-bottom-left-radius: 6px; box-shadow: inset 0 1px 0 rgb(255 255 255 / .06); }
.ch-voce { align-self: flex-end; margin: 6px 0; background: var(--casca); color: var(--area); border-bottom-right-radius: 6px; }
.ch-fim:focus-visible { outline: 2px solid var(--casca); outline-offset: 2px; }
@keyframes ch-entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* digitando (pensando) */
.ch-digitando { display: inline-flex; align-items: center; gap: 4px; padding: 13px 14px; }
.ch-digitando i { width: 6px; height: 6px; border-radius: 50%; background: var(--t2); opacity: .35; animation: ch-ponto 1s ease-in-out infinite; }
.ch-digitando i + i { animation-delay: 160ms; }
.ch-digitando i + i + i { animation-delay: 320ms; }
@keyframes ch-ponto { 0%, 100% { opacity: .25; transform: none; } 40% { opacity: .9; transform: translateY(-2px); } }

/* links de recurso e fonte da dúvida, dentro do balão da Cléo */
.ch-link { display: grid; gap: 2px; margin-top: 10px; padding: 10px 12px; border-radius: 14px; background: rgb(255 255 255 / .75); color: var(--casca); text-decoration: none; box-shadow: inset 0 0 0 1px rgb(46 59 44 / .10); }
.ch-link:hover { box-shadow: inset 0 0 0 1px var(--casca); }
.ch-link span { font-size: 13px; color: var(--t1); }
.ch-fonte { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--casca); text-decoration: underline; text-underline-offset: 3px; }
.ch-link:focus-visible, .ch-fonte:focus-visible { outline: 2px solid var(--casca); outline-offset: 2px; }

/* controles: chips em pílula que quebram linha e links discretos */
.ch-controles { display: grid; gap: 8px; margin-top: 8px; animation: ch-entra 320ms var(--out) both; animation-delay: 80ms; }
.ch-controles:empty { display: none; }
.ch-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ch-chip {
  min-height: 38px; padding: 9px 14px; border-radius: 9999px; border: 1px solid rgb(46 59 44 / .22); background: rgb(255 255 255 / .35);
  color: var(--casca); font: 500 14px/1.2 var(--f-ui); text-align: left; cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms var(--out);
}
.ch-chip:hover { background: rgb(255 255 255 / .6); border-color: var(--casca); box-shadow: 0 6px 16px -8px rgb(46 59 44 / .3); }
.ch-chip:active { transform: scale(.97); }
.ch-chip:focus-visible { outline: none; border-color: var(--casca); box-shadow: 0 0 0 3px rgb(195 207 82 / .55); }
.ch-linha { display: flex; flex-wrap: wrap; gap: 0 16px; }
.ch-sec {
  align-self: flex-start; justify-self: start; padding: 6px 2px; border: 0; background: none; cursor: pointer;
  font: 500 13px/1.2 var(--f-ui); color: var(--casca);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgb(46 59 44 / .45);
}
.ch-sec:hover { color: var(--casca); text-decoration-color: currentColor; }
.ch-sec:focus-visible { outline: none; border-radius: 6px; box-shadow: 0 0 0 3px rgb(195 207 82 / .55); }

/* botões finais */
.ch-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px;
  border-radius: 9999px; font: 600 15px/1.2 var(--f-ui); text-decoration: none; cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.ch-btn-p { background: var(--casca); color: var(--branco); border: 1px solid var(--casca); }
.ch-btn-p:hover { background: var(--casca-h); }
.ch-btn-p:disabled { opacity: .6; cursor: default; }
.ch-btn-s { background: rgb(255 255 255 / .4); color: var(--casca); border: 1px solid rgb(46 59 44 / .22); }
.ch-btn-s:hover { background: rgb(255 255 255 / .7); border-color: var(--casca); }
.ch-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgb(195 207 82 / .55); }

/* mini-formulário */
.ch-form-caixa { padding: 14px; border-radius: 20px; background: rgb(255 255 255 / .5); border: 1px solid rgb(255 255 255 / .8); }
.ch-form-t { margin: 0 0 10px; font-size: 14px; font-weight: 600; line-height: 1.45; color: var(--casca); }
.ch-form { display: grid; gap: 10px; }
.ch-campo { display: grid; gap: 4px; }
.ch-campo label { font-size: 13px; font-weight: 600; color: var(--casca); }
.ch-campo input:not([type="checkbox"]), .ch-campo select { height: 44px; padding: 0 14px; border: 1px solid rgb(46 59 44 / .16); border-radius: 12px; background: var(--branco); color: var(--casca); font: 400 16px/1 var(--f-ui); transition: border-color 160ms ease, box-shadow 160ms ease; }
.ch-campo input:not([type="checkbox"]):focus, .ch-campo select:focus { outline: none; border-color: var(--pomelo); box-shadow: 0 0 0 3px rgb(195 207 82 / .55); }
.ch-campo input[aria-invalid="true"], .ch-campo select[aria-invalid="true"] { border-color: var(--polpa); }
.ch-aceite { display: flex; align-items: flex-start; gap: 8px; font-weight: 400 !important; line-height: 1.4; }
.ch-aceite input { flex-shrink: 0; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--casca); }
.ch-erro { font-size: 12.5px; color: #BB3636; }
.ch-erro:empty { display: none; }
.ch-enviar { width: 100%; }
.ch-pe, .ch-falha { margin: 2px 0 0; font-size: 12.5px; color: var(--t1); }
.ch-pe a { color: var(--casca); font-weight: 600; }
.ch-falha { color: #BB3636; }
.ch-wa { display: grid; gap: 6px; margin-top: 12px; }
.ch-wa p { margin: 0; font-size: 12.5px; color: var(--t1); text-align: center; }
.ch-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============================================================
   Celular: folha inferior; o robô espia pela direita, para não cobrir o logo do site
   ============================================================ */
@media (max-width: 479px) {
  .js .ch { right: 16px; bottom: 16px; }
  .ch-painel {
    left: 0; right: 0; bottom: 0; width: auto; height: calc(100vh - 92px); height: calc(100dvh - 92px); max-height: none;
    border-radius: 28px 28px 0 0; border-bottom: 0; transform-origin: bottom center; animation-name: ch-sobe;
  }
  .ch-rolo { border-radius: 0; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .ch-espia { left: auto; right: 22px; }
  .ch-espia-chao { left: auto; right: 28px; }
  .ch-msg { max-width: 90%; }
  .ch-chip { min-height: 42px; font-size: 15px; }
  html.ch-aberto, html.ch-aberto body { overflow: hidden; }
}
@keyframes ch-sobe { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================
   Reduzir movimento: só troca de cor (o site.css já zera animação e transição em tudo)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .ch-painel, .ch-msg, .ch-controles, .ch-botao.ch-chama .ch-ag, .ch-luz i, .ch-painel:not([hidden]) .ch-espia .ch-ag { animation: none !important; }
  .ch-botao.ch-chama .ch-ag { filter: drop-shadow(0 1px 2px rgb(36 48 35 / .22)) drop-shadow(0 0 3px rgb(232 144 140 / .6)); }
  .ch-botao:hover, .ch-chip:active, .ch-botao:hover .pm-robo { transform: none; }
  .ch-digitando i { animation: none; opacity: .55; }
}
