/**
 * Mobile Keyboard CSS - Solução Otimizada
 * Adaptação responsiva para teclado virtual
 */

/* ==================== ESTADOS DO TECLADO ==================== */

/* Estado normal */
body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Estado quando teclado está aberto */
body.keyboard-open {
    overflow: hidden;
}

body.keyboard-open .whatsapp-container {
    height: 100dvh;
    max-height: 100dvh;
}

body.keyboard-open .chat {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 120px;
}

body.keyboard-open .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--whatsapp-white, #FFFFFF);
    border-top: 1px solid var(--whatsapp-gray, #E5DDD5);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

body.keyboard-open .quick-replies {
    position: fixed;
    bottom: 66px;
    left: 0;
    right: 0;
    z-index: 999;
    background: var(--whatsapp-white, #FFFFFF);
    border-top: 1px solid var(--whatsapp-gray, #E5DDD5);
}

/* ==================== MOBILE ESPECÍFICO ==================== */

@media (max-width: 768px) {
    html {
        overflow: hidden;
        height: 100%;
    }
    
    body {
        overflow: hidden;
        height: 100%;
        position: fixed;
        width: 100%;
    }
    
    .whatsapp-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
    }
    
    .chat {
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
        /* Adicionar espaço no final do chat para visualização */
        padding-bottom: 100px;
    }
    
    /* Input area sempre visível */
    .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        position: relative;
        z-index: 1000;
    }
    
    /* Prevenir zoom no iOS */
    .input-field,
    .date-input {
        font-size: 16px !important;
    }
    
    /* Otimizar touch */
    .quick-reply,
    .send-btn,
    .flavor-option,
    .flavor-confirm-btn,
    .date-confirm-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* ==================== IOS ESPECÍFICO ==================== */

@supports (-webkit-touch-callout: none) {
    html,
    body {
        height: -webkit-fill-available;
    }
    
    .whatsapp-container {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
    
    .input-field {
        font-size: 16px !important;
    }
    
    /* Prevenir bounce scroll indesejado */
    body {
        overscroll-behavior-y: none;
    }
}

/* ==================== ANDROID ESPECÍFICO ==================== */

@supports not (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .chat {
            /* Android geralmente tem melhor suporte para dvh */
            max-height: calc(100dvh - 140px);
        }
    }
}

/* ==================== LANDSCAPE MODE MOBILE ==================== */

@media (max-width: 768px) and (orientation: landscape) {
    .chat {
        padding-bottom: 80px;
    }
    
    body.keyboard-open .chat {
        padding-bottom: 100px;
    }
    
    body.keyboard-open .quick-replies {
        bottom: 58px;
    }
}

/* ==================== OTIMIZAÇÃO DE PERFORMANCE ==================== */

/* Melhorar performance de scroll */
.chat,
.quick-replies {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Smooth scrolling melhorado */
@media (prefers-reduced-motion: no-preference) {
    .chat {
        scroll-behavior: smooth;
    }
}

/* ==================== CORREÇÃO DE BUGS MOBILE ==================== */

/* Prevenir overflow horizontal */
.whatsapp-container,
.chat,
.input-area,
.quick-replies {
    max-width: 100vw;
}

/* Garantir que elementos não ultrapassem os limites */
.message-content,
.flavor-selector,
.date-picker {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
