/* ============================================================================
   CHAT DE ATENDIMENTO (visitante) — identidade institucional do STJ
   ============================================================================
   Usa a mesma paleta, a mesma fonte, o mesmo brasão e o mesmo filete dourado
   do tema do site (tema.css). Os valores têm reserva entre parênteses para o
   caso de o tema não carregar.
   ============================================================================ */

.chat__botao {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 2px solid var(--ouro, #F2B705);
    border-radius: 50%;
    background: var(--navy-800, #0E2E4F);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(11, 36, 64, .34);
    cursor: pointer;
    z-index: 2147483000;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.chat__botao:hover {
    background: var(--navy-700, #143C66);
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(11, 36, 64, .38);
}

.chat__botao:active { transform: translateY(0); }

/* Enquanto o operador não chamar, o chat fica invisível para o visitante. */
.chat__botao--oculto { display: none !important; }

.chat__botao--novo { animation: chatPulso 1.8s infinite; }

.chat__selo {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 2px solid var(--navy-800, #0E2E4F);
    border-radius: 10px;
    background: var(--ouro, #F2B705);
    color: var(--navy-900, #0B2440);
    font: bold 11px/16px var(--fonte, Arial, Helvetica, sans-serif);
    text-align: center;
}

@keyframes chatPulso {
    0%, 100% { box-shadow: 0 6px 18px rgba(11, 36, 64, .34); }
    50%      { box-shadow: 0 0 0 12px rgba(28, 99, 168, .16); }
}

.chat__janela {
    position: fixed;
    right: 18px;
    bottom: 88px;
    width: 352px;
    max-width: calc(100vw - 24px);
    height: 490px;
    max-height: calc(100vh - 120px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: var(--raio, 10px);
    box-shadow: 0 18px 40px rgba(11, 36, 64, .34);
    z-index: 2147483001;
    font-family: var(--fonte, Arial, Helvetica, sans-serif);
    color: var(--tinta, #1E2A35);
}

.chat__janela.aberto { display: flex; }

.chat__topo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 9px;
    background: linear-gradient(135deg, var(--navy-900, #0B2440) 0%, var(--navy-700, #143C66) 100%);
    border-bottom: 3px solid var(--ouro, #F2B705);
    color: #fff;
}

.chat__brasao {
    flex: 0 0 auto;
    width: 27px;
    height: 27px;
    object-fit: contain;
}

.chat__titulo { flex: 1 1 auto; min-width: 0; line-height: 1.25; }

.chat__orgao {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .8);
}

.chat__assunto {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}

.chat__status {
    display: inline-block;
    margin-left: 7px;
    font-size: 10px;
    font-weight: 400;
    color: rgba(255, 255, 255, .82);
    vertical-align: middle;
}

.chat__ponto {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 4px;
    border-radius: 50%;
    background: var(--ouro, #F2B705);
    vertical-align: middle;
}

.chat__ponto.ligado { background: #4ade80; }

.chat__fechar {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    padding: 2px 6px;
    cursor: pointer;
    opacity: .85;
}

.chat__fechar:hover { opacity: 1; }

.chat__lista {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px;
    background: var(--azul-100, #E5EDF6);
}

.chat__aviso {
    margin: 0 auto 12px;
    max-width: 260px;
    padding: 9px 11px;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: var(--raio-sm, 8px);
    background: #fff;
    color: var(--tinta-2, #46505C);
    font-size: 12px;
    text-align: center;
}

.chat__msg {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.chat__msg--eu { align-items: flex-end; }
.chat__msg--op { align-items: flex-start; }

.chat__bolha {
    max-width: 82%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat__msg--eu .chat__bolha {
    background: var(--azul-600, #17518C);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat__msg--op .chat__bolha {
    background: #fff;
    color: var(--tinta, #1E2A35);
    border: 1px solid var(--linha, #D3DAE2);
    border-bottom-left-radius: 4px;
}

.chat__hora {
    margin-top: 3px;
    font-size: 10px;
    color: var(--tinta-3, #6B7887);
}

.chat__erro {
    display: none;
    padding: 8px 12px;
    background: var(--vermelho-050, #FDF1F0);
    border-top: 1px solid var(--vermelho-600, #B3261E);
    color: var(--vermelho-700, #931A14);
    font-size: 12px;
}

.chat__rodape {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--linha, #D3DAE2);
    background: #fff;
}

.chat__campo {
    flex: 1 1 auto;
    min-height: 40px;
    max-height: 110px;
    padding: 10px 12px;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: var(--raio-sm, 8px);
    /* 16px é o mínimo para o iPhone não dar zoom ao focar o campo */
    font: 16px/1.4 var(--fonte, Arial, Helvetica, sans-serif);
    color: var(--tinta, #1E2A35);
    resize: none;
    outline: none;
    background: #fff;
    /* No iOS, deixar o toque no padrão do navegador é o que garante o teclado */
    touch-action: auto;
    -webkit-user-select: text;
    user-select: text;
}

.chat__campo:focus { border-color: var(--azul-500, #1C63A8); }

.chat__enviar {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: var(--azul-600, #17518C);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.chat__enviar:hover { background: var(--azul-500, #1C63A8); }
.chat__enviar:disabled { opacity: .55; cursor: default; }

/* --- Comprovante (anexo) --------------------------------------------------- */

.chat__anexo {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: none;                 /* aparece quando o atendimento libera */
    align-items: center;
    justify-content: center;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: 50%;
    background: #fff;
    color: var(--azul-600, #17518C);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.chat__anexo:hover { background: var(--azul-100, #E5EDF6); }

.chat__anexo-bloco {
    margin-top: 4px;
    max-width: 82%;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.chat__anexo-img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    background: #000;
}

.chat__anexo-pdf {
    display: block;
    width: 100%;
    height: 240px;
    border: 0;
    background: #fff;
}

.chat__anexo-barra {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-top: 1px solid var(--linha, #D3DAE2);
}

.chat__anexo-nome {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--tinta-3, #6B7887);
    font-size: 10px;
}

.chat__anexo-acao {
    flex: none;
    padding: 4px 9px;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: 7px;
    color: var(--azul-600, #17518C);
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
}

.chat__anexo-acao--forte {
    background: var(--azul-600, #17518C);
    border-color: transparent;
    color: #fff;
}

@media (max-width: 520px) {
    .chat__anexo-bloco { max-width: 94%; }
    .chat__anexo-pdf { height: 200px; }
}

/* --- Recado do sistema (centralizado) -------------------------------------- */

.chat__msg--sis { align-items: center; }
.chat__msg--sis .chat__sistema { font-size: 12px; max-width: 290px; }

@media (max-width: 520px) {
    .chat__janela {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: var(--chat-altura, 100dvh);
        max-height: var(--chat-altura, 100dvh);
        border: 0;
        border-radius: 0;
    }

    .chat__botao { right: 14px; bottom: 14px; }
}

/* --- Atendimento em andamento (processo travado) --------------------------- */

.chat__trava {
    position: fixed;
    inset: 0;
    background: rgba(11, 36, 64, .78);
    z-index: 2147483000;
    display: none;
}

.chat__trava.ativo { display: block; }

.chat__travado-aviso {
    display: none;
    padding: 7px 12px;
    background: var(--amber-050, #FFF8E6);
    border-bottom: 1px solid var(--amber-linha, #E3B341);
    color: var(--amber-700, #7A5200);
    font-size: 12px;
    text-align: center;
}

.chat__janela--travada .chat__travado-aviso { display: block; }
.chat__janela--travada .chat__fechar { display: none; }

.chat__janela--travada {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: 430px;
    max-width: calc(100vw - 24px);
    height: 560px;
    max-height: calc(100vh - 40px);
    z-index: 2147483001;
}

.chat__sistema {
    margin: 10px auto;
    max-width: 270px;
    padding: 7px 10px;
    border: 1px solid var(--linha, #D3DAE2);
    border-radius: var(--raio-sm, 8px);
    background: #fff;
    color: var(--tinta-2, #46505C);
    font-size: 11px;
    text-align: center;
}

@media (max-width: 520px) {
    .chat__janela--travada {
        left: 0;
        top: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        height: var(--chat-altura, 100dvh);
        max-height: var(--chat-altura, 100dvh);
        border-radius: 0;
    }
}
