/* chat-widget.css — balão de chat da loja (layout C: WhatsApp escuro, escolha do dono em 27/10/2026).
   Prefixo cw-, tudo sob #cw (o id vence os estilos globais da loja: a, p, strong, :focus-visible...).
   O launcher nasce no template (partes/chat_widget.html); o painel é montado por chat-widget.js na primeira abertura.
   Protótipo de referência: docs/prototipos/chat/c.html. Sem o logo do WhatsApp, de propósito. */

#cw {
  --cw-hdr: #202c33;      /* cabeçalho, rodapé e bolha recebida */
  --cw-bg: #0b141a;       /* fundo da conversa */
  --cw-in: #202c33;
  --cw-out: #005c4b;      /* bolha enviada */
  --cw-tx: #e9edef;
  --cw-tx2: #8696a0;
  --cw-ic: #aebac1;
  --cw-lida: #53bdeb;     /* ✓✓ lida */
  --cw-tick: #a3b4ba;     /* ✓ e relógio sobre a bolha verde (>= 3:1) */
  --cw-meta-out: #b8cec9; /* hora sobre a bolha verde (AA) */
  --cw-send: #00a884;
  --cw-on-send: #111b21;
  --cw-pill: #182229;
  --cw-field: #2a3942;
  --cw-ph: #a0aeb5;       /* placeholder sobre o campo (AA) */
  --cw-amber: #ffd279;
  --cw-online: #25d366;
  --cw-erro: #ff9b9b;
  --cw-r: 7.5px;
  --cw-sombra: 0 1px .5px rgba(11, 20, 26, .13);
  --cw-sat: 0px;
  --cw-sab: 0px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 14.2px;
  line-height: 19px;
  color: var(--cw-tx);
  -webkit-text-size-adjust: 100%;
}
#cw p, #cw h2 { margin: 0; }
#cw button { -webkit-tap-highlight-color: transparent; }

/* fim da página: o botão fixo não cobre o rodapé */
.cw-espaco { height: 88px; }

/* ---------- launcher (é um <a> no template: sem JS leva para Contato ou Mensagens) ---------- */
#cw .cw-launcher {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 70;
  width: 60px; height: 60px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center;
  color: #fff; text-decoration: none; cursor: pointer;
  background: linear-gradient(135deg, #3b6cff 0%, #d63bff 100%);
  box-shadow: 0 10px 28px rgba(59, 108, 255, .36), 0 2px 8px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .18);
  transition: transform .2s var(--ease), opacity .18s;
  -webkit-tap-highlight-color: transparent;
}
#cw .cw-launcher:hover, #cw .cw-launcher:focus { color: #fff; }
#cw .cw-launcher:hover { transform: scale(1.06); }
#cw .cw-launcher:focus-visible { outline: 2px solid var(--foco); outline-offset: 3px; border-radius: 50%; }
#cw .cw-launcher svg { grid-area: 1 / 1; transition: opacity .15s, transform .22s var(--ease); }
#cw .cw-launcher .cw-ic-chev { opacity: 0; transform: rotate(45deg) scale(.6); }
#cw .cw-launcher.cw-aberto .cw-ic-bal { opacity: 0; transform: rotate(-45deg) scale(.6); }
#cw .cw-launcher.cw-aberto .cw-ic-chev { opacity: 1; transform: none; }
#cw .cw-badge {
  position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 5px; border: 2px solid #07080a; border-radius: 11px;
  background: #25d366; color: #0b141a; font-size: 12px; line-height: 18px; font-weight: 700; text-align: center;
}
#cw .cw-launcher.cw-aberto .cw-badge { display: none; }
/* tem botão ou campo da página embaixo: o launcher sai de cena (volta com o Tab, para quem navega pelo teclado) */
#cw.cw-sob .cw-launcher { opacity: 0; pointer-events: none; }
#cw.cw-sob .cw-launcher:focus-visible { opacity: 1; pointer-events: auto; }

