/**
 * Pit Stop — navegação mobile (carregar por último)
 */
@media (max-width: 768px) {
    /* Barra do topo — só quando o menu está fechado */
    .mobile-topbar {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        order: -2;
        width: 100%;
        position: sticky;
        top: 0;
        z-index: 300;
        padding: 0.6rem 0.85rem;
        padding-top: max(0.6rem, env(safe-area-inset-top));
        background: #0a0e27;
        border-bottom: 1px solid rgba(255, 107, 53, 0.35);
    }

    body.mobile-nav-open .mobile-topbar {
        display: none !important;
    }

    .mobile-topbar-actions {
        display: flex !important;
        flex-shrink: 0;
        gap: 0.4rem;
    }

    .mobile-topbar-title {
        flex: 1;
        font-weight: 600;
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar-icon-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 46px;
        min-height: 46px;
        padding: 0 0.65rem;
        border-radius: 12px;
        border: 1px solid rgba(255, 107, 53, 0.5);
        background: linear-gradient(145deg, #ff6b35 0%, #e55a2b 100%);
        color: #fff;
        font-size: 1.2rem;
        line-height: 1;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
        gap: 0.35rem;
    }

    .topbar-icon-btn .btn-menu-label {
        font-size: 0.72rem;
        font-weight: 700;
    }

    .sidebar-overlay {
        position: fixed !important;
        inset: 0 !important;
        z-index: 400 !important;
        background: rgba(0, 0, 0, 0.6) !important;
    }

    .sidebar-overlay.hidden {
        display: none !important;
    }

    /* Sem barra branca / X no topo */
    .sidebar-mobile-close {
        display: none !important;
    }

    #dashboard .sidebar,
    .dashboard-layout .sidebar {
        display: flex !important;
        flex-direction: column !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: min(300px, 92vw) !important;
        max-width: 92vw !important;
        height: 100% !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        padding: 1rem 0.85rem !important;
        padding-top: max(1rem, env(safe-area-inset-top)) !important;
        z-index: 450 !important;
        transform: translate3d(-105%, 0, 0) !important;
        transition: transform 0.28s ease, max-height 0.3s ease !important;
        border-right: 2px solid var(--primary-blue) !important;
        border-bottom: none !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    #dashboard .sidebar.mobile-open,
    .dashboard-layout .sidebar.mobile-open {
        transform: translate3d(0, 0, 0) !important;
    }

    /* Recolhido para cima: só logo + botão expandir */
    #dashboard .sidebar.mobile-open.mobile-folded,
    .dashboard-layout .sidebar.mobile-open.mobile-folded {
        height: auto !important;
        max-height: min(220px, 38vh) !important;
        bottom: auto !important;
        overflow: hidden !important;
    }

    #dashboard .sidebar.mobile-folded .nav-menu,
    #dashboard .sidebar.mobile-folded #syncStatus,
    #dashboard .sidebar.mobile-folded .sidebar-title,
    #dashboard .sidebar.mobile-folded .sidebar-subtitle,
    #dashboard .sidebar.mobile-folded .btn-voltar {
        display: none !important;
    }

    #dashboard .sidebar.mobile-folded .sidebar-header {
        margin-bottom: 0.5rem !important;
        padding-bottom: 0.5rem !important;
        border-bottom: none !important;
    }

    #dashboard .sidebar.mobile-folded .sidebar-logo-img {
        max-height: 100px !important;
        max-width: 100% !important;
    }

    #dashboard .sidebar.mobile-folded .sidebar-footer {
        margin-top: 0 !important;
        padding-top: 0 !important;
        border-top: none !important;
    }

    #dashboard .sidebar .sidebar-toggle {
        display: none !important;
    }

    #dashboard .sidebar .sidebar-footer {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
        margin-top: auto !important;
        padding-top: 0.75rem !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .btn-sidebar-fold-mobile {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
        width: 100%;
        min-height: 44px;
        padding: 0.65rem 1rem;
        border: 1px solid rgba(255, 107, 53, 0.45);
        border-radius: 10px;
        background: linear-gradient(145deg, rgba(255, 107, 53, 0.25) 0%, rgba(255, 107, 53, 0.12) 100%);
        color: #fff;
        font-size: 0.88rem;
        font-weight: 600;
        cursor: pointer;
        touch-action: manipulation;
    }

    .btn-sidebar-fold-mobile .fold-icon {
        font-size: 0.75rem;
        opacity: 0.9;
    }

    #dashboard .sidebar.collapsed .nav-menu,
    #dashboard .sidebar.collapsed .sidebar-footer,
    #dashboard .sidebar .nav-menu {
        flex-direction: column !important;
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        display: flex !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        max-height: none !important;
    }

    .main-content {
        order: 0;
        width: 100% !important;
        margin-left: 0 !important;
        padding-bottom: 1.5rem !important;
    }

    body.mobile-nav-open {
        overflow: hidden !important;
    }

    body.mobile-nav-open .main-content {
        pointer-events: none;
    }
}

@media (min-width: 769px) {
    .mobile-topbar,
    .btn-sidebar-fold-mobile {
        display: none !important;
    }
}
