/*
 * Phone layout for MudTable rows.
 * Applies to every table that stacks on small screens (MudTable Breakpoint="Breakpoint.Sm" -> .mud-sm-table):
 * each record becomes a card with alternating backgrounds and a coloured accent bar, label on the left, value on the right.
 */
@media (max-width: 959.95px) {
    .mud-table.mud-sm-table {
        background: transparent;
        box-shadow: none;
    }

    .mud-table.mud-sm-table .mud-table-container {
        overflow: visible;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row {
        background: var(--mud-palette-surface);
        border-left: 5px solid var(--mud-palette-primary);
        border-radius: 14px;
        box-shadow: 0 1px 5px rgba(0, 0, 0, .14);
        display: block;
        margin: 0 0 12px;
        overflow: hidden;
    }

    /* strip colours: odd = surface + primary bar, even = tinted + teal bar */
    .mud-table.mud-sm-table tbody tr.mud-table-row:nth-child(odd) {
        background: var(--mud-palette-surface);
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row:nth-child(even) {
        background: rgba(89, 74, 226, .09);
        border-left-color: #14b8c4;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell {
        align-items: center;
        border-bottom: 1px solid rgba(128, 128, 128, .15);
        display: flex;
        gap: 12px;
        justify-content: space-between;
        padding: 9px 14px;
        text-align: right !important;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell:last-child {
        border-bottom: 0;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell::before {
        color: var(--mud-palette-text-secondary);
        flex: 0 0 38%;
        font-size: .75rem;
        font-weight: 500;
        text-align: left;
    }
}

/*
 * Compact rows: show only the first 3 fields (plus any action buttons) at a glance;
 * tap the card (js/mobile-rows.js toggles .br-open) to see everything.
 */
@media (max-width: 959.95px) {
    .mud-table.mud-sm-table tbody tr.mud-table-row {
        cursor: pointer;
        position: relative;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell {
        padding: 6px 40px 6px 14px;
    }

    /* hide detail fields until the card is opened; keep summary fields and cells holding buttons */
    .mud-table.mud-sm-table tbody tr.mud-table-row:not(.br-open) td.mud-table-cell:nth-child(n+4):not(:has(button.mud-button-root, a.mud-button-root)) {
        display: none;
    }

    /* the last visible cell must not show a divider when the rest is collapsed */
    .mud-table.mud-sm-table tbody tr.mud-table-row:not(.br-open) td.mud-table-cell:nth-child(3) {
        border-bottom: 0;
    }

    /* details chevron */
    .mud-table.mud-sm-table tbody tr.mud-table-row::after {
        border-bottom: 2px solid var(--mud-palette-text-secondary);
        border-right: 2px solid var(--mud-palette-text-secondary);
        content: "";
        height: 8px;
        pointer-events: none;
        position: absolute;
        right: 16px;
        top: 16px;
        transform: rotate(45deg);
        transition: transform .15s;
        width: 8px;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row.br-open::after {
        transform: rotate(225deg);
    }

    /* buttons inside a cell must stay tappable and not toggle the card visually */
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell .mud-button-root {
        cursor: pointer;
    }
}

/* row-number columns are noise on a phone card; show one more field in the summary instead */
@media (max-width: 959.95px) {
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="No"],
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Id"],
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="#"],
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="S/N"] {
        display: none;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row:not(.br-open):has(> td:is([data-label="No"],[data-label="Id"],[data-label="#"],[data-label="S/N"]):first-child) td.mud-table-cell:nth-child(4):not(:has(button.mud-button-root, a.mud-button-root)) {
        display: flex;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row:not(.br-open):has(> td:is([data-label="No"],[data-label="Id"],[data-label="#"],[data-label="S/N"]):first-child) td.mud-table-cell:nth-child(3) {
        border-bottom: 1px solid rgba(128, 128, 128, .15);
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row:not(.br-open):has(> td:is([data-label="No"],[data-label="Id"],[data-label="#"],[data-label="S/N"]):first-child) td.mud-table-cell:nth-child(4) {
        border-bottom: 0;
    }
}

/* Collapsible filter area (Shared/MobileCollapse.razor): desktop shows the body only, phones get a collapsed bar */
.br-collapse-toggle {
    display: none;
}

@media (max-width: 959.95px) {
    .br-collapse {
        margin-bottom: 12px;
    }

    .br-collapse-toggle {
        align-items: center;
        background: var(--mud-palette-surface);
        border: 1px solid rgba(128, 128, 128, .3);
        border-radius: 12px;
        color: var(--mud-palette-text-primary);
        cursor: pointer;
        display: flex;
        font: inherit;
        font-weight: 500;
        gap: 8px;
        justify-content: space-between;
        padding: 10px 14px;
        width: 100%;
    }

    .br-collapse-toggle > span {
        flex: 1;
        text-align: left;
    }

    .br-collapse:not(.br-open) > .br-collapse-body {
        display: none;
    }

    .br-collapse.br-open > .br-collapse-body {
        margin-top: 8px;
    }

    /* the filter card inside already carries its own bottom margin */
    .br-collapse > .br-collapse-body > .mud-paper {
        margin-bottom: 0 !important;
    }

    /* Reload is not needed on a phone */
    button[title="Reload"],
    .mud-icon-button[title="Reload"] {
        display: none !important;
    }
}

/* Native-style bottom tab bar (Shared/MobileBottomNav.razor) */
.br-bottom-nav,
.br-bottom-nav-spacer {
    display: none;
}

@media (max-width: 959.95px) {
    .br-bottom-nav {
        background: var(--mud-palette-surface);
        border-top: 1px solid rgba(128, 128, 128, .25);
        bottom: 0;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, .12);
        display: flex;
        justify-content: space-around;
        left: 0;
        padding-bottom: env(safe-area-inset-bottom);
        position: fixed;
        right: 0;
        z-index: 1200;
    }

    .br-bottom-nav-spacer {
        display: block;
        height: calc(68px + env(safe-area-inset-bottom));
    }

    .br-bottom-nav .br-tab {
        align-items: center;
        background: none;
        border: 0;
        color: var(--mud-palette-text-secondary);
        cursor: pointer;
        display: flex;
        flex: 1;
        flex-direction: column;
        font: inherit;
        font-size: .68rem;
        gap: 2px;
        justify-content: center;
        min-height: 60px;
        padding: 6px 2px;
        text-decoration: none;
    }

    .br-bottom-nav .br-tab.active {
        color: var(--mud-palette-primary);
        font-weight: 600;
    }

    .br-bottom-nav .br-tab-primary .mud-icon-root {
        color: var(--mud-palette-primary);
        font-size: 2.1rem;
    }
}

/* Comfortable touch targets: small icon buttons/buttons get a 40px hit area on phones */
@media (max-width: 959.95px) {
    .mud-icon-button.mud-icon-button-size-small {
        min-height: 40px;
        min-width: 40px;
    }

    .mud-button-root.mud-button-size-small {
        min-height: 36px;
    }
}

/* List/card view switch: pointless where the table already stacks into cards, so hide it only on those pages */
@media (max-width: 959.95px) {
    .mud-main-content:has(.mud-sm-table) .mud-icon-button[title="Card view" i],
    .mud-main-content:has(.mud-sm-table) .mud-icon-button[title="List view" i] {
        display: none !important;
    }
}

/*
 * Sessions calendar (Pages/Features/Session/SessionCalendarGrid.razor): on phones the 7-column week grid becomes a
 * vertical day-by-day agenda; the Month toggle is hidden (a 7-column month grid does not fit a phone).
 * Selectors are deliberately specific to win over the component's own <style>.
 */
@media (max-width: 959.95px) {
    .sess-mode-switch {
        display: none !important;
    }

    .sess-calendar-table-wrap table.sess-week-table,
    .sess-calendar-table-wrap table.sess-week-table tbody,
    .sess-calendar-table-wrap table.sess-week-table tr {
        display: block;
        min-width: 0;
        width: 100%;
    }

    .sess-calendar-table-wrap table.sess-week-table thead {
        display: none;
    }

    .sess-calendar-table-wrap table.sess-week-table td {
        border: 0;
        border-bottom: 1px solid rgba(128, 128, 128, .2);
        display: block;
        min-width: 0 !important;
        padding: 12px 14px;
        text-align: left;
        width: 100%;
    }

    .sess-calendar-table-wrap table.sess-week-table td:last-child {
        border-bottom: 0;
    }

    .sess-calendar-table-wrap table.sess-week-table td::before {
        color: var(--mud-palette-primary);
        content: attr(data-day);
        display: block;
        font-size: .85rem;
        font-weight: 700;
        margin-bottom: 8px;
    }

    .sess-calendar-table-wrap table.sess-week-table td:not(:has(.sess-block))::after {
        color: var(--mud-palette-text-secondary);
        content: "No sessions";
        font-size: .8rem;
    }

    .sess-calendar-table-wrap table.sess-week-table .sess-day-cell-inner {
        align-items: stretch;
        min-height: 0;
    }

    .sess-calendar-table-wrap table.sess-week-table .sess-block {
        align-items: center;
        display: flex;
        font-size: .85rem;
        gap: 10px;
        justify-content: space-between;
        padding: 10px 12px;
    }

    .sess-calendar-table-wrap table.sess-week-table .sess-block-patient {
        text-align: right;
    }
}

/* Calendar header on phones: [<]  date range  [>] on one row, "This week" pill centred below */
@media (max-width: 959.95px) {
    .sess-nav {
        align-items: center;
        display: grid !important;
        gap: 6px 4px !important;
        grid-template-columns: auto 1fr auto;
        width: 100%;
    }

    .sess-nav > :nth-child(1) { grid-column: 1; grid-row: 1; }
    .sess-nav > :nth-child(3) { grid-column: 2; grid-row: 1; justify-content: center; }
    .sess-nav > :nth-child(4) { grid-column: 3; grid-row: 1; }
    .sess-nav > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}

/* Forms on phones: bigger fields, and chip sets (e.g. booking time slots) as a 3-column grid of 40px chips */
@media (max-width: 959.95px) {
    .mud-main-content .mud-input > .mud-input-slot.mud-input-root {
        padding-bottom: 11px;
        padding-top: 11px;
    }

    .mud-main-content .mud-chipset {
        display: grid !important;
        gap: 8px;
        grid-template-columns: repeat(3, 1fr);
    }

    .mud-main-content .mud-chipset .mud-chip {
        justify-content: center;
        margin: 0;
        min-height: 40px;
    }
}

/* Money fields are what people look for: always show them in the collapsed card; buttons in cards get a real tap size */
@media (max-width: 959.95px) {
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Balance Due"],
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Balance"],
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Amount To Pay"] {
        display: flex !important;
        font-weight: 600;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell .mud-button-root {
        min-height: 38px;
    }
}

/* Expandable cards (e.g. client packages): summary always, details on tap. Desktop shows everything, no summary line. */
.br-pkg-summary {
    display: none;
}

@media (max-width: 959.95px) {
    .br-expandable {
        cursor: pointer;
        position: relative;
    }

    .br-expandable .br-pkg-summary {
        display: block;
        margin-bottom: 4px;
    }

    .br-expandable:not(.br-open) .br-details {
        display: none;
    }

    .br-expandable::after {
        border-bottom: 2px solid var(--mud-palette-text-secondary);
        border-right: 2px solid var(--mud-palette-text-secondary);
        bottom: 12px;
        content: "";
        height: 8px;
        pointer-events: none;
        position: absolute;
        right: 16px;
        transform: rotate(45deg);
        transition: transform .15s;
        width: 8px;
    }

    .br-expandable.br-open::after {
        transform: rotate(225deg);
    }
}

/*
 * Working Hours / shifts calendar (Pages/Features/TherapistAvailability/ShiftCalendar.razor): same day-by-day agenda
 * treatment as the sessions calendar. The therapist/summary label cell becomes a heading row above each therapist's days.
 */
@media (max-width: 959.95px) {
    .shift-calendar-table-wrap table.shift-week-table,
    .shift-calendar-table-wrap table.shift-week-table tbody,
    .shift-calendar-table-wrap table.shift-week-table tr {
        display: block;
        min-width: 0;
        width: 100%;
    }

    .shift-calendar-table-wrap table.shift-week-table colgroup,
    .shift-calendar-table-wrap table.shift-week-table thead {
        display: none;
    }

    .shift-calendar-table-wrap table.shift-week-table td {
        border: 0;
        border-bottom: 1px solid rgba(128, 128, 128, .2);
        display: block;
        min-width: 0 !important;
        padding: 12px 14px;
        text-align: left;
        width: 100%;
    }

    .shift-calendar-table-wrap table.shift-week-table td.shift-label-col {
        background: rgba(89, 74, 226, .08);
        font-weight: 600;
        padding: 10px 14px;
    }

    .shift-calendar-table-wrap table.shift-week-table td[data-day]::before {
        color: var(--mud-palette-primary);
        content: attr(data-day);
        display: block;
        font-size: .85rem;
        font-weight: 700;
        margin-bottom: 8px;
    }

    .shift-calendar-table-wrap table.shift-week-table td[data-day]:not(:has(.shift-block))::after {
        color: var(--mud-palette-text-secondary);
        content: "No shift";
        font-size: .8rem;
    }

    .shift-calendar-table-wrap table.shift-week-table .shift-day-cell-inner {
        align-items: stretch;
        min-height: 0;
    }

    .shift-calendar-table-wrap table.shift-week-table .shift-block {
        padding: 10px 12px;
    }

    .shift-calendar-table-wrap table.shift-week-table .shift-block-time,
    .shift-calendar-table-wrap table.shift-week-table .shift-block-break-label,
    .shift-calendar-table-wrap table.shift-week-table .shift-block-break-time {
        text-align: left;
    }
}

/* Nested cards/panels each add their own padding; on a phone that leaves ~60% of the width. Tighten the layers. */
@media (max-width: 959.95px) {
    .mud-main-content > .mud-container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .mud-main-content .mud-expand-panel-content.mud-expand-panel-gutters {
        padding: 8px 12px;
    }

    .mud-main-content .mud-paper.pa-4 {
        padding: 12px !important;
    }
}

/* Numeric field spinner arrows are tiny; people type numbers on a phone */
@media (max-width: 959.95px) {
    .mud-main-content .mud-input-numeric-spin,
    .mud-dialog .mud-input-numeric-spin {
        display: none;
    }
}

/* Dialog action buttons (Cancel / Save / Update) get a comfortable tap size */
@media (max-width: 959.95px) {
    .mud-dialog .mud-dialog-actions .mud-button-root {
        min-height: 42px;
    }
}

/* Table pager ("Rows per page", range, arrows) wraps and centres instead of running off the screen */
@media (max-width: 959.95px) {
    .mud-table-pagination-toolbar {
        flex-wrap: wrap;
        height: auto;
        justify-content: center;
        min-height: 52px;
        row-gap: 4px;
    }

    .mud-table.mud-sm-table td.mud-table-cell a.mud-link {
        align-items: center;
        display: inline-flex;
        min-height: 32px;
    }
}

/* Table toolbar (search + filter selects + buttons) wraps: each control takes a full row instead of overflowing */
@media (max-width: 959.95px) {
    .mud-table-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        height: auto;
        min-height: 56px;
        padding-bottom: 8px;
        padding-top: 8px;
    }

    .mud-table-toolbar > .mud-input-control,
    .mud-table-toolbar > .mud-select {
        flex: 1 1 100%;
        margin: 0;
        max-width: 100%;
        min-width: 0;
        width: 100%;
    }

    .mud-table-toolbar > .mud-toolbar-spacer,
    .mud-table-toolbar > .mud-spacer {
        display: none;
    }
}

/* MobileCollapse wrappers are invisible on desktop (their children lay out as if the wrapper were not there) */
.br-collapse,
.br-collapse-body {
    display: contents;
}

@media (max-width: 959.95px) {
    .br-collapse {
        display: block;
        width: 100%;
    }

    .br-collapse-body {
        display: block;
    }

    .br-collapse:not(.br-open) > .br-collapse-body {
        display: none;
    }

    .br-collapse-body > .mud-input-control,
    .br-collapse-body > .mud-select {
        margin: 0 0 8px;
        max-width: 100%;
        width: 100%;
    }
}

/*
 * Tenant / Branch admin dashboards. The scoped component CSS hard-codes widths that add up to more than a phone screen;
 * these !important rules only apply on phones.
 */
@media (max-width: 959.95px) {
    /* branch selector: was a fixed 280px on every part of the control */
    body .mud-main-content .tenant-admin-dashboard-branch,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-input-control,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-input-control-input-container,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-select,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-input-root,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-input-slot,
    body .mud-main-content .tenant-admin-dashboard-branch .mud-select-input {
        flex: 1 1 auto !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    body .mud-main-content .tenant-admin-dashboard-branch .mud-input-adornment {
        flex: 0 0 auto !important;
        width: auto !important;
    }

    /* chart legend wraps */
    .branch-stats__legend {
        flex-wrap: wrap !important;
        gap: 6px 14px !important;
        padding: 8px 12px 12px !important;
    }

    /* week day strip: seven equal columns instead of fixed 40px tiles + a 74px selected pill */
    .branch-appt__days {
        gap: 4px !important;
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
    }

    .branch-appt__day {
        max-width: 44px;
        width: 100% !important;
    }

    .branch-appt__day.is-selected {
        justify-content: center !important;
        padding-left: 0 !important;
        width: 100% !important;
    }

    .branch-appt__day.is-selected::after {
        display: none !important;
    }
}

/* Admin dashboards on phones: date-range / branch filter row wraps; KPI cards are compact 2x2 tiles (no chart/range text) */
@media (max-width: 959.95px) {
    .dash-filter-row {
        flex-wrap: wrap;
    }

    .dash-filter-controls {
        flex: 1 1 100%;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .branch-kpi-card {
        padding: 12px !important;
    }

    .branch-kpi-card__content {
        align-items: flex-start !important;
        flex-direction: column !important;
        gap: 6px !important;
    }

    .branch-kpi-card__right {
        align-items: flex-start !important;
        width: 100%;
    }

    .branch-kpi-card__chart,
    .branch-kpi-card__range {
        display: none !important;
    }

    .branch-kpi-card__value {
        font-size: 1.35rem !important;
    }
}

/* 404 page illustration is a fixed 550px SVG */
@media (max-width: 959.95px) {
    svg[viewBox="0 0 569 384.7"] {
        height: auto;
        max-width: 100%;
    }
}

/* Expand-arrow cells: no caption, control on the right */
@media (max-width: 959.95px) {
    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Expand"]::before {
        display: none;
    }

    .mud-table.mud-sm-table tbody tr.mud-table-row td.mud-table-cell[data-label="Expand"] {
        justify-content: flex-end;
    }
}

/* Therapist dashboard KPI cards (Therapist/Components/KpiCard.razor): 2x2 compact tiles, no mini chart */
@media (max-width: 959.95px) {
    .br-kpi-card {
        flex-direction: column;
        height: auto !important;
        min-height: 0;
        padding: 12px !important;
    }

    .br-kpi-card > div {
        margin: 6px 0 0 !important;
        text-align: left !important;
        width: 100%;
    }

    .br-kpi-card .mud-typography-h3 {
        font-size: 1.6rem !important;
    }

    .br-kpi-card .br-kpi-chart {
        display: none !important;
    }

    .br-kpi-avatar {
        height: 40px !important;
        width: 40px !important;
    }
}

/* Admin KPI tiles: keep long values (e.g. "RM200.00") inside the tile */
@media (max-width: 959.95px) {
    .branch-kpi-card__icon {
        height: 36px !important;
        width: 36px !important;
    }

    .branch-kpi-card__left {
        gap: 8px !important;
    }

    .branch-kpi-card__value {
        font-size: 1.15rem !important;
        white-space: nowrap;
    }
}

/*
 * KPI tiles as native-app pastel tiles (supersedes the earlier compact-card rules above):
 * a horizontally scrolling row; each tile = coloured icon, big number, small label underneath.
 * Applies to the therapist, tenant and branch dashboards (.br-kpi-row is on their KPI grid).
 */
@media (max-width: 959.95px) {
    .br-kpi-row {
        flex-wrap: nowrap !important;
        gap: 10px;
        margin: 0 !important;
        overflow-x: auto;
        padding: 2px 2px 8px;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        width: 100% !important;
    }

    .br-kpi-row::-webkit-scrollbar {
        display: none;
    }

    .br-kpi-row > .mud-grid-item {
        flex: 0 0 auto !important;
        max-width: none !important;
        padding: 0 !important;
        scroll-snap-align: start;
        width: 128px !important;
    }

    .br-kpi-row > .mud-grid-item:nth-child(1) { --kpi: #16a34a; --kpi-bg: #e6f7ee; }
    .br-kpi-row > .mud-grid-item:nth-child(2) { --kpi: #2563eb; --kpi-bg: #e6f0ff; }
    .br-kpi-row > .mud-grid-item:nth-child(3) { --kpi: #ea580c; --kpi-bg: #fff0e2; }
    .br-kpi-row > .mud-grid-item:nth-child(4) { --kpi: #9333ea; --kpi-bg: #f3e8ff; }

    /* therapist dashboard tile */
    .br-kpi-row .br-kpi-card {
        align-items: flex-start !important;
        background: var(--kpi-bg) !important;
        border-radius: 16px !important;
        box-shadow: none !important;
        color: #111827 !important;
        height: auto !important;
        padding: 14px 12px !important;
    }

    .br-kpi-row .br-kpi-avatar {
        background: transparent !important;
        border: 0 !important;
        box-shadow: none !important;
        color: var(--kpi) !important;
        height: auto !important;
        width: auto !important;
    }

    .br-kpi-row .br-kpi-card > div {
        display: flex;
        flex-direction: column;
    }

    .br-kpi-row .br-kpi-card .mud-typography-h3 {
        color: #111827;
        font-size: 1.7rem !important;
        order: 1;
    }

    .br-kpi-row .br-kpi-card .mud-typography-subtitle2 {
        color: #4b5563;
        font-size: .78rem !important;
        font-weight: 500 !important;
        opacity: 1 !important;
        order: 2;
    }

    /* tenant / branch dashboard tile */
    .br-kpi-row .branch-kpi-card {
        background: var(--kpi-bg) !important;
        border-radius: 16px !important;
        box-shadow: none !important;
        height: 100%;
        padding: 14px 12px !important;
    }

    .br-kpi-row .branch-kpi-card__left {
        align-items: flex-start !important;
        flex-direction: column !important;
        gap: 4px !important;
    }

    .br-kpi-row .branch-kpi-card__icon {
        background: transparent !important;
        box-shadow: none !important;
        color: var(--kpi) !important;
        height: auto !important;
        width: auto !important;
    }

    .br-kpi-row .branch-kpi-card__icon .mud-icon-root {
        color: var(--kpi) !important;
    }

    .br-kpi-row .branch-kpi-card__meta {
        display: flex;
        flex-direction: column;
    }

    .br-kpi-row .branch-kpi-card__value {
        color: #111827 !important;
        font-size: 1.35rem !important;
        order: 1;
    }

    .br-kpi-row .branch-kpi-card__title {
        color: #4b5563 !important;
        font-size: .78rem !important;
        order: 2;
    }

    .br-kpi-row .branch-kpi-card__pill {
        font-size: .68rem !important;
        padding: 2px 8px !important;
    }
}

/* KPI tile labels wrap inside the tile instead of being clipped */
@media (max-width: 959.95px) {
    .br-kpi-row .br-kpi-card .mud-typography-subtitle2,
    .br-kpi-row .branch-kpi-card__title {
        overflow-wrap: anywhere;
        white-space: normal !important;
    }

    .br-kpi-row .branch-kpi-card__meta,
    .br-kpi-row .br-kpi-card > div {
        min-width: 0;
        width: 100%;
    }
}

/*
 * Dashboard page background + cards (therapist / tenant / branch): soft primary-tinted gradient behind white rounded cards,
 * like native dashboard apps. Tinted from theme variables so it also works in dark mode.
 */
@media (max-width: 959.95px) {
    .mud-main-content:has(.br-kpi-row) {
        background: linear-gradient(180deg,
            color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-background)) 0%,
            color-mix(in srgb, var(--mud-palette-primary) 5%, var(--mud-palette-background)) 40%,
            var(--mud-palette-background) 100%);
        min-height: 100vh;
    }

    .mud-main-content:has(.br-kpi-row) .mud-paper:not(.br-kpi-card):not(.branch-kpi-card) {
        border-radius: 16px !important;
        box-shadow: 0 2px 12px rgba(37, 99, 235, .08) !important;
    }
}

/* slightly deeper pastels so the tiles stay distinct on the tinted dashboard background */
@media (max-width: 959.95px) {
    .br-kpi-row > .mud-grid-item:nth-child(1) { --kpi-bg: #d9f4e3; }
    .br-kpi-row > .mud-grid-item:nth-child(2) { --kpi-bg: #d6e6ff; }
    .br-kpi-row > .mud-grid-item:nth-child(3) { --kpi-bg: #ffe6cf; }
    .br-kpi-row > .mud-grid-item:nth-child(4) { --kpi-bg: #ecdcff; }
}

/*
 * Tenant/Branch admin KPI row: 3 equal tiles per row (not a scroller like the therapist row), short labels.
 * Overrides the earlier .br-kpi-row rules for this component only (branch-kpi-card, not br-kpi-card).
 */
@media (max-width: 959.95px) {
    .br-kpi-row:has(.branch-kpi-card) {
        display: grid !important;
        flex-wrap: unset !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        overflow-x: visible;
    }

    .br-kpi-row:has(.branch-kpi-card) > .mud-grid-item {
        min-width: 0 !important;
        width: auto !important;
    }

    .br-kpi-row:has(.branch-kpi-card) > .mud-grid-item:nth-child(4) {
        grid-column: 1 / -1;
    }

    .br-kpi-row .branch-kpi-card .br-title-full {
        display: none;
    }

    .br-kpi-row .branch-kpi-card .br-title-short {
        display: inline;
    }

    .br-kpi-row .branch-kpi-card__value {
        overflow-wrap: anywhere;
    }
}

/* Desktop: the mobile-only short label stays hidden */
.br-title-short {
    display: none;
}

/* KPI tile right column (pill/range) must not force the tile — or the page — wider than its grid track */
@media (max-width: 959.95px) {
    .branch-kpi-card__right {
        flex-shrink: 1;
        max-width: 100%;
        min-width: 0 !important;
    }
}
