/* StellarChat mobile layout pass.
   Loaded last. This file owns phone/APK layout only. */

:root {
    --mobile-top-gap: 30px;
    --mobile-nav-height: 82px;
    --mobile-bottom-buffer: 18px;
    --mobile-page-bottom: calc(var(--mobile-nav-height) + var(--mobile-bottom-buffer) + 22px);
}

@media (max-width: 900px) {
    html,
    body {
        width: 100%;
        min-height: 100dvh;
        overflow-x: hidden;
        background: var(--bg);
    }

    .app-shell {
        min-height: 100dvh;
        overflow: hidden;
    }

    .app-screen {
        min-height: 100dvh;
        padding: calc(var(--mobile-top-gap) + 14px) 16px var(--mobile-page-bottom) !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .screen-header {
        padding: 0 4px 20px !important;
    }

    .screen-header h1 {
        font-size: 32px;
        line-height: 1.05;
    }

    /* Floored app navigation. No floating island. */
    .bottom-nav {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        height: var(--mobile-nav-height) !important;
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        border-radius: 0 !important;
        border-left: 0 !important;
        border-right: 0 !important;
        border-bottom: 0 !important;
        border-top: 1px solid var(--border) !important;
        background: var(--surface) !important;
        box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.16) !important;
        backdrop-filter: none !important;
        overflow: hidden !important;
        z-index: 220 !important;
    }

    .nav-item {
        margin: 0 !important;
        padding: 8px 3px 11px !important;
        border-radius: 0 !important;
        gap: 4px !important;
    }

    .nav-item.is-active {
        background: var(--surface-soft) !important;
    }

    .nav-icon {
        font-size: 22px !important;
    }

    .nav-item span:last-child {
        font-size: 12px !important;
    }

    .nav-item.has-unread::after {
        top: 10px !important;
    }

    /* Chat thread is full-screen mode. The app nav leaves. */
    html.is-chat-thread-open .bottom-nav {
        display: none !important;
    }

    html.is-chat-thread-open .app-screen[data-screen="chats"] {
        padding: var(--mobile-top-gap) 12px 12px !important;
        overflow: hidden !important;
    }

    html.is-chat-thread-open #chatsListView {
        display: none !important;
    }

    html.is-chat-thread-open #chatThreadView,
    html.is-chat-thread-open .chat-thread {
        height: calc(100dvh - var(--mobile-top-gap) - 12px) !important;
        min-height: 0 !important;
        display: grid !important;
        grid-template-rows: auto auto minmax(0, 1fr) auto !important;
        overflow: hidden !important;
        padding: 0 !important;
    }

    .chat-header {
        grid-template-columns: auto minmax(0, 1fr) repeat(5, auto) !important;
        gap: 8px !important;
        padding: 4px 0 10px !important;
    }

    .chat-header h1 {
        font-size: 19px !important;
    }

    .chat-header-action {
        width: 36px !important;
        height: 36px !important;
    }

    .messages-list {
        min-height: 0 !important;
        overflow-y: auto !important;
        padding-bottom: 12px !important;
        -webkit-overflow-scrolling: touch;
    }

    .message-composer {
        position: relative !important;
        z-index: 140 !important;
        padding: 10px 0 0 !important;
        background: var(--bg) !important;
        box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.08) !important;
    }

    .message-composer textarea {
        height: 44px !important;
        min-height: 44px !important;
    }

    .chat-create-button,
    .groups-create-button {
        bottom: calc(var(--mobile-nav-height) + 18px) !important;
        z-index: 230 !important;
    }

    /* Sheets and overlays: solid, scroll inside, never behind nav. */
    .new-chat-sheet,
    .groups-sheet,
    .call-overlay,
    .confirm-dialog {
        position: fixed !important;
        inset: 0 !important;
        z-index: 400 !important;
        background: rgba(15, 23, 42, 0.68) !important;
        backdrop-filter: blur(10px);
    }

    .new-chat-sheet.is-hidden,
    .groups-sheet.is-hidden,
    .call-overlay.is-hidden,
    .confirm-dialog.is-hidden {
        display: none !important;
    }

    .new-chat-sheet,
    .groups-sheet {
        display: grid !important;
        align-items: end !important;
        padding: calc(var(--mobile-top-gap) + 10px) 14px calc(var(--mobile-nav-height) + 18px) !important;
    }

    html.is-chat-thread-open .new-chat-sheet,
    html.is-chat-thread-open .groups-sheet {
        padding-bottom: 18px !important;
    }

    .new-chat-panel,
    .groups-sheet-panel,
    .groups-sheet-card,
    .confirm-card,
    .call-panel,
    .call-overlay-card {
        width: 100% !important;
        max-height: 78dvh !important;
        overflow-y: auto !important;
        color: var(--text) !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        border-radius: 24px !important;
        box-shadow: 0 24px 70px rgba(15, 23, 42, 0.34) !important;
    }

    .call-overlay {
        display: grid !important;
        place-items: center !important;
        padding: calc(var(--mobile-top-gap) + 12px) 14px 18px !important;
    }

    .call-panel,
    .call-overlay-card {
        width: min(94vw, 430px) !important;
        max-height: 86dvh !important;
    }

    .call-video-stage {
        width: 100% !important;
        min-height: 210px !important;
        max-height: 42dvh !important;
        border-radius: 18px !important;
        background: #020617 !important;
        overflow: hidden !important;
    }

    .call-video-stage video,
    .call-remote-video,
    .call-local-video {
        background: #020617 !important;
        object-fit: cover !important;
    }

    /* Settings cards must stack. Desktop flex rows were causing the ugly columns. */
    .settings-card,
    .profile-card,
    .account-card {
        border-radius: 24px !important;
    }

    .translation-settings-card,
    .feedback-settings-card {
        display: grid !important;
        grid-template-columns: 1fr !important;
        align-items: stretch !important;
        gap: 16px !important;
    }

    .translation-settings-card > div,
    .feedback-settings-card > div {
        display: grid !important;
        gap: 6px !important;
    }

    .translation-settings-card .field,
    .feedback-settings-card .field {
        margin: 0 !important;
    }

    .translation-settings-card select {
        min-height: 50px !important;
        border-radius: 16px !important;
        background: var(--surface-soft) !important;
        color: var(--text) !important;
        font-weight: 800 !important;
    }

    .settings-toggle-row,
    .settings-notification-row {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 14px !important;
        border: 1px solid var(--border) !important;
        border-radius: 18px !important;
        background: var(--surface-soft) !important;
    }

    .settings-toggle-row span,
    .settings-notification-row span {
        display: grid !important;
        gap: 4px !important;
        min-width: 0 !important;
    }

    .settings-toggle-row small,
    .settings-notification-row small {
        color: var(--muted) !important;
        font-size: 12px !important;
        line-height: 1.35 !important;
    }

    .settings-toggle-row input[type="checkbox"] {
        width: 24px !important;
        height: 24px !important;
        accent-color: var(--accent);
    }

    .settings-notification-row .secondary-button,
    .feedback-settings-card .secondary-button,
    .translation-settings-card .primary-button {
        width: 100% !important;
        justify-content: center !important;
    }

    .settings-notification-row {
        grid-template-columns: 1fr !important;
    }

    html[data-theme="light"] .bottom-nav,
    html[data-theme="light"] .new-chat-panel,
    html[data-theme="light"] .groups-sheet-panel,
    html[data-theme="light"] .groups-sheet-card,
    html[data-theme="light"] .confirm-card,
    html[data-theme="light"] .call-panel,
    html[data-theme="light"] .call-overlay-card {
        background: #ffffff !important;
        color: #0f172a !important;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --mobile-top-gap: 12px;
        --mobile-nav-height: 68px;
    }

    .app-screen {
        padding-top: 20px !important;
    }

    .new-chat-panel,
    .groups-sheet-panel,
    .groups-sheet-card,
    .call-panel,
    .call-overlay-card {
        width: min(92vw, 760px) !important;
        max-height: 84dvh !important;
    }

    .call-video-stage {
        min-height: 170px !important;
        max-height: 54dvh !important;
    }
}
