/* =============================================================================
   souce-grid.css — Layer 1 of docs/DESIGN/LIST_PAGE_AND_DATAGRID_STANDARD.md
   Date: 2026-10-22

   WHY THIS FILE EXISTS
     The standard's §3.1 audit found ~39 `souce-*` class names referenced in .razor
     markup and exactly TWO with a CSS rule. Everything else resolved to nothing, so:

       - status "pills" had no padding, no border-radius and no font-size. They were
         coloured rectangles of body-size text, because only the inline background
         and colour landed;
       - MiniStatCard's label/value/sub had no typography of their own;
       - the parent spec's grid header styling was applied to no grid at all.

     That is why the standard calls this the root cause, and why Layer 1 comes before
     any component work: every grid already carrying these names picks the correct
     look up from here without being touched.

   §7 DECISIONS, SETTLED 2026-10-22
     1. Grids are FLAT with an 8px radius, per the parent design system. KPI cards keep
        12px and a shadow. The grid and the cards above it therefore differ, which is
        deliberate rather than an oversight — a table is a surface you read, a card is
        an object you glance at.
     2. Column titles are written title-case in markup and uppercased HERE. So
        `Title="Reference"` is correct and a hand-typed `"REF-NO"` is wrong at source.

   TOKENS, NOT HEX
     Values come through var(--mud-palette-*) wherever MudBlazor exposes an equivalent,
     with the parent spec's hex as the fallback. Inlining the hex would break dark mode,
     which is the one thing a global stylesheet is well placed to get right.

   SCOPE
     Global on purpose. Scoped .razor.css cannot reach MudBlazor's internal DOM without
     ::deep gymnastics (standard §3.4), and these rules target MudBlazor's own markup.
   ============================================================================= */

