/* =============================================================================
   Mobile bottom nav — clearance + cleaner bar
   Ensures fixed bottom nav never covers page content when scrolled to the end.
   Loaded after social.min.css / portal theme so it always wins.

   IMPORTANT: clearance is applied ONCE (body only). Never pad both body and
   .page — that double-stacked empty space and broke Messages / full-height UIs.
   ============================================================================= */

:root {
    /* Full bar height (padding + icon row). Safe-area added separately. */
    --nav-mobile: 58px;
    --mobile-nav-pad-y: 6px;
    --mobile-nav-icon-box: 46px;
    --mobile-nav-clearance: calc(
        var(--nav-mobile)
        + env(safe-area-inset-bottom, 0px)
        + 10px
    );
}

/* ---------- Bar shell ---------- */
@media (max-width: 1100px) {
    .mobile-nav,
    .portal-mobile-nav {
        display: block;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 40;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding:
            var(--mobile-nav-pad-y)
            max(6px, env(safe-area-inset-left, 0px))
            calc(var(--mobile-nav-pad-y) + env(safe-area-inset-bottom, 0px))
            max(6px, env(safe-area-inset-right, 0px));
        box-sizing: border-box;
        background: rgba(0, 0, 0, 0.92);
        background: color-mix(in srgb, var(--bg, #000) 92%, transparent);
        border-top: 1px solid var(--social-border, #2f3336);
        box-shadow:
            0 -8px 28px rgba(0, 0, 0, 0.35),
            inset 0 1px 0 rgba(255, 255, 255, 0.03);
        -webkit-backdrop-filter: blur(18px) saturate(1.2);
        backdrop-filter: blur(18px) saturate(1.2);
    }

    /* Solid fallback when backdrop-filter unsupported / low-end */
    @supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
        .mobile-nav,
        .portal-mobile-nav {
            background: var(--bg, #000);
        }
    }

    html[data-theme="light"] .mobile-nav,
    html[data-theme="light"] .portal-mobile-nav {
        background: rgba(255, 255, 255, 0.94);
        border-top-color: var(--social-border, #cfd9de);
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08);
    }

    .mobile-nav-items,
    .portal-mobile-nav .mobile-nav-items {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
        align-items: center;
        justify-items: center;
        width: 100%;
        max-width: 560px;
        margin: 0 auto;
        gap: 2px;
        padding: 0;
    }

    .mobile-nav-items-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .mobile-nav-items-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .mobile-nav-items-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 0;
        height: var(--mobile-nav-icon-box);
        min-height: var(--mobile-nav-icon-box);
        margin: 0;
        padding: 4px 2px;
        border-radius: 14px;
        color: var(--text-muted, #71767b);
        text-decoration: none;
        position: relative;
        transition: color 0.14s ease, background 0.14s ease, transform 0.12s ease;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .mobile-nav-item::before {
        content: "";
        position: absolute;
        inset: 3px 4px;
        border-radius: 12px;
        background: rgba(29, 155, 240, 0.1);
        opacity: 0;
        transition: opacity 0.14s ease;
        pointer-events: none;
        z-index: 0;
    }

    .mobile-nav-item:hover {
        color: var(--text, #e7e9ea);
    }

    .mobile-nav-item:active {
        transform: scale(0.96);
    }

    .mobile-nav-item.active {
        color: var(--social-blue, #1d9bf0);
    }

    .mobile-nav-item.active::before {
        opacity: 1;
    }

    .mobile-nav-item:focus-visible {
        outline: 2px solid var(--social-blue, #1d9bf0);
        outline-offset: -2px;
    }

    .mobile-nav-icon {
        width: 24px;
        height: 24px;
        position: relative;
        z-index: 1;
        display: block;
        flex-shrink: 0;
    }

    /*
     * Unread pill on icon top-right.
     * Must set right:auto — base .nav-badge uses right:-10px, and left+right
     * together stretch the badge off-screen on narrow nav slots.
     */
    .mobile-nav,
    .portal-mobile-nav,
    .mobile-nav-items,
    .portal-mobile-nav .mobile-nav-items,
    .mobile-nav-item {
        overflow: visible;
    }

    .mobile-nav-item .nav-badge {
        position: absolute;
        top: 2px;
        left: 50%;
        right: auto;
        transform: translate(6px, 0);
        margin: 0;
        min-width: 16px;
        max-width: calc(100% - 4px);
        height: 16px;
        font-size: 10px;
        font-weight: 800;
        line-height: 1;
        padding: 0 4px;
        border-radius: 999px;
        border: 2px solid var(--bg, #000);
        background: #f4212e;
        color: #fff;
        box-shadow: none;
        box-sizing: border-box;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        z-index: 2;
        overflow: hidden;
        white-space: nowrap;
        pointer-events: none;
    }

    html[data-theme="light"] .mobile-nav-item .nav-badge {
        border-color: #fff;
    }

    .mobile-nav-profile {
        width: 26px;
        height: 26px;
        border-radius: 50%;
        overflow: hidden;
        position: relative;
        z-index: 1;
    }

    .mobile-nav-item.active .mobile-nav-profile {
        box-shadow: 0 0 0 2px var(--bg, #000), 0 0 0 3.5px var(--social-blue, #1d9bf0);
    }

    /* ---------- Content clearance: ONCE on body only ---------- */
    body.social-page,
    body.social-portal-page,
    body.social-portal-embed,
    body.portal-themed {
        padding-bottom: var(--mobile-nav-clearance) !important;
        box-sizing: border-box;
    }

    /* Kill social.css .page bottom padding so we never double-stack */
    body.social-page .page,
    body.social-portal-page .page,
    body.social-portal-embed .page,
    body.portal-themed .page,
    .page {
        padding-bottom: 0 !important;
        box-sizing: border-box;
        min-height: auto;
    }

    body.social-page .layout-grid,
    body.social-portal-page .layout-grid,
    body.social-portal-page .layout-grid.layout-portal,
    .layout-grid.layout-portal,
    .main-content,
    .portal-main-content {
        padding-bottom: 0; /* body already clears; avoid nested extras */
    }

    /* Feeds / lists that scroll inside themselves */
    body.social-page .feed,
    body.social-page .notifications-feed,
    body.social-page .search-results,
    body.social-page .discovery-feed,
    body.social-page .profile-main,
    body.social-portal-page .portal-main-content,
    body.social-portal-page #portal-profile,
    body.social-portal-page .pp-storage-list {
        scroll-padding-bottom: var(--mobile-nav-clearance);
    }

    /* Extra end spacer so last cards aren't tight against the bar */
    body.social-page .main-content::after,
    body.social-portal-page .portal-main-content::after {
        content: "";
        display: block;
        width: 100%;
        height: 8px;
        pointer-events: none;
    }

    /*
     * Messages is a full-height app shell: it sizes itself with calc(100dvh - header - nav).
     * Body/page padding here would stack with that height and blow out the layout.
     */
    body.social-messages,
    body.portal-section-messages {
        padding-bottom: 0 !important;
        overflow-x: clip;
    }

    body.social-messages .page,
    body.portal-section-messages .page {
        padding-bottom: 0 !important;
    }

    /* Open thread: hide bottom nav (rules also in portal-messages / social.css) */
    body.social-messages.msg-has-thread,
    body.portal-section-messages.msg-has-thread {
        padding-bottom: 0 !important;
        overflow: hidden !important;
    }

    body.social-messages.msg-has-thread .page,
    body.portal-section-messages.msg-has-thread .page {
        padding-bottom: 0 !important;
    }

    /* Composer / floating FABs stay above the bar */
    .composer-fab,
    .feed-compose-fab,
    .mobile-compose-fab,
    .bp-toast-region {
        bottom: calc(var(--mobile-nav-clearance) + 12px) !important;
    }
}

/* Desktop: never force clearance */
@media (min-width: 1101px) {
    body.social-page,
    body.social-portal-page,
    body.social-portal-embed,
    body.portal-themed,
    body.social-messages,
    body.portal-section-messages,
    .page {
        padding-bottom: 0 !important;
    }
}

