/* ===================================================================
   Mnzil EWA - Mobile Responsive Overrides
   Breakpoints: 768px (tablet), 480px (phone)
   Updated: 2026-03-29 - Full mobile layout rewrite
   Fixes: overlapping layers, broken grids, stacking issues
   =================================================================== */

/* -- Mobile Hamburger Button -- */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: .875rem;
    left: .875rem;
    z-index: 201;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,.1);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all .2s ease;
}
.mobile-menu-btn:active {
    transform: scale(.92);
}
.mobile-menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--primary, #3043e3);
    border-radius: 2px;
    transition: all .3s ease;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.mobile-menu-btn span:nth-child(1) { top: 12px; }
.mobile-menu-btn span:nth-child(2) { top: 19px; }
.mobile-menu-btn span:nth-child(3) { top: 26px; }
.mobile-menu-btn.open span:nth-child(1) {
    top: 19px;
    transform: translateX(-50%) rotate(45deg);
}
.mobile-menu-btn.open span:nth-child(2) {
    opacity: 0;
}
.mobile-menu-btn.open span:nth-child(3) {
    top: 19px;
    transform: translateX(-50%) rotate(-45deg);
}

/* -- Mobile Overlay -- */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    transition: opacity .3s ease;
}
.mobile-overlay.active {
    opacity: 1;
}

