/* NGBVD responsive standard layer
   Purpose: keep dashboard cards, forms, tables, charts and legacy pcoded pages usable across desktop, tablet and mobile.
   Loaded after ngbvd-ui.css so it can safely correct older fixed-width rules. */

:root {
    --ngbvd-responsive-gap: 16px;
}

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

body.ngbvd-body,
.ngbvd-app-shell,
.ngbvd-main,
.ngbvd-content,
.ngbvd-page-container,
.pcoded-content,
.pcoded-inner-content,
.main-body,
.page-wrapper,
.page-body,
.card,
.card-block,
.card-body {
    min-width: 0 !important;
    max-width: 100% !important;
}

.ngbvd-content {
    overflow-x: hidden !important;
}

.ngbvd-page-container {
    width: 100% !important;
}

/* Bootstrap/legacy column safety */
.row,
.ngbvd-content .row,
.pcoded-content .row {
    display: flex;
    flex-wrap: wrap;
    min-width: 0;
}

.row > [class*="col-"],
.ngbvd-content [class*="col-"],
.pcoded-content [class*="col-"] {
    min-width: 0 !important;
}

/* Dashboard KPI cards */
.ngbvd-dashboard-page {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
}

.ngbvd-dashboard-tiles {
    align-items: stretch !important;
}

.ngbvd-dashboard-tiles > [class*="col-"] {
    display: flex !important;
}

.ngbvd-dashboard-tiles .ngbvd-kpi-card,
.ngbvd-kpi-card {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 132px !important;
    overflow: hidden !important;
}

.ngbvd-kpi-card .card-block-small {
    min-width: 0 !important;
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 56px minmax(0, 1fr) !important;
    grid-template-rows: auto auto auto !important;
    gap: 6px 14px !important;
    align-items: center !important;
    padding: 18px !important;
}

.ngbvd-kpi-card .card1-icon {
    grid-row: 1 / span 3 !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    line-height: 56px !important;
    border-radius: 16px !important;
    font-size: 27px !important;
}

.ngbvd-kpi-card span,
.ngbvd-kpi-card h4,
.ngbvd-kpi-card small {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: anywhere !important;
}

.ngbvd-kpi-card span {
    display: block !important;
    font-size: clamp(14px, 1.05vw, 20px) !important;
    line-height: 1.25 !important;
}

.ngbvd-kpi-card h4 {
    display: block !important;
    font-size: clamp(26px, 2.7vw, 42px) !important;
    line-height: 1.03 !important;
    margin: 0 !important;
    letter-spacing: -.035em !important;
}

.ngbvd-kpi-card small {
    display: block !important;
    font-size: clamp(12px, .95vw, 16px) !important;
    line-height: 1.35 !important;
}

/* Dashboard header responsiveness */
.ngbvd-dashboard-header {
    max-width: 100% !important;
    min-width: 0 !important;
}
.ngbvd-dashboard-header > div {
    min-width: 0 !important;
}
.ngbvd-dashboard-header h2 {
    font-size: clamp(26px, 3.1vw, 42px) !important;
    line-height: 1.12 !important;
    overflow-wrap: anywhere !important;
}
.ngbvd-dashboard-header p {
    line-height: 1.45 !important;
}
.ngbvd-dashboard-actions .btn {
    white-space: normal !important;
    text-align: center !important;
}

/* Charts should not create page-level horizontal scroll */
.ngbvd-chart-card,
.ngbvd-chart-card .card-block,
.highcharts-container,
.highcharts-root,
#top_districts,
#national_status,
#regions,
#column-chart,
#column-chart-agegroups,
#line-example,
#donut-example {
    max-width: 100% !important;
    min-width: 0 !important;
}

