/* Mobile topbar hidden by default, shown under 768px */
.mobile-topbar {
    display: none !important;
}

/* Mobile collapsible panel hidden by default */
.mobile-menu-panel {
    display: none;
}

@media (max-width: 767.98px) {

    /* Solid background for the logo bar on mobile */
    .mobile-topbar {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1030;
        background-color: var(--main-bg);
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background-image: none !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }

    .mobile-topbar .brand {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-menu-panel {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background-color: var(--main-bg);
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
        display: none;
        z-index: 1029;
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-menu-panel.open {
        display: block !important;
    }

    /* Hide the sidebar on mobile to avoid duplication */
    aside.sidebar {
        display: none !important;
    }

    /* Hide the desktop topbar on mobile */
    header.d-flex.justify-content-between.align-items-start.mb-5 {
        display: none !important;
    }

    /* Remove any leftover sidebar offset and ensure content starts below the topbar */
    body {
        padding-top: 56px;
    }

    /* Lock page scroll when mobile menu is open */
    html.noscroll,
    body.noscroll {
        overflow: hidden;
    }

    main,
    .content,
    .page-content,
    .main-content,
    .container,
    .container-fluid,
    .wrapper,
    .layout,
    .with-sidebar {
        /* Center the content and add horizontal padding when mobile menu is active */
        margin-left: auto !important;
        margin-right: auto !important;
        padding: 0 1rem !important; /* some breathing space */
    }
}

/* Dark theme fallback for solid bar */
[data-theme='dark'] .mobile-topbar,
body.dark .mobile-topbar,
body.dark-mode .mobile-topbar {
    background-color: var(--main-bg);
    border-bottom-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Dark theme solid background for mobile menu panel (no glass) */
[data-theme='dark'] .mobile-menu-panel,
body.dark .mobile-menu-panel,
body.dark-mode .mobile-menu-panel {
    background-color: var(--main-bg);
    border-bottom-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Match desktop sidebar logo neon effect */
.mobile-topbar .mobile-logo {
    transition: none;
}

/* Dark theme (default) neon effect */
body:not(.light-theme) .mobile-topbar .mobile-logo {
    filter: brightness(0) saturate(100%) invert(81%) sepia(13%) saturate(5840%) hue-rotate(178deg) brightness(114%) contrast(84%)
}

/* Light theme neon effect */
.light-theme .mobile-topbar .mobile-logo {
    filter: none;
}

/* Theme-aware styles for menu toggle button */
.mobile-topbar .mobile-menu-toggle {
    background: transparent;
    color: var(--primary-text);
    border: 1px solid var(--secondary-text);
    transition: background .15s ease, color .15s ease, border-color .15s ease;
    /* Normalize spacing */
    padding: 0;
    height: 40px;
    width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-sizing: border-box;
    border-radius: 8px;
}

.mobile-topbar .mobile-menu-toggle .material-icons {
    color: inherit;
    transition: color .15s ease;
    line-height: 1;
    display: block;
}

.mobile-topbar .mobile-menu-toggle:hover {
    background: var(--hover-bg, rgba(0, 0, 0, 0.04));
}

/* Dark theme hover fallbacks if variables are not provided */
[data-theme='dark'] .mobile-topbar .mobile-menu-toggle:hover,
body.dark .mobile-topbar .mobile-menu-toggle:hover,
body.dark-mode .mobile-topbar .mobile-menu-toggle:hover {
    background: var(--hover-bg-dark, rgba(255, 255, 255, 0.08));
}

/* Pressed/open state */
.mobile-topbar .mobile-menu-toggle[aria-pressed='true'] {
    background: var(--primary-accent, #0d6efd);
    color: var(--card-bg, #fff);
    border-color: var(--primary-accent, #0d6efd);
}