/* ======= TABLET - max 768px ======= */
@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; }

    /* Sidebar: slide-in from left */
    .sidebar {
        display: flex !important;
        transform: translateX(-100%);
        transition: transform .3s cubic-bezier(.16,1,.3,1);
        z-index: 200;
        box-shadow: none;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 8px 0 30px rgba(0,0,0,.12);
    }
    .mobile-overlay.active { display: block; opacity: 1; }

    /* PAGE LAYOUT - prevent overlap */
    body { overflow-x: hidden; }
    .page {
        margin-inline-start: 0 !important;
        padding: 0 1rem 3rem !important;
        overflow-x: hidden;
        box-sizing: border-box;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* PAGE BANNERS - room for hamburger */
    .page-banner {
        margin: 0 -1rem 1.25rem !important;
        padding: 3.75rem 1rem 1.25rem !important;
        border-radius: 0 0 1rem 1rem !important;
    }
    .page-banner h1 { font-size: 1.25rem !important; }
    .page-banner .page-subtitle { font-size: .75rem !important; }
    .page-banner .page-banner-row {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }
    .page-banner .page-banner-row > div:last-child {
        width: 100%;
        flex-wrap: wrap;
        gap: .5rem !important;
    }
    .page-banner .page-banner-row > div:last-child .form-input {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none !important;
    }
    .page-banner .btn-banner {
        flex-shrink: 0;
        font-size: .75rem !important;
        padding: .4375rem .875rem !important;
        white-space: nowrap;
    }

    /* EMPLOYEE PORTAL - welcome hero */
    .welcome-hero {
        margin: 0 -1rem 1.25rem !important;
        padding: 3.75rem 1rem 1.25rem !important;
        border-radius: 0 0 1rem 1rem !important;
    }
    .welcome-hero .welcome-name { font-size: 1.125rem !important; }
    .welcome-hero .welcome-subtitle { font-size: .75rem !important; }
    .welcome-top { gap: .75rem !important; }
    .welcome-avatar { width: 42px !important; height: 42px !important; font-size: 1rem !important; }

    /* Earnings grid - 2 cols */
    .earnings-grid { grid-template-columns: repeat(2, 1fr) !important; gap: .5rem !important; }
    .earning-card { padding: .75rem 1rem !important; }
    .earning-card .ec-value { font-size: 1rem !important; }
    .earning-card .ec-icon { width: 32px !important; height: 32px !important; margin-bottom: .375rem !important; }

    /* Daily counter - stack */
    .daily-counter-card {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 1rem !important;
        gap: .75rem !important;
    }
    .daily-counter-right {
        text-align: left !important;
        padding-top: .75rem;
        border-top: 1px solid rgba(48,67,227,.08);
    }
    .daily-counter-value { font-size: 1.375rem !important; }

    /* Balance hero */
    .balance-hero { padding: 1.5rem 1rem !important; margin-bottom: 1.25rem !important; }
    .balance-hero .balance-amount { font-size: 1.5rem !important; }

    /* Stat row */
    .stat-row { grid-template-columns: repeat(2, 1fr) !important; gap: .625rem !important; }

    /* Quick actions */
    .quick-actions { flex-direction: column !important; }
    .quick-action-card { min-width: 0 !important; }

    /* EMPLOYER DASHBOARD */
    .banner-company-row { gap: .75rem !important; }
    .banner-icon { width: 32px !important; height: 32px !important; }
    .banner-info h1 { font-size: 1.125rem !important; }
    .banner-ar { font-size: .75rem !important; }
    .company-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: .75rem !important;
    }
    .company-avatar { width: 44px !important; height: 44px !important; font-size: 1rem !important; }
    .company-name-en { font-size: 1.125rem !important; }
    .company-meta { flex-wrap: wrap !important; }

    /* KPI grid compact - 2 cols */
    .kpi-grid-compact { grid-template-columns: repeat(2, 1fr) !important; gap: .5rem !important; }
    .kpi-mini { padding: .75rem .875rem !important; }
    .kpi-mini-value { font-size: 1rem !important; }

    /* Funding card - stack */
    .funding-compact,
    .funding-card {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: .5rem !important;
        padding: .875rem 1rem !important;
    }

    /* MNZIL ADMIN DASHBOARD */
    .admin-grid { grid-template-columns: repeat(2, 1fr) !important; gap: .625rem !important; }
    .stat-card { padding: .75rem .875rem !important; }
    .stat-card .stat-value { font-size: 1rem !important; }

    /* Pending banner - stack */
    .pending-banner {
        padding: .75rem 1rem !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: .5rem !important;
    }
    .pending-banner .pb-label {
        border-right: none !important;
        padding-right: 0 !important;
        margin-right: 0 !important;
        padding-bottom: .375rem;
        border-bottom: 2px solid var(--gray-200);
        width: 100%;
    }
    .pending-item { font-size: .75rem !important; padding: .3rem .625rem !important; }

    /* KPI cards - 2 cols */
    .kpi-grid, #kpiCards { grid-template-columns: repeat(2, 1fr) !important; gap: .625rem !important; }
    .kpi-card { padding: .75rem .875rem !important; }
    .kpi-value { font-size: 1rem !important; }

    /* ADVANCE TRACKING */
    .at-stats { grid-template-columns: repeat(2, 1fr) !important; gap: .5rem !important; }
    .at-stat { padding: .75rem !important; }
    .at-stat-value { font-size: 1.125rem !important; }
    .at-stat-icon { width: 32px !important; height: 32px !important; }
    .at-toolbar { flex-direction: column !important; align-items: stretch !important; }
    .at-search { min-width: 0 !important; width: 100% !important; }
    .at-count { margin-left: 0 !important; text-align: center; }
    .at-table-card { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
    .at-table { min-width: 600px; }

    /* GRIDS - stack properly */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 1rem !important; }
    .recon-grid, .metrics-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* TABLES - horizontal scroll */
    .table-wrapper {
        border-radius: .75rem !important;
        margin: 0 -.25rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table { font-size: .75rem !important; min-width: 500px; }
    .data-table th,
    .data-table td { padding: .625rem .5rem !important; font-size: .6875rem !important; }
    .data-table th { font-size: .5625rem !important; white-space: nowrap; }
    .table-toolbar { flex-direction: column; gap: .5rem !important; padding: .75rem !important; }
    .table-search { min-width: 0 !important; width: 100% !important; }
    .table-pagination { flex-direction: column; gap: .5rem; text-align: center; padding: .75rem !important; }
    .table-pagination-btns { justify-content: center; }

    /* Column menu */
    .cm-menu { width: calc(100vw - 2rem) !important; max-width: 300px !important; left: 1rem !important; right: 1rem !important; }

    /* Action buttons in table */
    .action-cell { gap: .25rem !important; }
    .action-icon { width: 26px !important; height: 26px !important; }

    /* STATUS TABS & FILTERS */
    .status-tabs { flex-wrap: wrap !important; gap: .25rem !important; }
    .status-tab { font-size: .6875rem !important; padding: .3rem .625rem !important; }
    .filters-bar { flex-direction: column !important; align-items: stretch !important; }
    .filters-bar .form-input,
    .filters-bar .form-select { max-width: none !important; width: 100% !important; }

    /* CARDS */
    .card { padding: 1.125rem !important; }

    /* SETTINGS PAGE */
    .settings-tabs {
        gap: 0 !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .settings-tabs::-webkit-scrollbar { display: none; }
    .settings-tab { padding: .625rem .75rem !important; font-size: .75rem !important; white-space: nowrap; }
    .stab-content { max-width: 100% !important; }
    .s-card { padding: 1rem !important; }
    .info-grid { grid-template-columns: 1fr !important; }
    .pw-grid-3 { grid-template-columns: 1fr !important; }
    .notif-event-row { flex-direction: column !important; align-items: flex-start !important; gap: .5rem !important; }

    /* TEAM MANAGEMENT */
    .users-grid { grid-template-columns: 1fr !important; }
    .user-card { padding: 1rem !important; }
    .emp-stats, .users-stats { gap: .625rem !important; flex-wrap: wrap !important; }
    .emp-stat, .users-stat { font-size: .75rem !important; }

    /* MODALS */
    .modal-box {
        max-width: calc(100vw - 2rem) !important;
        padding: 1.5rem !important;
        margin: 1rem;
        max-height: 85vh !important;
    }
    .modal-form-body { padding: 1.25rem 1rem !important; }
    #addEmployerModal .modal-box { max-width: calc(100vw - 1rem) !important; }
    #addEmployerModal .modal-form-body { padding: 1rem !important; }

    /* DRAWERS */
    .ae-drawer { width: 100vw !important; max-width: 100vw !important; right: -100vw; }
    .review-drawer { width: 100vw !important; max-width: 100vw !important; }

    /* WITHDRAWAL FLOW */
    .withdrawal-form-card { padding: 1.25rem !important; }
    .amount-input-wrapper .form-input {
        font-size: 1.25rem !important;
        padding: 1rem 1.25rem !important;
        padding-inline-end: 3.5rem !important;
    }
    .quick-amounts { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: .375rem !important; }
    .quick-amount-btn { font-size: .75rem !important; padding: .5rem .25rem !important; }
    .eligibility-card { padding: 1.25rem !important; }
    .elig-row { font-size: .8125rem !important; flex-direction: column !important; gap: .25rem !important; }
    .fee-breakdown { padding: 1rem !important; }

    /* HR ADMIN */
    .bulk-bar {
        left: .75rem !important;
        right: .75rem !important;
        transform: none !important;
        padding: .5rem .75rem !important;
        border-radius: 12px !important;
    }
    .bulk-bar.show { bottom: 1rem !important; }
    .bb-actions { flex-wrap: wrap; gap: .25rem !important; }
    .bb-btn { font-size: .6875rem !important; padding: .3rem .5rem !important; }

    /* COMPLIANCE PAGE */
    .compliance-tabs, .report-tabs { flex-wrap: wrap !important; gap: .25rem !important; }

    /* PAGINATION */
    .ae-pagination { flex-direction: column !important; align-items: center !important; gap: .5rem !important; }

    /* NOTIFICATIONS & TOASTS */
    .notification-container { top: .75rem !important; right: .75rem !important; left: .75rem !important; max-width: none !important; }
    .notification { font-size: .75rem !important; padding: .75rem 1rem !important; }
    .toast { left: 1rem !important; right: 1rem !important; transform: none !important; max-width: none !important; }

    /* LOGIN */
    .login-card {
        max-width: calc(100vw - 2rem) !important;
        padding: 2rem 1.5rem !important;
        border-radius: 1.25rem !important;
        margin: 1rem;
    }

    /* BUTTONS & HEADINGS */
    .btn { font-size: .8125rem !important; padding: .625rem 1rem !important; }
    .btn-lg { padding: .75rem 1.5rem !important; font-size: .875rem !important; }
    .section-header { flex-direction: column; align-items: flex-start !important; gap: .5rem; }
    h1 { font-size: 1.25rem !important; }
    h2 { font-size: 1rem !important; }

    /* FORMS */
    .form-input, .form-select { font-size: .875rem !important; padding: .625rem .875rem !important; }
    .ed-grid-2 { grid-template-columns: 1fr !important; }
}


/* ======= SMALL PHONE - max 480px ======= */
@media (max-width: 480px) {
    /* KPIs: stack to 1 column */
    .kpi-grid, #kpiCards, .kpi-grid-compact { grid-template-columns: 1fr !important; }
    .stat-row { grid-template-columns: 1fr !important; }
    .recon-grid, .metrics-grid { grid-template-columns: 1fr !important; }
    .admin-grid { grid-template-columns: 1fr !important; }
    .earnings-grid { grid-template-columns: 1fr !important; }
    .at-stats { grid-template-columns: 1fr !important; }

    /* Login */
    .login-card { padding: 1.5rem 1.25rem !important; border-radius: 1rem !important; }

    /* Page */
    .page { padding: 0 .75rem 4rem !important; }
    .page-banner {
        margin: 0 -.75rem 1rem !important;
        padding: 3.5rem .75rem 1rem !important;
    }
    .page-banner h1 { font-size: 1.125rem !important; }
    .welcome-hero {
        margin: 0 -.75rem 1rem !important;
        padding: 3.5rem .75rem 1rem !important;
    }

    /* Tables: horizontal scroll */
    .data-table { min-width: 500px; }
    .data-table th,
    .data-table td { padding: .5rem .375rem !important; font-size: .625rem !important; }

    /* Modal: near full-screen */
    .modal-box {
        padding: 1.25rem !important;
        border-radius: 1rem !important;
        max-width: calc(100vw - .5rem) !important;
        margin: .25rem !important;
    }

    /* Buttons */
    .btn { font-size: .75rem !important; padding: .5rem .75rem !important; }

    /* Hamburger adjustments */
    .mobile-menu-btn { top: .625rem; left: .625rem; width: 36px; height: 36px; }
    .mobile-menu-btn span { width: 16px; }
    .mobile-menu-btn span:nth-child(1) { top: 10px; }
    .mobile-menu-btn span:nth-child(2) { top: 17px; }
    .mobile-menu-btn span:nth-child(3) { top: 24px; }
    .mobile-menu-btn.open span:nth-child(1) { top: 17px; }
    .mobile-menu-btn.open span:nth-child(3) { top: 17px; }

    /* Quick amounts: 2 cols */
    .quick-amounts { grid-template-columns: repeat(2, 1fr) !important; }

    /* Wizard step options */
    .role-option-card { padding: .75rem !important; }
    .role-option-icon { width: 32px !important; height: 32px !important; font-size: 1rem !important; }

    /* HR Admin: banner actions stack */
    .page-banner .page-banner-row > div:last-child {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: .5rem !important;
    }
    .page-banner .page-banner-row > div:last-child .form-input {
        width: 100% !important;
        max-width: none !important;
    }
    .page-banner .btn-banner { width: 100% !important; text-align: center; justify-content: center; }

    /* HR Admin: emp stats 2 per row */
    .emp-stats {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: .5rem !important;
    }
    .emp-stat strong { font-size: .9375rem !important; }

    /* HR Admin: wizard modal fills screen */
    #addEmpModal .modal-box,
    #addEmpModal .modal-box.wide {
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        height: 100vh;
        max-height: 100vh;
    }
    .wizard-body { padding: 1rem !important; }
    .wizard-footer { padding: .75rem 1rem !important; }
    .method-picker, .group-sub-picker { grid-template-columns: 1fr !important; }

    /* HR Admin: result count + pagination */
    #resultCount { font-size: .75rem !important; }
    #pagination .btn { min-width: 28px !important; padding: .375rem .5rem !important; font-size: .6875rem !important; }

    /* Settings tabs */
    .settings-tab { padding: .5rem .625rem !important; font-size: .6875rem !important; }

    /* Company header tiny */
    .company-name-en { font-size: 1rem !important; }
    .company-meta { font-size: .6875rem !important; }

    /* Withdrawal form */
    .withdrawal-form-card { padding: 1rem !important; }
    .amount-input-wrapper .form-input { font-size: 1rem !important; padding: .875rem 1rem !important; }

    /* Employer add modal: full screen */
    #addEmployerModal .modal-box {
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
    }

    /* Welcome hero adjustments */
    .welcome-avatar { width: 36px !important; height: 36px !important; font-size: .875rem !important; }
    .welcome-name { font-size: 1rem !important; }
    .balance-hero .balance-amount { font-size: 1.25rem !important; }
}


/* ======= Safe area / bottom bar spacing ======= */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .page { padding-bottom: calc(3rem + env(safe-area-inset-bottom)) !important; }
}
