/* ══════════════════════════════════════════════════════════════
   Chat de atendimento — Trator Esperança
   Tudo prefixado com .te-chat para não colidir com o CSS do site.
   ══════════════════════════════════════════════════════════════ */

.te-chat {
    --tc-amarelo: #F5B700;
    --tc-amarelo-2: #FFC72C;
    --tc-amarelo-escuro: #c99400;
    --tc-preto: #15171a;
    --tc-preto-2: #23272d;
    --tc-cinza: #6b7280;
    --tc-cinza-claro: #f3f4f6;
    --tc-borda: #e5e7eb;
    --tc-verde: #16a34a;
    --tc-sombra: 0 24px 60px -12px rgba(15, 17, 20, .38), 0 8px 20px -8px rgba(15, 17, 20, .22);
    --tc-raio: 20px;

    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9990;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--tc-preto);
    -webkit-font-smoothing: antialiased;
}
.te-chat[hidden] { display: none; }
.te-chat *, .te-chat *::before, .te-chat *::after { box-sizing: border-box; }
.te-chat button { font-family: inherit; cursor: pointer; }
.te-chat [hidden] { display: none !important; }

/* ── Lançador ───────────────────────────────────────────────── */
.te-chat-lancador {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 0;
    background: linear-gradient(140deg, var(--tc-amarelo-2), var(--tc-amarelo) 55%, var(--tc-amarelo-escuro));
    color: var(--tc-preto);
    display: grid;
    place-items: center;
    box-shadow: 0 12px 32px -6px rgba(245, 183, 0, .65), 0 4px 10px rgba(15, 17, 20, .18);
    transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s;
    animation: tc-entrar .5s cubic-bezier(.34, 1.56, .64, 1) both;
}
.te-chat-lancador:hover { transform: scale(1.07) rotate(-4deg); }
.te-chat-lancador:active { transform: scale(.95); }
.te-chat-lancador:focus-visible { outline: 3px solid var(--tc-preto); outline-offset: 3px; }

/* anel pulsando enquanto o cliente ainda não abriu */
.te-chat:not(.aberto):not(.visto) .te-chat-lancador::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--tc-amarelo);
    animation: tc-pulso 2.2s cubic-bezier(.2, .6, .35, 1) infinite;
}

.te-chat-lancador-icone,
.te-chat-lancador-fechar {
    grid-area: 1 / 1;
    display: grid;
    place-items: center;
    transition: transform .3s cubic-bezier(.34, 1.56, .64, 1), opacity .2s;
}
.te-chat-lancador-fechar { opacity: 0; transform: rotate(-90deg) scale(.5); }
.te-chat.aberto .te-chat-lancador-icone { opacity: 0; transform: rotate(90deg) scale(.5); }
.te-chat.aberto .te-chat-lancador-fechar { opacity: 1; transform: none; }

.te-chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
    animation: tc-pop .35s cubic-bezier(.34, 1.56, .64, 1);
}

/* ── Etiqueta "Vendedor Online" ─────────────────────────────── */
.te-chat-online {
    position: absolute;
    right: 76px;
    bottom: 13px;
    display: none;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px 0 13px;
    border: 0;
    border-radius: 19px;
    background: var(--tc-preto);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .01em;
    white-space: nowrap;
    box-shadow: 0 10px 26px -8px rgba(15, 17, 20, .55);
    animation: tc-subir .45s cubic-bezier(.34, 1.56, .64, 1) .3s both, tc-piscar 1.2s ease-in-out 1s infinite;
}
.te-chat.online:not(.aberto) .te-chat-online { display: inline-flex; }
.te-chat-online:hover { animation-play-state: running, paused; opacity: 1; }
.te-chat-online-ponto {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    animation: tc-online 1.2s infinite;
}

/* ── Balão de convite ───────────────────────────────────────── */
.te-chat-balao {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: 238px;
    padding: 14px 34px 14px 16px;
    background: #fff;
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--tc-sombra);
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    animation: tc-subir .45s cubic-bezier(.34, 1.56, .64, 1) both;
}
.te-chat-balao strong { font-size: 14.5px; }
.te-chat-balao span { font-size: 13px; color: var(--tc-cinza); }
.te-chat-balao-x {
    position: absolute;
    top: 6px;
    right: 8px;
    border: 0;
    background: none;
    font-size: 20px;
    line-height: 1;
    color: var(--tc-cinza);
    padding: 2px 4px;
}
.te-chat.aberto .te-chat-balao { display: none; }

/* ── Janela ─────────────────────────────────────────────────── */
.te-chat-janela {
    position: absolute;
    right: 0;
    bottom: 80px;
    width: 380px;
    height: min(620px, calc(100vh - 120px));
    background: #fff;
    border-radius: var(--tc-raio);
    box-shadow: var(--tc-sombra);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: tc-abrir .32s cubic-bezier(.34, 1.4, .64, 1) both;
}

