/*
===============================================================================
MA MOBILE RESPONSIVE SYSTEM
===============================================================================
Mobile navigation follows the Visitor system pattern:
- compact top header
- hamburger button
- slide-in left navigation drawer
- dark backdrop
- existing MA navigation is reused
- no fixed bottom navigation
===============================================================================
*/

/* Mobile-only elements are hidden on desktop */
.ma-mobile-header,
.ma-mobile-overlay {
    display: none;
}

@media (max-width: 768px) {

    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden !important;
    }

    body.ma-menu-open {
        overflow: hidden !important;
    }

    /* -----------------------------------------------------------------------
       TOP MOBILE HEADER
       ----------------------------------------------------------------------- */
    .ma-mobile-header {
        position: sticky;
        top: 0;
        z-index: 1400;
        width: 100%;
        min-height: 64px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 14px;
        background: rgba(255, 255, 255, 0.94);
        border-bottom: 1px solid rgba(226, 232, 240, 0.85);
        box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
    }

    .ma-mobile-menu-btn {
        position: relative;
        z-index: 1401;
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 0;
        border: 1px solid rgba(148, 163, 184, 0.28);
        border-radius: 12px;
        background: rgba(248, 250, 252, 0.9);
        color: #334155;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: all 0.2s ease;
    }

    .ma-mobile-menu-btn span {
        display: block;
        width: 19px;
        height: 2px;
        border-radius: 999px;
        background: currentColor;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .ma-mobile-menu-btn.is-open span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .ma-mobile-menu-btn.is-open span:nth-child(2) {
        opacity: 0;
    }

    .ma-mobile-menu-btn.is-open span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    .ma-mobile-brand {
        min-width: 0;
        flex: 1;
        display: flex;
        align-items: center;
        gap: 9px;
    }

    .ma-mobile-brand-icon {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
        display: grid;
        place-items: center;
        border-radius: 11px;
        background: rgba(124, 58, 237, 0.08);
        font-size: 18px;
    }

    .ma-mobile-brand strong,
    .ma-mobile-brand small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ma-mobile-brand strong {
        color: #0f172a;
        font-size: 13px;
        line-height: 1.25;
        font-weight: 800;
    }

    .ma-mobile-brand small {
        margin-top: 2px;
        color: #64748b;
        font-size: 10px;
        line-height: 1.2;
        font-weight: 600;
    }

    .ma-mobile-header-spacer {
        width: 42px;
        flex: 0 0 42px;
    }

    /* -----------------------------------------------------------------------
       BACKDROP
       ----------------------------------------------------------------------- */
    .ma-mobile-overlay {
        position: fixed;
        inset: 0;
        z-index: 1200;
        display: block;
        background: rgba(15, 23, 42, 0.42);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.22s ease, visibility 0.22s ease;
    }

    .ma-mobile-overlay.ma-mobile-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* -----------------------------------------------------------------------
       EXISTING MA SIDEBAR -> VISITOR-STYLE SLIDE-IN DRAWER
       ----------------------------------------------------------------------- */
    .slim-sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: auto !important;
        left: 0 !important;
        right: auto !important;

        width: min(82vw, 290px) !important;
        height: 100dvh !important;
        min-height: 100vh !important;

        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;

        margin: 0 !important;
        padding: 22px 14px calc(18px + env(safe-area-inset-bottom, 0px)) !important;

        border-radius: 0 20px 20px 0 !important;
        border: 0 !important;
        border-right: 1px solid rgba(226, 232, 240, 0.8) !important;

        transform: translateX(-105%) !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: none !important;

        z-index: 1300 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;

        background: rgba(255, 255, 255, 0.98) !important;
        box-shadow: 12px 0 36px rgba(15, 23, 42, 0.16) !important;

        transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1) !important;
    }

    .slim-sidebar.ma-mobile-open {
        transform: translateX(0) !important;
        pointer-events: auto !important;
    }

    .slim-sidebar .logo-circle {
        display: flex !important;
        width: 46px !important;
        height: 46px !important;
        flex: 0 0 46px !important;
        margin: 0 0 20px 2px !important;
        border-radius: 14px !important;
    }

    .slim-sidebar .icon-nav {
        width: 100% !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;

        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;

        gap: 5px !important;
        overflow: visible !important;
    }

    .slim-sidebar .nav-icon,
    .slim-sidebar .nav-icon.logout {
        position: relative !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 48px !important;
        flex: 0 0 48px !important;

        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 12px !important;

        padding: 0 14px !important;
        margin: 0 !important;

        border-radius: 13px !important;
        color: #64748b !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;

        text-decoration: none !important;
        transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease !important;
    }

    .slim-sidebar .nav-icon::after {
        content: attr(title);
        display: block;
        font-family: inherit;
        font-size: 12.5px;
        font-weight: 700;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .slim-sidebar .nav-icon svg {
        width: 20px !important;
        height: 20px !important;
        flex: 0 0 20px !important;
    }

    .slim-sidebar .nav-icon > span {
        flex: 0 0 20px !important;
        width: 20px !important;
        text-align: center !important;
    }

    .slim-sidebar .nav-icon:hover,
    .slim-sidebar .nav-icon:focus-visible {
        background: rgba(124, 58, 237, 0.08) !important;
        color: #7c3aed !important;
        transform: translateX(2px) !important;
        outline: none !important;
    }

    .slim-sidebar .nav-icon.active {
        background: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%) !important;
        color: #ffffff !important;
        box-shadow: 0 8px 20px rgba(124, 58, 237, 0.22) !important;
        transform: none !important;
    }

    .slim-sidebar .nav-icon.logout {
        flex: 0 0 48px !important;
        margin-top: auto !important;
        color: #dc2626 !important;
        background: rgba(220, 38, 38, 0.06) !important;
    }

    .slim-sidebar .nav-icon.logout::after {
        content: attr(title);
    }

    .slim-sidebar .nav-icon.logout:hover {
        background: rgba(220, 38, 38, 0.12) !important;
        color: #b91c1c !important;
    }

    /* -----------------------------------------------------------------------
       MAIN PAGE AREA
       ----------------------------------------------------------------------- */
    .app-window {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: calc(100dvh - 64px) !important;

        padding: 12px !important;
        padding-bottom: 24px !important;
        margin: 0 !important;
    }

    .dashboard-body {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        gap: 14px !important;
    }

    .dashboard-body > *,
    .grid-content,
    .grid-content > *,
    .main-column,
    .right-column,
    .report-display-card,
    .report-generator-card,
    .table-responsive,
    .custom-table-container {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* Keep wide tables inside their own scroll area. */
    .table-responsive,
    .custom-table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Forms and common dashboard grids */
    .grid-content,
    .top-dashboard-row,
    .availability-grid,
    .profile-grid {
        grid-template-columns: 1fr !important;
    }

    .kpi-container,
    .stats-grid,
    .report-metrics-grid {
        grid-template-columns: 1fr !important;
    }

    /* Prevent oversized headings/buttons from creating horizontal overflow. */
    .top-header,
    .page-header,
    .report-header-toolbar {
        max-width: 100% !important;
        flex-wrap: wrap !important;
    }

    .page-title,
    .report-title {
        max-width: 100% !important;
        overflow-wrap: anywhere !important;
    }

    button,
    .btn,
    input,
    select,
    textarea {
        max-width: 100%;
    }
}

/* Smaller phones */
@media (max-width: 420px) {
    .ma-mobile-header {
        padding-left: 10px;
        padding-right: 10px;
    }

    .ma-mobile-brand strong {
        font-size: 12px;
    }

    .ma-mobile-brand small {
        font-size: 9px;
    }

    .ma-mobile-header-spacer {
        width: 38px;
        flex-basis: 38px;
    }

    .ma-mobile-menu-btn {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .app-window {
        padding: 10px !important;
    }
}

/* Landscape phones */
@media (max-width: 768px) and (orientation: landscape) {
    .ma-mobile-header {
        min-height: 54px;
    }

    .slim-sidebar {
        width: min(330px, 72vw) !important;
    }
}

/* Desktop safety: never allow the mobile drawer state to affect desktop. */
@media (min-width: 769px) {
    .ma-mobile-header,
    .ma-mobile-overlay {
        display: none !important;
    }

    .slim-sidebar.ma-mobile-open {
        transform: none !important;
    }
}