/* ---------- painel ---------- */
#cw .cw-painel {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: 92px; z-index: 70; width: 380px; height: 620px;
  max-height: calc(100vh - 108px); max-height: calc(100dvh - 108px);
  display: flex; flex-direction: column; overflow: hidden; border-radius: 14px; background: var(--cw-bg);
  box-shadow: 0 28px 70px rgba(0, 0, 0, .62), 0 6px 18px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .07);
  transform-origin: 100% 100%; animation: cw-abre .2s var(--ease);
}
#cw .cw-painel[hidden] { display: none; }
@keyframes cw-abre { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

/* cabeçalho */
#cw .cw-hdr { flex: none; display: flex; align-items: center; gap: 10px; min-height: 60px; padding: calc(10px + var(--cw-sat)) 6px 10px 12px; background: var(--cw-hdr); }
#cw .cw-av { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #0b141a; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
#cw .cw-av img { display: block; width: auto; max-width: none; height: 22px; }
#cw .cw-id { flex: 1; min-width: 0; }
#cw .cw-id h2 { font-size: 16px; line-height: 21px; font-weight: 500; letter-spacing: 0; color: var(--cw-tx); }
#cw .cw-st { display: flex; align-items: flex-start; gap: 6px; min-width: 0; font-size: 12.5px; line-height: 17px; color: var(--cw-tx2); }
#cw .cw-dot { flex: none; width: 8px; height: 8px; margin-top: 4.5px; border-radius: 50%; background: var(--cw-tx2); }
#cw .cw-on .cw-dot { background: var(--cw-online); box-shadow: 0 0 0 3px rgba(37, 211, 102, .18); }
#cw .cw-st-t { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cw .cw-ic { flex: none; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; color: var(--cw-ic); }
#cw button.cw-ic { cursor: pointer; }
#cw button.cw-ic:hover { background: rgba(255, 255, 255, .07); }
#cw .cw-mais { pointer-events: none; }
#cw .cw-x .cw-i-volta { display: none; }

/* aviso de respostas novas nos pedidos (só logado) */
#cw .cw-peds { flex: none; display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-bottom: 1px solid rgba(134, 150, 160, .18); background: var(--cw-pill); color: var(--cw-tx); font-size: 12.5px; line-height: 17px; text-decoration: none; }
#cw .cw-peds:hover { color: var(--cw-tx); background: #1d2b33; }
#cw .cw-peds:focus-visible { outline-offset: -3px; border-radius: 0; }
#cw .cw-peds strong { color: var(--cw-send); font-weight: 600; }
#cw .cw-peds svg { flex: none; margin-left: auto; color: var(--cw-tx2); }

/* conversa */
#cw .cw-lista {
  flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 10px 14px 12px;
  background-color: var(--cw-bg); background-image: var(--cw-doodle); background-size: 252px 252px;
  scrollbar-width: thin; scrollbar-color: rgba(134, 150, 160, .35) transparent;
}
#cw .cw-lista:focus-visible { outline-offset: -3px; border-radius: 0; }
#cw .cw-lista.cw-foco-js:focus-visible { outline: none; }

#cw .cw-dia { display: flex; justify-content: center; margin: 8px 0 6px; }
#cw .cw-dia span { padding: 5px 12px 4px; border-radius: var(--cw-r); background: var(--cw-pill); color: var(--cw-tx2); font-size: 12.5px; line-height: 21px; text-transform: uppercase; box-shadow: var(--cw-sombra); }
#cw .cw-sis { display: block; max-width: 92%; margin: 8px auto 6px; padding: 6px 12px 7px; border-radius: var(--cw-r); background: var(--cw-pill); color: var(--cw-amber); font-size: 12.5px; line-height: 17px; text-align: center; box-shadow: var(--cw-sombra); }
#cw .cw-sis svg { display: inline-block; width: 12px; height: 12px; margin: 0 4px 0 0; vertical-align: -1.5px; }