.te-chat-topo {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 14px 16px 18px;
    background: var(--tc-preto);
    background-image:
        radial-gradient(120% 140% at 100% 0%, rgba(245, 183, 0, .28), transparent 55%),
        linear-gradient(135deg, var(--tc-preto), var(--tc-preto-2));
    color: #fff;
    flex-shrink: 0;
}
.te-chat-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--tc-amarelo);
    color: var(--tc-preto);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.te-chat-ponto {
    position: absolute;
    right: 0;
    bottom: 1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #9ca3af;
    border: 2px solid var(--tc-preto);
}
.te-chat.com-atendente .te-chat-ponto { background: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: tc-online 2s infinite; }

.te-chat-topo-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.te-chat-titulo {
    font-family: 'Barlow Condensed', 'Inter', sans-serif;
    font-weight: 700;
    font-size: 19px;
    letter-spacing: .01em;
    text-transform: uppercase;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.te-chat-sub { font-size: 12.5px; color: rgba(255, 255, 255, .72); }

.te-chat-acoes { display: flex; gap: 2px; }
.te-chat-acoes button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, .8);
    display: grid;
    place-items: center;
    transition: background .2s, color .2s;
}
.te-chat-acoes button:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.te-chat-menu {
    position: absolute;
    right: 14px;
    top: 58px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--tc-sombra);
    padding: 6px;
    z-index: 3;
    animation: tc-pop .2s ease-out;
}
.te-chat-menu button {
    border: 0;
    background: none;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    color: #b91c1c;
    white-space: nowrap;
}
.te-chat-menu button:hover { background: #fef2f2; }

/* ── Passo 1: identificação ─────────────────────────────────── */
.te-chat-ident {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: linear-gradient(180deg, #fffbeb, #fff 140px);
}
.te-chat-ident-intro { display: flex; gap: 10px; align-items: flex-start; }
.te-chat-ident-intro p { margin: 0; font-size: 14.5px; color: #374151; }
.te-chat-onda { font-size: 24px; line-height: 1; animation: tc-acenar 2s ease-in-out 2; transform-origin: 70% 70%; }

.te-chat-campo { display: flex; flex-direction: column; gap: 5px; }
.te-chat-campo span { font-size: 12.5px; font-weight: 600; color: #374151; letter-spacing: .01em; }
.te-chat-campo em { font-weight: 400; font-style: normal; color: var(--tc-cinza); }
.te-chat-campo input,
.te-chat-campo textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--tc-borda);
    border-radius: 12px;
    font: inherit;
    font-size: 15px;
    color: var(--tc-preto);
    background: #fff;
    resize: none;
    transition: border-color .2s, box-shadow .2s;
}
.te-chat-campo input:focus,
.te-chat-campo textarea:focus {
    outline: none;
    border-color: var(--tc-amarelo);
    box-shadow: 0 0 0 4px rgba(245, 183, 0, .18);
}
.te-chat-campo input.erro { border-color: #ef4444; box-shadow: 0 0 0 4px rgba(239, 68, 68, .12); }

.te-chat-erro {
    margin: -4px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 13.5px;
}

.te-chat-iniciar {
    margin-top: 4px;
    height: 50px;
    border: 0;
    border-radius: 14px;
    background: var(--tc-preto);
    color: #fff;
    font-weight: 700;
    font-size: 15.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform .15s, background .2s;
}
.te-chat-iniciar:hover { background: #000; }
.te-chat-iniciar:hover svg { transform: translateX(3px); }
.te-chat-iniciar svg { transition: transform .2s; color: var(--tc-amarelo); }
.te-chat-iniciar:active { transform: scale(.98); }
.te-chat-iniciar:disabled { opacity: .7; cursor: wait; }

.te-chat-lgpd { margin: 0; font-size: 11.5px; color: var(--tc-cinza); text-align: center; }
.te-chat-lgpd a { color: inherit; }

/* ── Passo 2: conversa ──────────────────────────────────────── */
.te-chat-conversa { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #f7f7f5; }

.te-chat-protocolo {
    text-align: center;
    font-size: 11.5px;
    color: var(--tc-cinza);
    padding: 8px 0 2px;
    letter-spacing: .02em;
}
.te-chat-protocolo:empty { display: none; }

.te-chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.te-chat-msg {
    max-width: 82%;
    padding: 9px 13px 7px;
    border-radius: 16px;
    font-size: 14.5px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: tc-msg .28s cubic-bezier(.34, 1.3, .64, 1) both;
    position: relative;
}
.te-chat-msg .te-hora { display: block; text-align: right; font-size: 10.5px; margin-top: 2px; opacity: .6; }
.te-chat-msg .te-quem { display: block; font-size: 11.5px; font-weight: 700; color: var(--tc-amarelo-escuro); margin-bottom: 1px; }
.te-chat-msg a { color: inherit; text-decoration: underline; }

.te-chat-msg.eu {
    align-self: flex-end;
    background: var(--tc-preto);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.te-chat-msg.eles {
    align-self: flex-start;
    background: #fff;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(15, 17, 20, .08);
}
.te-chat-msg.sistema {
    align-self: center;
    max-width: 92%;
    background: #fff8db;
    color: #6b5300;
    font-size: 13px;
    text-align: center;
    border-radius: 12px;
    padding: 8px 12px;
}
.te-chat-msg.sistema .te-hora { display: none; }
.te-chat-msg.enviando { opacity: .55; }
.te-chat-msg.falhou { outline: 2px solid #ef4444; }

.te-chat-msg img.te-img {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border-radius: 10px;
    margin: 2px 0 4px;
    cursor: zoom-in;
    background: var(--tc-cinza-claro);
}
.te-chat-pdf {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin: 2px 0 4px;
    border-radius: 10px;
    background: rgba(127, 127, 127, .12);
    text-decoration: none !important;
}
.te-chat-pdf b { display: block; font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-chat-pdf small { font-size: 11px; opacity: .7; }
.te-chat-pdf-ico {
    width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    background: #dc2626; color: #fff; font-size: 10px; font-weight: 800;
    display: grid; place-items: center; letter-spacing: .03em;
}

.te-chat-digitando {
    align-self: flex-start;
    margin: 0 14px 8px;
    padding: 12px 14px;
    background: #fff;
    border-radius: 16px;
    display: flex;
    gap: 4px;
}
.te-chat-digitando i { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; animation: tc-dig 1.2s infinite; }
.te-chat-digitando i:nth-child(2) { animation-delay: .15s; }
.te-chat-digitando i:nth-child(3) { animation-delay: .3s; }

.te-chat-envio {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 10px 12px;
    background: #fff;
    border-top: 1px solid var(--tc-borda);
    flex-shrink: 0;
}
.te-chat-clipe,
.te-chat-enviar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 0;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    transition: background .2s, transform .15s, color .2s;
}
.te-chat-clipe { background: transparent; color: var(--tc-cinza); }
.te-chat-clipe:hover { background: var(--tc-cinza-claro); color: var(--tc-preto); }
.te-chat-enviar { background: var(--tc-amarelo); color: var(--tc-preto); }
.te-chat-enviar:not(:disabled):hover { transform: scale(1.06); }
.te-chat-enviar:disabled { background: var(--tc-cinza-claro); color: #c4c7cc; cursor: default; }

.te-chat-texto {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1.5px solid var(--tc-borda);
    border-radius: 12px;
    font: inherit;
    font-size: 15px;
    resize: none;
    color: var(--tc-preto);
    background: #fff;
    line-height: 1.4;
}
.te-chat-texto:focus { outline: none; border-color: var(--tc-amarelo); }

.te-chat-encerrada {
    margin: 0 14px 12px;
    padding: 14px;
    background: #fff;
    border-radius: 14px;
    text-align: center;
    font-size: 14px;
}
.te-chat-encerrada p { margin: 0 0 10px; color: #374151; }
.te-chat-nova {
    border: 0;
    border-radius: 10px;
    background: var(--tc-preto);
    color: #fff;
    padding: 10px 16px;
    font-weight: 600;
}

/* visualizador de imagem em tela cheia */
.te-chat-zoom {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(10, 11, 13, .9);
    display: grid;
    place-items: center;
    padding: 20px;
    cursor: zoom-out;
    animation: tc-fade .2s;
}
.te-chat-zoom img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ── Celular: janela em tela cheia ──────────────────────────── */
@media (max-width: 560px) {
    .te-chat { right: 16px; bottom: 16px; }
    .te-chat-janela {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        animation: tc-subir-mobile .3s cubic-bezier(.2, .8, .3, 1) both;
    }
    .te-chat.aberto .te-chat-lancador { display: none; }
    .te-chat-texto, .te-chat-campo input, .te-chat-campo textarea { font-size: 16px; } /* evita zoom do iOS */
}

/* ── Animações ──────────────────────────────────────────────── */
@keyframes tc-entrar { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tc-pulso { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(1.55); opacity: 0; } }
@keyframes tc-pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tc-subir { from { transform: translateY(14px) scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tc-abrir { from { transform: translateY(18px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tc-subir-mobile { from { transform: translateY(100%); } to { transform: none; } }
@keyframes tc-msg { from { transform: translateY(8px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tc-dig { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes tc-online { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); } 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
@keyframes tc-acenar { 0%, 100% { transform: rotate(0); } 20%, 60% { transform: rotate(16deg); } 40%, 80% { transform: rotate(-8deg); } }
@keyframes tc-piscar { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes tc-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    .te-chat *, .te-chat *::before { animation: none !important; transition: none !important; }
}
