/* Theo — mascote de atendimento do workspace (public/assets/js/workspace/mascote-theo*.js).
   O painel de conversa reaproveita loop-atendimento-chat.css (.loop-chat-*); aqui fica o personagem e o balao. */
.theo {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 850;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.theo > *, .theo-palco > * { pointer-events: auto; }
.theo-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------ palco: balao + personagem */
.theo-palco {
  display: flex; align-items: flex-end; gap: 6px; pointer-events: none;
  /* Desvio: quando cobre um botao, o Theo desliza para um lugar livre (--theo-dx/--theo-dy,
     definidos em mascote-theo.js) e volta para o canto quando deixa de atrapalhar. */
  transform: translate(var(--theo-dx, 0px), var(--theo-dy, 0px));
  transition: transform .55s cubic-bezier(.34, 1.4, .64, 1);
}
.theo.is-desviando .theo-figura { animation: theo-desviar .6s ease; }

.theo-personagem {
  position: relative; width: 108px; height: 117px; padding: 0; border: 0; background: none; cursor: pointer;
  opacity: 0; transform: translateY(40px) scale(.6);
  transition: opacity .35s ease, transform .55s cubic-bezier(.34, 1.56, .64, 1);
  -webkit-tap-highlight-color: transparent;
}
.theo.is-presente .theo-personagem { opacity: 1; transform: none; }
.theo-personagem:focus-visible { outline: 3px solid var(--loop-accent, #ffbe00); outline-offset: 2px; border-radius: 24px; }
.theo-corpo-container { display: block; width: 100%; height: 100%; }
.theo-figura { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 8px 14px rgba(111, 53, 165, .22)); }

/* Flutua (sobe/desce com leve squash & stretch, como um balao fofinho); a sombra acompanha. */
.theo-figura .theo-corpo-grupo { transform-box: view-box; transform-origin: 60px 112px; animation: theo-respirar 3.4s ease-in-out infinite; }
/* Pontinhos de "digitando" na barriga do balao: aparecem quando ele pensa ou fala. */
.theo-figura .theo-digitando { opacity: 0; transition: opacity .2s ease; }
.theo-figura .theo-digitando circle { transform-box: fill-box; transform-origin: center; animation: theo-ponto 1.1s ease-in-out infinite; }
.theo-figura .theo-digitando circle:nth-child(2) { animation-delay: .15s; }
.theo-figura .theo-digitando circle:nth-child(3) { animation-delay: .3s; }
.emo-pensando .theo-digitando, .is-falando .theo-digitando { opacity: 1; }
/* As ondas do cabelo balancam de leve, como cabelo ondulado mexendo. */
.theo-figura .theo-cabelo-ondas { animation: theo-ondular 2.4s ease-in-out infinite; }
.theo-figura .theo-sombra { transform-box: fill-box; transform-origin: center; animation: theo-sombra 3.4s ease-in-out infinite; }
.theo-figura .theo-olho { transform-box: fill-box; transform-origin: center; transition: transform 90ms ease-in; }
.theo-figura .theo-sobrancelha { transform-box: fill-box; transform-origin: center; transition: transform .25s ease; }
.theo-figura .theo-zzz { opacity: 0; }

/* Piscar e emocoes (classes aplicadas pelo controlador em mascote-theo.personagem.js) */
.is-piscando .theo-olho, .emo-dormindo .theo-olho { transform: scaleY(.08); }
.emo-feliz .theo-sobrancelha { transform: translateY(-2.5px); }
.emo-surpreso .theo-sobrancelha { transform: translateY(-5px); }
.emo-surpreso .theo-olho { transform: scale(1.08); }
.emo-pensando .theo-sobrancelha-esquerda { transform: translateY(-4px) rotate(-8deg); }
.emo-pensando .theo-sobrancelha-direita { transform: translateY(1px) rotate(6deg); }
.emo-ouvindo .theo-sobrancelha { transform: translateY(-3px); }
.emo-ouvindo .theo-corpo-grupo { animation-duration: 2.4s; }
.emo-dormindo .theo-sobrancelha { transform: translateY(2px); }
.emo-dormindo .theo-corpo-grupo { animation-duration: 5s; }
.emo-dormindo .theo-zzz { animation: theo-zzz 2.6s ease-in-out infinite; }
/* Sem boca: ao falar, o corpo "pulsa" de leve e as sobrancelhas acompanham. */
.is-falando .theo-corpo-grupo { animation: theo-falar .32s ease-in-out infinite; }
.is-falando .theo-sobrancelha { animation: theo-sobrancelha-falar .64s ease-in-out infinite; }
.is-pulando .theo-figura { animation: theo-pular .6s cubic-bezier(.3, 1.5, .5, 1); }
.theo-personagem:hover .theo-figura { animation: theo-balancar .7s ease-in-out; }
.theo-personagem:active .theo-figura { transform: scale(.94, 1.04); }

/* "..." de pensando na cabeca, como balaozinho de pensamento */
.theo-pensando {
  position: absolute; top: 4px; right: -2px; display: flex; gap: 3px; padding: 6px 8px; border-radius: 12px;
  background: var(--surface, #fff); box-shadow: 0 6px 16px rgba(47, 23, 72, .2);
  opacity: 0; transform: scale(.4) translateY(6px); transform-origin: bottom left; transition: opacity .2s ease, transform .25s ease;
}
.theo-pensando i { width: 5px; height: 5px; border-radius: 50%; background: var(--loop-secondary, #6f35a5); animation: loop-chat-dot 1.1s infinite ease-in-out; }
.theo-pensando i:nth-child(2) { animation-delay: .15s; }
.theo-pensando i:nth-child(3) { animation-delay: .3s; }
.theo.is-pensando .theo-pensando { opacity: 1; transform: none; }

/* Balao de fala (avisos proativos), no estilo "nome em destaque + mensagem" */
.theo-balao {
  position: relative; align-self: center; width: max-content; max-width: min(270px, calc(100vw - 150px)); margin-bottom: 54px;
  padding: 12px 34px 12px 16px; border-radius: 18px 18px 6px 18px; background: var(--surface, #fff); color: var(--ink, #18131f);
  box-shadow: 0 16px 38px rgba(47, 23, 72, .2); border: 1px solid var(--line, #e4ddea);
  animation: theo-balao-entrar .3s cubic-bezier(.34, 1.56, .64, 1);
}
.theo-balao[hidden] { display: none; }
.theo-balao::after {
  content: ''; position: absolute; right: -7px; bottom: 12px; width: 14px; height: 14px; background: inherit;
  border-right: 1px solid var(--line, #e4ddea); border-bottom: 1px solid var(--line, #e4ddea); transform: rotate(-45deg); border-radius: 0 0 4px 0;
}
.theo-balao-nome { display: block; margin-bottom: 2px; font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--loop-secondary, #6f35a5); }
.theo-balao-texto { margin: 0; min-height: 1.4em; font-size: 14.5px; line-height: 1.45; font-weight: 500; color: var(--ink, #18131f); }
.theo-balao-rodape { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.theo-balao-rodape:has(.theo-balao-acoes:empty) { justify-content: flex-end; }
.theo-balao-acao {
  padding: 6px 12px; border: 0; border-radius: 999px; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 700;
  background: var(--loop-primary, #481775); color: #fff;
}
.theo-balao-acao:hover, .theo-balao-acao:focus-visible { background: var(--loop-secondary, #6f35a5); outline: none; }
.theo-balao-link { padding: 2px 0; border: 0; background: none; cursor: pointer; font: inherit; font-size: 11.5px; color: var(--muted, #706978); text-decoration: underline; }
.theo-balao-fechar {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted, #706978); font-size: 17px; line-height: 1; cursor: pointer;
}
.theo-balao-fechar:hover, .theo-balao-fechar:focus-visible { background: var(--soft, #f7f4fa); outline: none; }

/* ------------------------------------------------------------ conversa */
.theo-chat { width: min(390px, calc(100vw - 32px)); max-width: none; height: min(520px, calc(100dvh - 160px)); }
.theo.is-aberto .theo-balao { display: none; }

.theo-opcoes { display: flex; flex-wrap: wrap; gap: 6px; max-width: 92%; animation: loop-chat-in .18s ease-out; }
.theo-opcao {
  padding: 7px 12px; border: 1px solid var(--loop-secondary, #6f35a5); border-radius: 999px; background: #fff;
  color: var(--loop-primary, #481775); font: inherit; font-size: 13px; font-weight: 600; line-height: 1.3; text-align: left; cursor: pointer;
  transition: transform .12s ease;
}
.theo-opcao:hover:not(:disabled), .theo-opcao:focus-visible { background: var(--soft, #f7f4fa); outline: none; box-shadow: 0 0 0 3px rgba(111, 53, 165, .16); transform: translateY(-1px); }
.theo-opcao.is-destaque { background: var(--loop-primary, #481775); border-color: var(--loop-primary, #481775); color: #fff; }
.theo-opcao.is-destaque:hover:not(:disabled), .theo-opcao.is-destaque:focus-visible { background: var(--loop-secondary, #6f35a5); }
.theo-opcao:disabled { opacity: .45; cursor: default; }
.theo-opcao.is-escolhida { opacity: 1; background: var(--soft, #f7f4fa); color: var(--loop-primary, #481775); border-color: var(--loop-secondary, #6f35a5); }

.theo-atalho {
  display: block; margin-top: 10px; padding: 8px 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--soft, #f7f4fa); color: var(--loop-primary, #481775); font: inherit; font-size: 13px; font-weight: 700;
}
.theo-atalho::after { content: ' →'; }
.theo-atalho:hover, .theo-atalho:focus-visible { background: var(--line, #e4ddea); outline: none; }

/* ------------------------------------------------------------ animacoes */
@keyframes theo-respirar {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-7px) scale(.98, 1.03); }
  55% { transform: translateY(-7px) scale(.98, 1.03); }
}
@keyframes theo-sombra { 0%, 100% { transform: scale(1); opacity: .16; } 50% { transform: scale(.75); opacity: .08; } }
@keyframes theo-ponto { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-3px); opacity: 1; } }
@keyframes theo-ondular { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(1.2px); } 75% { transform: translateX(-1.2px); } }
@keyframes theo-falar { 0%, 100% { transform: translateY(-3px) scale(1, 1); } 50% { transform: translateY(-3px) scale(1.03, .97); } }
@keyframes theo-sobrancelha-falar { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes theo-pular {
  0% { transform: none; }
  25% { transform: translateY(4px) scale(1.08, .9); }
  55% { transform: translateY(-16px) scale(.94, 1.08); }
  80% { transform: translateY(2px) scale(1.04, .96); }
  100% { transform: none; }
}
@keyframes theo-desviar { 0%, 100% { transform: none; } 30% { transform: rotate(-11deg) scale(.94, 1.06); } 70% { transform: rotate(7deg); } }
@keyframes theo-balancar { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(5deg); } }
@keyframes theo-zzz { 0% { opacity: 0; transform: translate(0, 6px); } 30%, 70% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -8px); } }
@keyframes theo-balao-entrar { from { opacity: 0; transform: translateY(10px) scale(.9); transform-origin: bottom right; } to { opacity: 1; transform: none; } }

/* Ate 1100px: Theo menor, no canto (o antigo botao flutuante "Novo documento" saiu dali). */
@media (max-width: 1100px) {
  .theo { bottom: max(14px, env(safe-area-inset-bottom)); right: max(10px, env(safe-area-inset-right)); }
  .theo-personagem { width: 84px; height: 91px; }
  .theo-balao { margin-bottom: 34px; }
}
@media (max-width: 600px) {
  .theo-chat { width: calc(100vw - 24px); height: min(480px, calc(100dvh - 230px)); }
  .theo-balao { max-width: calc(100vw - 120px); }
}
/* Com o menu lateral aberto no mobile, o Theo sai do caminho (drawer/backdrop ficam em 1000/1001). */
.workspace.mobile-menu-open .theo { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .theo-figura .theo-corpo-grupo, .theo-figura .theo-cabelo-ondas, .theo-figura .theo-digitando circle, .theo-figura .theo-sombra, .theo-figura .theo-sobrancelha, .theo-figura,
  .theo-balao, .theo-opcoes, .emo-dormindo .theo-zzz { animation: none !important; }
  .theo-personagem { transition: opacity .2s ease; transform: none; }
  .theo-palco { transition: none; }
  .emo-dormindo .theo-zzz { opacity: 1; }
}

/* Bloco que o Theo esta explicando nas Configuracoes (apresentacao por secao). */
.theo-destaque { position: relative; outline: 3px solid var(--loop-accent, #ffbe00); outline-offset: 4px; border-radius: 18px; animation: theo-destaque-pulso 1.6s ease-in-out 3; }
@keyframes theo-destaque-pulso { 0%, 100% { outline-color: var(--loop-accent, #ffbe00); } 50% { outline-color: rgba(255, 190, 0, .25); } }
@media (prefers-reduced-motion: reduce) { .theo-destaque { animation: none; } }
