/* ═══════════════════════════════════════════════════════════════
   DGINL Admin — Comprehensive Responsive & Mobile-First Overhaul
   ═══════════════════════════════════════════════════════════════ */

/* ── Mobile Bottom Navigation Bar ─────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,.08);
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: stretch;
}

.mob-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    padding: 6px 2px 4px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: .62rem;
    font-weight: 700;
    cursor: pointer;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    min-width: 0;
}

.mob-nav-btn i {
    font-size: 1.15rem;
    margin-bottom: 1px;
    transition: transform .15s;
}

.mob-nav-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.mob-nav-btn.active {
    color: var(--accent);
}

.mob-nav-btn.active i {
    transform: scale(1.12);
}

.mob-nav-btn.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2.5px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
}

/* ── Mobile "More" Bottom Sheet ─────────────────────────────── */
.mob-more-menu {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 350;
}

.mob-more-menu.open {
    display: block;
}

.mob-more-menu-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.35);
    animation: fadeIn .2s ease;
}

.mob-more-menu-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 12px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0,0,0,.12);
    animation: slideUpSheet .25s ease;
}

@keyframes slideUpSheet {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.mob-more-menu-handle {
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: #ddd;
    margin: 0 auto 16px;
}

.mob-more-menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.mob-more-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}

.mob-more-item i {
    font-size: 1.3rem;
    color: var(--accent);
}

.mob-more-item:active {
    background: rgba(99,102,241,.08);
    border-color: var(--accent-light);
    transform: scale(.96);
}

/* ══════════════════════════════════════════════════════════════
   TABLET BREAKPOINT (768px – 1024px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    /* Sidebar becomes an overlay on tablet too */
    #menuToggle { display: flex !important; }
    .sidebar { transform: translateX(-100%) !important; }
    html[dir="rtl"] .sidebar { transform: translateX(100%) !important; }
    .sidebar.open { transform: translateX(0) !important; }
    html[dir="rtl"] .sidebar.open { transform: translateX(0) !important; }
    .main-area { margin-left: 0 !important; margin-right: 0 !important; }

    /* Prevent horizontal overflow */
    .main-area { overflow-x: hidden; }
    body { overflow-x: hidden; }

    /* Content breathing room */
    .content { padding: 16px 20px 24px; }
    .workspace-shell { padding: 18px 20px 0; }

    /* Grids adapt */
    .dash-payment-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    .dashboard-queue-grid { grid-template-columns: repeat(2, 1fr); }
    .forms4-stats { grid-template-columns: repeat(2, 1fr); }

    /* Tables scrollable container */
    .table-wrap,
    .ws-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -4px;
        padding: 0 4px;
    }
    .table-wrap table,
    .ws-table-wrap table {
        min-width: 600px;
    }
}


