/* VivDoc — balão de chat interno. Único elemento com cor de destaque na interface: os tokens --chat-* são
   definidos por tema (e alto contraste) para que o balão sempre se diferencie do fundo. */
:root {
  --chat-fundo: #855e00; --chat-fundo-hover: #6e4e00; --chat-icone: #ffffff;
  --chat-anel: rgba(133,94,0,.28); --chat-badge: #c62f24; --chat-badge-texto: #ffffff; --chat-badge-borda: #ffffff;
  --chat-meu: #493f2e; --chat-meu-texto: #fef7f2; --chat-vivia: #fbf3df; --chat-vivia-borda: #ecd9a8;
}
html[data-tema="azul"] {
  --chat-fundo: #0f4c8a; --chat-fundo-hover: #0b3a6e; --chat-icone: #ffffff; --chat-anel: rgba(15,76,138,.28);
  --chat-meu: #1f3a5c; --chat-meu-texto: #ffffff; --chat-vivia: #e9f0f7; --chat-vivia-borda: #c3d4e6;
}
html[data-tema="neutro"] {
  --chat-fundo: #111111; --chat-fundo-hover: #000000; --chat-icone: #ffffff; --chat-anel: rgba(0,0,0,.25);
  --chat-meu: #2a2a2a; --chat-meu-texto: #ffffff; --chat-vivia: #f1f1f1; --chat-vivia-borda: #d6d6d6;
}
html[data-tema="noturno"] {
  --chat-fundo: #e2bd66; --chat-fundo-hover: #f0cd7c; --chat-icone: #15120f; --chat-anel: rgba(226,189,102,.30);
  --chat-badge: #ef5b4b; --chat-badge-texto: #15120f; --chat-badge-borda: #15120f;
  --chat-meu: #d8ccb6; --chat-meu-texto: #15120f; --chat-vivia: #302611; --chat-vivia-borda: #5b4920;
}
html.alto-contraste { --chat-fundo: #000000; --chat-fundo-hover: #222222; --chat-icone: #ffffff; --chat-badge: #b00000; }
html[data-tema="noturno"].alto-contraste { --chat-fundo: #ffd77a; --chat-fundo-hover: #ffe39c; --chat-icone: #000000; --chat-badge: #ff6b5b; --chat-badge-texto: #000; }
html.alto-contraste .chat-fab { outline: 3px solid var(--c-superficie); box-shadow: 0 0 0 5px var(--chat-fundo); }

.chat { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  bottom: calc(20px + env(safe-area-inset-bottom)); font-family: inherit; }
.chat-fab { position: relative; width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--chat-fundo); color: var(--chat-icone); box-shadow: 0 6px 18px rgba(0,0,0,.22), 0 0 0 4px var(--chat-anel);
  transition: background .15s, transform .15s; }
.chat-fab:hover { background: var(--chat-fundo-hover); }
.chat-fab:focus-visible { outline: 3px solid var(--c-foco); outline-offset: 3px; }
.chat-fab .ic { width: 26px; height: 26px; }
.chat-badge { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--chat-badge); color: var(--chat-badge-texto); border: 2px solid var(--chat-badge-borda);
  font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; }
.chat-fab.pulo { animation: chat-pulo .7s cubic-bezier(.3,1.6,.5,1); }
@keyframes chat-pulo { 0% { transform: translateY(0); } 30% { transform: translateY(-10px); } 55% { transform: translateY(0); } 75% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .chat-fab.pulo { animation: none; } }

/* prévia da mensagem recebida */
.chat-aviso { position: relative; max-width: min(300px, calc(100vw - 40px)); background: var(--c-superficie); color: var(--c-texto);
  border: 1px solid var(--c-borda-forte); border-radius: 14px 14px 4px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.16); animation: chat-entra .2s ease-out; }
.chat-aviso[hidden] { display: none; }
.chat-aviso-corpo { display: flex; flex-direction: column; gap: 2px; text-align: left; background: none; border: 0; color: inherit; font: inherit;
  padding: 10px 34px 10px 14px; cursor: pointer; width: 100%; }
