/**
 * Mobile Responsive Styles for Chat Widget
 * 
 * @package WooCommerce_Live_Chat_JSON
 * @since 1.0.0
 */

/* ==========================================================================
   Mobile Responsive Improvements
   ========================================================================== */

/* Mobile breakpoints */
@media (max-width: 768px) {
    /* Chat button positioning */
    .wlc-chat-button {
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
    }
    
    /* Chat window mobile optimization */
    .wlc-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height - không bao gồm thanh địa chỉ */
        max-width: none;
        max-height: none;
        border-radius: 0;
        z-index: 999999;
    }
    
    /* Chat header mobile */
    .wlc-chat-header {
        padding: 15px;
        border-radius: 0;
    }
    
    .wlc-chat-header h3 {
        font-size: 18px;
    }
    
    /* Chat messages mobile */
    .wlc-chat-messages {
        height: 83vh;
        height: 83dvh; /* Dynamic viewport height */
        padding: 10px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    /* Message bubbles mobile */
    .wlc-message {
        margin-bottom: 12px;
    }
    
    .wlc-message-bubble {
        max-width: 85%;
        padding: 10px 12px;
        font-size: 14px;
        line-height: 1.4;
    }
    
    /* Chat input mobile */
    .wlc-chat-input {
        padding: 15px;
        border-radius: 0;
        position: sticky;
        bottom: 0;
        background: #2c2c2c;
        z-index: 10;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }
    
    .wlc-message-textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 12px !important;
        min-height: 44px !important; /* Touch-friendly */
        max-height: 100px !important;
    }
    
    .wlc-send-btn {
        padding: 12px 20px;
        font-size: 14px;
        min-height: 44px;
    }
    
    /* Welcome screen mobile */
    .wlc-welcome-screen {
        padding: 20px;
    }
    
    .wlc-welcome-screen h3 {
        font-size: 20px;
        margin-bottom: 15px;
    }
    
    .wlc-welcome-screen p {
        font-size: 14px;
        margin-bottom: 20px;
    }
    
    .wlc-welcome-form {
        gap: 15px;
    }
    
    .wlc-welcome-form input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px;
        min-height: 44px;
    }
    
    .wlc-welcome-form button {
        padding: 12px 20px;
        font-size: 14px;
        min-height: 44px;
    }
    
    /* Close button mobile */
    .wlc-close-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    /* Minimize button mobile */
    .wlc-minimize-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .wlc-chat-button {
        width: 56px;
        height: 56px;
        /* bottom: 16px; */
        right: -20px !important;
    }
    
    .wlc-chat-window {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
    }
    
    .wlc-chat-header {
        padding: 12px;
        flex-shrink: 0;
    }
    
    .wlc-chat-header h3 {
        font-size: 16px;
    }
    
    .wlc-chat-messages {
        height: 80vh;
        height: 80dvh; /* Dynamic viewport height */
        padding: 8px;
        flex: 1;
    }
    
    .wlc-message-bubble {
        max-width: 90%;
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .wlc-chat-input {
        padding: 12px;
        position: sticky;
        bottom: 0;
        flex-shrink: 0;
    }
    
    .wlc-welcome-screen {
        padding: 15px;
    }
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
    .wlc-chat-window {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
    }
    
    .wlc-chat-messages {
        height: calc(100vh - 120px);
        height: calc(100dvh - 120px); /* Dynamic viewport height */
    }
    
    .wlc-chat-input {
        padding: 10px 15px;
    }
}

/* Prevent iOS Safari zoom and address bar issues */
@media (max-width: 768px) {
    /* Ensure body doesn't scroll when chat is open */
    body.wlc-chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }
    
    /* Fix for iOS safe area */
    @supports (padding: max(0px)) {
        .wlc-chat-input {
            padding-bottom: max(15px, env(safe-area-inset-bottom));
        }
    }
}

/* ==========================================================================
   Chat State Management
   ========================================================================== */

/* Hidden chat state */
.wlc-chat-hidden .wlc-chat-window {
    display: none !important;
}

.wlc-chat-hidden .wlc-chat-button {
    /* display: block !important; */
}

/* Show chat button when window is hidden */
.wlc-chat-hidden .wlc-chat-button {
    animation: wlc-pulse 2s infinite;
}

@keyframes wlc-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(35, 123, 20, 0.7);
    }
    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(35, 123, 20, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(35, 123, 20, 0);
    }
}
