/**
 * iOS-only fixes (Safari + WebView).
 * Applies only under html.xam-ios — does not change Android / desktop rules.
 *
 * Safari keyboard rule: shell height = visualViewport, composer bottom:0.
 * Never combine shrunk --app-height with --composer-keyboard-inset (input flies to top).
 */

/* —— Shell: stop rubber-band page scroll fighting fixed UI —— */
html.xam-ios.force-mobile-ui,
html.xam-ios.force-mobile-ui body {
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* iOS Safari: pin shell to visualViewport (same idea as embedded WebView) */
html.xam-ios-safari.force-mobile-ui,
html.xam-ios-safari.force-mobile-ui body {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: var(--app-top, 0px) !important;
    width: 100% !important;
    height: var(--app-height, 100dvh) !important;
    max-height: var(--app-height, 100dvh) !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

html.xam-ios-safari.force-mobile-ui .messenger-container,
html.xam-ios-safari.force-mobile-ui .screen,
html.xam-ios-safari.force-mobile-ui .chat-area,
html.xam-ios-safari.force-mobile-ui .chat-view,
html.xam-ios-safari.force-mobile-ui #auth-screen.active {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
}

/* —— Composer sits on the bottom of the vv-sized shell (NOT lifted again) —— */
@media (max-width: 768px) {
    html.xam-ios-safari .message-input-container,
    html.xam-ios-safari .message-input-container.keyboard-open,
    html.xam-ios-safari .message-input-container.composer-focused,
    html.xam-ios-safari .message-input-container.keyboard-closing {
        bottom: 0 !important;
        padding-bottom: var(--xam-safe-bottom, env(safe-area-inset-bottom, 0px)) !important;
        transition: none !important;
    }

    html.xam-ios-safari.xam-ios-kb-open .message-input-container,
    html.xam-ios-safari body.composer-keyboard-open .message-input-container {
        /* Keyboard open: home indicator is behind IME — no extra pad */
        padding-bottom: 0 !important;
        bottom: 0 !important;
    }

    html.xam-ios .message-input-container.keyboard-open .message-input,
    html.xam-ios .message-input-container.composer-focused .message-input {
        font-size: 16px !important; /* prevent iOS focus zoom */
    }

    html.xam-ios-safari.xam-ios-kb-open .messages-container,
    html.xam-ios-safari body.composer-keyboard-open .messages-container {
        padding-bottom: calc(var(--mobile-composer-inset, 68px) + 8px) !important;
    }

    /* Keep top chrome inside the vv shell */
    html.xam-ios-safari #chat-top-overlay.mobile-top-nick-pill-wrap,
    html.xam-ios-safari #chat-top-overlay {
        position: fixed !important;
        top: calc(8px + env(safe-area-inset-top, 0px)) !important;
        left: 0 !important;
        right: 0 !important;
    }
}

/* —— Hide desktop-only chrome that iOS sometimes still shows (hover:hover quirk) —— */
html.xam-ios.force-mobile-ui .sidebar-pc-resize-gutter,
html.xam-ios.force-mobile-ui #sidebar-pc-resize-gutter {
    display: none !important;
}

html.xam-ios body.layout-mobile-phone .message:not(.message--media-card):not(.system-message) .message-hover-actions {
    display: none !important;
}

html.xam-ios body.layout-mobile-phone .message:not(.message--media-card):not(.system-message) {
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* —— Inputs / taps —— */
html.xam-ios input,
html.xam-ios textarea,
html.xam-ios select,
html.xam-ios .message-input {
    -webkit-appearance: none;
    appearance: none;
}

html.xam-ios button,
html.xam-ios a,
html.xam-ios .chat-item,
html.xam-ios .message {
    -webkit-tap-highlight-color: transparent;
}

/* —— Scroll areas —— */
html.xam-ios .messages-container,
html.xam-ios .chats-list,
html.xam-ios .chats-drum-viewport,
html.xam-ios .modal-content,
html.xam-ios .personalization-settings,
html.xam-ios .settings-content {
    -webkit-overflow-scrolling: touch;
}

html.xam-ios .xam-confirm-sheet-panel,
html.xam-ios .privacy-consent-sheet-panel {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
}

html.xam-ios #auth-screen.active {
    min-height: var(--app-height, 100dvh) !important;
}

html.xam-ios.force-mobile-ui body.xam-liquid-glass-enabled .message-input-container .message-input-pill,
html.xam-ios.force-mobile-ui body.xam-liquid-glass-enabled .message-input-container .input-attach-buttons,
html.xam-ios.force-mobile-ui body.xam-liquid-glass-enabled .message-input-container .voice-send-slot .btn-voice:not(.recording):not(.is-recording-active),
html.xam-ios.force-mobile-ui body.xam-liquid-glass-enabled .message-input-container .voice-send-slot .btn-send {
    -webkit-backdrop-filter: blur(14px) saturate(140%) !important;
    backdrop-filter: blur(14px) saturate(140%) !important;
}
