/* Reset e Estilos Globais */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* WhatsApp Paleta de Cores Realista */
    --wa-header-bg: #008069;
    --wa-header-title: #ffffff;
    --wa-header-status: #d1f4ec;
    --wa-body-bg: #efeae2;
    --wa-body-pattern-opacity: 0.4;
    --wa-incoming-bg: #ffffff;
    --wa-outgoing-bg: #d9fdd3;
    --wa-text-primary: #111b21;
    --wa-text-secondary: #667781;
    --wa-time-color: #8696a0;
    --wa-blue-check: #53bdeb;
    --wa-system-bg: #ffeecd;
    --wa-system-text: #111b21;
    
    /* Botões Rápidos e Inputs */
    --wa-btn-bg: #ffffff;
    --wa-btn-border: #e9edef;
    --wa-btn-hover: #f0f2f5;
    --wa-accent-green: #00a884;
    --wa-accent-green-dark: #008f72;
    --wa-input-bg: #ffffff;
    --wa-input-placeholder: #8696a0;
    
    /* Sombras e Bordas */
    --shadow-header: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-bubble: 0 1px 1.5px rgba(11, 20, 26, 0.13);
    --shadow-input: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-btn: 0 1px 2px rgba(11, 20, 26, 0.08);
    
    --keyboard-height: 0px;
    /* Footer & Header heights for calculations */
    --header-height: 64px;
    --footer-height: 70px;
    /* Visual viewport height */
    --vvh: 100dvh;
}

html, body {
    width: 100%;
    height: var(--vvh);
    margin: 0;
    padding: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

body {
    background: #111b21; /* Fundo escuro para destacar o celular em desktops */
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--wa-text-primary);
    overflow: hidden;
}

/* Wrapper principal: limita a largura no Desktop e fica tela cheia no Mobile */
.app-wrapper {
    width: 100%;
    height: var(--vvh);
    display: flex;
    justify-content: center;
    align-items: center;
}

.chat-container {
    width: 100%;
    max-width: 480px;
    height: calc(var(--vvh) - var(--header-height) - var(--footer-height) - var(--keyboard-height, 0));
    background: var(--wa-body-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    overflow: hidden;
    padding-bottom: var(--footer-height);
}

/* Ajuste para telas menores ou Mobile nativo */
@media (max-width: 480px) {
    .chat-container {
        max-width: 100%;
        height: 100vh;
        height: var(--vvh, 100dvh);
        max-height: 100vh;
        max-height: var(--vvh, 100dvh);
        border-radius: 0;
    }
    body {
        background: var(--wa-body-bg);
    }
}

/* Cabeçalho do Chat (Header) */
.chat-header {
    height: 64px;
    background: var(--wa-header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    color: var(--wa-header-title);
    box-shadow: var(--shadow-header);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.back-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.back-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.avatar-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid rgba(255, 255, 255, 0.7);
}

.online-indicator-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background-color: var(--wa-green);
    border: 1.5px solid var(--wa-header-bg);
    border-radius: 50%;
}

.contact-info {
    display: flex;
    flex-direction: column;
}

.contact-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.contact-status {
    font-size: 12px;
    color: var(--wa-header-status);
    font-weight: 300;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-right: 4px;
}

.header-icon-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 16px;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.header-icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Área de Mensagens (Corpo) */
.chat-body {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

/* Wallpaper do WhatsApp usando padrão SVG inline sutil */
.chat-background-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--wa-body-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='%239C92AC' fill-opacity='0.06'%3E%3Cpath fill-rule='evenodd' d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zM11 6c2.761 0 5-2.239 5-5s-2.239-5-5-5-5 2.239-5 5 2.239 5 5 5zm5 24c0 2.761-2.239 5-5 5s-5-2.239-5-5 2.239-5 5-5 5 2.239 5 5zm60 35c-2.761 0-5 2.239-5 5s2.239 5 5 5 5-2.239 5-5-2.239-5-5-5zm0-24c-2.761 0-5 2.239-5 5s2.239 5 5 5 5-2.239 5-5-2.239-5-5-5zm-38 8c0-2.761 2.239-5 5-5s5 2.239 5 5-2.239 5-5 5-5-2.239-5-5zm10-30c0-2.761 2.239-5 5-5s5 2.239 5 5-2.239 5-5 5-5-2.239-5-5zm-8 48c-2.761 0-5-2.239-5-5s2.239-5 5-5 5 2.239 5 5-2.239 5-5 5zm-28-8c-2.761 0-5-2.239-5-5s2.239-5 5-5 5 2.239 5 5-2.239 5-5 5zm6-38c-2.761 0-5-2.239-5-5s2.239-5 5-5 5 2.239 5 5-2.239 5-5 5z'/%3E%3C/g%3E%3C/svg%3E");
    opacity: var(--wa-body-pattern-opacity);
    z-index: 1;
    pointer-events: none;
}

.messages-log {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* Ocultar barra de rolagem mas permitir funcionalidade */
.chat-body::-webkit-scrollbar {
    width: 4px;
}
.chat-body::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.1);
    border-radius: 4px;
}

/* Balões de Criptografia e Data */
.system-message {
    align-self: center;
    background-color: var(--wa-system-bg);
    color: var(--wa-system-text);
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
    max-width: 90%;
    margin-bottom: 8px;
}

.system-message-text i {
    font-size: 9px;
    margin-right: 4px;
}

