/* Chat da epode: botão flutuante e painel lateral no papel da marca; no celular, folha de tela cheia que
   acompanha o teclado (docs/CHAT.md 7). */

.chat-launcher {
  position: fixed;
  right: 22px;
  /* --chat-lift (chat.js) só sobe o botão enquanto a faixa verde do início passa por trás dele. */
  bottom: calc(22px + var(--chat-lift, 0px));
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 0 20px 0 16px;
  border: 1px solid var(--forest);
  border-radius: 999px;
  background: var(--forest);
  color: var(--paper);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 12px 26px #183e3540;
  cursor: pointer;
  transition: background .2s, transform .2s, bottom .18s ease-out;
}
.chat-launcher:hover { background: var(--wine); border-color: var(--wine); transform: translateY(-2px); }
.chat-launcher:focus-visible { outline: 2px solid var(--wine); outline-offset: 4px; }
.chat-launcher svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.chat-launcher svg circle { fill: currentColor; stroke: none; }
.chat-launcher[hidden] { display: none; }
html.chat-open .chat-launcher,
html.menu-open .chat-launcher { visibility: hidden; }

:root { --chat-width: 420px; }

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  width: min(var(--chat-width), 100vw);
  border-left: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  box-shadow: -24px 0 48px #183e3524;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .28s;
}
.chat-panel.is-open { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
.chat-panel .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Mesma altura do cabeçalho do site (--header-height mais a borda de 1px), para as duas faixas se alinharem. */
.chat-head { box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: calc(var(--header-height, 94px) + 1px); padding: 0 20px; background: var(--forest); color: var(--paper); }
.chat-kicker { display: block; color: #e3c486; font-size: .62rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.chat-kicker .brand-term { text-transform: none; letter-spacing: .02em; }
.chat-head h2 { display: flex; align-items: center; gap: 10px; margin: 4px 0 0; font-size: 1.9rem; line-height: 1; color: var(--paper); }
.chat-scope { padding-left: 10px; border-left: 1px solid #f5efdf40; color: #e3c486; font-family: var(--body); font-size: .7rem; font-weight: 400; letter-spacing: .02em; white-space: nowrap; }
.chat-head__actions { display: flex; gap: 6px; }
.chat-icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid #f5efdf40; border-radius: 50%; background: transparent; color: var(--paper); cursor: pointer; transition: background .2s, border-color .2s; }
.chat-icon-button:hover { border-color: #e3c486; background: #f5efdf14; }
.chat-icon-button:focus-visible { outline: 2px solid #e3c486; outline-offset: 2px; }
.chat-icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

.chat-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px 8px; scroll-behavior: smooth; }
/* A conversa rola com a roda do mouse, o toque e o teclado, mas sem barra: a barra roubaria largura do
   painel e mudaria a quebra das linhas quando aparece. */
.chat-body { scrollbar-width: none; }
.chat-body::-webkit-scrollbar { display: none; }
.chat-intro { display: grid; grid-template-columns: 54px 1fr; gap: 4px 14px; align-content: center; align-items: center; padding-bottom: 16px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.chat-intro img { box-sizing: border-box; width: 54px; height: 54px; padding: 9px 7px; border-radius: 50%; background: var(--forest); object-fit: contain; }
.chat-intro p { margin: 0; font-size: .86rem; line-height: 1.6; color: #4f5a4d; }
.chat-panel.has-messages .chat-intro { display: none; }

.chat-log { display: flex; flex-direction: column; gap: 14px; margin: 0; padding: 0; list-style: none; }
.chat-msg { max-width: 100%; font-size: .9rem; line-height: 1.65; overflow-wrap: anywhere; }
.chat-msg--user { align-self: flex-end; max-width: 86%; padding: 10px 14px; border-radius: 14px 14px 4px 14px; background: var(--forest); color: var(--paper); white-space: pre-wrap; }
.chat-msg--assistant { align-self: stretch; padding: 2px 0; color: var(--ink); }
.chat-msg--assistant p { margin: 0 0 10px; line-height: 1.7; }
.chat-msg--assistant p:last-child { margin-bottom: 0; }
.chat-msg--assistant ul, .chat-msg--assistant ol { margin: 6px 0 10px; padding-left: 20px; }
.chat-msg--assistant li::marker { color: var(--wine); }
.chat-msg--assistant code { padding: 1px 5px; border-radius: 4px; background: var(--paper-deep); font-size: .84em; }
.chat-msg__note { display: block; margin-top: 6px; color: var(--muted); font-size: .74rem; font-style: italic; }
.chat-msg--error { padding: 10px 12px; border: 1px solid #69373b40; border-radius: 8px; background: #69373b0d; color: var(--wine); font-size: .85rem; }
.chat-retry { margin-top: 8px; padding: 7px 12px; border: 1px solid var(--wine); border-radius: 4px; background: transparent; color: var(--wine); font-size: .76rem; font-weight: 700; cursor: pointer; }
.chat-retry:hover { background: var(--wine); color: var(--paper); }

/* Esperando: um ponto que respira; escrevendo: um cursor que pisca no fim do texto. */
.chat-msg.is-pending::after { content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #1460ff; animation: chat-breathe 1.2s ease-in-out infinite; }
.chat-msg.is-streaming > :last-child::after { content: ''; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--wine); animation: chat-caret 1s steps(2) infinite; }
@keyframes chat-breathe { 50% { transform: scale(.55); opacity: .5; } }
@keyframes chat-caret { 50% { opacity: 0; } }

.chat-sources { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; font-size: .78rem; }
.chat-sources summary { cursor: pointer; color: var(--muted); font-weight: 700; letter-spacing: .02em; }
.chat-sources summary:hover { color: var(--wine); }
.chat-sources ul { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.chat-sources a { color: var(--forest); font-weight: 600; border-bottom: 1px solid #79917d; }
.chat-sources a:hover { color: var(--wine); border-color: var(--wine); }
.chat-sources span { color: var(--muted); }

.chat-jump { align-self: center; margin: -6px auto 6px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--forest); font-size: .74rem; font-weight: 700; box-shadow: 0 6px 14px #183e3520; cursor: pointer; }
.chat-jump[hidden] { display: none; }

.chat-suggestions { display: flex; flex-wrap: nowrap; flex-shrink: 0; gap: 6px; padding: 4px 20px 2px; overflow-x: auto; }
.chat-suggestions[hidden] { display: none; }
.chat-suggestions button { flex: 0 0 auto; padding: 8px 9px; border: 1px solid var(--line); border-radius: 999px; background: #fbf7ec; color: var(--forest); font-size: .76rem; font-weight: 700; white-space: nowrap; cursor: pointer; transition: border-color .2s, color .2s; }
.chat-suggestions button:hover { border-color: var(--wine); color: var(--wine); }

.chat-status { min-height: 1.2em; margin: 0; padding: 0 20px; color: var(--muted); font-size: .72rem; }
/* Sem mensagem de status, a linha some e as sugestões ficam junto da caixa de texto. */
.chat-status:empty { min-height: 0; }

.chat-composer { display: grid; grid-template-columns: 1fr 46px; gap: 8px; align-items: end; padding: 8px 20px 10px; }
.chat-composer textarea { box-sizing: border-box; width: 100%; min-height: 46px; max-height: 160px; padding: 12px 14px; border: 1px solid #b9b19b; border-radius: 10px; background: #fffdf7; color: var(--ink); font: inherit; font-size: .9rem; line-height: 1.45; resize: none; }
.chat-composer textarea:focus { outline: 2px solid var(--forest); outline-offset: 1px; border-color: var(--forest); }
.chat-send, .chat-stop { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 0; border-radius: 10px; background: var(--forest); color: var(--paper); cursor: pointer; transition: background .2s; }
.chat-send:hover, .chat-stop:hover { background: var(--wine); }
.chat-send:disabled { background: #a9b0a2; cursor: default; }
.chat-send:focus-visible, .chat-stop:focus-visible { outline: 2px solid var(--wine); outline-offset: 2px; }
.chat-send svg, .chat-stop svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-stop svg rect { fill: currentColor; stroke: none; }
.chat-stop[hidden], .chat-send[hidden] { display: none; }

.chat-disclaimer { margin: 0; padding: 0 20px 14px; color: var(--muted); font-size: .68rem; line-height: 1.5; }
.chat-disclaimer a { color: var(--forest); font-weight: 700; border-bottom: 1px solid #79917d; }

/* Telas largas: o painel empurra a página para a esquerda em vez de cobri-la (como na Batalha de Mitos).
   Abaixo de 1280px a página que sobraria ficaria estreita demais para o menu do desktop, então lá o painel
   continua por cima. */
@media (min-width: 1280px) {
  body { transition: padding-right .28s cubic-bezier(.2, .8, .2, 1); }
  html.chat-open body { padding-right: var(--chat-width); }
  html.chat-open :is(.portal-section-pager, .portal-section-arrow-hint) { left: calc(50% - var(--chat-width) / 2); }
  html.chat-open .header-tagline { display: none; }
  .chat-panel { box-shadow: none; }
}
@media (min-width: 1280px) and (prefers-reduced-motion: reduce) {
  body { transition: none; }
}

/* Celular: folha de tela cheia que encolhe com o teclado (visualViewport, em chat.js). */
@media (max-width: 760px) {
  .chat-launcher { right: 16px; bottom: 16px; width: 54px; height: 54px; min-height: 0; padding: 0; justify-content: center; }
  .chat-launcher span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .chat-panel { top: var(--chat-top, 0px); bottom: auto; width: 100vw; height: var(--chat-height, 100dvh); border-left: 0; box-shadow: none; }
  .chat-head { padding: 0 16px; }
  .chat-head h2 { font-size: 1.6rem; }
  .chat-body { padding: 14px 16px 6px; }
  .chat-suggestions, .chat-status, .chat-disclaimer { padding-inline: 16px; }
  .chat-composer { padding: 6px 16px 8px; }
  .chat-composer textarea { font-size: 16px; } /* abaixo de 16px o iOS amplia a página ao focar */
  html.chat-open { overflow: hidden; } /* só o html: veja navigation.css */
}
@media (max-width: 760px) and (max-height: 560px) {
  .chat-intro, .chat-suggestions, .chat-disclaimer { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-panel, .chat-panel.is-open, .chat-launcher { transition: none; }
  .chat-body { scroll-behavior: auto; }
  .chat-msg.is-pending::after, .chat-msg.is-streaming > :last-child::after { animation: none; }
}
