/* The website's mobile navigation (≤991px): top bar, side drawer, bottom
 * bar — markup in includes/navigations/mobile_nav.php, behaviour in
 * assets/js/sb_mobile_nav.js. Every colour is a sb_theme.css token, so the
 * bars follow Light/Dark/Auto with no rules of their own. */

/* The no-FOUC script marks <html> before <body> gets .theme-dark: give the
   bars the dark tokens from the first paint too. Same values as
   body.theme-dark in sb_theme.css. */
html.theme-dark-pre body {
    --sb-bg:          #161922;
    --sb-surface:     #1f2330;
    --sb-text:        #ffffff;
    --sb-text-muted:  rgba(255,255,255,0.55);
    --sb-border:      #2c3142;
    --sb-danger:      #e25e4d;
    --sb-surface-2:   #262b3a;
    --sb-hover:       #2a2f3e;
    --sb-input-bg:    #14171f;
    --sb-link:        #4ea8ff;
}

.sbm-topbar, .sbm-bottombar, .sbm-drawer, .sbm-overlay { display: none; }

@media (max-width: 991px) {
    :root {
        --sbm-top-h: 56px;
        --sbm-bottom-h: 60px;
        --sbm-safe-b: env(safe-area-inset-bottom, 0px);
    }

    body { padding-bottom: calc(var(--sbm-bottom-h) + var(--sbm-safe-b) + 8px); }
    #scroll-to-top { bottom: calc(var(--sbm-bottom-h) + var(--sbm-safe-b) + 16px) !important; }

    .sbm-topbar, .sbm-bottombar {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 1030;
        display: flex;
        align-items: center;
        background: var(--sb-surface);
        color: var(--sb-text);
        font-family: var(--sb-font, inherit);
        transition: transform .25s ease, background-color .2s ease;
        will-change: transform;
    }

    /* ---- top bar ---------------------------------------------------- */
    .sbm-topbar {
        top: 0;
        height: var(--sbm-top-h);
        padding: 0 6px;
        border-bottom: 1px solid var(--sb-border);
    }
    html.sb-ev-on .sbm-topbar { top: var(--sb-ev-h, 0px); }
    html.sbm-bars-hidden .sbm-topbar { transform: translateY(calc(-100% - var(--sb-ev-h, 0px) - 2px)); }

    .sbm-logo { display: flex; align-items: center; height: 100%; padding: 0 6px; }
    .sbm-logo img { height: 30px; width: auto; }

    .sbm-top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }

    .sbm-icon-btn {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: transparent;
        color: var(--sb-text) !important;
        font-size: 21px;
        line-height: 1;
        cursor: pointer;
        text-decoration: none !important;
        -webkit-tap-highlight-color: transparent;
    }
    .sbm-icon-btn:hover, .sbm-icon-btn:focus-visible { background: var(--sb-hover); outline: none; }
    .sbm-icon-btn:active { background: var(--sb-hover-strong, var(--sb-hover)); }
    .sbm-icon-btn i { text-shadow: none !important; }

    .sbm-login {
        padding: 7px 16px;
        border-radius: 18px;
        background: var(--sb-accent);
        color: #fff !important;
        font-weight: 600;
        text-decoration: none !important;
    }

    /* Badges: the pollers drop a <span class="badge"> in here. */
    .sbm-badge:empty { display: none; }
    .sbm-badge .badge {
        position: absolute;
        top: 3px;
        right: 1px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        border: 2px solid var(--sb-surface);
        background: var(--sb-danger) !important;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 14px;
        box-sizing: border-box;
    }

    /* Search: a row over the top bar, results drop below it. */
    .sbm-search {
        position: absolute;
        inset: 0;
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 0 6px 0 14px;
        background: var(--sb-surface);
    }
    .sbm-search[hidden] { display: none; }
    .sbm-search > .feather-search { color: var(--sb-text-muted); font-size: 18px; }
    .sbm-search input.sbm-search-input {
        flex: 1;
        height: 38px;
        margin: 0 !important;
        border: 1px solid var(--sb-border) !important;
        border-radius: 19px !important;
        background: var(--sb-input-bg) !important;
        color: var(--sb-text) !important;
        box-shadow: none !important;
        font-size: 15px;
    }
    .sbm-search-results:empty { display: none; }
    .sbm-search-results {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: calc(100vh - var(--sbm-top-h) - 20px);
        overflow-y: auto;
        background: var(--sb-surface);
        color: var(--sb-text);
        border-bottom: 1px solid var(--sb-border);
        box-shadow: 0 8px 18px rgba(0,0,0,.15);
    }
    .sbm-search-results .notify-arrow { display: none; }

    /* ---- bottom bar ------------------------------------------------- */
    .sbm-bottombar {
        bottom: 0;
        height: calc(var(--sbm-bottom-h) + var(--sbm-safe-b));
        padding-bottom: var(--sbm-safe-b);
        border-top: 1px solid var(--sb-border);
        justify-content: space-around;
    }
    html.sbm-bars-hidden .sbm-bottombar { transform: translateY(100%); }

    .sbm-tab {
        position: relative;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        height: 100%;
        padding: 0;
        border: 0;
        background: transparent;
        color: var(--sb-text-muted) !important;
        font-size: 11px;
        font-weight: 600;
        text-decoration: none !important;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .sbm-tab > i { font-size: 22px; line-height: 1; }
    .sbm-tab.is-active { color: var(--sb-accent) !important; }
    body.theme-dark .sbm-tab.is-active { color: var(--sb-link) !important; }
    .sbm-tab:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: -4px; border-radius: 10px; }
    .sbm-tab .sbm-badge .badge { top: 4px; right: calc(50% - 22px); }

    .sbm-tab-avatar {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        object-fit: cover;
        border: 2px solid transparent;
    }
    .sbm-tab.is-active .sbm-tab-avatar { border-color: var(--sb-accent); }

    .sbm-post-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 30px;
        border-radius: 15px;
        background: var(--sb-accent);
        color: #fff;
        font-size: 20px;
        box-shadow: 0 2px 6px rgba(0,115,183,.35);
    }
    .sbm-tab-post:active .sbm-post-icon { transform: scale(.94); }

    /* ---- drawer ----------------------------------------------------- */
    .sbm-overlay {
        position: fixed;
        inset: 0;
        z-index: 1035;
        display: block;
        background: rgba(0,0,0,.45);
        opacity: 0;
        transition: opacity .25s ease;
    }
    .sbm-overlay[hidden] { display: none; }
    html.sbm-drawer-open .sbm-overlay { opacity: 1; }

    .sbm-drawer {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1036;
        display: flex;
        flex-direction: column;
        width: min(84vw, 320px);
        background: var(--sb-surface);
        color: var(--sb-text);
        font-family: var(--sb-font, inherit);
        box-shadow: 4px 0 24px rgba(0,0,0,.25);
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .25s ease, visibility 0s linear .25s;
        outline: none;
    }
    html.sbm-drawer-open .sbm-drawer {
        transform: none;
        visibility: visible;
        transition: transform .25s ease, visibility 0s;
    }
    html.sbm-drawer-open, html.sbm-drawer-open body { overflow: hidden; }

    .sbm-drawer-head {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: calc(14px + var(--sb-ev-h, 0px)) 8px 14px 16px;
        border-bottom: 1px solid var(--sb-border);
    }
    .sbm-drawer-user {
        flex: 1;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 12px;
        color: var(--sb-text) !important;
        text-decoration: none !important;
    }
    .sbm-drawer-user img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; }
    .sbm-drawer-user span { display: flex; flex-direction: column; min-width: 0; }
    .sbm-drawer-user strong, .sbm-drawer-user small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .sbm-drawer-user strong { font-size: 16px; }
    .sbm-drawer-user small { color: var(--sb-text-muted); font-size: 12.5px; }

    .sbm-drawer-body {
        flex: 1;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 6px 0 calc(16px + var(--sbm-safe-b));
    }
}

