/**
 * Mobile-only navigation. All rules scoped under @media (max-width: 767px).
 * Desktop sidebar (#sidebar, #sidebar-menu) is never styled here.
 */

:root {
    --mob-nav-h: 62px;
    --mob-nav-primary: #2563eb;
}

/* Hide mobile UI on desktop — zero impact on desktop layout */
@media (min-width: 768px) {
    #mobile-bottom-nav,
    #mobile-nav-backdrop,
    #mobile-menu-drawer {
        display: none !important;
    }
}

@media (max-width: 767px) {
    body.has-mobile-nav {
        padding-bottom: calc(var(--mob-nav-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Hide legacy sidebar on mobile — desktop sidebar DOM stays intact for >=768px */
    body.has-mobile-nav #content > #sidebar {
        display: none !important;
    }

    body.has-mobile-nav.off-screen #content > #sidebar {
        display: none !important;
    }

    body.has-mobile-nav #page-container,
    body.has-mobile-nav #page-container.hide {
        display: block !important;
        width: 100% !important;
    }

    body.has-mobile-nav #page-content.p20,
    body.has-mobile-nav #page-content.kb-page {
        padding: 12px !important;
    }

    /* Bottom bar */
    #mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1040;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        min-height: var(--mob-nav-h);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: #fff;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 6px 4px 8px;
        min-height: var(--mob-nav-h);
        color: #64748b;
        text-decoration: none !important;
        background: transparent;
        border: none;
        font-size: 10px;
        font-weight: 600;
        line-height: 1.2;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
    }

    .mobile-nav-item i {
        font-size: 20px;
    }

    .mobile-nav-item.is-active {
        color: var(--mob-nav-primary);
    }

    .mobile-nav-item.is-active i {
        color: var(--mob-nav-primary);
    }

    .mobile-nav-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
    }

    /* Backdrop */
    #mobile-nav-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 1045;
        background: rgba(15, 23, 42, 0.45);
    }

    body.mobile-drawer-open #mobile-nav-backdrop {
        display: block;
    }

    body.mobile-drawer-open {
        overflow: hidden;
    }

    /* Drawer panel — separate from #sidebar */
    #mobile-menu-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(320px, 92vw);
        z-index: 1050;
        background: #f8fafc;
        transform: translateX(-105%);
        transition: transform 0.28s ease;
        display: flex;
        flex-direction: column;
        box-shadow: none;
    }

    body.mobile-drawer-open #mobile-menu-drawer {
        transform: translateX(0);
        box-shadow: 4px 0 32px rgba(15, 23, 42, 0.18);
    }

    .mobile-drawer-header {
        flex-shrink: 0;
        padding: max(14px, env(safe-area-inset-top)) 14px 14px;
        background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
        color: #fff;
    }

    .mobile-drawer-header-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .mobile-drawer-title {
        margin: 0;
        font-size: 16px;
        font-weight: 700;
    }

    .mobile-drawer-close {
        width: 36px;
        height: 36px;
        border: none;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.15);
        color: #fff;
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
        flex-shrink: 0;
    }

    .mobile-drawer-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0 16px;
    }

    /* Cloned menu inside drawer only */
    #mobile-drawer-menu {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    #mobile-drawer-menu .mobile-menu-section {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    #mobile-drawer-menu .mobile-menu-section-title {
        padding: 14px 16px 6px;
        margin: 0;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: #94a3b8;
    }

    #mobile-drawer-menu .mobile-menu-section-list {
        list-style: none;
        margin: 0;
        padding: 0 8px;
        display: block;
    }

    #mobile-drawer-menu li.main {
        margin: 0 0 2px;
        padding: 0;
    }

    #mobile-drawer-menu li.main > a {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 48px;
        padding: 10px 12px;
        border-radius: 10px;
        background: #fff;
        border: 1px solid #e2e8f0;
        color: #334155 !important;
        text-decoration: none !important;
    }

    #mobile-drawer-menu li.main > a:hover,
    #mobile-drawer-menu li.main.active > a {
        background: #eff6ff !important;
        border-color: #bfdbfe;
        color: var(--mob-nav-primary) !important;
    }

    #mobile-drawer-menu li.main > a > i.fa:first-child {
        font-size: 18px !important;
        width: 28px;
        text-align: center;
        color: var(--mob-nav-primary);
        margin: 0 !important;
    }

    #mobile-drawer-menu li.main > a > span:not(.badge),
    #mobile-drawer-menu li.main.expand ul > li > a span {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        font-size: 14px;
        font-weight: 500;
        flex: 1;
    }

    #mobile-drawer-menu li.expand > a:before {
        content: '\f105';
        font-family: 'FontAwesome';
        margin-left: auto;
        color: #94a3b8;
        font-size: 14px;
        transition: transform 0.2s ease;
    }

    #mobile-drawer-menu li.expand.open > a:before {
        content: '\f107';
    }

    #mobile-drawer-menu li.main.expand > ul {
        list-style: none;
        margin: -2px 0 2px;
        padding: 0;
        max-height: 0;
        overflow: hidden;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-top: none;
        border-radius: 0 0 10px 10px;
        transition: max-height 0.28s ease;
    }

    #mobile-drawer-menu li.main.expand.open > ul {
        max-height: 480px;
    }

    #mobile-drawer-menu li.main.expand.open > a {
        border-radius: 10px 10px 0 0;
        border-bottom-color: transparent;
    }

    #mobile-drawer-menu li.main.expand ul > li > a {
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 42px;
        padding: 8px 12px 8px 48px;
        color: #475569 !important;
        text-decoration: none !important;
        font-size: 13px;
        font-weight: 500;
    }

    #mobile-drawer-menu li.main.expand ul > li.active > a,
    #mobile-drawer-menu li.main.expand ul > li > a:active {
        color: var(--mob-nav-primary) !important;
        background: #f8fafc;
    }

    #mobile-drawer-menu li.main.expand ul .dot {
        display: none;
    }

    #mobile-drawer-menu .devider {
        display: none;
    }
}

@media (max-width: 480px) {
    .mobile-nav-label {
        font-size: 9px;
    }
}
