/* ==========================================================================
   MSA CODE — PÁGINA DE CONTATO (ÁREA CONVERSACIONAL INTEGRADA)
   Caixa principal no off-white oficial (var(--bg-light, #F1F0EC)),
   respostas prontas sólidas e sem bordas, botão voltar editorial discreto,
   sem divisores aparentes, balões e espaçamentos preservados.
   ========================================================================== */

/* Coluna Direita do Chat */
.contact-assistant-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
}

/* Caixa Principal do Chat (Off-white oficial var(--bg-light, #F1F0EC)) */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 580px;
    max-height: calc(100vh - 180px);
    min-height: 480px;
    background: var(--bg-light, #F1F0EC);
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 45px -15px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

/* Ações Superiores do Chat (Link Editorial Discreto) */
.chat-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.85rem 1.25rem 0.25rem;
    background: var(--bg-light, #F1F0EC);
    border: none;
    min-height: 24px;
    z-index: 5;
    flex-shrink: 0;
}

.chat-back-btn {
    background: none;
    border: none;
    color: var(--text-dark-muted, #71717a);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    padding: 0.2rem 0;
    text-transform: none;
    opacity: 0.75;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.chat-back-btn:hover {
    color: var(--text-dark, #111111);
    opacity: 1;
}

.chat-back-btn:focus-visible {
    outline: 2px solid var(--text-dark, #111111);
    outline-offset: 2px;
}

/* Área de Fluxo de Mensagens (Scrollable) */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    background: var(--bg-light, #F1F0EC);
}

/* Scrollbar minimalista e discreta */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Linha da Mensagem */
.chat-msg-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-msg-row.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.chat-msg-row.system {
    align-self: flex-start;
    max-width: 88%;
}

.chat-msg-row.user {
    align-self: flex-end;
    align-items: flex-end;
    max-width: 82%;
}

/* Label textual superior (Sutil e elegante) */
.chat-msg-sender {
    font-family: var(--font-body);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #88888e;
    padding: 0 0.35rem;
}

/* Balão do Bot / MSA: Tom claro / neutro (#ffffff no fundo off-white), sem contorno aparente */
.chat-bubble.system {
    background: #ffffff;
    border: none;
    border-radius: 14px;
    padding: 0.95rem 1.25rem;
    color: var(--text-dark, #111111);
    font-family: var(--font-body);
    font-size: 0.94rem;
    line-height: 1.6;
    box-shadow: none;
    word-break: break-word;
}

/* Balão do Usuário: Lado direito, preto elegante, sem contorno aparente */
.chat-bubble.user {
    background: var(--text-dark, #111111);
    border: none;
    border-radius: 14px;
    padding: 0.9rem 1.2rem;
    color: #ffffff;
    font-family: var(--font-body);
    font-size: 0.94rem;
    line-height: 1.55;
    box-shadow: none;
    word-break: break-word;
}

/* Indicador de Digitação (Typing Indicator: "...") — Idêntico ao balão MSA */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0.35rem 0.2rem;
    height: 14px;
}

.typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #71717a;
    animation: dotPulse 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-4px);
        opacity: 0.9;
    }
}

/* Área de Opções Clicáveis no Rodapé (Desativada) */
.chat-options-container {
    display: none !important;
}

/* Opções de Resposta do Usuário (Alinhadas ao lado direito) */
.chat-options-row,
.chat-inline-options {
    display: flex;
    flex-direction: column;
    align-self: flex-end;
    align-items: flex-end;
    gap: 0.45rem;
    max-width: 82%;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-options-row.is-visible,
.chat-inline-options.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Respostas Prontas: Alinhadas à direita, fundo escuro/grafite, texto branco,
   sem borda, sem outline, cantos suaves, hover discreto, aparência de escolha do usuário */
.chat-chip-option {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    text-align: right;
    background: #18181b;
    border: none;
    outline: none;
    border-radius: 12px;
    color: #ffffff;
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.4;
    padding: 0.65rem 1.15rem;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}

.chat-chip-option:hover {
    background: #27272a;
    color: #ffffff;
    transform: translateX(-2px);
}

.chat-chip-option:active,
.chat-chip-option.is-selected {
    background: #000000;
    color: #ffffff;
}

.chat-chip-option:focus-visible {
    outline: 2px solid #18181b;
    outline-offset: 2px;
}

.chat-chip-option .chip-arrow {
    display: none !important;
}

/* Barra Inferior Fixa de Resposta — Integrada, sem divisor visível */
.chat-input-wrapper {
    background: var(--bg-light, #F1F0EC);
    border: none;
    border-top: none;
    padding: 0.85rem 1.25rem 1.15rem;
    position: relative;
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 0.35rem 0.5rem 0.35rem 1.15rem;
    box-shadow: none;
    transition: box-shadow 0.2s ease;
}

.chat-form:focus-within {
    box-shadow: none;
    outline: none;
}

.chat-input-field {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    color: var(--text-dark, #111111);
    font-family: var(--font-body);
    font-size: 0.92rem;
    padding: 0.55rem 0;
    line-height: 1.4;
}

.chat-input-field:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

.chat-input-field::placeholder {
    color: #88888e;
}

.chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: #a1a1aa;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: not-allowed;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-icon {
    font-size: 1rem;
    line-height: 1;
    font-weight: 700;
}

.chat-send-btn:enabled {
    background: var(--text-dark, #111111);
    color: #ffffff;
    cursor: pointer;
}

.chat-send-btn:enabled:hover {
    transform: translateY(-1px);
    background: #000000;
}

.chat-send-btn:focus-visible {
    outline: 2px solid var(--text-dark, #111111);
    outline-offset: 2px;
}

.chat-error-msg {
    color: #dc2626;
    font-size: 0.75rem;
    font-family: var(--font-body);
    margin-top: 0.5rem;
    padding-left: 0.25rem;
}

/* Card de Resumo Final no Chat */
.chat-summary-box {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.chat-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.82rem;
    gap: 1rem;
}

.chat-summary-label {
    color: var(--text-dark-muted, #71717a);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.chat-summary-value {
    color: var(--text-dark, #111111);
    font-weight: 600;
    text-align: right;
}

/* Botão Final de WhatsApp no Chat */
.chat-whatsapp-cta {
    margin-top: 1.15rem;
    background: var(--text-dark, #111111);
    color: #ffffff;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    padding: 0.85rem 1.25rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.chat-whatsapp-cta:hover {
    background: #000000;
    transform: translateY(-1px);
}

.chat-whatsapp-cta:focus-visible {
    outline: 2px solid var(--text-dark, #111111);
    outline-offset: 3px;
}

/* Topo Mobile oculto na versão desktop / telas > 768px */
.chat-mobile-header {
    display: none;
}

/* Responsividade Mobile Intermediária (Tablets 769px - 900px) */
@media (max-width: 900px) and (min-width: 769px) {
    .chat-container {
        height: 520px;
        max-height: 75vh;
        border-radius: 12px;
    }
    
    .chat-messages {
        padding: 0.5rem 1rem 1rem;
    }
    
    .chat-options-container {
        padding: 0.5rem 1rem 0.75rem;
    }

    .chat-input-wrapper {
        padding: 0.75rem 1rem 1rem;
    }

    .chat-msg-row.system {
        max-width: 94%;
    }
    
    .chat-msg-row.user {
        max-width: 90%;
    }
}

/* ==========================================================================
   EXPERIÊNCIA CONVERSACIONAL MOBILE MSA CODE (ESTILO WHATSAPP <= 768px)
   Totalmente imersiva, tela cheia (100dvh), scroll travado no body,
   input colado ao teclado e preservação absoluta da versão desktop.
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Trava geral do documento e viewport do navegador */
    html,
    body.page-contato {
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        min-height: 100% !important;
        max-height: 100% !important;
        overflow: hidden !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: var(--bg-light, #F1F0EC) !important;
        overscroll-behavior: none !important;
        -webkit-overflow-scrolling: auto !important;
    }

    /* 2. Remoção completa de elementos que não fazem parte do bate-papo */
    .page-contato .navbar,
    .page-contato .mobile-menu-overlay,
    .page-contato .contact-info,
    .page-contato .footer,
    .page-contato .chat-header {
        display: none !important;
    }

    /* 3. Adaptação dos containers ancestrais para 100% da viewport */
    .page-contato main {
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .page-contato .contact-section {
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        min-height: 0 !important;
        max-height: none !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: stretch !important;
        align-items: stretch !important;
        overflow: hidden !important;
        background: var(--bg-light, #F1F0EC) !important;
    }

    .page-contato .contact-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0 !important;
        overflow: hidden !important;
    }

    .page-contato .contact-assistant-wrapper {
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        flex: 1 1 100% !important;
        display: flex !important;
        flex-direction: column !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    /* 4. Caixa de conversa estilo WhatsApp em tela cheia */
    .page-contato .chat-container {
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        max-height: none !important;
        min-height: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
        background: var(--bg-light, #F1F0EC) !important;
        overflow: hidden !important;
    }

    /* 5. Cabeçalho Superior WhatsApp / Atendimento Oficial MSA Code */
    .chat-mobile-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        background: #ffffff !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.07) !important;
        padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.85rem 0.6rem 0.85rem !important;
        min-height: 56px !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
        z-index: 20 !important;
    }

    .chat-mobile-header-left {
        display: flex !important;
        align-items: center !important;
        gap: 0.65rem !important;
    }

    .chat-mobile-home-btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        color: var(--text-dark, #111111) !important;
        text-decoration: none !important;
        transition: background-color 0.15s ease !important;
        flex-shrink: 0 !important;
    }

    .chat-mobile-home-btn:active {
        background: rgba(0, 0, 0, 0.06) !important;
    }

    .chat-mobile-avatar {
        width: 40px !important;
        height: 40px !important;
        border-radius: 50% !important;
        background: #0066FF !important; /* Fundo azul com o logo da MSA Code */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        overflow: hidden !important;
        padding: 6px !important;
        box-sizing: border-box !important;
    }

    .chat-mobile-avatar-img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        display: block !important;
    }

    .chat-mobile-profile-info {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }

    .chat-mobile-name {
        font-family: var(--font-body) !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        color: var(--text-dark, #111111) !important;
        letter-spacing: -0.01em !important;
        line-height: 1.2 !important;
    }

    .chat-mobile-header-right {
        display: flex !important;
        align-items: center !important;
    }

    .chat-mobile-undo-btn {
        background: none !important;
        border: none !important;
        color: var(--text-dark-muted, #71717a) !important;
        font-family: var(--font-body) !important;
        font-size: 0.78rem !important;
        font-weight: 500 !important;
        padding: 0.35rem 0.65rem !important;
        border-radius: 6px !important;
        cursor: pointer !important;
        transition: background-color 0.15s ease, color 0.15s ease !important;
    }

    .chat-mobile-undo-btn:active {
        background: rgba(0, 0, 0, 0.05) !important;
        color: var(--text-dark, #111111) !important;
    }

    /* 6. Fluxo de Mensagens Central e Scroll Exclusivo */
    .page-contato .chat-messages {
        flex: 1 1 auto !important;
        height: auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 1rem 0.85rem !important;
        gap: 1rem !important;
        background: var(--bg-light, #F1F0EC) !important;
    }

    .chat-msg-row.system {
        max-width: 90% !important;
    }

    .chat-msg-row.user {
        max-width: 88% !important;
    }

    .chat-bubble.system {
        font-size: 0.95rem !important;
        line-height: 1.55 !important;
        padding: 0.85rem 1.05rem !important;
        border-radius: 14px !important;
        border-bottom-left-radius: 4px !important;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
    }

    .chat-bubble.user {
        font-size: 0.95rem !important;
        line-height: 1.5 !important;
        padding: 0.85rem 1.05rem !important;
        border-radius: 14px !important;
        border-bottom-right-radius: 4px !important;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06) !important;
    }

    /* Opções Clicáveis no Mobile */
    .chat-options-row,
    .chat-inline-options {
        max-width: 92% !important;
        gap: 0.5rem !important;
    }

    .chat-chip-option {
        font-size: 0.9rem !important;
        padding: 0.75rem 1.15rem !important;
        border-radius: 12px !important;
        width: fit-content !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    /* 7. Barra Inferior de Digitação (Fixada, Responsiva e Segura) */
    .page-contato .chat-input-wrapper {
        flex-shrink: 0 !important;
        background: #ffffff !important;
        border-top: 1px solid rgba(0, 0, 0, 0.07) !important;
        padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom, 0px)) 0.75rem !important;
        box-sizing: border-box !important;
        z-index: 20 !important;
    }

    .page-contato .chat-form {
        display: flex !important;
        align-items: center !important;
        gap: 0.45rem !important;
        background: #F4F3EF !important;
        border: none !important;
        outline: none !important;
        border-radius: 24px !important;
        padding: 0.35rem 0.4rem 0.35rem 1.05rem !important;
        box-shadow: none !important;
    }

    .page-contato .chat-form:focus-within {
        box-shadow: none !important;
        outline: none !important;
        border: none !important;
        background: #F4F3EF !important;
    }

    .page-contato .chat-input-field {
        flex: 1 !important;
        font-size: 16px !important; /* Impede zoom automático do iOS Safari ao focar */
        line-height: 1.35 !important;
        padding: 0.5rem 0 !important;
        color: var(--text-dark, #111111) !important;
        border: none !important;
        outline: none !important;
        box-shadow: none !important;
        background: transparent !important;
        -webkit-appearance: none !important;
    }

    .page-contato .chat-input-field:focus {
        outline: none !important;
        border: none !important;
        box-shadow: none !important;
    }

    .page-contato .chat-send-btn {
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        flex-shrink: 0 !important;
    }
}
