:global(:root) {
    /* align with centralized dashboard footer height */
    --app-footer-height: 5vh; /* changed from 2.4vh to 5vh */
}

:global(html, body) {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden; /* prevent tiny horizontal overflow */
}

/* Reserve footer space so main content doesn't get hidden under the fixed footer */
:global(body) {
    padding-bottom: var(--app-footer-height) !important;
}

:global(#app) {
    min-height: 100%;
}

/* Host content area: make available height = viewport - footer */
:host {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--app-footer-height));
    width: 99%;
}

/* Dashboard layout */
.dashboard-compact {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 99%;
    margin: 0 !important;
    padding: 0 !important;
}

    .dashboard-compact .row {
        --bs-gutter-x: .375rem;
        --bs-gutter-y: .25rem;
    }

@media (min-width: 992px) {
    .dashboard-compact .row {
        --bs-gutter-x: .375rem;
        --bs-gutter-y: .35rem;
    }
}

@media (min-width: 1400px) {
    .dashboard-compact .row {
        --bs-gutter-x: .75rem;
        --bs-gutter-y: .4rem;
    }
}

/* Row heights - slightly reduced to avoid overflow */
.vh-row-20 {
    min-height: 5vh;
}

.vh-row-30 {
    min-height: 40vh;
    height: 40.4vh;
}



/* JS-based fallback: body.browser-fullscreen added by script below */
body.browser-fullscreen .vh-row-30 {
    min-height: 40.7vh;
    height: 40.7vh;
}

@media (max-height: 650px) and (orientation: landscape) {
    .vh-row-30 {
        min-height: 34vh;
        height: 34vh;
    }
}

.vh-row-20 .card,
.vh-row-30 .card {
    height: 100%;
}

    .vh-row-30 .card .card-body {
        min-height: 0;
    }

    /* Remove default card margins that can add vertical spacing */
.card {
    margin-top: 0;
    margin-bottom: 0;
}

    /* Card body - reduced padding to remove extra vertical space inside cards */
    .card.themed-card .card-body {
        display: flex;
        flex-direction: column;
        padding: .25rem;
    }

@media (min-width: 992px) {
    .card.themed-card .card-body {
        padding: .5rem;
    }
}

/* Chart area */
.chart-fill {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
}

/* List fill */
.list-fill {
    flex: 1 1 auto;
    overflow: auto;
    margin-bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    flex: 1 1 0;
}

/* Headings/titles - tightened margins */
.dashboard-compact h1,
.dashboard-compact h2,
.dashboard-compact h3,
.dashboard-compact h4,
.dashboard-compact h5,
.dashboard-compact h6 {
    margin-top: .05rem;
    margin-bottom: .15rem;
}

.card-title {
    margin-bottom: .15rem;
}

h3 {
    margin-bottom: .15rem;
}

/* List group */
.dashboard-compact .list-group {
    margin: 0;
}

.dashboard-compact .list-group-item {
    padding: .25rem .375rem;
}

/* Row charts widths */
@media (min-width: 992px) {
    .dashboard-compact .row-charts-1,
    .dashboard-compact .row-charts-2 {
        flex-wrap: nowrap;
    }

        .dashboard-compact .row-charts-1 > [class*="col-"]:nth-child(1),
        .dashboard-compact .row-charts-2 > [class*="col-"]:nth-child(1) {
            flex: 0 0 20.833333% !important;
            max-width: 20.833333% !important;
        }

        .dashboard-compact .row-charts-1 > [class*="col-"]:nth-child(2),
        .dashboard-compact .row-charts-2 > [class*="col-"]:nth-child(2),
        .dashboard-compact .row-charts-1 > [class*="col-"]:nth-child(3),
        .dashboard-compact .row-charts-2 > [class*="col-"]:nth-child(3),
        .dashboard-compact .row-charts-1 > [class*="col-"]:nth-child(4),
        .dashboard-compact .row-charts-2 > [class*="col-"]:nth-child(4) {
            flex: 0 0 26.388889% !important;
            max-width: 26.388889% !important;
        }
}

/* HEADER: grid and widgets */
.page-header {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
    align-items: center;
    column-gap: .2rem;
    min-height: 2.25rem;
    margin-bottom: .3rem;
}

    .page-header > * {
        min-width: 0;
    }

    .page-header .page-title {
        font-size: clamp(1rem, 1.8vw, 2rem);
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 99%;
    }

    .page-header .header-widget {
        font-size: clamp(.75rem, 1vw, .95rem);
        padding: clamp(.2rem, .5vw, .35rem) clamp(.4rem, .8vw, .6rem);
        color: var(--nav-text) !important;
        background: transparent;
        border-color: var(--surface-border);
    }

        .page-header .header-widget i {
            color: var(--nav-text) !important;
        }

    .page-header .last-refresh {
        color: var(--nav-text) !important;
        white-space: nowrap;
    }

    .page-header .header-widget:hover {
        filter: none;
        background: rgba(255,255,255,.06);
    }

    .page-header .theme-toggle {
        grid-column: 1;
        justify-self: start;
    }

    .page-header .page-title {
        grid-column: 2;
        justify-self: center;
        margin: 0;
        text-align: center;
    }

    .page-header .last-refresh {
        grid-column: 3;
        justify-self: end;
    }

@media (max-width: 576px) {
    .header-widget {
        padding: .2rem .45rem;
    }

    .page-header {
        column-gap: .2rem;
    }
}

@media (max-width: 400px) {
    .page-header {
        column-gap: .2rem;
    }

        .page-header .header-widget {
            padding: .2rem .35rem;
        }
}

