/* ==========================================================================
   One font, calm fields — the last word on the type and on the form fields.
   Linked LAST in Components/App.razor, so it settles what the earlier layers
   left mixed, without touching their layouts (the shell's menus keep theirs).

   1. One family. --font-display and --font-mono were three families on one
      screen (the text face, the display face of the headings and names, a
      monospace for amounts, dates and account codes — Bank Matching showed all
      three). Now everything is --font-text; figures line up through tabular
      figures, not a monospace. --font-code is kept for what people read as code
      (a template's source, an API key, a webhook secret).
   2. Calm fields in the forms people fill (the invoice / bill / credit note
      editor, a digitized document's review, the bank dialogs, every .form /
      .form-card): one caption style, one field height, one value size, the
      field's look set by the --field-* tokens below. The layouts stay as they
      are — the editor's label-left column (IDE-001, the accountant's Variant C)
      and its folds.
   3. Bank Matching's figures and names in the same family, at quieter sizes.

   A variant changes only the :root tokens of the "Variant" block at the end
   (and serves its font files from wwwroot/fonts). Every colour is a theme token.
   ========================================================================== */

:root {
    /* One family: the variant sets --font-text. */
    --font-display: var(--font-text);
    --font-mono: var(--font-text);
    --font-code: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

    /* Type in the forms. */
    --form-label-size: 13px;
    --form-label-weight: 500;
    --form-label-color: var(--ink-soft);
    --form-value-size: 14px;
    --form-note-size: 12px;
    --form-section-size: 14px;
    --form-row-gap: 8px;

    /* The field (the variant's look). */
    --field-h: 34px;
    --field-pad-x: 10px;
    --field-radius: 0;
    --field-bg: transparent;
    --field-bg-hover: var(--panel-hover);
    --field-bg-focus: var(--panel);
    --field-border: transparent;
    --field-border-hover: transparent;
    --field-underline: var(--line-strong);
    --field-underline-hover: var(--muted-2);
    --field-focus-border: var(--brand);
    --field-focus-shadow: 0 0 0 3px var(--ring);
}

/* ─── 1. One family ───────────────────────────────────────────────────────── */

html, body { font-family: var(--font-text); font-variant-numeric: tabular-nums; }
button, input, select, textarea { font-family: inherit; }
h1, h2, h3, h4 { font-family: var(--font-text); }

/* ─── 2. The fields of a form ─────────────────────────────────────────────── */

/* The caption of a field: the first child of a pair (the editor's column and pairs), the first span of a
   form's <label>. */
:is(.form-column, .form-pairs) > :not(.form-pairs__full, .form-lock--pairs, .form-column__side) > :first-child,
:is(.form-column, .form-pairs) > .form-lock--pairs > :not(.form-pairs__full, .form-column__side) > :first-child,
:is(.form, .form-card) label > span:first-child,
.bankmatch-pane .form-rows > label > span:first-child {
    color: var(--form-label-color);
    font-size: var(--form-label-size);
    font-weight: var(--form-label-weight);
    letter-spacing: 0;
    text-transform: none;
}
.form-column { grid-template-columns: 12em minmax(0, 1fr) minmax(0, 12em); row-gap: var(--form-row-gap); }
.form-pairs { row-gap: var(--form-row-gap); }

/* The field itself. Not inside a grid (a list's filter row, the editor's lines are the grid's to draw). */
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane)
    :is(input:not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=button], [type=submit]), select, textarea):not(.dxg *) {
    min-height: var(--field-h);
    padding: 0 var(--field-pad-x);
    border: 1px solid var(--field-border);
    border-bottom-color: var(--field-underline);
    border-radius: var(--field-radius);
    background: var(--field-bg);
    color: var(--ink);
    font-size: var(--form-value-size);
    font-weight: 400;
    line-height: 1.3;
    box-shadow: none;
}
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane)
    :is(input:not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=button], [type=submit]), select, textarea):not(.dxg *):hover:not(:disabled, :focus) {
    background: var(--field-bg-hover);
    border-color: var(--field-border-hover);
    border-bottom-color: var(--field-underline-hover);
}
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane)
    :is(input:not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=button], [type=submit]), select, textarea):not(.dxg *):focus {
    outline: none;
    background: var(--field-bg-focus);
    border-color: var(--field-focus-border);
    box-shadow: var(--field-focus-shadow);
}
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) textarea:not(.dxg *) { padding-block: 7px; min-height: calc(var(--field-h) * 2); }
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) select:not(.dxg *) { padding-right: 26px; }
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) :is(input, select, textarea):not(.dxg *)::placeholder { color: var(--muted-2); font-weight: 400; }
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) :is(input, select, textarea):not(.dxg *):disabled { opacity: 1; color: var(--muted); cursor: not-allowed; }

