@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Serif:wght@600&display=swap');

:root {
    --dash-ink: #0B1F33;
    --dash-muted: #5B6B7C;
    --dash-line: #D7E0EA;
    --dash-surface: #FFFFFF;
    --dash-canvas: #F4F7FB;
    --dash-accent: #0F4C81;
    --dash-accent-soft: #E7F0F8;
    --dash-warn: #B45309;
    --dash-ok: #0F766E;
    --dash-shadow: 0 1px 2px rgba(11, 31, 51, 0.04), 0 8px 24px rgba(11, 31, 51, 0.06);
    --dash-radius: 14px;
}

.dashboard-shell {
    min-height: calc(100vh - 64px);
    padding: 0 0 2rem;
    background:
        radial-gradient(1200px 420px at 10% -10%, #dbe7f4 0%, transparent 55%),
        radial-gradient(900px 380px at 95% 0%, #e7f3ef 0%, transparent 50%),
        var(--dash-canvas);
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--dash-ink);
}

.dash-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 0.65rem 1.1rem;
    border-bottom: 1px solid rgba(15, 76, 129, 0.08);
    background: rgba(255, 255, 255, 0.96);
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 0;
}

.dash-topbar-brand {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.75rem;
    min-width: 0;
}

.dash-eyebrow {
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--dash-accent);
    font-weight: 600;
}

.dash-title {
    margin: 0;
    font-family: "IBM Plex Serif", Georgia, serif;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--dash-ink);
}

.dash-subtitle { display: none; }

.dash-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0;
}

.dash-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--dash-line);
    background: #fff;
    color: var(--dash-muted);
    font-size: 0.68rem;
    font-weight: 600;
}

.dash-chip-warn {
    color: var(--dash-warn);
    border-color: #F6D7A8;
    background: #FFF8EE;
}

.dash-chip-busy {
    color: var(--dash-accent);
    border-color: #B7D0E6;
    background: var(--dash-accent-soft);
}

.dash-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 0.75rem;
    align-items: end;
    justify-content: flex-end;
}

.dash-filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dash-filter-field label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--dash-muted);
}

.dash-filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}

.dash-refresh-btn {
    min-width: 118px;
}

.dash-admin-link {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--dash-muted);
    text-decoration: none;
    padding: 0.45rem 0.7rem;
    border-radius: 8px;
}

.dash-admin-link:hover {
    color: var(--dash-accent);
    background: var(--dash-accent-soft);
}

.dash-alert-wrap {
    padding: 1rem 1.5rem 0;
}

.dash-page-loading,
.dashboard-widget-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 140px;
    color: var(--dash-muted);
    font-size: 0.9rem;
}

.dash-refresh-banner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.85rem;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    background: var(--dash-accent-soft);
    color: var(--dash-accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.dashboard-grid-wrap {
    padding: 0.85rem 1.1rem 1.5rem;
}

.grid-stack-item-content {
    inset: 4px !important;
    overflow: auto !important;
    border-radius: var(--dash-radius);
    background: var(--dash-surface);
    border: 1px solid rgba(15, 76, 129, 0.08);
    box-shadow: var(--dash-shadow);
}

.dashboard-widget-body {
    flex: 1;
    min-height: 0;
    padding: 0.4rem 0.65rem 0.85rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dashboard-apex-wrap {
    width: 100%;
    flex: 1 1 auto;
    min-height: 220px;
    height: 100%;
    overflow: hidden;
}

.dashboard-apex-wrap.is-hbar {
    min-height: 240px;
}

.dashboard-apex-wrap.is-vbar {
    min-height: 220px;
    padding-bottom: 0.15rem;
}

.dashboard-apex-wrap .apexcharts-canvas {
    max-width: 100% !important;
}

@media (max-width: 1024px) {
    .dashboard-apex-wrap,
    .dashboard-apex-wrap.is-hbar,
    .dashboard-apex-wrap.is-vbar {
        min-height: 260px;
    }

    .grid-stack-item-content {
        inset: 6px !important;
    }
}

@media (max-width: 640px) {
    .dashboard-grid-wrap {
        padding: 0.65rem 0.55rem 1.25rem;
    }

    .dashboard-apex-wrap,
    .dashboard-apex-wrap.is-hbar,
    .dashboard-apex-wrap.is-vbar {
        min-height: 240px;
    }

    .dashboard-widget-heading h2 {
        white-space: normal;
    }
}

.dashboard-grid-host.grid-stack {
    position: relative;
    width: 100%;
    min-height: 620px;
}

.dashboard-widget-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
}

.dashboard-widget-card.is-loading {
    opacity: 0.92;
}

.dashboard-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem 0.35rem;
    border-bottom: 1px solid #EDF2F7;
}

.dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-header {
    padding: 0.28rem 0.55rem 0.15rem;
    border-bottom: none;
}

.dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-heading h2 {
    font-size: 0.72rem;
}

.dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-ms,
.dashboard-widget-card:has(.dashboard-kpi-card) .dash-chip-busy {
    display: none;
}

.dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-body {
    padding: 0.15rem 0.5rem 0.35rem;
}

.dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-icon {
    font-size: 0.9rem !important;
}

.dashboard-widget-heading {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.dashboard-widget-heading h2 {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--dash-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dashboard-widget-icon {
    color: var(--dash-accent) !important;
    font-size: 1.05rem !important;
}

.dashboard-widget-ms {
    font-size: 0.68rem;
    color: #94A3B8;
    font-variant-numeric: tabular-nums;
}

.dash-tabs {
    display: flex;
    gap: 4px;
    margin: 0.75rem 1rem 0.25rem;
    padding: 4px;
    width: fit-content;
    background: #EEF2F7;
    border-radius: 12px;
}

.dash-tab {
    padding: 0.45rem 1.1rem;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-size: 0.86rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.dash-tab:hover {
    background: rgba(255, 255, 255, 0.7);
}

.dash-tab.is-active {
    background: #FFFFFF;
    color: var(--brand-red, #C13636);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.dash-tab:focus-visible {
    outline: 2px solid var(--brand-red, #C13636);
    outline-offset: 2px;
}

.dash-tab-panel {
    padding: 0.5rem 1rem 1rem;
}

.dashboard-widget-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.dashboard-widget-open {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.1rem 0.45rem;
    font-size: 0.68rem;
    font-weight: 650;
    color: var(--dash-accent);
    background: transparent;
    border: 1px solid #DCE4EE;
    border-radius: 999px;
    cursor: pointer;
}

.dashboard-widget-open:hover {
    background: #F1F5F9;
}

.dashboard-widget-open:focus-visible {
    outline: 2px solid var(--dash-accent);
    outline-offset: 1px;
}

.dashboard-widget-open .rzi {
    font-size: 0.8rem !important;
}

.dashboard-kpi-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.1rem 0.15rem;
}

.dashboard-kpi-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--dash-muted);
    letter-spacing: 0.02em;
}

.dashboard-kpi-value {
    font-size: clamp(1.15rem, 1.7vw, 1.45rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.dashboard-kpi-change {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.68rem;
    color: var(--dash-muted);
    line-height: 1.2;
}

.dashboard-kpi-change.positive { color: var(--dash-ok); }
.dashboard-kpi-change.negative { color: #B91C1C; }

.dashboard-kpi-card.has-split {
    gap: 0.25rem;
}

.dashboard-kpi-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
}

.dashboard-kpi-split.has-three {
    grid-template-columns: repeat(3, 1fr);
}

.dashboard-kpi-split-item {
    min-width: 0;
    padding: 0.25rem 0.35rem;
    border-radius: 0.4rem;
    background: rgba(15, 76, 129, 0.06);
}

.dashboard-kpi-split-label {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--dash-muted);
    letter-spacing: 0.02em;
    margin-bottom: 0.05rem;
}

.dashboard-kpi-split-value {
    font-size: clamp(0.92rem, 1.3vw, 1.15rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    word-break: break-word;
}

.dashboard-kpi-total {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--dash-muted);
    font-variant-numeric: tabular-nums;
}

.dashboard-kpi-split-item.is-clickable,
button.dashboard-kpi-split-item {
    border: 0;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    width: 100%;
}

.dashboard-kpi-split-item.is-clickable:hover {
    background: rgba(15, 76, 129, 0.12);
}

.dashboard-kpi-split-item:disabled {
    cursor: default;
}

.dashboard-kpi-drill {
    align-self: flex-start;
    margin-top: 0.15rem;
    border: 0;
    background: transparent;
    color: var(--dash-accent);
    font-size: 0.68rem;
    font-weight: 650;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.dashboard-kpi-drill:hover {
    color: #0a3a63;
}

.dash-drill-dialog {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 240px;
}

.dash-drill-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.dash-drill-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
}

.dash-drill-subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.78rem;
    color: var(--dash-muted);
}

.dash-drill-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}

.dash-drill-footer {
    font-size: 0.75rem;
    color: var(--dash-muted);
}

.dash-drill-hint {
    margin: 0.25rem 0 0;
    font-size: 0.72rem;
    color: var(--dash-accent);
    font-weight: 600;
}

.dash-drill-grid.is-row-clickable .rz-data-row {
    cursor: pointer;
}

.dash-drill-grid.is-row-clickable .rz-data-row:hover {
    background: rgba(15, 76, 129, 0.06) !important;
}

.dashboard-widget-error,
.dashboard-widget-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    color: var(--dash-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

.dash-spinner {
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
    border: 2px solid rgba(15, 76, 129, 0.2);
    border-top-color: var(--dash-accent);
    animation: dash-spin 0.7s linear infinite;
    flex: 0 0 auto;
}

.dash-spinner-lg {
    width: 1.35rem;
    height: 1.35rem;
    border-width: 3px;
}

@keyframes dash-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 1100px) {
    .dash-topbar {
        align-items: flex-start;
    }

    .dash-filters {
        justify-content: flex-start;
    }
}

/* Light professional colour. Visual only: no size, position, or behaviour change. */
.dashboard-shell {
    --grp-bg: #ffffff;
    --grp-bar: #0F4C81;
}

.dashboard-shell .dash-topbar {
    box-shadow: inset 0 3px 0 #0F4C81, 0 4px 14px rgba(11, 31, 51, 0.05);
}

.dashboard-shell .dash-eyebrow {
    padding: 0.12rem 0.45rem;
    border-radius: 6px;
    color: #0F4C81;
    background: #E7F0F8;
}

.dashboard-shell .dash-tabs {
    background: transparent;
    border-bottom: 2px solid #D5E1EE;
    border-radius: 0;
    padding: 0 0.15rem;
    width: auto;
}

.dashboard-shell .dash-tab {
    margin-bottom: -2px;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    border-radius: 10px 10px 0 0;
    background: transparent;
}

.dashboard-shell .dash-tab.is-active {
    background: #ffffff;
    border-color: #D5E1EE;
    border-bottom-color: #ffffff;
    box-shadow: inset 0 3px 0 var(--brand-red, #C13636);
}

.dashboard-shell .grid-stack-item .grid-stack-item-content,
.dashboard-shell .grid-stack-item .dashboard-widget-card {
    background: var(--grp-bg);
    box-shadow: inset 0 3px 0 var(--grp-bar), var(--dash-shadow);
}

/* Billing */
.dashboard-shell .grid-stack-item[gs-id="mgmt_billing_fy"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_billing_ytd"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_billing_lq"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_revenue_mtd"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_billing_growth_ly"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_revenue_trend"] {
    --grp-bg: #D6E6F8;
    --grp-bar: #1D4E89;
}

/* Cash and dues */
.dashboard-shell .grid-stack-item[gs-id="mgmt_collections_vs_billing"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_outstanding_dso"] {
    --grp-bg: #D3EFE8;
    --grp-bar: #0F6E63;
}

/* Margin and health */
.dashboard-shell .grid-stack-item[gs-id="mgmt_gross_contribution"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_collections_cover_salary"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_health_score"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_billing_receipts_trend"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_client_billing_vs_salary"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_branch_margin"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_sites_attention"] {
    --grp-bg: #F3E4C4;
    --grp-bar: #A16207;
}

/* Salary and people */
.dashboard-shell .grid-stack-item[gs-id="mgmt_payroll_payout_mtd"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_payroll_payout_l12m"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_site_office_salary"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_guard_strength"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_salary_trend"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_guard_strength_by_branch"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_corporate_salary_by_dept"] {
    --grp-bg: #E3D9F6;
    --grp-bar: #5B4B8A;
}

/* Clients and POs */
.dashboard-shell .grid-stack-item[gs-id="mgmt_clients_sites_billed"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_lost_clients"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_lost_clients_detail"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_po_expiring"],
.dashboard-shell .grid-stack-item[gs-id="mgmt_aging_top_customers"] {
    --grp-bg: #F6D5DC;
    --grp-bar: #9D3D52;
}

.dashboard-shell .dashboard-widget-card:has(.dashboard-kpi-card) .dashboard-widget-header {
    background: transparent;
    border-bottom-color: transparent;
}

.dashboard-shell .dashboard-kpi-split-item {
    background: rgba(255, 255, 255, 0.72);
}