.chat-aviso-corpo b { font-size: 13px; }
.chat-aviso-corpo span { font-size: 14px; color: var(--c-texto-2, var(--c-texto)); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chat-aviso-x { position: absolute; top: 6px; right: 6px; background: none; border: 0; color: var(--c-suave); cursor: pointer; padding: 4px; border-radius: 6px; }
@keyframes chat-entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* painel */
.chat-painel { position: fixed; right: 20px; bottom: calc(92px + env(safe-area-inset-bottom)); width: 380px; height: min(580px, calc(100vh - 130px));
  display: flex; flex-direction: column; background: var(--c-superficie); color: var(--c-texto); border: 1px solid var(--c-borda-forte);
  border-radius: 16px; box-shadow: 0 16px 48px rgba(0,0,0,.22); overflow: hidden; animation: chat-entra .18s ease-out; }
.chat-painel[hidden] { display: none; }
.chat-cab { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--c-borda); }
.chat-cab-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-cab-txt b { font-size: 15px; }
.chat-cab-txt small { font-size: 12px; color: var(--c-suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-btn { background: none; border: 0; color: var(--c-icone); width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.chat-btn:hover { background: var(--c-hover); color: var(--c-texto); }
.chat-btn[hidden] { display: none; }

.chat-lista { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.chat-lista[hidden] { display: none; }
.chat-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; background: none; color: inherit; font: inherit;
  text-align: left; border-radius: 10px; cursor: pointer; }
.chat-item:hover, .chat-item:focus-visible { background: var(--c-hover); }
.chat-av { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 600;
  background: var(--c-superficie-2, var(--c-hover)); color: var(--c-texto); border: 1px solid var(--c-borda); }
.chat-vivia .chat-av { background: var(--chat-fundo); color: var(--chat-icone); border-color: transparent; }
.chat-item-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-item-txt b { font-size: 14px; }
.chat-item-txt small { font-size: 13px; color: var(--c-suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-cont { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--chat-badge); color: var(--chat-badge-texto);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }

.chat-conv { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-conv[hidden] { display: none; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--c-fundo); }
.chat-msg { max-width: 86%; padding: 8px 12px 6px; border-radius: 14px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere;
  background: var(--c-superficie); border: 1px solid var(--c-borda); align-self: flex-start; }
.chat-msg.meu { align-self: flex-end; background: var(--chat-meu); color: var(--chat-meu-texto); border-color: transparent; border-bottom-right-radius: 4px; }
.chat-msg.outro { border-bottom-left-radius: 4px; }
.chat-msg.vivia { background: var(--chat-vivia); border-color: var(--chat-vivia-borda); border-bottom-left-radius: 4px; }
.chat-msg.erro { border-color: var(--c-erro-borda); background: var(--c-erro-fundo); color: var(--c-erro-texto); }
.chat-autor { display: block; font-size: 12px; font-weight: 600; color: var(--c-suave); margin-bottom: 2px; }
.chat-msg time { display: block; text-align: right; font-size: 11px; opacity: .7; margin-top: 2px; }
.chat-msg a.chat-pac { color: var(--c-link); font-weight: 600; text-decoration: underline; }
.chat-msg.meu a.chat-pac { color: inherit; }
.chat-pensando { padding: 6px 14px; font-size: 13px; color: var(--c-suave); background: var(--c-fundo); display: flex; align-items: center; gap: 3px; }
.chat-pensando[hidden] { display: none; }
.chat-pensando span { width: 6px; height: 6px; border-radius: 50%; background: var(--c-icone); animation: chat-pisca 1.2s infinite; }
.chat-pensando span:nth-child(2) { animation-delay: .2s; } .chat-pensando span:nth-child(3) { animation-delay: .4s; margin-right: 6px; }
@keyframes chat-pisca { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-sugestoes { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; background: var(--c-fundo); }
.chat-sugestoes[hidden] { display: none; }
.chat-sugestoes button { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--c-borda-forte);
  background: var(--c-superficie); color: var(--c-texto); cursor: pointer; text-align: left; }
.chat-sugestoes button[data-acao] { border-color: var(--chat-fundo); }
.chat-acoes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-acoes a, .chat-acoes button { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 10px; min-height: 32px; border-radius: 8px;
  border: 1px solid var(--c-borda-forte); background: var(--c-superficie); color: var(--c-texto); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; }
.chat-acoes [hidden] { display: none; }
@media (max-width: 640px) { .chat-acoes a, .chat-acoes button { min-height: 40px; } }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--c-borda); }
.chat-form textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--c-borda-forte);
  background: var(--c-superficie); color: var(--c-texto); font: inherit; font-size: 15px; line-height: 1.35; }
.chat-form textarea:focus { outline: 2px solid var(--c-foco); outline-offset: 0; }
.chat-enviar { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--chat-fundo); color: var(--chat-icone); display: grid; place-items: center; cursor: pointer; }
.chat-enviar:hover { background: var(--chat-fundo-hover); }

/* celular/tablet: fica ACIMA da barra de navegação de baixo (e da barra de ações, quando a página tem uma) */
@media (max-width: 960px) {
  .chat { right: 14px; bottom: calc(var(--tabbar, 64px) + 14px + env(safe-area-inset-bottom)); }
  body:has(.barra-acoes) .chat { bottom: calc(var(--tabbar, 64px) + 78px + env(safe-area-inset-bottom)); }
  .chat-fab { width: 52px; height: 52px; }
  .chat-painel { left: 8px; right: 8px; width: auto; top: calc(8px + env(safe-area-inset-top));
    bottom: calc(var(--tabbar, 64px) + 8px + env(safe-area-inset-bottom)); height: auto; }
  .chat.aberto .chat-fab, .chat.aberto .chat-aviso { display: none; }
}
@media print { .chat { display: none !important; } }
/* Vivia na agenda: cartão de confirmação (16/11/2026) */
.ag-card { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--c-borda-forte); border-radius: 10px; background: var(--c-superficie); color: var(--c-texto); }
.ag-card-dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; margin: 0; font-size: 13px; }
.ag-card-dl dt { color: var(--c-suave); }
.ag-card-dl dd { margin: 0; overflow-wrap: anywhere; }
.ag-card .chat-acoes { margin-top: 10px; }
.ag-card .ag-sim { background: var(--chat-fundo); border-color: var(--chat-fundo); color: var(--chat-icone); }
.ag-card .ag-sim:hover { background: var(--chat-fundo-hover); }
.ag-opcoes button { flex-direction: column; align-items: flex-start; text-align: left; }
.ag-opcoes button small { font-weight: 400; color: var(--c-suave); font-size: 12px; }
.ag-card button:disabled { opacity: .55; cursor: default; }
.ag-card-st { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--c-suave); }
.chat-sugestoes button.chip-agenda { border-style: dashed; color: var(--c-texto-2); }
html.alto-contraste .ag-card { border-width: 2px; }

/* botões "É de Fulano" na pergunta automática da Recepção (arquivo do WhatsApp sem paciente) */
.chat-msg .chat-vinc { display: inline-block; margin: 4px 4px 0 0; padding: 6px 10px; min-height: 36px; border-radius: 999px; border: 1px solid var(--c-borda); background: var(--c-superficie); color: var(--c-link); font: inherit; font-weight: 600; cursor: pointer; }
.chat-msg .chat-vinc:disabled { opacity: .7; cursor: default; }
.chat-msg .chat-vinc.ok { color: var(--c-texto-2); }
