/* ==========================================================================
   EWER 2.0 CMS — DASHBOARD LAYOUT RECOVERY v1.0.94

   Conservative responsive repair. Restores the established desktop/laptop
   column rules and only adds overflow safety. It intentionally does not
   redefine the AI province grid or the regional map grid.
   ========================================================================== */

#dashboardView {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: clip;
}

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

#dashboardView > *,
#dashboardView .card,
#dashboardView .card-body,
#dashboardView .card-header,
#dashboardView .chart-card,
#dashboardView .stat-card,
#dashboardView .table-container {
    min-width: 0;
    max-width: 100%;
}

/* Keep the original four-card laptop/desktop KPI arrangement. */
#dashboardView > .stats-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: clamp(.75rem, 1vw, 1rem) !important;
    width: 100%;
}

#dashboardView > .stats-grid > .stat-card {
    width: 100%;
    min-width: 0;
    height: auto;
    overflow: hidden;
}

#dashboardView > .stats-grid .stat-header {
    min-width: 0;
    gap: .55rem;
}

#dashboardView > .stats-grid .stat-title,
#dashboardView > .stats-grid .stat-muted {
    min-width: 0;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

#dashboardView .dashboard-header,
#dashboardView .card-header {
    min-width: 0;
    max-width: 100%;
}

#dashboardView .card-header {
    gap: .75rem;
    flex-wrap: wrap;
}

/* Overflow guards only. The established AI and map styles keep ownership of
   their column counts and breakpoints. */
#dashboardView #aiHotspotsContainer,
#dashboardView #aiHotspotsContainer .ewer-ai4-body,
#dashboardView #aiHotspotsContainer .ewer-ai4-grid,
#dashboardView #aiHotspotsContainer .ai4-province-card,
#dashboardView .ewer-regional-card-body-v2,
#dashboardView #zambiaMapContainer,
#dashboardView #mapInfoPanel,
#dashboardView .ewer-map-info-panel-v2,
#dashboardView .ewer-predictive-panel {
    min-width: 0;
    max-width: 100%;
}

#dashboardView canvas,
#dashboardView svg,
#dashboardView img {
    max-width: 100%;
}

#dashboardView .chart-container,
#dashboardView .ewer-forecast-chart {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

#dashboardView .table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tablet/small-laptop shell: two KPI cards per row. The sidebar is already
   converted to an overlay by sidebar.css at this width. */
@media (max-width: 1024px) {
    #dashboardView > .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 560px) {
    #dashboardView > .stats-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    #dashboardView .card-header {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Compact-height laptop optimisation without changing the grid structure. */
@media (max-height: 760px) and (min-width: 1025px) {
    #dashboardView > .stats-grid > .stat-card {
        padding: .9rem 1rem !important;
    }

    #dashboardView .dashboard-header {
        margin-bottom: 1rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    #dashboardView .stat-card,
    #dashboardView .card,
    #dashboardView .map-path {
        transition: none !important;
        animation: none !important;
    }
}
