/* ============================================================
   Assistente Fábrica — a bolha de chat (static/assistente.css)

   Widget presente em toda tela que estende o base.html (e no login).

   ILHA DELIBERADA NO DESIGN (03/09/2026, pedido do dono): o resto do sistema
   segue o contrato do ui.css — raio 0, sem sombra. O chat NÃO. O dono pediu
   "mais visível e com aparência moderna", no modelo dos widgets de site
   (Leadster): bolha redonda com avatar humana, balões arredondados, sombra
   suave, painel flutuante. É a única exceção ao contrato, escopada em `.af`,
   e continua consumindo os tokens `--u-*` (teal, tinta, fonte Archivo) para
   não virar um sistema à parte. Não declara nenhum `--g-*`
   (tests/test_css_tokens.py). Prefixo `af-`, sem exceção.
   ============================================================ */

.af,
.af *,
.af *::before,
.af *::after { box-sizing: border-box; }

.af {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60; /* acima do rail (40); os <dialog> nativos ficam no top layer e cobrem tudo */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--u-font, 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
  font-size: 15px;
  line-height: 1.5;
  color: var(--u-ink, #1a1b1b);
  -webkit-font-smoothing: antialiased;
}
.af[hidden] { display: none; }

.af :focus-visible {
  outline: 3px solid var(--u-teal, #2ba193);
  outline-offset: 2px;
}
.af button, .af textarea, .af a { font: inherit; }
.af button { cursor: pointer; }
.af button[disabled] { opacity: .45; cursor: not-allowed; }

@keyframes af-subir { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes af-anel { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes af-pulso { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- lançador: rótulo + bolha com a avatar ---------- */
.af-lancador { display: flex; align-items: center; gap: 12px; }
.af-rotulo {
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--u-ink, #1a1b1b);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(20, 104, 95, .22);
  animation: af-subir .3s ease-out;
}
.af-rotulo:hover { color: var(--u-teal-texto, #0f5f57); }
.af-rotulo[hidden] { display: none; }

.af-bolha {
  position: relative;
  width: 66px;
  height: 66px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 10px 30px rgba(20, 104, 95, .38);
  transition: transform .15s ease;
}
.af-bolha:hover { transform: scale(1.06); }
.af-bolha img { width: 100%; height: 100%; display: block; border-radius: 50%; object-fit: cover; }
.af-bolha .af-online {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #22c55e;
  border: 2.5px solid #fff;
}
.af-bolha .af-fechar-x { display: none; color: #fff; font-size: 30px; line-height: 1; }
.af-bolha.af-pulso::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 3px solid var(--u-teal, #2ba193);
  animation: af-anel 1.8s ease-out 4;
  pointer-events: none;
}
.af-aberto .af-bolha { background: var(--u-teal-campo, #14685f); border-color: var(--u-teal-campo, #14685f); }
.af-aberto .af-bolha img,
.af-aberto .af-bolha .af-online { display: none; }
.af-aberto .af-bolha .af-fechar-x { display: block; }

/* ---------- provocação (balão junto da bolha) ---------- */
.af-teaser {
  position: relative;
  max-width: 300px;
  padding: 14px 42px 14px 16px;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
  cursor: pointer;
  animation: af-subir .3s ease-out;
}
.af-teaser[hidden] { display: none; }
.af-teaser b { font-weight: 700; }
.af-teaser-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--u-ink-3, #5c6360);
  font-size: 18px;
  line-height: 1;
}
.af-teaser-x:hover { background: #eef4f3; color: var(--u-ink, #1a1b1b); }

/* ---------- painel ---------- */
.af-painel {
  width: 400px;
  height: min(680px, calc(100vh - 116px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  background: #f4f8f7;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
  animation: af-subir .2s ease-out;
}
.af-painel[hidden] { display: none; }

.af-cab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 16px;
  background: linear-gradient(135deg, #1e4a44 0%, #14685f 55%, #2ba193 130%);
  color: #fff;
}
.af-cab img { width: 46px; height: 46px; flex: none; display: block; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .75); }
.af-cab-quem { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.af-cab-quem b { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.af-status { font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; opacity: .92; }
.af-led { width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: rgba(255, 255, 255, .55); }
.af-status.af-on .af-led { background: #4ade80; }
.af-status.af-off .af-led { background: #fbbf24; }
.af-cab-acoes { display: flex; gap: 2px; flex: none; }
.af-cab-acoes a,
.af-cab-acoes button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
}
.af-cab-acoes a:hover,
.af-cab-acoes button:hover { background: rgba(255, 255, 255, .18); }

/* ---------- mensagens ---------- */
.af-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.af-linha { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; }
.af-linha-bot { align-self: flex-start; }
.af-linha-user { align-self: flex-end; max-width: 86%; }
.af-mini { width: 28px; height: 28px; flex: none; border-radius: 50%; display: block; }
.af-msg { font-size: 14.5px; min-width: 0; }
.af-msg-user {
  padding: 10px 14px;
  border-radius: 18px 18px 4px 18px;
  background: linear-gradient(135deg, #14685f, #1a7d72);
  color: #fff;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.af-msg-bot {
  padding: 12px 14px;
  border-radius: 18px 18px 18px 4px;
  background: #fff;
  color: var(--u-ink, #1a1b1b);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
}
.af-msg-bot.af-erro { border-left: 4px solid var(--u-crit, #b91c1c); }
.af-texto { white-space: pre-wrap; word-wrap: break-word; }
.af-titulo { font-weight: 700; margin: 0 0 4px; }
.af-msg-bot a { color: var(--u-teal-texto, #0f5f57); }
.af-msg-bot a:hover { color: var(--u-teal-link-hover, #12756c); }

.af-aviso, .af-escalar {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--u-ink-2, #444141);
  background: #fff7ed;
  border-left: 4px solid var(--u-warn, #b45309);
}
.af-escalar { background: #fef2f2; border-left-color: var(--u-crit, #b91c1c); }

/* chips: sugestões e boas-vindas */
.af-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.af-chips-rotulo { width: 100%; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--u-ink-3, #5c6360); }
.af-chip {
  padding: 8px 14px;
  border: 1.5px solid var(--u-teal-campo, #14685f);
  border-radius: 999px;
  background: #fff;
  color: var(--u-teal-texto, #0f5f57);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  transition: background .12s ease, color .12s ease;
}
.af-chip:hover { background: var(--u-teal-campo, #14685f); color: #fff; }

/* fontes */
.af-fontes { margin-top: 8px; font-size: 13px; }
.af-fontes summary { cursor: pointer; color: var(--u-ink-3, #5c6360); font-weight: 600; }
.af-fontes summary:hover { color: var(--u-ink, #1a1b1b); }
.af-fonte { margin: 6px 0 0; padding: 6px 0 0; border-top: 1px solid #e3ecea; display: flex; gap: 8px; align-items: flex-start; }
.af-fonte-txt { flex: 1; min-width: 0; }
.af-fonte-txt small { display: block; color: var(--u-ink-3, #5c6360); }
.af-thumb { width: 64px; height: 48px; object-fit: cover; flex: none; border-radius: 8px; border: 1px solid #e3ecea; background: #fff; }
.af-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.af-imgs a { display: block; }
.af-imgs img { height: 84px; max-width: 100%; border-radius: 10px; border: 1px solid #e3ecea; background: #fff; display: block; }

/* lista de compra */
.af-lista { margin-top: 8px; font-size: 12px; }
.af-lista table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.af-lista th, .af-lista td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #e3ecea; }
.af-lista th { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--u-ink-3, #5c6360); }
.af-lista td.af-num, .af-lista th.af-num { text-align: right; }
.af-lista-pe { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; color: var(--u-ink-3, #5c6360); }
.af-btn-mini {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 14px;
  border: 1.5px solid var(--u-teal-campo, #14685f);
  border-radius: 999px;
  background: #fff;
  color: var(--u-teal-texto, #0f5f57);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
}
.af-btn-mini:hover { background: var(--u-teal-campo, #14685f); color: #fff; }
a.af-btn-mini { color: var(--u-teal-texto, #0f5f57); }
a.af-btn-mini:hover { color: #fff; }

/* feedback */
.af-fb { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; color: var(--u-ink-3, #5c6360); }
.af-fb button {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #d3dcda;
  border-radius: 999px;
  background: #fff;
  color: var(--u-ink-2, #444141);
  font-size: 12px;
}
.af-fb button:hover { border-color: var(--u-teal-campo, #14685f); color: var(--u-teal-texto, #0f5f57); }
.af-corrigir { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.af-corrigir textarea {
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  border: 1.5px solid #d3dcda;
  border-radius: 12px;
  background: #fff;
  color: var(--u-ink, #1a1b1b);
  font-size: 14px;
  resize: vertical;
}
.af-corrigir textarea:focus { outline: none; border-color: var(--u-teal-campo, #14685f); }
.af-corrigir-acoes { display: flex; gap: 6px; }

/* "digitando" */
.af-digitando { display: inline-flex; gap: 4px; padding: 4px 0; vertical-align: middle; }
.af-digitando-txt { font-size: 12.5px; color: var(--u-ink-3, #5c6360); }
.af-revisando { margin-top: 8px; font-size: 12.5px; color: var(--u-ink-3, #5c6360); animation: af-pulso 1.6s infinite; }
.af-revisao-nota { background: #eef4f3; border-left-color: var(--u-teal, #2ba193); }
.af-digitando i { width: 7px; height: 7px; border-radius: 50%; background: var(--u-ink-3, #5c6360); animation: af-pulso 1s infinite; }
.af-digitando i:nth-child(2) { animation-delay: .15s; }
.af-digitando i:nth-child(3) { animation-delay: .3s; }

/* ---------- rodapé: campo + enviar ---------- */
.af-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 12px 8px;
  background: #fff;
  border-top: 1px solid #e3ecea;
}
.af-form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 16px;
  border: 1.5px solid #d3dcda;
  border-radius: 22px;
  background: #f4f8f7;
  color: var(--u-ink, #1a1b1b);
  font-size: 16px; /* 16px evita o zoom automático do iOS ao focar */
  line-height: 1.4;
  resize: none;
}
.af-form textarea:focus { outline: none; border-color: var(--u-teal-campo, #14685f); background: #fff; }
.af-enviar {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--u-teal-campo, #14685f);
  color: #fff;
  transition: background .12s ease, transform .12s ease;
}
.af-enviar svg { width: 20px; height: 20px; display: block; }
.af-enviar:hover { background: var(--u-teal-600, #10554e); transform: scale(1.05); }
.af-enviar:active { background: var(--u-teal-700, #0c443e); transform: none; }
.af-nota { padding: 0 16px 10px; font-size: 11px; color: var(--u-ink-3, #5c6360); background: #fff; text-align: center; }

/* ---------- celular / PWA: o painel vira tela inteira ---------- */
@media (max-width: 560px) {
  .af { right: 14px; bottom: 14px; }
  .af-rotulo { display: none; }
  .af-bolha { width: 60px; height: 60px; }
  .af-teaser { max-width: calc(100vw - 100px); }
  .af-painel {
    position: fixed;
    inset: 0;
    width: auto;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .af-aberto .af-lancador,
  .af-aberto .af-teaser { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .af-bolha, .af-rotulo, .af-teaser, .af-painel, .af-chip, .af-enviar { animation: none; transition: none; }
  .af-bolha.af-pulso::before { animation: none; display: none; }
  .af-digitando i { animation: none; opacity: .6; }
}

@media print { .af { display: none !important; } }