.ngbvd-chart-card .card-block {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* Tables: keep page intact and scroll table content only */
.table-responsive,
.ngbvd-responsive-table,
.dataTables_wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

.card-block > table.table,
.card-body > table.table,
.section > table.table,
.ngbvd-table-card table.table,
.ngbvd-datatable-card table.table,
.pcoded-content table.table {
    width: 100% !important;
}

@media (max-width: 767px) {
    .card-block > table.table,
    .card-body > table.table,
    .section > table.table,
    .ngbvd-table-card table.table,
    .ngbvd-datatable-card table.table,
    .pcoded-content table.table {
        min-width: 720px !important;
    }
}

.dataTables_wrapper .row,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dt-buttons {
    max-width: 100% !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
}

.dataTables_wrapper .dataTables_filter input {
    max-width: 100% !important;
}

/* Forms and settings pages */
.ngbvd-form-section .row,
.ngbvd-form-card .row,
form .row {
    row-gap: 12px;
}

.form-control,
.form-select,
.selectize-control,
.selectize-input,
select,
input,
textarea {
    max-width: 100% !important;
}

.ngbvd-settings-page .ngbvd-settings-grid,
.ngbvd-theme-template-grid {
    min-width: 0 !important;
}

/* Top bar and navigation on smaller screens */
.ngbvd-topbar,
.ngbvd-topbar-left,
.ngbvd-user-menu {
    min-width: 0 !important;
}
.ngbvd-topbar-title,
.ngbvd-topbar-subtitle {
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 1200px) and (max-width: 1500px) {
    .ngbvd-content { padding: 18px !important; }
    .ngbvd-dashboard-page { padding: 18px 18px 34px !important; }
    .ngbvd-dashboard-header { padding: 24px !important; }
    .ngbvd-kpi-card .card-block-small {
        grid-template-columns: 52px minmax(0, 1fr) !important;
        gap: 6px 12px !important;
        padding: 16px !important;
    }
    .ngbvd-kpi-card .card1-icon {
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        line-height: 52px !important;
        font-size: 25px !important;
    }
    .ngbvd-kpi-card h4 { font-size: clamp(25px, 2.25vw, 36px) !important; }
    .ngbvd-kpi-card span { font-size: clamp(13px, .95vw, 18px) !important; }
}

@media (max-width: 1199px) {
    .ngbvd-dashboard-header {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .ngbvd-dashboard-actions {
        width: 100% !important;
    }
    .ngbvd-dashboard-actions .btn {
        flex: 1 1 220px !important;
        justify-content: center !important;
    }
}

@media (max-width: 991px) {
    .ngbvd-main { margin-left: 0 !important; width: 100% !important; }
    .ngbvd-content { padding: 16px !important; }
    .ngbvd-dashboard-page { padding: 14px !important; }
    .ngbvd-dashboard-header { padding: 20px !important; border-radius: 20px !important; }
    .ngbvd-topbar { gap: 10px !important; }
    .ngbvd-user-menu { gap: 8px !important; }
}

@media (max-width: 767px) {
    body.ngbvd-body { font-size: 13px; }
    .ngbvd-content { padding: 12px !important; }
    .ngbvd-dashboard-page { padding: 10px !important; }
    .ngbvd-dashboard-header { padding: 18px !important; }
    .ngbvd-dashboard-actions .btn { flex-basis: 100% !important; }
    .ngbvd-dashboard-tiles > [class*="col-"] { width: 100% !important; flex: 0 0 100% !important; max-width: 100% !important; }
    .ngbvd-kpi-card .card-block-small {
        grid-template-columns: 50px minmax(0, 1fr) !important;
        padding: 16px !important;
    }
    .ngbvd-kpi-card .card1-icon {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        line-height: 50px !important;
        font-size: 23px !important;
    }
    .ngbvd-kpi-card h4 { font-size: clamp(26px, 8vw, 38px) !important; }
    .ngbvd-kpi-card span { font-size: 15px !important; }
    .ngbvd-topbar-subtitle { display: none !important; }
    .ngbvd-user-pill { padding: 6px 8px !important; }
    .ngbvd-logout { padding: 8px 10px !important; }
    .ngbvd-form-section,
    .ngbvd-form-shell,
    .ngbvd-repeatable-section {
        padding: 14px !important;
        border-radius: 16px !important;
    }
    .nav-tabs .nav-link,
    .ngbvd-wizard-tabs a {
        width: 100% !important;
        text-align: center !important;
    }
}

@media (max-width: 420px) {
    .ngbvd-kpi-card .card-block-small {
        grid-template-columns: 1fr !important;
        text-align: left !important;
    }
    .ngbvd-kpi-card .card1-icon {
        grid-row: auto !important;
        margin-bottom: 4px !important;
    }
}