#cw .cw-msg { display: flex; margin-top: 2px; }
#cw .cw-msg.cw-cauda { margin-top: 10px; }
#cw .cw-in { justify-content: flex-start; }
#cw .cw-out { justify-content: flex-end; }
#cw .cw-col { min-width: 0; max-width: 84%; }
#cw .cw-form { width: min(310px, 86%); }

#cw .cw-bal { position: relative; padding: 6px 7px 8px 9px; border-radius: var(--cw-r); background: var(--cw-in); box-shadow: var(--cw-sombra); overflow-wrap: anywhere; }
#cw .cw-bal::after { content: ""; display: table; clear: both; }
#cw .cw-out .cw-bal { background: var(--cw-out); }
#cw .cw-p { font-size: 1em; line-height: 19px; }
#cw .cw-p + .cw-p { margin-top: 6px; }
#cw .cw-link, #cw .cw-link:hover { color: var(--cw-lida); text-decoration: none; }
#cw .cw-link:hover { text-decoration: underline; }

/* rabinho: só na primeira bolha de cada grupo */
#cw .cw-cauda .cw-bal::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: no-repeat center / 100% 100%; }
#cw .cw-in.cw-cauda .cw-bal { border-top-left-radius: 0; }
#cw .cw-in.cw-cauda .cw-bal::before { left: -8px; background-image: var(--cw-cauda-in); }
#cw .cw-out.cw-cauda .cw-bal { border-top-right-radius: 0; }
#cw .cw-out.cw-cauda .cw-bal::before { right: -8px; background-image: var(--cw-cauda-out); }

/* hora e ✓/✓✓ dentro da bolha, canto inferior direito */
#cw .cw-meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 7px 0 -5px 10px; font-size: 11px; line-height: 15px; color: var(--cw-tx2); white-space: nowrap; user-select: none; }
#cw .cw-out .cw-meta { color: var(--cw-meta-out); }
#cw .cw-tk { flex: none; display: block; color: var(--cw-tick); }
#cw .cw-tk.cw-lida { color: var(--cw-lida); }
#cw .cw-tk.cw-tkerr { color: var(--cw-amber); }

/* mensagem que não saiu: o aviso fica fora da bolha, sobre o fundo escuro (contraste) */
#cw .cw-falha { margin-top: 3px; font-size: 12px; line-height: 16px; text-align: right; color: var(--cw-erro); }
#cw .cw-falha button { min-height: 28px; margin-left: 2px; padding: 2px 6px; border: 0; border-radius: 4px; background: transparent; color: var(--cw-amber); font-size: 1em; text-decoration: underline; cursor: pointer; }
#cw .cw-falha button:hover { background: rgba(255, 255, 255, .06); }

/* botões de resposta rápida (estilo mensagem interativa do WhatsApp Business) */
#cw .cw-qrs { margin-top: 2px; overflow: hidden; border-radius: var(--cw-r); background: var(--cw-in); box-shadow: var(--cw-sombra); }
#cw .cw-qr { display: flex; align-items: center; justify-content: center; gap: 7px; width: 100%; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 0; background: transparent; color: var(--cw-send); font-size: 1em; font-weight: 500; line-height: 19px; text-align: center; text-decoration: none; cursor: pointer; }
#cw .cw-qr + .cw-qr { border-top: 1px solid rgba(134, 150, 160, .2); }
#cw .cw-qr:hover { color: var(--cw-send); background: rgba(255, 255, 255, .045); }
#cw .cw-qr:focus-visible { outline-offset: -3px; border-radius: 0; }
#cw .cw-qr svg { flex: none; }