/* What sits inside a field keeps its room: the calendar of a date, the buttons of a lookup. */
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) .dateinput > input.dateinput-text:not(.dxg *) { padding-right: 34px; }
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) .lookup > input.lookup-input:not(.dxg *) { padding-right: 54px; }
:is(.form, .form-card, .form-column, .form-pairs, .bankmatch-pane) .lookup.has-open > input.lookup-input:not(.dxg *) { padding-right: 78px; }

/* A read-only value and a note under a field. */
.form-column .form-column__text { font-size: var(--form-value-size); font-weight: 400; color: var(--ink); }
:is(.form-column, .form-pairs) small,
:is(.form, .form-card) label small { font-size: var(--form-note-size); font-weight: 400; color: var(--muted); }

/* The folds' heads and the editor's small headed blocks (Payment, …): one style, no capitals. */
.form-section__toggle,
.invoice-payment__head :is(h3, h4, strong, .onix-overline),
.form-card > h3:first-child {
    font-family: var(--font-text);
    font-size: var(--form-section-size);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink);
}

/* ─── 2b. Nothing scrolls sideways ────────────────────────────────────────── */

/* A list fits the window (DataGrid: Fit to screen is on unless the person turned it off); every other table — the
   editor's lines, a report matrix, a plain table.grid / table.lines, the wrappers that used to scroll — shares the
   width it has: fixed layout, a cell too narrow ends in an ellipsis (hover shows the title where the page sets one). */
.edg-scroll, .ledger-scroll, .bi-table-wrap, .home-bi-table-wrap, .re-scroll, .mayla-data-scroll { overflow-x: hidden; }
.edg .edg-table { table-layout: fixed; width: 100%; min-width: 0; }
.edg .edg-table :is(th, td) { overflow: hidden; }
table.lines, .ledger-scroll table, .bi-table-wrap table, .home-bi-table-wrap table, .re-scroll table, .mayla-data-scroll table {
    width: 100%; max-width: 100%; table-layout: fixed;
}
table.lines th, table.lines td, .ledger-scroll td, .ledger-scroll th { overflow: hidden; text-overflow: ellipsis; }
table.lines th, table.lines td { white-space: nowrap; }
.content table.grid:not(.dxg-table) { width: 100%; max-width: 100%; table-layout: fixed; }
.content table.grid:not(.dxg-table) :is(th, td) { overflow: hidden; text-overflow: ellipsis; }
img, svg, iframe, video { max-width: 100%; }
/* A chip in a table's row (a state, "Sent to <company>") is never cut flat at the cell's edge: longer than the cell,
   it ends in an ellipsis like the text beside it (the whole text is its title). A chip is an inline-flex box, which
   the cell's text-overflow cannot shorten, so in a row it is an inline block with its dot set by hand. */