/* ══════════════════════════════════════════════════════════════
   MOBILE BREAKPOINT (max-width: 768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Show bottom nav */
    .mobile-bottom-nav { display: flex; }

    /* Add bottom padding for content so it doesn't hide behind bottom nav */
    .content {
        padding: 12px 14px calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* ── Header adjustments ── */
    .top-header {
        height: 50px;
        padding: 0 12px !important;
    }
    .header-right {
        gap: 8px;
    }
    .header-right h1 {
        font-size: .88rem !important;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .header-date { display: none !important; }
    .header-left {
        gap: 6px !important;
    }
    /* Hide refresh button text, keep icon */
    .header-left .btn {
        font-size: .72rem !important;
        padding: 5px 8px !important;
    }
    /* Hide user name/role text on mobile */
    .user-menu-compact > div:not(.user-avatar) {
        display: none !important;
    }
    .btn-icon { width: 34px; height: 34px; }
    .user-avatar { width: 30px; height: 30px; font-size: .72rem; }

    /* ── Workspace shell ── */
    .workspace-shell {
        padding: 14px 14px 0 !important;
    }
    .workspace-shell-main {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    .workspace-shell-title { font-size: 1.3rem !important; }
    .workspace-shell-description { font-size: .85rem; }
    .workspace-shell-meta { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
    .shell-meta-item { padding: 10px 12px; }
    .shell-meta-item strong { font-size: .82rem; }
    .workspace-shell-actions {
        padding: 8px 10px;
        border-radius: 12px;
    }

    /* ── Workspace sub-navigation — horizontal scroll ── */
    .workspace-subnav-wrap {
        margin: 0 -14px !important;
        padding: 0 14px 10px !important;
        position: sticky;
        top: 50px;
    }
    .workspace-subnav {
        gap: 6px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .workspace-subnav-item {
        padding: 8px 12px;
        font-size: .78rem;
        border-radius: 10px;
        min-height: 38px;
    }
    .workspace-subnav-item i { font-size: .78rem; }
    .workspace-subnav-item .badge { font-size: .58rem; padding: 1px 6px; }

    /* ── Cards ── */
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; font-size: .84rem; }

    /* ── KPI cards ── */
    .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 10px; margin-bottom: 16px; }
    .kpi-card { padding: 14px 12px; gap: 10px; }
    .kpi-icon { width: 36px; height: 36px; font-size: .9rem; border-radius: 10px; }
    .kpi-value { font-size: 1.3rem; }
    .kpi-label { font-size: .7rem; }

    /* ── Dashboard queue cards ── */
    .dashboard-queue-grid { grid-template-columns: 1fr !important; gap: 10px; }
    .queue-card { padding: 14px; min-height: unset; gap: 10px; }
    .queue-card-value { font-size: 1.5rem; }
    .queue-card-note { min-height: unset; font-size: .78rem; }

    /* ── Dashboard ops strip ── */
    .dashboard-ops-strip { grid-template-columns: 1fr 1fr !important; gap: 8px; }
    .ops-strip-item { padding: 12px; }
    .ops-strip-value { font-size: 1.1rem; }

    /* ── Alert banner ── */
    .dashboard-alert-banner {
        flex-direction: column;
        padding: 14px;
        border-radius: 14px;
    }
    .dashboard-alert-banner-icon { width: 42px; height: 42px; }

    /* ── Dash2 styles ── */
    .dash2-hero { grid-template-columns: 1fr !important; }
    .dash2-columns { grid-template-columns: 1fr !important; }
    .dash2-breakdown-grid { grid-template-columns: 1fr !important; }
    .dash2-stat-grid.three { grid-template-columns: 1fr 1fr 1fr; }
    .dash2-stat-grid.four { grid-template-columns: 1fr 1fr !important; }
    .dash2-quick-stats { grid-template-columns: 1fr !important; }
    .dash2-attn-strip {
        flex-wrap: nowrap;
        gap: 8px;
    }

    /* ── Payment rows ── */
    .pay-row { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
    .pay-row-name { font-size: .82rem; }
    .pay-row-meta { font-size: .68rem; }
    .pay-row-amount { font-size: .85rem; }
    .pay-row-date { font-size: .68rem; min-width: unset; }

    /* ── Tables — horizontal scroll on mobile ── */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrap .ws-table,
    .ws-table { min-width: 550px; }
    .ws-table th { font-size: .7rem; padding: 8px 6px; white-space: nowrap; }
    .ws-table td { font-size: .78rem; padding: 8px 6px; }

    /* ── Filter bars ── */
    .ws-filter-bar {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .ws-filter-search { min-width: 100% !important; }
    .ws-filter-bar select,
    .ws-filter-bar .search-box,
    .ws-filter-bar input[type="text"],
    .ws-filter-bar input[type="search"] {
        width: 100%;
    }

    /* ── Side panel full width ── */
    .side-panel {
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* ── Modal full screen on mobile ── */
    .modal-overlay {
        align-items: flex-end !important;
        justify-content: stretch !important;
    }
    .modal {
        width: 100vw !important;
        max-height: 92vh;
        border-radius: 20px 20px 0 0 !important;
        margin: 0;
    }
    html[dir="rtl"] .modal {
        border-radius: 20px 20px 0 0 !important;
    }

    /* ── Finance workspace ── */
    .fin-header { grid-template-columns: 1fr !important; }
    .fin-class-bar { flex-direction: column; }
    .fin-class-item { border-left: none; border-bottom: 1px solid var(--border); }
    .fin-class-item:last-child { border-bottom: none; }
    .fin-totals-strip { flex-direction: column; }
    .fin-total-item { border-left: none; }
    .fin-chart-summary { grid-template-columns: 1fr 1fr !important; }
    .fin-chart-header { flex-direction: column; gap: 6px; }

    /* ── Forms ── */
    .forms4-stats { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
    .forms4-toolbar { flex-direction: column; }
    .forms4-grid { grid-template-columns: 1fr !important; }
    .forms4-featured-grid { grid-template-columns: 1fr !important; }
    .forms3-hero { grid-template-columns: 1fr !important; }

    /* ── System ── */
    .sys-settings-grid { grid-template-columns: 1fr !important; }
    .sys-users-grid { grid-template-columns: 1fr !important; }
    .sys-field-row { flex-direction: column; }

    /* ── Export panel ── */
    .export-panel { grid-template-columns: 1fr !important; }

    /* ── Profile ── */
    .profile-hero { flex-direction: column; align-items: center; text-align: center; }
    .profile-grid { grid-template-columns: 1fr !important; }
    .profile-form-row { grid-template-columns: 1fr !important; }

    /* ── Member cards ── */
    .member-grid { grid-template-columns: 1fr !important; }
    .member-card .member-details { grid-template-columns: 1fr !important; }

    /* ── Attention strip scroll ── */
    .attention-strip { gap: 6px; padding: 6px 10px; }
    .attention-strip-label { font-size: .75rem; }
    .attention-chip { padding: 3px 8px; font-size: .68rem; }

    /* ── Pagination on mobile ── */
    .pagination-controls {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }
    .pagination-controls button { padding: 8px 14px; }

    /* ── Toast container above bottom nav ── */
    .toast-container {
        bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* ── Reports grid ── */
    .rpt-grid { grid-template-columns: 1fr !important; }

    /* ── User modal ── */
    .user-modal { max-width: 100vw !important; }

    /* ── Sidebar brand on mobile (when open) ── */
    .sidebar-brand { padding: 14px 16px; }
    .sidebar-brand-mark { width: 48px; min-width: 48px; height: 48px; }
    .sidebar-brand img { width: 36px; }

    /* ── ws-summary strip ── */
    .ws-summary-strip {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .ws-summary-item {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
    }
}


/* ══════════════════════════════════════════════════════════════
   SMALL MOBILE (max-width: 400px) — Compact layout
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
    .content { padding: 10px 10px calc(72px + env(safe-area-inset-bottom, 0px)) !important; }
    .workspace-shell { padding: 10px 10px 0 !important; }
    .workspace-shell-title { font-size: 1.15rem !important; }
    .workspace-shell-meta { grid-template-columns: 1fr !important; }

    .kpi-grid { grid-template-columns: 1fr !important; gap: 8px; }
    .dashboard-ops-strip { grid-template-columns: 1fr !important; }
    .dash2-stat-grid.three { grid-template-columns: 1fr; }
    .forms4-stats { grid-template-columns: 1fr !important; }
    .fin-chart-summary { grid-template-columns: 1fr !important; }

    .top-header { padding: 0 8px !important; }
    .header-right h1 { max-width: 90px; font-size: .78rem !important; }
    .header-right { gap: 6px; }

    /* Smaller bottom nav on tiny screens */
    .mob-nav-btn i { font-size: 1rem; }
    .mob-nav-btn span { font-size: .56rem; }

    .mob-more-menu-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .mob-more-item { padding: 12px 6px; font-size: .72rem; }
}


/* ══════════════════════════════════════════════════════════════
   TOUCH ENHANCEMENTS — Bigger tap targets, better spacing
   ══════════════════════════════════════════════════════════════ */
@media (pointer: coarse) {
    /* Minimum 44px touch targets */
    .btn, button, .nav-item, .nav-subitem, .mob-nav-btn {
        min-height: 44px;
    }
    .nav-item { padding: 10px 14px !important; }
    .nav-subitem { padding: 10px 14px !important; }

    /* Bigger checkboxes/radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }

    /* Prevent double-tap zoom */
    * {
        touch-action: manipulation;
    }

    /* Scroll snapping for horizontal scroll areas */
    .workspace-subnav {
        scroll-snap-type: x proximity;
    }
    .workspace-subnav-item {
        scroll-snap-align: start;
    }

    /* Better select styling for touch */
    select.form-control {
        min-height: 42px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="tel"],
    textarea {
        font-size: 16px; /* prevents iOS zoom */
    }
}


/* ══════════════════════════════════════════════════════════════
   LANDSCAPE MOBILE — Adjust for horizontal orientation
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) and (orientation: landscape) {
    .mobile-bottom-nav { padding: 2px 0 calc(2px + env(safe-area-inset-bottom, 0px)); }
    .mob-nav-btn { padding: 4px 2px 2px; }
    .mob-nav-btn i { font-size: 1rem; }
    .mob-nav-btn span { font-size: .56rem; }
    .content { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important; }
    .dashboard-queue-grid { grid-template-columns: repeat(2, 1fr) !important; }
}


/* ══════════════════════════════════════════════════════════════
   PRINT — Hide UI chrome
   ══════════════════════════════════════════════════════════════ */
@media print {
    .mobile-bottom-nav,
    .mob-more-menu,
    .sidebar,
    #sidebar-overlay,
    .top-header,
    #menuToggle { display: none !important; }
    .main-area { margin: 0 !important; }
    .content { padding: 0 !important; }
}