/* The menu list: in the drawer and on menus.php (any width). */
.sbm-menu { list-style: none; margin: 0; padding: 4px 8px; }
.sbm-menu li a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 12px;
    border-radius: 10px;
    color: var(--sb-text) !important;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none !important;
}
.sbm-menu li a:hover, .sbm-menu li a:focus-visible { background: var(--sb-hover); outline: none; }
.sbm-menu li a i { width: 22px; font-size: 19px; text-align: center; color: var(--sb-text-muted); }
.sbm-menu-minor { border-top: 1px solid var(--sb-border); margin-top: 6px; padding-top: 8px; }
.sbm-menu-minor li a { font-size: 14px; padding: 9px 12px; }

.sbm-theme {
    display: flex;
    gap: 4px;
    margin: 8px 16px;
    padding: 4px;
    border-radius: 12px;
    background: var(--sb-surface-2);
}
.sbm-theme button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 4px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--sb-text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.sbm-theme button[aria-checked="true"] {
    background: var(--sb-surface);
    color: var(--sb-text);
    box-shadow: var(--sb-shadow);
}
.sbm-theme button:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: 1px; }

/* menus.php: the same list as a page. */
.sbm-menu-page {
    max-width: 520px;
    margin: 0 auto;
    background: var(--sb-surface);
    color: var(--sb-text);
    border-radius: 14px;
    padding: 8px 0 12px;
}
.sbm-menu-page .sbm-drawer-user { padding: 10px 20px 14px; border-bottom: 1px solid var(--sb-border); margin-bottom: 4px; }