/* Shared header widget look */
.header-widget {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .25rem .5rem;
    border-radius: .5rem;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-card-bg);
    color: var(--bs-secondary-color);
    font-size: .875rem;
    user-select: none;
}

    .header-widget i {
        color: var(--bs-secondary-color);
    }

    .header-widget:hover {
        filter: brightness(0.98);
    }

/* Enhanced title visuals */
.page-header .page-title.fancy-title {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    position: relative;
}

/* Fancy title underline uses centralized tokens already */
.page-header .page-title.fancy-title::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -.2rem;
    height: 2px;
    background: linear-gradient(90deg, var(--bs-primary), var(--bs-orange));
    border-radius: 2px;
    opacity: .9;
    pointer-events: none;
}

    .page-header .page-title.fancy-title .title-icon {
        color: currentColor;
    }

.page-header .page-title .title-badge {
    display: inline-flex;
    align-items: center;
    padding: .15rem .45rem;
    border-radius: 999px;
    line-height: 1;
    font-size: .75rem;
    font-weight: 600;
    color: var(--bs-light);
    background: var(--bs-orange);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-sm);
}

.page-header .page-title .title-icon,
.page-header .page-title .title-badge {
    flex: 0 0 auto;
}

/* Theme-aware widget colors: keep these driven by centralized tokens */
:root[data-bs-theme="light"] .page-header .header-widget,
:root[data-bs-theme="light"] .page-header .header-widget i,
:root[data-bs-theme="light"] .page_header .theme-toggle,
:root[data-bs-theme="light"] .page-footer .header-widget,
:root[data-bs-theme="light"] .page_footer .header-widget i {
    color: var(--text-primary) !important;
}

/* Footer styles (legacy page-footer kept, app-footer is the component) */
.page-footer {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: .5rem .75rem;
    border-top: 1px solid var(--bs-border-color);
    color: var(--bs-secondary-color);
    background: transparent;
    min-height: var(--app-footer-height); /* ensure legacy footer respects variable */
}

    .page-footer .footer-content {
        width: 99%;
        max-width: 1600px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: clamp(.75rem, 1vw, .95rem);
    }

    .page-footer .header-widget {
        color: var(--nav-text);
        background: transparent;
        border: 1px solid var(--surface-border);
    }

    /* make visit/visit-date more visible in ER list */
.dashboard-compact .list-group-item .er-visit {
    font-weight: 700;
    color: var(--bs-emphasis-color);
    font-size: 0.98rem;
    letter-spacing: 0.2px;
    line-height: 1;
}

.dashboard-compact .list-group-item .er-visit-date {
    color: rgba(255,255,255,0.78);
    font-weight: 600;
    font-size: 0.82rem;
    opacity: 0.95;
}

/* Strong dark-theme selectors + common dark-mode class fallbacks.
   Ensures visit id is pure white in dark mode and provides a tiny text-shadow for legibility. */
html[data-bs-theme="dark"] .dashboard-compact .list-group-item .er-visit,
body[data-bs-theme="dark"] .dashboard-compact .list-group-item .er-visit,
:root[data-bs-theme="dark"] .dashboard-compact .list-group-item .er-visit,
body.dark, body.dark-mode, .dark, .dark-mode .dashboard-compact .list-group-item .er-visit {
    color: var(--text-primary) !important;
    text-shadow: 0 0 2px rgba(0,0,0,0.45);
}

/* Reduce spacing between the two chart rows and between row-charts-2 and the emergency-card row */
.row-charts-1 + .row-charts-2 {
    margin-top: 0.2rem !important; /* reduce from mt-2 (0.5rem) */
}

.row-charts-2 + .emergency-row2 {
    margin-top: 0.2rem !important; /* reduce from mt-2 / mt-3 */
}

/* Neutralize Bootstrap mt utilities if present on these rows */
.row-charts-1.mt-2,
.row-charts-2.mt-2,
.emergency-row2.mt-3 {
    margin-top: 0.2rem !important;
}

/* Tighten horizontal spacing between columns in the two chart rows */
.dashboard-compact .row-charts-1,
.dashboard-compact .row-charts-2 {
    --bs-gutter-x: .2rem; /* halves the horizontal gutter for these rows */
    --bs-gutter-y: .12rem; /* reduce vertical gutter between stacked cols (if any) */
    gap: .2rem; /* modern flex gap to further reduce space between items */
}

/* Slightly different values for large viewports so cards don't touch */
@media (min-width: 992px) {
    .dashboard-compact .row-charts-1,
    .dashboard-compact .row-charts-2 {
        --bs-gutter-x: .35rem;
        --bs-gutter-y: .18rem;
        gap: .35rem;
    }

        /* ensure cards fill column without extra margins */
        .dashboard-compact .row-charts-1 > [class*="col-"] .card,
        .dashboard-compact .row-charts-2 > [class*="col-"] .card {
            margin: 0;
        }
}

/* Slightly reduce vertical padding inside chart cards to tighten visual height */
.dashboard-compact .row-charts-1 .card.themed-card .card-body,
.dashboard-compact .row-charts-2 .card.themed-card .card-body {
    padding-top: .2rem;
    padding-bottom: .2rem;
}

/* Dark theme scrollbar (WebKit) — use centralized vars where possible */
.dashboard-container::-webkit-scrollbar {
    height: 10px;
}

.dashboard-container::-webkit-scrollbar-track {
    background: var(--bs-body-bg);
}

.dashboard-container::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
    border-radius: 6px;
}

    .dashboard-container::-webkit-scrollbar-thumb:hover {
        background: var(--surface-border);
    }

/* Keep remaining layout rules unchanged; colors are now driven by app-theme.css */