.date-badge {
    align-self: center;
    background-color: #ffffff;
    color: var(--wa-text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    box-shadow: var(--shadow-bubble);
    margin: 8px 0;
    text-transform: uppercase;
}

/* Estilos de Balões de Mensagem */
.message-bubble {
    max-width: 85%;
    padding: 8px 12px 6px 12px;
    border-radius: 8px;
    position: relative;
    font-size: 14.5px;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: var(--shadow-bubble);
    animation: slideUpFade 0.25s cubic-bezier(0.1, 0.8, 0.25, 1) forwards;
    transform-origin: left bottom;
}

/* Mensagem da Atendente (Incoming) */
.message-bubble.incoming {
    align-self: flex-start;
    background-color: var(--wa-incoming-bg);
    border-top-left-radius: 0;
    color: var(--wa-text-primary);
}

/* Triângulo lateral do balão esquerdo */
.message-bubble.incoming::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 10px 0;
    border-color: transparent var(--wa-incoming-bg) transparent transparent;
}

/* Mensagem do Usuário (Outgoing) */
.message-bubble.outgoing {
    align-self: flex-end;
    background-color: var(--wa-outgoing-bg);
    border-top-right-radius: 0;
    color: var(--wa-text-primary);
    transform-origin: right bottom;
}

/* Triângulo lateral do balão direito */
.message-bubble.outgoing::before {
    content: '';
    position: absolute;
    right: -8px;
    top: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 8px 0 0;
    border-color: var(--wa-outgoing-bg) transparent transparent transparent;
}

/* Informações internas do balão (Hora e Checks) */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    color: var(--wa-time-color);
    margin-top: 4px;
    text-align: right;
    float: right;
    margin-left: 10px;
}

.message-bubble.outgoing .message-meta {
    color: #5bb381; /* Cor esverdeada para o horário em balão verde */
}

.check-icon {
    font-size: 11px;
    color: var(--wa-blue-check);
}

/* Indicador de Digitação (Typing Indicator) */
.typing-bubble {
    align-self: flex-start;
    background-color: var(--wa-incoming-bg);
    border-radius: 8px;
    border-top-left-radius: 0;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: var(--shadow-bubble);
    position: relative;
    margin-bottom: 5px;
    animation: slideUpFade 0.2s ease-out forwards;
}

.typing-bubble::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 10px 0;
    border-color: transparent var(--wa-incoming-bg) transparent transparent;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #8696a0;
    border-radius: 50%;
    animation: bounceTyping 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Rodapé do Chat (Footer) */
.chat-footer {
    position: fixed;
    bottom: var(--keyboard-height, 0);
    left: 0;
    width: 100%;
    max-width: 480px;
    background: transparent;
    padding: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-sizing: border-box;
    /* Ajuste para safe‑area em iOS */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* Botões de Escolhas Rápidas */
.quick-replies {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    padding-bottom: 2px;
}

.quick-reply-btn {
    background-color: var(--wa-btn-bg);
    color: var(--wa-accent-green);
    border: 1px solid var(--wa-btn-border);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-btn);
    transition: all 0.2s ease-in-out;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideUpFade 0.3s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

.quick-reply-btn::after {
    content: '\f0da';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 12px;
    color: #a6b9bc;
    transition: transform 0.2s;
}

.quick-reply-btn:hover {
    background-color: var(--wa-btn-hover);
    border-color: var(--wa-accent-green);
    transform: translateY(-1px);
}

.quick-reply-btn:active {
    transform: translateY(0);
}

/* Formulário da Barra de Input */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    animation: slideUpFade 0.25s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

.input-actions-left,
.input-actions-right {
    display: flex;
    align-items: center;
}

.footer-icon-btn {
    background: none;
    border: none;
    color: var(--wa-text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.footer-icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.input-wrapper {
    flex: 1;
    background-color: var(--wa-input-bg);
    border-radius: 24px;
    padding: 2px 14px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-input);
    border: 1px solid var(--wa-btn-border);
}

.input-wrapper input {
    width: 100%;
    height: 38px;
    border: none;
    outline: none;
    font-size: 16px; /* Impede zoom automático do iOS e Chrome Mobile */
    color: var(--wa-text-primary);
}

.input-wrapper input::placeholder {
    color: var(--wa-input-placeholder);
}

/* Botão de Enviar (Círculo Verde do Whatsapp) */
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--wa-accent-green);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-btn);
    transition: all 0.2s ease-in-out;
}

.send-btn:hover {
    background-color: var(--wa-accent-green-dark);
    transform: scale(1.04);
}

.send-btn:active {
    transform: scale(0.96);
}

.send-btn i {
    font-size: 16px;
    /* Correção visual para centralizar o avião de papel */
    margin-left: 2px;
}

/* CTA de Conversão Final Especial */
.final-cta-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    animation: slideUpFade 0.4s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

.whatsapp-cta-btn {
    width: 100%;
    background-color: #25D366;
    color: #ffffff;
    border: none;
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.35);
    text-decoration: none;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulseGlow 2s infinite;
}

.whatsapp-cta-btn:hover {
    background-color: #20ba59;
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.45);
    transform: translateY(-2px);
}

.whatsapp-cta-btn:active {
    transform: translateY(1px);
}

.whatsapp-cta-btn i {
    font-size: 20px;
}

/* Classes utilitárias */
.hidden {
    display: none !important;
}

/* Animações */
@keyframes slideUpFade {
    0% {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bounceTyping {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6);
        transform: scale(1);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(37, 211, 102, 0);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0);
        transform: scale(1);
    }
}

/* Personalizações do Formulário em Dispositivos Móveis */
input[type="text"], input[type="tel"] {
    -webkit-appearance: none;
    appearance: none;
}