/* mini formulário dentro da bolha da loja */
#cw .cw-f label { display: block; margin: 9px 0 3px; font-size: 12px; line-height: 16px; color: var(--cw-tx2); }
#cw .cw-f input[type="text"], #cw .cw-f input[type="email"] { display: block; width: 100%; height: 42px; padding: 0 12px; border: 1px solid transparent; border-radius: 8px; background: var(--cw-field); color: var(--cw-tx); font-size: 1em; }
#cw .cw-f input::placeholder { color: var(--cw-ph); opacity: 1; }
#cw .cw-f input:focus-visible { outline: 2px solid var(--foco); outline-offset: 1px; border-radius: 8px; }
#cw .cw-f input[aria-invalid="true"] { border-color: #ff8f8f; }
#cw .cw-err { margin-top: 7px; font-size: 12.5px; line-height: 17px; color: var(--cw-erro); }
#cw .cw-err[hidden] { display: none; }
#cw .cw-btn { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin-top: 10px; padding: 0 16px; border: 0; border-radius: 22px; background: var(--cw-send); color: var(--cw-on-send); font-size: 1em; font-weight: 600; cursor: pointer; }
#cw .cw-btn:hover { filter: brightness(1.08); }
#cw .cw-btn:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; border-radius: 22px; }
#cw .cw-btn:disabled { opacity: .7; cursor: default; filter: none; }
#cw .cw-fmeta { display: flex; justify-content: flex-end; margin-top: 3px; font-size: 11px; line-height: 15px; color: var(--cw-tx2); }
/* campo-isca anti-robô: fora da tela (nunca display:none, que robô sabe pular), sem foco, sem leitor de tela */
#cw .cw-isca { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* compositor */
#cw .cw-comp { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--cw-sab)); background: var(--cw-hdr); }
#cw .cw-campo { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 8px; padding: 0 14px 0 10px; border-radius: 22px; background: var(--cw-field); }
#cw .cw-campo:focus-within { outline: 2px solid var(--foco); outline-offset: 1px; }
#cw .cw-emo { flex: none; width: 24px; height: 24px; margin-bottom: 9px; color: var(--cw-ic); }
#cw .cw-campo textarea { flex: 1; min-width: 0; height: 42px; max-height: 120px; margin: 0; padding: 11px 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--cw-tx); caret-color: var(--cw-send); font-size: 15px; line-height: 20px; }
#cw .cw-campo textarea::placeholder { color: var(--cw-ph); opacity: 1; }
#cw .cw-env { flex: none; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--cw-send); color: var(--cw-on-send); cursor: pointer; }
#cw .cw-env:hover { filter: brightness(1.08); }
#cw .cw-env:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; border-radius: 50%; }
#cw .cw-env svg { margin-left: 2px; }

/* ---------- celular: tela cheia ---------- */
@media (max-width: 480px) {
  #cw { font-size: 15px; line-height: 20px; }
  html.cw-trava, html.cw-trava body { overflow: hidden; }
  #cw .cw-launcher.cw-aberto { display: none; }
  #cw .cw-painel {
    --cw-sat: env(safe-area-inset-top, 0px); --cw-sab: env(safe-area-inset-bottom, 0px);
    left: 0; right: 0; bottom: auto; top: var(--cw-vt, 0px); width: auto; max-height: none; border-radius: 0; box-shadow: none; transform-origin: 50% 100%;
    height: 100vh; height: var(--cw-vh, 100dvh);
  }
  #cw .cw-hdr { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  #cw .cw-ic { width: 44px; height: 44px; }
  #cw .cw-x { order: -1; }
  #cw .cw-x .cw-i-x { display: none; }
  #cw .cw-x .cw-i-volta { display: block; }
  #cw .cw-st-t { white-space: normal; overflow: visible; text-overflow: clip; }
  #cw .cw-peds { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  #cw .cw-lista { padding: 8px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
  #cw .cw-comp { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  #cw .cw-campo { min-height: 44px; }
  #cw .cw-campo textarea { height: 44px; padding: 12px 0; font-size: 16px; }
  #cw .cw-emo { margin-bottom: 10px; }
  #cw .cw-env { width: 44px; height: 44px; }
  #cw .cw-f input[type="text"], #cw .cw-f input[type="email"] { height: 44px; font-size: 16px; }
}

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

@media print {
  #cw, .cw-espaco { display: none; }
}
