/* ==========================================================================
   Mobile Chat Widget Enhancements
   - Full-screen overlay on mobile
   - Keyboard handling with visualViewport API
   - Auto-scroll improvements
   - Large close button
   - Horizontal scrollable suggestion chips
   ========================================================================== */

/* --------------------------------------------------------------------------
   Full-screen overlay on mobile (< 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        z-index: 99999;
        pointer-events: none;
    }

    .chat-toggle {
        pointer-events: auto;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        pointer-events: auto;
    }

    .chat-window.open {
        display: flex;
        animation: mobileChatSlideUp 0.3s ease-out;
    }

    @keyframes mobileChatSlideUp {
        from {
            transform: translateY(100%);
            opacity: 0.5;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* --------------------------------------------------------------------------
   Large close button for mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-close {
        width: 44px;
        height: 44px;
        font-size: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        border-radius: 8px;
        transition: background 0.2s;
    }

    .chat-close:active {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* --------------------------------------------------------------------------
   Chat header safe area adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
        min-height: 56px;
    }
}

/* --------------------------------------------------------------------------
   Messages container - keyboard-aware height
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scroll-behavior: smooth;
    }

    /* When keyboard is open, the container will be resized by JS */
    .chat-body {
        flex: 1;
        min-height: 0;
    }

    .chat-message {
        max-width: 85%;
        word-break: break-word;
    }
}

/* --------------------------------------------------------------------------
   Input area - keyboard safe
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        gap: 8px;
        flex-shrink: 0;
        background: white;
        border-top: 1px solid #eee;
    }

    /* Keep input area visible above keyboard */
    .chat-input-area.keyboard-open {
        position: relative;
        z-index: 10;
    }

    .chat-input {
        font-size: 16px; /* Prevents iOS zoom */
        padding: 10px 14px;
        min-height: 44px;
        border-radius: 22px;
    }

    .chat-send {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }
}

/* --------------------------------------------------------------------------
   Suggestion chips - horizontal scroll
   -------------------------------------------------------------------------- */
.chat-suggestion-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px 16px;
    scroll-snap-type: x mandatory;
    flex-shrink: 0;
}

.chat-suggestion-chips::-webkit-scrollbar {
    display: none;
}

.chat-suggestion-chip {
    flex-shrink: 0;
    scroll-snap-align: start;
    padding: 8px 16px;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    background: white;
    color: #333;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 36px;
    display: flex;
    align-items: center;
}

.chat-suggestion-chip:hover,
.chat-suggestion-chip:active {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

@media (max-width: 768px) {
    .chat-suggestion-chips {
        padding: 8px 12px;
    }

    .chat-suggestion-chip {
        min-height: 40px;
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* --------------------------------------------------------------------------
   Live agent area on mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-live-agent {
        padding: 8px 12px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .live-agent-btn {
        min-height: 44px;
        font-size: 15px;
    }

    .agent-option-btn {
        min-height: 48px;
        padding: 12px 14px;
    }
}

/* --------------------------------------------------------------------------
   Itinerary panel mobile adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .itinerary-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }

    .itinerary-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .itinerary-back {
        min-height: 44px;
        padding: 8px 12px;
        display: flex;
        align-items: center;
    }

    .itinerary-footer {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .itinerary-item-remove {
        min-width: 44px;
        min-height: 44px;
    }
}

/* --------------------------------------------------------------------------
   Toast positioning on mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .chat-toast {
        left: 16px;
        right: 16px;
        bottom: auto;
        top: max(80px, calc(env(safe-area-inset-top) + 60px));
        text-align: center;
        border-radius: 12px;
    }
}

/* --------------------------------------------------------------------------
   Prevent body scroll when chat is open on mobile
   -------------------------------------------------------------------------- */
body.chat-open-mobile {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}
