/* ── Chat flutuante SAAE ─────────────────────────────────────────────── */

#webchat-saae-wrapper {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── Botão (bolinha) ─────────────────────────────────────────────────── */

.webchat-btn {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e40af, #2563eb);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(30, 64, 175, 0.35),
                0 2px 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    position: relative;
}

.webchat-btn:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 12px 32px rgba(30, 64, 175, 0.45),
                0 4px 10px rgba(0, 0, 0, 0.2);
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
}

.webchat-btn:active {
    transform: scale(0.97);
}

.webchat-btn:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 3px;
    box-shadow: 0 0 0 3px #fff, 0 8px 24px rgba(30, 64, 175, 0.35);
}

.webchat-btn .badge-nao-lidas {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.webchat-btn .badge-nao-lidas.visivel {
    display: flex;
}

/* ── Janela do chat ──────────────────────────────────────────────────── */

.webchat-janela {
    position: absolute;
    right: 0;
    bottom: 82px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22),
                0 4px 12px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: webchatAbrir 0.25s ease-out;
}

.webchat-janela.aberta {
    display: flex;
}

@keyframes webchatAbrir {
    from { opacity: 0; transform: scale(0.92) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Cabeçalho ───────────────────────────────────────────────────────── */

.webchat-header {
    background: linear-gradient(135deg, #1e40af, #2563eb);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.webchat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.webchat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.webchat-titulo {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.webchat-subtitulo {
    font-size: 12px;
    margin: 2px 0 0;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.webchat-status-online {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
    display: inline-block;
}

.webchat-fechar {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.webchat-fechar:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
    opacity: 1;
}

.webchat-fechar:hover {
    background: rgba(255, 255, 255, 0.15);
    opacity: 1;
}

/* ── Corpo / mensagens ──────────────────────────────────────────────── */

.webchat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.webchat-body::-webkit-scrollbar {
    width: 6px;
}
.webchat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.webchat-boas-vindas {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-radius: 12px;
    padding: 12px 14px;
    color: #1e3a8a;
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid #bfdbfe;
}

.webchat-boas-vindas strong {
    color: #1e40af;
}

.webchat-msg {
    max-width: 80%;
    min-width: 0;
    padding: 10px 14px;
    box-sizing: border-box;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}

.webchat-msg-conteudo {
    white-space: pre-wrap;
}

.webchat-msg-foto {
    display: block;
    width: min(260px, 100%);
    max-height: 280px;
    margin-top: 8px;
    border-radius: 10px;
    object-fit: contain;
    background: rgba(15, 23, 42, 0.06);
}

.webchat-pdf-cartao {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(320px, 100%);
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid #dbe4f0;
    border-radius: 12px;
    background: #fff;
    color: #172554;
    font: inherit;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.webchat-pdf-cartao:hover,
.webchat-pdf-cartao:focus-visible {
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.14);
    outline: 2px solid #bfdbfe;
    outline-offset: 1px;
}

.webchat-pdf-cartao:hover {
    transform: translateY(-1px);
}

.webchat-pdf-icone {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 48px;
    flex: 0 0 42px;
    border-radius: 9px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.webchat-pdf-informacoes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.webchat-pdf-nome {
    overflow: hidden;
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.webchat-pdf-orientacao {
    color: #475569;
    font-size: 11px;
}

.webchat-opcao {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    margin-top: 8px;
    padding: 9px 12px;
    border: 1px solid #2563eb;
    border-radius: 8px;
    background: #fff;
    color: #1e40af;
    font: inherit;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

.webchat-opcao:hover,
.webchat-opcao:focus-visible {
    background: #eff6ff;
    outline: 2px solid #1d4ed8;
    outline-offset: 1px;
}

.webchat-opcao:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #f1f5f9;
}

.webchat-msg.saida {
    align-self: flex-end;
    background: linear-gradient(135deg, #1e40af, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.webchat-msg.entrada,
.webchat-msg.sistema {
    align-self: flex-start;
    background: #fff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.webchat-msg.sistema {
    background: #fef3c7;
    border-color: #fde68a;
    color: #92400e;
    font-size: 12.5px;
    max-width: 90%;
}

.webchat-msg-hora {
    display: block;
    font-size: 11px;
    margin-top: 4px;
    color: #fff;
    text-align: right;
}

.webchat-msg.entrada .webchat-msg-hora,
.webchat-msg.sistema .webchat-msg-hora {
    color: #475569;
}

.webchat-digitando {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 12px 14px 10px;
    display: none;
    gap: 4px;
}

.webchat-digitando.visivel {
    display: flex;
}

.webchat-digitando span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: webchatPonto 1.2s infinite;
}

.webchat-digitando span:nth-child(2) { animation-delay: 0.15s; }
.webchat-digitando span:nth-child(3) { animation-delay: 0.3s; }

@keyframes webchatPonto {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Formulário de identificação (opcional) ─────────────────────────── */

.webchat-form-info {
    background: #f1f5f9;
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.webchat-form-info.oculto {
    display: none;
}

.webchat-form-info p {
    margin: 0 0 2px;
    font-size: 12px;
    color: #475569;
    font-weight: 600;
}

.webchat-form-info input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.webchat-form-info input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.webchat-form-info-linha {
    display: flex;
    gap: 8px;
}

.webchat-form-info-linha input {
    flex: 1;
}

/* ── Área de entrada ────────────────────────────────────────────────── */

.webchat-input-area {
    padding: 12px 14px 14px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.webchat-file-input {
    display: none;
}

.webchat-anexo-btn {
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #1e40af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    transition: background 0.15s ease, color 0.15s ease;
}

.webchat-anexo-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.webchat-anexo-btn:hover:not(:disabled),
.webchat-anexo-btn:focus-visible {
    background: #eff6ff;
    outline: 2px solid #1d4ed8;
    outline-offset: 1px;
}

.webchat-anexo-btn:disabled {
    color: #94a3b8;
    cursor: wait;
}

.webchat-foto-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 14px 10px;
    padding: 8px 10px;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    background: #eff6ff;
    color: #1e3a8a;
}

.webchat-foto-preview[hidden] {
    display: none;
}

.webchat-foto-preview > img {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    background: #dbeafe;
    flex: 0 0 44px;
}

.webchat-foto-preview-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.webchat-foto-preview-info strong {
    font-size: 12px;
}

.webchat-foto-preview-info span {
    overflow: hidden;
    color: #475569;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.webchat-foto-remover {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #475569;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    flex: 0 0 44px;
}

.webchat-foto-remover:hover,
.webchat-foto-remover:focus-visible {
    background: #dbeafe;
    outline: 2px solid #1d4ed8;
}

.webchat-input {
    flex: 1;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 110px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #f8fafc;
}

.webchat-input:focus {
    border-color: #3b82f6;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.webchat-input::placeholder {
    color: #64748b;
}

.webchat-enviar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1e40af, #2563eb);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.webchat-enviar:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(30, 64, 175, 0.35);
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
}

.webchat-enviar:focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.webchat-enviar:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    color: #94a3b8;
}

/* ── Status conexão ─────────────────────────────────────────────────── */

.webchat-status-msg {
    font-size: 12px;
    text-align: center;
    color: #475569;
    padding: 4px 0 0;
    min-height: 16px;
}

.webchat-status-msg.erro {
    color: #b91c1c;
}

.webchat-pdf-visualizador {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: #fff;
}

.webchat-pdf-visualizador[hidden] {
    display: none;
}

.webchat-pdf-cabecalho {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 62px;
    padding: 10px 12px;
    box-sizing: border-box;
    border-bottom: 1px solid #dbe4f0;
    background: #f8fafc;
}

.webchat-pdf-titulos {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.webchat-pdf-titulos span {
    color: #475569;
    font-size: 11px;
    font-weight: 600;
}

.webchat-pdf-titulos strong {
    overflow: hidden;
    color: #172554;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.webchat-pdf-acoes {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.webchat-pdf-acoes a,
.webchat-pdf-acoes button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    min-width: 0;
    padding: 0 10px;
    box-sizing: border-box;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #fff;
    color: #1d4ed8;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.webchat-pdf-acoes a:hover,
.webchat-pdf-acoes button:hover,
.webchat-pdf-acoes a:focus-visible,
.webchat-pdf-acoes button:focus-visible {
    border-color: #2563eb;
    background: #eff6ff;
    outline: 2px solid #bfdbfe;
    outline-offset: 1px;
}

.webchat-pdf-visualizador iframe {
    display: block;
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
    border: 0;
    background: #e2e8f0;
}

/* Os estilos globais do site estilizam input[type=file] depois deste arquivo.
   Mantenha os campos nativos ocultos; a seleção é feita pelos botões do chat. */
#webchat-saae-wrapper .webchat-file-input {
    display: none !important;
}

#webchat-saae-wrapper .webchat-input-area {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

#webchat-saae-wrapper .webchat-anexo-btn,
#webchat-saae-wrapper .webchat-enviar {
    box-sizing: border-box;
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
}

#webchat-saae-wrapper .webchat-anexo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: #1e40af;
    cursor: pointer;
}

#webchat-saae-wrapper .webchat-anexo-btn svg {
    display: block;
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
}

#webchat-saae-wrapper .webchat-enviar {
    display: flex;
    align-items: center;
    justify-content: center;
}

#webchat-saae-wrapper .webchat-input {
    box-sizing: border-box;
    width: 0;
    min-width: 0;
    flex: 1 1 auto;
}

@media (max-width: 480px) {
    #webchat-saae-wrapper {
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Janela aberta ocupa a tela toda; o botão flutuante some enquanto isso */
    .webchat-janela {
        position: fixed;
        inset: 0;
        width: auto;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border-radius: 0;
    }

    #webchat-saae-wrapper.aberto .webchat-btn {
        display: none;
    }

    .webchat-header {
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }

    .webchat-body {
        min-height: 0;
        padding: 12px;
    }

    .webchat-msg {
        max-width: 88%;
        padding: 9px 11px;
    }

    .webchat-pdf-cartao {
        gap: 8px;
        padding: 9px;
    }

    .webchat-pdf-icone {
        width: 38px;
        height: 44px;
        flex-basis: 38px;
    }

    .webchat-pdf-cabecalho {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    .webchat-pdf-titulos,
    .webchat-pdf-titulos strong {
        width: 100%;
    }

    .webchat-pdf-acoes {
        width: 100%;
    }

    .webchat-pdf-acoes a,
    .webchat-pdf-acoes button {
        flex: 1 1 0;
        padding: 0 8px;
        font-size: 10px;
    }

    #webchat-saae-wrapper .webchat-input-area {
        gap: 6px;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    }

    #webchat-saae-wrapper .webchat-anexo-btn {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
        padding: 10px;
    }

    #webchat-saae-wrapper .webchat-input {
        font-size: 16px;
        padding: 9px 11px;
    }
}

/* Respeita a preferência por menos movimento */
@media (prefers-reduced-motion: reduce) {
    .webchat-janela,
    .webchat-digitando span {
        animation: none;
    }

    .webchat-btn,
    .webchat-fechar,
    .webchat-pdf-cartao,
    .webchat-anexo-btn,
    .webchat-input,
    .webchat-enviar,
    .webchat-form-info input {
        transition: none;
    }

    .webchat-btn:hover,
    .webchat-pdf-cartao:hover,
    .webchat-enviar:hover:not(:disabled) {
        transform: none;
    }

    .webchat-digitando span {
        opacity: 0.7;
    }
}
