/* 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 {
    /* ===== TEMA CLARO WHATSAPP ===== */
    --wa-header-bg: #075e54;          /* Verde escuro do header WhatsApp */
    --wa-header-title: #ffffff;
    --wa-header-status: #d4f1e8;

    --wa-body-bg: #efeae2;            /* Bege claro clássico do WhatsApp */
    --wa-body-pattern-opacity: 0.55;

    --wa-incoming-bg: #ffffff;        /* Balão branco (incoming) */
    --wa-outgoing-bg: #d9fdd3;        /* Balão verde claro (outgoing) */

    --wa-text-primary: #111b21;       /* Texto principal - quase preto */
    --wa-text-secondary: #667781;
    --wa-time-color: #667781;
    --wa-blue-check: #53bdeb;

    --wa-system-bg: #d9f2e6;
    --wa-system-text: #075e54;

    /* Botões Rápidos e Inputs */
    --wa-btn-bg: #ffffff;
    --wa-btn-border: #ccd0d5;
    --wa-btn-hover: #f0f2f5;
    --wa-accent-green: #128c7e;
    --wa-accent-green-dark: #075e54;

    --wa-input-bg: #ffffff;
    --wa-input-text: #111b21;         /* Texto digitado - escuro e legível */
    --wa-input-placeholder: #8696a0;

    --wa-footer-bg: #f0f2f5;          /* Fundo do footer claro */

    /* Sombras e Bordas */
    --shadow-header: 0 2px 4px rgba(0, 0, 0, 0.18);
    --shadow-bubble: 0 1px 2px rgba(11, 20, 26, 0.13);
    --shadow-input: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-btn: 0 1px 2px rgba(11, 20, 26, 0.1);

    /* Visual viewport height */
    --vvh: 100dvh;
}

/* =============================================
   LAYOUT BASE – corrige bug do teclado mobile
   ============================================= */
html {
    height: 100%;
    overflow: hidden; /* evita que o teclado empurre a página */
}

body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #128c7e;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--wa-text-primary);
}

/* Wrapper principal */
.app-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Container do chat – flex column que ocupa toda a altura disponível */
.chat-container {
    width: 100%;
    max-width: 480px;
    height: 100%;
    background: var(--wa-body-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    border-radius: 16px;
    overflow: hidden;
}

/* Mobile: ocupa 100% da tela */
@media (max-width: 480px) {
    .chat-container {
        max-width: 100%;
        border-radius: 0;
        height: 100svh; /* small viewport height – exclui barra do browser */
    }
    body {
        background: var(--wa-body-bg);
    }
}

/* =============================================
   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;
    flex-shrink: 0; /* nunca encolhe */
}

.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.15);
}

.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: #4ade80;
    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: 200px;
    color: var(--wa-header-title);
}

.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);
}

/* =============================================
   CORPO DAS MENSAGENS
   flex: 1 + min-height: 0 é o segredo para scroll funcionar dentro de flex
   ============================================= */
.chat-body {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px 16px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Fundo com padrão de bolinhas do WhatsApp */
.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='%23a0a0a0' fill-opacity='0.07'%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: 0;
    pointer-events: none;
}

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

/* Scrollbar fina */
.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.18); border-radius: 4px; }

/* =============================================
   BALÕES DE SISTEMA E DATA
   ============================================= */
.system-message {
    align-self: center;
    background-color: var(--wa-system-bg);
    color: var(--wa-system-text);
    font-size: 11.5px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    max-width: 92%;
    margin-bottom: 6px;
}

.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 12px;
    border-radius: 6px;
    box-shadow: var(--shadow-bubble);
    margin: 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* =============================================
   BALÕES DE MENSAGEM
   ============================================= */
.message-bubble {
    max-width: 85%;
    padding: 7px 12px 5px 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.22s cubic-bezier(0.1, 0.8, 0.25, 1) forwards;
    transform-origin: left bottom;
    color: var(--wa-text-primary);
}

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

.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;
}

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

.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;
}

/* Meta da mensagem (hora + checks) */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    color: var(--wa-time-color);
    margin-top: 3px;
    text-align: right;
    float: right;
    margin-left: 10px;
}

.message-bubble.outgoing .message-meta {
    color: #5b9a72;
}

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

/* =============================================
   INDICADOR DE DIGITAÇÃO
   ============================================= */
.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: 4px;
    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; }

/* =============================================
   FOOTER – NÃO É FIXED, fica no fim do flex column
   Isso evita o bug do teclado subindo o conteúdo
   ============================================= */
.chat-footer {
    position: relative;
    width: 100%;
    background: var(--wa-footer-bg);
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-sizing: border-box;
    border-top: 1px solid #d1d7db;
    flex-shrink: 0;
}

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

.quick-reply-btn {
    background-color: var(--wa-btn-bg);
    color: var(--wa-accent-green);
    border: 1.5px solid #ccd0d5;
    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.18s ease-in-out;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideUpFade 0.28s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
    -webkit-tap-highlight-color: transparent;
}

.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,
.quick-reply-btn:focus {
    background-color: #f0faf8;
    border-color: var(--wa-accent-green);
    transform: translateY(-1px);
}

.quick-reply-btn:active {
    transform: translateY(0);
    background-color: #e4f5f2;
}

/* =============================================
   INPUT BAR
   ============================================= */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    animation: slideUpFade 0.22s 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: #8696a0;
    font-size: 22px;
    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.06);
}

.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 #d1d7db;
}

/* Input de texto – cor escura e legível */
.input-wrapper input {
    width: 100%;
    height: 40px;
    border: none;
    outline: none;
    font-size: 16px;       /* 16px evita zoom automático no iOS */
    color: #111b21;        /* texto escuro, sempre legível */
    background: transparent;
    caret-color: var(--wa-accent-green);
}

.input-wrapper input::placeholder {
    color: #8696a0;
}

/* Botão de Enviar */
.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: 0 2px 6px rgba(18, 140, 126, 0.4);
    transition: all 0.2s ease-in-out;
    flex-shrink: 0;
}

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

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

.send-btn i {
    font-size: 16px;
    margin-left: 2px;
}

/* =============================================
   CTA FINAL WHATSAPP
   ============================================= */
.final-cta-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 8px 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 14px rgba(37, 211, 102, 0.4);
    text-decoration: none;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulseGlow 2.2s infinite;
}

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

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

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

/* =============================================
   UTILITÁRIOS
   ============================================= */
.hidden {
    display: none !important;
}

input[type="text"],
input[type="tel"] {
    -webkit-appearance: none;
    appearance: none;
}

/* =============================================
   ANIMAÇÕES
   ============================================= */
@keyframes slideUpFade {
    0%   { opacity: 0; transform: translateY(14px) scale(0.97); }
    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.55); 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); }
}
