/* CHR-009: mobile web chrome (iPhone 375-430px, Android Chrome). Rules: docs/mobile-web-contract.md.
   Loaded after app.css (App.razor), so equal-specificity rules here win. Desktop (>= 600px, fine pointer)
   is untouched except where a rule is scoped to (pointer: coarse). */

/* ── Top bar: 48px with 44px targets on phones ─────────────────────────────────────────────── */
@media (max-width: 599.98px) {
    /* MudBlazor writes --mud-appbar-height (40px) on :root from the theme; the main-content offset,
       drawer top and scroll padding all read it, so one override moves everything together. */
    :root {
        --mud-appbar-height: 48px !important;
    }
    .mud-appbar.rf-topbar .mud-toolbar-appbar {
        padding-left: max(2px, env(safe-area-inset-left, 0px));
        padding-right: max(4px, env(safe-area-inset-right, 0px));
    }
    .mud-appbar.rf-topbar .mud-icon-button {
        padding: 12px; /* 20px icon + 24px = 44px target */
    }
    .mud-appbar.rf-topbar .mud-button-root:not(.mud-icon-button) {
        min-height: 44px;
    }
    .rf-topbar-brand {
        margin: 0 8px 0 2px;
    }
    /* Signed-in: Presenting + Light/Dark live in the drawer footer instead. */
    .rf-topbar-desktop-only {
        display: none !important;
    }
}

/* Theme / presenting toggles wrapper is inline in the bar on wider screens. */
.rf-topbar-desktop-only,
.rf-topbar-theme {
    display: inline-flex;
    align-items: center;
}

/* ── Drawer footer (AppChrome.razor, rendered only when the drawer is the mobile overlay) ──── */
.rf-drawer-footer {
    display: none;
}
@media (max-width: 599.98px) {
    .rf-drawer-footer {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        position: sticky;
        bottom: 0;
        margin-top: auto;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--rf-line, var(--mud-palette-lines-default));
        background: var(--mud-palette-drawer-background, var(--rf-panel));
        z-index: 1;
    }
    .rf-drawer-footer .mud-button-root {
        min-height: 44px;
        flex: 1 1 auto;
        justify-content: flex-start;
        text-transform: none;
    }
}

/* ── Composer: 44px touch targets ───────────────────────────────────────────────────────────── */
@media (max-width: 599.98px), (pointer: coarse) {
    .chat-input-toolbar .mud-icon-button,
    .chat-input-toolbar .mud-menu .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }
    /* Send / voice share one slot (app.css .rf-slot): grow the slot so its button stays fully tappable. */
    .chat-input-toolbar .rf-slot {
        width: 44px;
        height: 44px;
    }
    .chat-input-toolbar {
        padding: 0 2px 2px 2px;
    }
}

/* ── Chat prose: full width on phones ───────────────────────────────────────────────────────── */
@media (max-width: 599.98px) {
    /* Shave the stacked side gutters (main-content 8px + container 8px + list 8px + bubble 12px). */
    .chat-main-container {
        padding-left: 2px !important;
        padding-right: 2px !important;
    }
    #message-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    /* MessageBubble sets max-width inline (90% model / 80% user). */
    .message-wrapper[data-role="model"] {
        max-width: 100% !important;
        width: 100%;
    }
    .message-wrapper[data-role="user"] {
        max-width: 88% !important;
    }
    .message-wrapper[data-role="model"] > .mud-paper {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }
    /* Wide tables and code blocks already scroll inside the bubble (app.css .markdown-body table/pre). */
}

/* ── Keyboard: composer rides above the on-screen keyboard ──────────────────────────────────── */
/* chat-interop.js (keyboard-aware viewport) writes --rf-kb-height = layout viewport hidden below the
   visual viewport, and .rf-kb-open while it is > 80px. Android Chrome resizes the layout itself
   (interactive-widget=resizes-content in App.razor) so the value stays 0 there; on iOS Safari it is the
   keyboard height. The shell is 100dvh-based (App.razor), so subtracting the variable once is the only
   offset: never also pad the composer by it. `html` prefix outranks App.razor's later inline rule. */
@media (max-width: 599.98px), (pointer: coarse) {
    html .mud-main-content {
        height: calc(100dvh - var(--mud-appbar-height, 48px) - env(safe-area-inset-top, 0px) - var(--rf-kb-height, 0px));
    }
    /* The home indicator sits under the keyboard while it is open: drop the safe-area pad. */
    html.rf-kb-open .mud-main-content {
        padding-bottom: 0;
    }
    /* Maximize the message area while typing: hide non-essential chrome. */
    html.rf-kb-open .rf-drawer-footer {
        display: none !important;
    }
}
