/* ==============================================
   MOBILE CHAT - KEYBOARD-AWARE LAYOUT
   ==============================================

   Works with: interactive-widget=resizes-content in viewport meta tag.
   Uses 100dvh (dynamic viewport height) which tracks URL bar changes.
   ============================================== */

/* ==============================================
   MOBILE CHAT CONTAINER
   ============================================== */
.chat-mobile-container {
    /* Use inset: 0 with position: fixed - tracks visual viewport natively */
    position: fixed !important;
    top: 0px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 999 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #ffffff !important;
    overflow: hidden !important;
}

/* White backdrop that covers everything behind the chat */
.chat-mobile-container::before {
    content: '';
    position: fixed;
    top: -100px;
    left: -100px;
    right: -100px;
    bottom: -100px;
    background: #ffffff;
    z-index: -1;
}

/* ==============================================
   MOBILE HEADER - Fixed height
   ============================================== */
.chat-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    height: 48px;
    min-height: 48px;
    flex-shrink: 0;
    background: var(--mud-palette-surface, #fff);
    border-bottom: 1px solid var(--mud-palette-lines-default, #e0e0e0);
    padding-top: max(8px, env(safe-area-inset-top));
    
}

.chat-mobile-header-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0 8px;
    font-weight: 500;
}

/* ==============================================
   MOBILE MESSAGES - Flexible, scrollable
   ============================================== */
.chat-mobile-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Contain scroll - prevents triggering URL bar and pull-to-refresh */
    overscroll-behavior: contain;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Smooth scrolling */
    scroll-behavior: smooth;
}

/* ==============================================
   MOBILE INPUT - Fixed at bottom
   ============================================== */
.chat-mobile-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px;
    /* Add extra padding at bottom to fill gap to screen edge */
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    min-height: 56px;
    flex-shrink: 0;
    background: #ffffff;
    /* Remove border-top shadow - use a subtle line instead */
    border-top: 1px solid #e0e0e0;
    box-shadow: none;
}

.chat-mobile-textarea {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
    padding: 10px 14px;
    border: 1px solid var(--mud-palette-lines-default, #e0e0e0);
    border-radius: 20px;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    background: var(--mud-palette-background, #f5f5f5);
    color: var(--mud-palette-text-primary, #333);
}

.chat-mobile-textarea:focus {
    border-color: var(--mud-palette-primary, #1976d2);
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

.chat-mobile-textarea:disabled {
    opacity: 0.6;
    background: var(--mud-palette-background-grey, #eee);
}

.chat-mobile-textarea::placeholder {
    color: var(--mud-palette-text-secondary, #666);
}

/* ==============================================
   MOBILE WELCOME SCREEN
   ============================================== */
.chat-mobile-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    /* Prevent scroll on welcome screen */
    overflow: hidden;
}

/* ==============================================
   DIALOG OVERRIDES FOR MOBILE
   ============================================== */
@media (max-width: 600px) {
    /* Hide the bottom footer app bar on mobile */
    .mud-appbar[style*="bottom"],
    .mud-appbar-bottom,
    footer,
    .footer {
        display: none !important;
    }

    /* Use 100dvh for dynamic viewport that tracks URL bar changes */
    .mud-dialog-fullscreen {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        max-height: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        background: var(--mud-palette-surface, #fff) !important;
    }

    .mud-dialog-fullscreen .mud-dialog-content {
        padding: 0 !important;
        overflow: hidden !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .mud-dialog-fullscreen .mud-dialog-title,
    .mud-dialog-fullscreen .mud-dialog-actions {
        display: none !important;
    }

    .chat-dialog-container {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: 100dvh !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    /* Prevent body scroll when chat dialog is open */
    body.mud-dialog-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100dvh !important;
    }

    /* Chat dialog overlay - SCOPED to only affect dialogs containing chat.
       DO NOT use global .mud-overlay styling as it breaks date pickers
       and other MudBlazor popover components on the rest of the site! */
    .mud-dialog-container:has(.chat-dialog-container) .mud-overlay,
    .mud-dialog-container:has(.chat-dialog-container) .mud-overlay-dark {
        background: #ffffff !important;
        background-color: #ffffff !important;
        height: 110dvh !important;
        opacity: 1 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* Drawer - contain scroll within drawer */
    .mud-drawer-content {
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch !important;
    }
}