:root {
    /* The parent spec's palette, as fallbacks only. */
    --souce-border: var(--mud-palette-table-lines, #E2E8F0);
    /* MudBlazor spells this -gray, not -grey. With the British spelling the variable simply
       does not exist, so the fallback won EVERY time — a light #F1F5F9 header that stayed light
       in dark mode while the text colour correctly went light, leaving the column titles at
       1.13:1 against their own background. Measured by scripts/pos-ui/e2e_lending_ui.spec.js;
       invisible in light mode, which is why it survived to here. */
    --souce-header-bg: var(--mud-palette-background-gray, #F1F5F9);
    --souce-header-fg: var(--mud-palette-text-secondary, #94A2AF);
    --souce-body-fg: var(--mud-palette-text-primary, #151719);
    --souce-surface: var(--mud-palette-surface, #FFFFFF);

    --souce-grid-radius: 8px;   /* §7.1 — grids are 8px and flat */
    --souce-card-radius: 12px;  /* §7.1 — cards keep 12px and a shadow */

    /* §2.5 status colour map, as data. One source of truth; StatusColors.cs mirrors it. */
    --souce-status-success: #10B981;
    --souce-status-success-bg: rgba(16, 185, 129, 0.12);
    /* Through the theme token: light is #8C092E (unchanged), dark is a readable #F87171. */
    --souce-status-error: var(--mud-palette-error, #8C092E);
    --souce-status-error-bg: rgba(140, 9, 46, 0.10);
    --souce-status-info: #7560BA;
    --souce-status-info-bg: rgba(117, 96, 186, 0.12);
    --souce-status-warning: #B45309;
    --souce-status-warning-bg: rgba(245, 158, 11, 0.14);
    --souce-status-muted: #94A2AF;
    --souce-status-muted-bg: rgba(148, 162, 175, 0.15);
    --souce-status-primary: #EF3B69;
    --souce-status-primary-bg: rgba(239, 59, 105, 0.10);
}

/* ── Dark-mode status tokens ─────────────────────────────────────────────────
   The light map's amber (#B45309) and purple (#7560BA) are 2.6:1 and 3.0:1 on the dark
   surface — status you cannot read. MainLayout puts .souce-theme-dark on the root that wraps
   the popover/dialog providers *and* MudLayout, so ⋮ menus and dialogs get the tokens too;
   only the pill tokens change: the MudBlazor Warning/Info palette (245 uses across the app)
   is left alone. Error text is handled by the dark palette itself (#F87171); its tint is
   re-based on that red here, since the light crimson tint is invisible on the dark surface.
   Ratios measured by scripts/pos-ui/e2e_list_pages_ui.spec.js. */
.souce-theme-root {
    display: contents;   /* a token carrier only — must not add a box to the layout */
}

.souce-theme-dark {
    --souce-status-warning: #F59E0B;   /* 6.1:1 */
    --souce-status-info: #A78BFA;      /* 5.6:1 */
    --souce-status-error-bg: rgba(248, 113, 113, 0.14);
}

/* ── Grid container ──────────────────────────────────────────────────────────
   One border, 8px, no shadow. The standard's §3.2 recorded CashRequestForm
   shipping 12px *with* a shadow against a parent spec that says neither; this is
   the parent spec winning. */
.souce-grid-wrap {
    border: 1px solid var(--souce-border);
    border-radius: var(--souce-grid-radius);
    overflow: hidden;
    background: var(--souce-surface);
    box-shadow: none;
}

.souce-grid-wrap .mud-paper,
.souce-grid-wrap.mud-paper {
    box-shadow: none !important;
    border-radius: var(--souce-grid-radius);
}

/* ── Tier B: a legacy MudTable carrying its own container ────────────────────
   §5 Tier B keeps MudTable on ~110 master-data screens and changes only the look. With no
   SouceDataGrid wrapper around it, the table's own root takes the container role: one border,
   8px, flat — and `.souce-grid` on the same element pulls in the header/body rules below, so a
   Tier B table and a SouceDataGrid read as the same component. */
.mud-table.souce-grid-standalone,
.mud-simple-table.souce-grid-standalone {
    border: 1px solid var(--souce-border);
    border-radius: var(--souce-grid-radius);
    overflow: hidden;
    background: var(--souce-surface);
    box-shadow: none !important;
}

/* MudTable puts its toolbar inside the container; give it the same breathing room as the
   list-page toolbar above a SouceDataGrid. */
.mud-table.souce-grid-standalone .mud-toolbar {
    padding-left: 16px;
    padding-right: 16px;
    border-bottom: 1px solid var(--souce-border);
}

/* ── Header row ───────────────────────────────────────────────────────────────
   Specificity matters here. MudBlazor styles header cells with
   `.mud-table-root .mud-table-head .mud-table-cell` (0,3,0), which beat the earlier
   `.souce-grid .mud-table-head th` (0,2,1) on every property MudBlazor also sets — so
   text-transform, size, weight and colour never applied and only the background (which
   MudBlazor leaves alone) got through. Found by scripts/pos-ui/e2e_list_pages_ui.spec.js.
   The selector below adds `.souce-grid` to MudBlazor's own chain, so it wins at (0,4,0). */
.souce-grid .mud-table-root .mud-table-head .mud-table-cell,
.souce-grid .mud-table-head th,
.souce-grid thead th {
    background: var(--souce-header-bg);
    color: var(--souce-header-fg);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 10px 16px;

    /* §7.2 — titles are title-case at source and uppercased here. */
    text-transform: uppercase;
    white-space: nowrap;
}

/* MudBlazor puts the sort label inside the th; it inherits nothing by default. */
.souce-grid .mud-table-root .mud-table-head .mud-table-cell .mud-button-root,
.souce-grid .mud-table-head th .mud-button-root,
.souce-grid .mud-table-head th .mud-table-sort-label {
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    color: inherit;
}

/* ── Body cells ─────────────────────────────────────────────────────────────── */
.souce-grid .mud-table-root .mud-table-body .mud-table-cell,
.souce-grid .mud-table-body td,
.souce-grid tbody td {
    color: var(--souce-body-fg);
    font-size: 0.8125rem;
    padding: 12px 16px;
    border-bottom: 1px solid var(--souce-border);
}

.souce-grid .mud-table-root .mud-table-body tr:last-child .mud-table-cell,
.souce-grid .mud-table-body tr:last-child td {
    border-bottom: none;
}

/* Sticky columns need their own background or rows show through them when the
   grid scrolls horizontally, plus an edge shadow so the seam is legible. */
/* MudBlazor 9 names these `sticky-left` / `sticky-right`; the older `mud-table-cell-sticky-*`
   names are kept for safety but matched nothing. */
.souce-grid .mud-table-root .mud-table-cell.sticky-left,
.souce-grid .mud-table-root .mud-table-cell.sticky-right,
.souce-grid .mud-table-cell-sticky-left,
.souce-grid .mud-table-cell-sticky-right {
    background: var(--souce-surface);
}

.souce-grid .mud-table-root .mud-table-head .mud-table-cell.sticky-left,
.souce-grid .mud-table-root .mud-table-head .mud-table-cell.sticky-right,
.souce-grid .mud-table-head .mud-table-cell-sticky-left,
.souce-grid .mud-table-head .mud-table-cell-sticky-right {
    background: var(--souce-header-bg);
}

.souce-grid .mud-table-root .mud-table-cell.sticky-left,
.souce-grid .mud-table-cell-sticky-left {
    box-shadow: 1px 0 0 0 var(--souce-border);
}

.souce-grid .mud-table-root .mud-table-cell.sticky-right,
.souce-grid .mud-table-cell-sticky-right {
    box-shadow: -1px 0 0 0 var(--souce-border);
}

/* ── Status pill (§2.5) ──────────────────────────────────────────────────────
   The class whose absence was most visible. Colour still arrives inline or via a
   modifier; this supplies the shape and type that were missing. */
.souce-status-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.6;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.souce-status-success { color: var(--souce-status-success); background: var(--souce-status-success-bg); }
.souce-status-error   { color: var(--souce-status-error);   background: var(--souce-status-error-bg); }
.souce-status-info    { color: var(--souce-status-info);    background: var(--souce-status-info-bg); }
.souce-status-warning { color: var(--souce-status-warning); background: var(--souce-status-warning-bg); }
.souce-status-muted   { color: var(--souce-status-muted);   background: var(--souce-status-muted-bg); }
.souce-status-primary { color: var(--souce-status-primary); background: var(--souce-status-primary-bg); }

/* ── Money ──────────────────────────────────────────────────────────────────
   Tabular figures so columns of numbers line up on the decimal point, which is
   the whole reason a money column is right-aligned in the first place. */
.souce-cell-amount {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    justify-content: flex-end;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.souce-cell-amount .souce-amount-symbol {
    color: var(--souce-header-fg);
    font-size: 0.75rem;
}

.souce-cell-amount .souce-amount-value {
    font-weight: 500;
}

/* A negative figure reads as a problem; it should not need a second glance. */
.souce-cell-amount.souce-amount-negative .souce-amount-value {
    color: var(--souce-status-error);
}

/* Rows that open their record on click (SouceDataGrid Class="souce-grid-rowlink"). */
.souce-grid-rowlink .mud-table-body .mud-table-row {
    cursor: pointer;
}

/* ── Row actions ──────────────────────────────────────────────────────────────
   Every ⋮ menu passes this as its MudMenu ListClass, so it styles the LIST inside the popover,
   not the cell. It used to be `display:flex` with no direction — a ROW — which put the items
   side by side: two fit (Invoice), but Cash Request's ten squeezed each item to 24px, stretched
   each divider to 780px and pushed the menu ~1,270px off the left edge of the screen. A menu
   stacks. Found 2026-11-25 by the row-actions step in e2e_list_pages_ui.spec.js. */
.souce-row-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 200px;
    padding: 4px 0;
}

.souce-row-actions .mud-menu-item,
.souce-row-actions .mud-list-item {
    white-space: nowrap;
}

.souce-row-actions .mud-divider {
    width: auto;
    margin: 4px 0;
}

/* §2.3 — destructive items are tinted, never a full red row. */
.souce-menu-destructive {
    color: var(--souce-status-error) !important;
}

.souce-columns-menu {
    min-width: 220px;
    padding: 4px 0;
}

.souce-columns-menu .mud-list-item {
    padding-top: 2px;
    padding-bottom: 2px;
}

.souce-columns-menu-body {
    padding: 8px 12px;
    min-width: 220px;
}

.souce-columns-menu-caption {
    display: block;
    color: var(--souce-header-fg);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ── KPI cards (§7.1 — 12px and a shadow, unlike the grid) ─────────────────── */
.souce-stat-card {
    border: 1px solid var(--souce-border);
    border-radius: var(--souce-card-radius);
    padding: 16px;
    background: var(--souce-surface);
    box-shadow: 0 1px 2px rgba(21, 23, 25, 0.04);
    height: 100%;
}

.souce-stat-label {
    color: var(--souce-header-fg);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.souce-stat-value {
    color: var(--souce-body-fg);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
}

.souce-stat-sub {
    color: var(--souce-header-fg);
    font-size: 0.75rem;
    margin-top: 2px;
}

.souce-stat-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--souce-status-primary-bg);
    color: var(--souce-status-primary);
}

/* ── Empty / loading ───────────────────────────────────────────────────────── */
.souce-grid-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--souce-header-fg);
}

/* ── Lending: the five-figure dispatch breakdown (§6.2) ─────────────────────
   Not a grid, but it belongs with the grid vocabulary rather than in a scoped
   file: it is a money read-out and must use the same tabular figures and the same
   muted/emphasis treatment as an amount cell, or the two disagree on the same page. */
.souce-figure-rows {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.souce-figure-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--souce-border);
}

.souce-figure-row:last-child {
    border-bottom: none;
}

.souce-figure-row .souce-figure-label {
    color: var(--souce-body-fg);
    font-size: 0.8125rem;
}

.souce-figure-row .souce-figure-hint {
    color: var(--souce-header-fg);
    font-size: 0.6875rem;
    display: block;
}

.souce-figure-row .souce-figure-value {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* The total that leaves the wallet, and the principal. Emphasised because those are
   the two figures an operator is accountable for. */
.souce-figure-row.souce-figure-total {
    border-top: 1px solid var(--souce-border);
    border-bottom: none;
    margin-top: 4px;
    padding-top: 10px;
}

.souce-figure-row.souce-figure-total .souce-figure-label,
.souce-figure-row.souce-figure-total .souce-figure-value {
    font-weight: 600;
    font-size: 0.9375rem;
}

/* A fee the borrower repays is not the same kind of number as the loan; tint it so
   the separation the whole module turns on is visible on the screen too. */
.souce-figure-row.souce-figure-recoverable .souce-figure-value {
    color: var(--souce-status-info);
}

.souce-figure-row.souce-figure-lender .souce-figure-value {
    color: var(--souce-status-warning);
}

/* ── Advanced-filter panel ──────────────────────────────────────────────────
   The collapsible filter strip between the toolbar and the grid (§2 part 4). Same border
   and radius as the grid below it, so the two read as one surface. Replaces an inline
   #E2E8F0 that stayed light in dark mode. */
.souce-filter-panel {
    border: 1px solid var(--souce-border);
    border-radius: var(--souce-grid-radius);
}

/* ── Emphasis text ──────────────────────────────────────────────────────────
   For a figure or date that is a problem (an overdue due date, a balance still owed) or
   settled. Token colours, so they follow dark mode; they replace inline #DC2626 / #10B981. */
.souce-text-error   { color: var(--souce-status-error);   font-weight: 600; }
.souce-text-success { color: var(--souce-status-success); font-weight: 600; }
.souce-text-muted   { color: var(--souce-header-fg); }

/* An AmountCell inside emphasis text takes the emphasis colour. */
.souce-text-error .souce-amount-value,
.souce-text-success .souce-amount-value { color: inherit; }
