/* ==========================================================================
   Affscash Global 100% Responsive Engine
   Covers Admin, Affiliate, Affiliate Manager, and Advertiser panels.
   Enforces clean 2-cards-per-row on mobile/tablet and zero horizontal overflow.
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

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

.app-layout,
.main-content,
.page-body {
    min-width: 0;
    max-width: 100%;
}

/* Universal table horizontal scroll safety */
.table-responsive,
.table-wrap,
.fds-table-wrap,
.data-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* Prevent images, canvases, and charts from breaking containers */
.page-body img,
.page-body canvas,
.page-body svg {
    max-width: 100%;
}

/* ── Tablet (<= 1024px) ───────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .charts-2,
    .charts-3,
    .fds-grid-2,
    .dashboard-split,
    .split-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ── Mobile (<= 768px): Strict 2 Cards Per Row Everywhere ─────────────────── */
@media (max-width: 768px) {
    .page-body {
        padding: 12px 10px 24px !important;
        overflow-x: hidden !important;
    }

    /* Enforce 2-cards-per-row across ALL KPI / Stat / Summary grids */
    .stats-grid,
    .kpi-grid,
    .fds-kpi-grid,
    .fds-stat-grid,
    .rep-stats-grid,
    .modern-stat-grid,
    .mgr-stats-grid,
    .vpn-stats-grid,
    .stat-grid-5,
    .stat-grid-6,
    .inv-stats-grid,
    .tb-kpi-grid,
    .rd-stats-grid,
    .po-kpi-grid,
    .ov-stat-grid,
    .dup-stats-grid,
    .cr-stats-grid,
    .cr-admin-stats-grid,
    .camp-kpi-grid,
    .an-kpi-grid,
    .aig-kpi-grid,
    .adv-stat-grid,
    .act-summary-grid,
    .ac-kpi-grid,
    .dash-stats-grid,
    .summary-grid,
    .metrics-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    /* Compact, crisp card sizing inside 2-column mobile stat grids */
    .stats-grid > *,
    .kpi-grid > *,
    .fds-kpi-grid > *,
    .fds-stat-grid > *,
    .rep-stats-grid > *,
    .modern-stat-grid > *,
    .mgr-stats-grid > *,
    .vpn-stats-grid > *,
    .stat-grid-5 > *,
    .stat-grid-6 > *,
    .inv-stats-grid > *,
    .tb-kpi-grid > *,
    .rd-stats-grid > *,
    .po-kpi-grid > *,
    .ov-stat-grid > *,
    .dup-stats-grid > *,
    .cr-stats-grid > *,
    .cr-admin-stats-grid > *,
    .camp-kpi-grid > *,
    .an-kpi-grid > *,
    .aig-kpi-grid > *,
    .adv-stat-grid > *,
    .act-summary-grid > *,
    .ac-kpi-grid > * {
        min-width: 0 !important;
        padding: 12px 12px !important;
        border-radius: 12px !important;
        overflow: hidden;
    }

    /* Prevent large currency/metric numbers from overflowing 2-up cards */
    .stat-value,
    .kpi-value,
    .fds-stat-value,
    .fds-kpi-val,
    .mgr-stat-val,
    .rep-stat-val,
    .adv-stat-val {
        font-size: clamp(16px, 4.8vw, 22px) !important;
        line-height: 1.2 !important;
        word-break: break-word;
    }

    .stat-label,
    .kpi-label,
    .fds-stat-label,
    .fds-kpi-label {
        font-size: 10.5px !important;
        line-height: 1.3 !important;
        white-space: normal !important;
    }

    /* Page headers, toolbars, and filter rows wrap cleanly */
    .page-header,
    .card-header,
    .toolbar,
    .filter-bar,
    .filters-bar,
    .rep-filters,
    .action-bar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .filter-bar input,
    .filter-bar select,
    .filters-bar input,
    .filters-bar select,
    .rep-filters input,
    .rep-filters select {
        min-width: 0 !important;
        max-width: 100% !important;
        flex: 1 1 140px;
    }

    /* Cards & tables padding on mobile */
    .card {
        border-radius: 14px !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .card-body {
        padding: 14px !important;
    }

    /* Wrap bare tables inside cards smoothly */
    .card {
        overflow-x: auto;
    }

    .table th,
    .table td,
    .fds-table th,
    .fds-table td {
        padding: 9px 10px !important;
        font-size: 12px !important;
    }

    /* Modals fit mobile viewport cleanly */
    .modal-dialog,
    .modal-content,
    .modal-box {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        margin: 12px auto !important;
    }

    /* Pagination wraps nicely */
    .pagination {
        flex-wrap: wrap !important;
        gap: 4px !important;
        justify-content: center !important;
    }
}

/* ── Extra-Small Phones (<= 380px): Still 2 Cards Per Row, Tighter Gap ────── */
@media (max-width: 380px) {
    .stats-grid,
    .kpi-grid,
    .fds-kpi-grid,
    .fds-stat-grid,
    .rep-stats-grid,
    .modern-stat-grid,
    .mgr-stats-grid,
    .inv-stats-grid {
        gap: 8px !important;
    }

    .stats-grid > *,
    .kpi-grid > *,
    .fds-kpi-grid > *,
    .fds-stat-grid > * {
        padding: 10px 9px !important;
    }
}