.dxg .dxg-table tbody tr.dxg-row > td .badge {
    display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.dxg .dxg-table tbody tr.dxg-row > td .badge::before { display: inline-block; vertical-align: middle; margin: -2px 5px 0 0; }

/* A grid too narrow for its columns (js/onix-gridcards.js sets data-cards): each row a card of its fields, every
   field under its column's name, the row's tools at the card's end. The header gives way (sorting and filters stay
   in the control row's Filters and ⋯), the totals keep their figures. */
/* The cards scroll up and down inside the grid as its rows did (the frame clips: an overflow left visible would cut
   the list at the frame's foot); never sideways. */
.dxg[data-cards] .dxg-scroll { overflow-x: hidden; overflow-y: auto; }
.dxg[data-cards] .dxg-table { display: block; width: 100% !important; min-width: 0 !important; table-layout: auto; }
.dxg[data-cards] .dxg-table > colgroup,
.dxg[data-cards] .dxg-table > thead { display: none; }
.dxg[data-cards] .dxg-table > tbody,
.dxg[data-cards] .dxg-table > tfoot { display: block; }
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(130px, 100%), 1fr));
    gap: 8px 18px;
    align-items: start;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
    background: transparent;
}
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td {
    display: block;
    position: static;
    min-width: 0;
    max-width: none;
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
    text-align: left;
    box-shadow: none;
}
.dxg[data-cards] .dxg-table td[data-title]::before {
    content: attr(data-title);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
}
.dxg[data-cards] .dxg-table td:empty { display: none; }
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td,
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td > * { height: auto; min-height: 0; max-height: none; }
/* Nothing in a card's field runs over the field beside it: a chip ("Sent to <company>", a state), a link, a figure
   wraps inside its own cell instead. The row's tools and its check box keep their own layout. */
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td:not(.dxg-command, .edg-command, .dxg-col-check) *:not(input, select, textarea, button, svg, svg *) {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td .badge {
    display: inline-flex; align-items: flex-start; height: auto; line-height: 1.3; text-align: left; overflow: visible; text-overflow: clip;
}
.dxg[data-cards] .dxg-table > :is(tbody, tfoot) > tr > td .badge::before { flex: none; margin: 0.4em 0 0; }
/* The row's tools: across the card's foot, at the right; the check box first. */
.dxg[data-cards] .dxg-table td:is(.dxg-command, .edg-command) { grid-column: 1 / -1; justify-self: end; display: flex; gap: 6px; }
.dxg[data-cards] .dxg-table td.dxg-col-check { grid-column: 1 / -1; }

/* Choosing rows while they are cards. The header is gone, so its select-all box stays as a strip above the cards,
   with its words; each card's box sits in a gutter at the card's left, larger, its touch area the gutter's width,
   and a chosen card is tinted, so a choice is seen at a glance. */
.dxg[data-cards] .dxg-table > thead:has(.dxg-check) { display: block; position: sticky; top: 0; z-index: 3; background: var(--dxg-surface); }
.dxg[data-cards] .dxg-table > thead > tr:not(.dxg-head) { display: none; }
.dxg[data-cards] .dxg-table > thead > tr.dxg-head { display: flex; align-items: center; min-height: 44px; padding: 0 4px; border-bottom: 1px solid var(--line); background: transparent; }
.dxg[data-cards] .dxg-table > thead > tr.dxg-head > th { display: none; }
.dxg[data-cards] .dxg-table > thead > tr.dxg-head > th.dxg-col-check:has(.dxg-check) {
    display: block; position: static; width: auto; height: auto; padding: 0 !important; border: 0; background: transparent; box-shadow: none;
}
.dxg[data-cards] .dxg-check-all { gap: 12px; min-height: 44px; padding-right: 12px; }
.dxg[data-cards] .dxg-check-caption { display: inline; color: var(--ink); font-size: 14px; font-weight: 500; text-transform: none; letter-spacing: 0; }
.dxg[data-cards] .dxg-table > tbody > tr:has(> td.dxg-col-check > .dxg-check) { position: relative; padding-left: 44px; }
.dxg[data-cards] .dxg-table > tbody > tr > td.dxg-col-check:has(> .dxg-check) {
    position: absolute; left: 0; top: 0; bottom: 0; grid-column: auto; width: 44px; padding: 12px 0 0 10px !important; box-shadow: none;
}
.dxg[data-cards] .dxg-table > :is(thead, tbody) > tr > :is(th, td) .dxg-check { width: 22px; height: 22px; min-height: 22px; border-width: 2px; border-radius: 6px; }
.dxg[data-cards] .dxg-check[aria-checked="false"] { border-color: color-mix(in srgb, var(--ink) 40%, transparent); }
.dxg[data-cards] .dxg-check::before { content: ""; position: absolute; inset: -11px; }
.dxg[data-cards] .dxg-table > tbody > tr.selected { background: color-mix(in srgb, var(--brand) 8%, transparent); box-shadow: inset 3px 0 0 var(--brand); }
.dxg[data-cards] .dxg-table > tbody > tr.selected > td { box-shadow: none; }
.dxg[data-cards] .dxg-table td.edg-handle { display: none; }
/* A group's head, a detail panel, an empty note: the whole width. */
.dxg[data-cards] .dxg-table td[colspan] { grid-column: 1 / -1; }
/* A field in a card of the line editor fills its cell. */
.dxg[data-cards].edg .dxg-table td :is(input, select, textarea, .lookup, .dateinput) { width: 100%; max-width: 100%; }

/* ─── 2c. The document editor (invoices, bills, credit notes) ─────────────── */

/* Calm: the header's rows breathe, the helpers beside a field (the registers' buttons, a record's ↗, a lookup's
   caret) appear when the row is pointed at or has the focus, the sections are headed quietly, the lines and the
   totals are flat on the page, the one filled button is the form's. The layout — the label-left column, the folds,
   the tabs — is unchanged. */
.invoice-form { --form-row-gap: 10px; }
.invoice-form .form-column.invoice-header { gap: var(--form-row-gap) 14px; }
.invoice-form .form-section__head { min-height: 32px; margin: 10px 0 6px; }
.invoice-form .form-section__body { padding-bottom: 4px; }

/* Helpers fade in with the pointer: the row stays the field and its value. */
.invoice-form .register-fill,
.invoice-form .lookup-open,
.invoice-form .lookup-toggle,
.invoice-form .lookup-clear,
.invoice-form .dateinput-pick { opacity: 0.38; transition: opacity var(--dur, .16s) ease; }
.invoice-form :is(label, .form-pair, .form-column__side, .field-with-action):is(:hover, :focus-within) :is(.register-fill, .lookup-open, .lookup-toggle, .lookup-clear, .dateinput-pick) { opacity: 1; }
.invoice-form .register-fill .button { border-color: transparent; background: transparent; }
.invoice-form .register-fill:hover .button { border-color: var(--line); background: var(--panel); }

/* "Fill from previous bill / PO…": a quiet text button, not a chip over the form. */
.invoice-form .editor-badge__button.is-ai { background: transparent; border-color: transparent; color: var(--brand); font-weight: 500; padding-left: 0; box-shadow: none; }
.invoice-form .editor-badge__button.is-ai:hover { text-decoration: underline; }

/* The section tabs: text with an underline, in the form's own type. */
.invoice-form .onix-segmented { background: transparent; border: 0; padding: 0; gap: 18px; margin: 14px 0 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.invoice-form .onix-segmented button { padding: 8px 0; border-radius: 0; background: transparent; color: var(--muted); font-size: var(--form-value-size); font-weight: 500; box-shadow: none; }
.invoice-form .onix-segmented button:hover { color: var(--ink); }
.invoice-form .onix-segmented button.is-active { background: transparent; color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--brand); }

/* The lines: no frame around the grid, a rule under the head, quiet row lines; the add links a row of their own. */
.invoice-form .edg .dxg-frame { border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.invoice-form .edg .dxg-table thead th { background: transparent; border-bottom: 1px solid var(--line-strong); font-size: 12px; letter-spacing: .03em; color: var(--muted); }
.invoice-form .edg .dxg-table tbody td { border-bottom: 1px solid var(--line); }
.invoice-form .edg-add, .invoice-form .edg-foot { padding: 6px 0; }

/* The totals: a block at the right with a rule over the total, no card. */
.invoice-form .onix-card.editor-totals { background: transparent; border: 0; box-shadow: none; padding: 6px 0 0; margin-left: auto; max-width: 380px; }
.invoice-form .editor-totals__row { padding: 5px 0; border: 0; }
.invoice-form .editor-totals__row:last-child { border-top: 1px solid var(--line-strong); margin-top: 4px; padding-top: 8px; }
.invoice-form .editor-totals__amount { font-variant-numeric: tabular-nums; }

/* Payment, Terms, Installments: one quiet heading each, a hairline above. */
.invoice-form .invoice-payment { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.invoice-form .invoice-payment__head { margin-bottom: 8px; }

/* The form's own buttons: Validate is the filled one, Cancel a text button; Save stays in the bar. */
.invoice-form .form-actions { gap: 10px; }
.invoice-form .form-actions .button:not(.primary) { border-color: transparent; background: transparent; color: var(--muted); }
.invoice-form .form-actions .button:not(.primary):hover { color: var(--ink); background: var(--panel-hover); }

/* On a narrow screen the record's commands wrap onto a second line instead of running off the edge. */
@media (max-width: 767.98px) {
    .editor-commands, .page-trail-tools, .page-trail-actions { flex-wrap: wrap; min-width: 0; max-width: 100%; }
    .page-trail.has-tools { flex-wrap: wrap; }
}

/* The editor's Layout menu: the header fold and the split view as switches above the fields, ticked while on. */
.field-chooser__extra { display: flex; flex-direction: column; padding: 4px 0 6px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.field-chooser__switch {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 7px 10px; border: 0; border-radius: 8px; background: transparent;
    color: var(--ink); font: inherit; font-size: var(--form-value-size); text-align: left; cursor: pointer;
}
.field-chooser__switch:hover { background: var(--panel-hover); }
.field-chooser__switch svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.field-chooser__switch[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--brand); font-weight: 600; }

/* ─── 3. Bank Matching: one family, quieter sizes ─────────────────────────── */

.bankmatch-pane-who { font-size: 18px; font-weight: 600; }
.bankmatch-pane-sum, .bankmatch-pane-diff { font-size: 22px; font-weight: 600; }
.bankmatch-balance-figure { font-size: 18px; font-weight: 600; letter-spacing: 0; }
.bankmatch-pane-when, .bankmatch-facts dd, .bankmatch-day-net { font-size: 13px; }
.bankmatch-money { font-weight: 500; }

/* ─── Variant ─────────────────────────────────────────────────────────────── */
