/*
    The whole of this application's styling.

    There is no component suite behind it — see
    docs/ui/component-library-decision-record.md for why, and for the cost this
    file is the accepted half of. What that decision buys is control over the one
    thing the users will actually judge this port on: density. The application
    being replaced is a WinForms client whose grid rows are about 22 pixels tall
    and whose forms put a label directly against its box. Anything appreciably
    airier reads to those users as a different, slower program.

    So the numbers here are deliberate and small, and they are in one place. Change
    --row-height and every table in the application moves together.

    Three themes: Light (the :root values below, and the default), Off-white and
    Dark. The picker in MainLayout's header sets an attribute — data-theme="dark"
    or data-theme="off-white" — on <html>, and App.razor writes that same
    attribute from a cookie before the page is sent, so there is no flash of the
    wrong theme on first paint. Nothing outside the two blocks below reads that
    attribute; a theme is nothing more than a second set of values for the custom
    properties every rule in this file already uses, which is why adding one never
    touches a selector anywhere else. Measured contrast ratios for all three are
    recorded next to the blocks below and in the commit that added them; every
    body-text pair clears WCAG AA (4.5:1).

    Density is not a theme concern. --row-height and the other metrics below are
    colour-independent and identical in all three.

    Light's own measured ratios, unchanged since before this file had a theme
    picker and recorded here for the same reason Off-white and Dark's are recorded
    next to them — so "at least 4.5:1" is a number that was checked, not asserted:
      ink / surface            17.7:1
      ink-muted / surface       7.7:1
      accent-ink / accent       6.7:1
      accent-ink / accent-dark  8.7:1  (.shell-brand)
      danger / danger-wash      6.8:1
      ink / warning-wash       15.9:1
      ink / accent-wash        14.5:1
*/

:root {
    /*
        Type. 13.5px is the size a dense desktop grid is read at; the browser
        default of 16px is a reading size for prose and puts a third fewer rows on
        the screen. The system stack means Segoe UI on the Windows machines these
        users are on — the font the application they know is drawn in.
    */
    --font: -apple-system, "Segoe UI", system-ui, sans-serif;
    --font-mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
    --text: 13.5px;
    --text-small: 12px;
    --text-heading: 1.15rem;

    /*
        Spacing. A four-pixel grid: everything is a multiple, so nothing is
        eyeballed and density stays even across screens written by different hands.
    */
    --gap-tight: 4px;
    --gap: 8px;
    --gap-wide: 16px;
    --gap-section: 24px;

    /* Grid and control metrics — the density dial. */
    --row-height: 26px;
    --control-height: 28px;
    --radius: 3px;

    /*
        Neutrals, warm-free. Grey with a blue cast reads as a business
        application rather than a document.
    */
    --page: #f3f4f6;
    --surface: #ffffff;
    --ink: #18181b;
    --ink-muted: #52525b;
    --ink-faint: #71717a;
    --line: #d4d4d8;
    --line-strong: #a1a1aa;
    --hover: #eef2ff;
    --stripe: #fafafa;

    /*
        One accent, used for what is selected, focused or primary — and for
        nothing else. A palette with several accents makes the user work out
        which colour means what.
    */
    --accent: #1d4ed8;
    --accent-dark: #1e40af;
    --accent-ink: #ffffff;
    --accent-wash: #dbeafe;

    --danger: #991b1b;
    --danger-dark: #7f1d1d;
    --danger-wash: #fee2e2;
    --danger-line: #fca5a5;
    --warning-wash: #fef3c7;
    --warning-line: #fcd34d;

    /*
        Row status, not danger or warning: an inactive offering or a delivered
        worksheet is a STATE, not something wrong. Violet and green so neither
        reads as a dimmer danger-wash or warning-wash, and neither shares the
        accent's blue. Both have to be this pale for --ink-faint (used on a
        deleted row sitting on one of these, boundary condition 2) to clear
        4.5:1 — --ink-faint on plain white is already only 4.83:1, so there is
        very little room left once the wash takes any of it.

        ink / status-inactive-wash        16.4:1
        ink-faint / status-inactive-wash   4.51:1
        ink / status-delivered-wash       16.6:1
        ink-faint / status-delivered-wash  4.52:1
    */
    --status-inactive-wash: #f9f6fc;
    --status-delivered-wash: #f2f9f3;

    /* Chrome. */
    --sidebar-width: 208px;
    --header-height: 44px;

    /*
        Tells the browser this page is light, so its own UI — native <select> and
        type="date" popups, the scrollbar — matches instead of defaulting to
        whatever the OS is set to. The Dark block below sets this to dark; nothing
        else in either block is about the browser's own chrome.
    */
    color-scheme: light;
}

/*
    Off-white: the same neutrals, warmed and softened, and nothing else. Accent,
    danger and warning keep their :root values — they already read at 6.7:1 or
    better against this surface, so redefining them would only be two more numbers
    to keep in sync with Light for no visible change.

    Measured (relative-luminance contrast formula, foreground against the
    background it sits on):
      ink / surface            16.4:1
      ink-muted / surface       7.2:1
      accent-ink / accent       6.7:1  (unchanged from Light)
      danger / danger-wash      6.8:1  (unchanged from Light)
      ink / warning-wash       15.9:1  (unchanged from Light)
      ink / accent-wash        14.5:1  (unchanged from Light)
      ink-faint / status-inactive-wash   4.51:1  (unchanged from Light)
      ink-faint / status-delivered-wash  4.52:1  (unchanged from Light)
*/
:root[data-theme="off-white"] {
    color-scheme: light;

    --page: #ece7dc;
    --surface: #f8f6ef;
    --line: #ddd6c4;
    --line-strong: #b3a98f;
    --hover: #eceadf;
    --stripe: #f2efe6;
}

/*
    Dark. Every neutral changes, and so does every colour that sits directly on
    one of them — accent, danger and warning all get their own shade here, because
    the Light versions were picked to sit on a near-white surface and do not carry
    over: white accent-ink on the Light --accent is readable at 6.7:1 on a white
    page, but it is still the same --accent on a page that is now almost black,
    which is not what "dark theme" means.

    Measured the same way as above:
      ink / surface            13.6:1
      ink-muted / surface       7.1:1
      accent-ink / accent       6.5:1
      accent-ink / accent-dark  9.4:1  (.shell-brand)
      danger / danger-wash      5.9:1
      ink / warning-wash       10.6:1
      ink / accent-wash        10.7:1  (selected row)
      ink-faint / status-inactive-wash   4.69:1
      ink-faint / status-delivered-wash  4.71:1
*/
:root[data-theme="dark"] {
    color-scheme: dark;

    --page: #121317;
    --surface: #1b1d22;
    --ink: #e6e6ea;
    --ink-muted: #a6a7b0;
    --ink-faint: #83838d;
    --line: #33353c;
    --line-strong: #4a4c55;
    --hover: #262933;
    --stripe: #1f2126;

    --accent: #2657c2;
    --accent-dark: #1c4291;
    --accent-ink: #ffffff;
    --accent-wash: #1c2f52;

    --danger: #f87171;
    --danger-dark: #b91c1c;
    --danger-wash: #3b1414;
    --danger-line: #7f2b2b;

    --warning-wash: #3a2f10;
    --warning-line: #8a6d1f;

    --status-inactive-wash: #1c1626;
    --status-delivered-wash: #0a1c11;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--text);
    line-height: 1.45;
    color: var(--ink);
    background: var(--page);
}

h1 {
    margin: 0 0 var(--gap-wide);
    font-size: var(--text-heading);
    font-weight: 600;
}

h2 {
    margin: var(--gap-section) 0 var(--gap);
    font-size: 1rem;
    font-weight: 600;
}

a {
    color: var(--accent);
}

code {
    font-family: var(--font-mono);
    font-size: var(--text-small);
}

/*
    One focus ring, on everything, and never removed. Keyboard use is a stated
    requirement of this port: these users drive the desktop app by tab and arrow
    keys, and a focus outline they cannot see is the fastest way to lose them.
    :focus-visible rather than :focus so a mouse click does not leave a ring
    behind it.
*/
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ---------------------------------------------------------------- chrome -- */

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
        "brand header"
        "nav content";
    height: 100vh;
}

.shell-brand {
    grid-area: brand;
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 0 var(--gap-wide);
    background: var(--accent-dark);
    color: var(--accent-ink);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.shell-brand a {
    color: inherit;
    text-decoration: none;
}

.shell-header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--gap-wide);
    padding: 0 var(--gap-wide);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.shell-version {
    color: var(--ink-faint);
    font-size: var(--text-small);
}

.theme-picker {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
}

.theme-picker-label {
    color: var(--ink-faint);
    font-size: var(--text-small);
}

.theme-picker select {
    height: var(--control-height);
    padding: 0 var(--gap-tight);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-small);
}

.shell-user {
    color: var(--ink-muted);
}

.shell-nav {
    grid-area: nav;
    overflow-y: auto;
    padding: var(--gap) 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.shell-content {
    grid-area: content;
    overflow: auto;
}

/*
    A sticky child pins to the scroll container's PADDING BOX, so padding put
    directly on .shell-content stays fixed on screen above the sticky grid
    header while rows scroll underneath it — a transparent gap with content
    sliding past behind it. Moving the padding onto this inner wrapper (see
    MainLayout.razor) keeps the scroll container's own edge flush with the
    content, so a sticky header has nothing above it to leave a gap.
*/
.shell-content-inner {
    padding: var(--gap-wide) var(--gap-section);
}

/*
    Below this the sidebar stops paying for itself. The application is used at
    desks and this is a fallback, not a mobile design: the chrome stacks, the
    navigation becomes a row, and the content keeps the full width.
*/
@media (max-width: 720px) {
    .shell {
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-height) auto 1fr;
        grid-template-areas:
            "brand"
            "nav"
            "content";
    }

    .shell-header {
        display: none;
    }

    .shell-nav {
        display: flex;
        flex-wrap: wrap;
        padding: var(--gap-tight);
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .shell-content-inner {
        padding: var(--gap-wide);
    }
}

/* ------------------------------------------------------------ navigation -- */

.nav-link {
    display: block;
    padding: 6px var(--gap-wide);
    color: var(--ink);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: var(--hover);
}

/*
    NavLink adds .active on the entry matching the current route. Colour alone
    would not carry it for a user who cannot separate these two blues, so the
    marker is a bar and a weight change as well.
*/
.nav-link.active {
    background: var(--accent-wash);
    border-left-color: var(--accent);
    font-weight: 600;
}

.nav-sign-out {
    margin-top: var(--gap);
    padding-top: var(--gap);
    border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------- tables -- */

/*
    Every table in the application, including the ones QuickGrid renders — it
    emits a plain <table class="quickgrid">, so it inherits all of this and the
    class is there for the few rules that are its own.

    Dense, ruled, striped, with a header that stays put when the body scrolls.
    Borders rather than whitespace to separate columns: whitespace-separated
    tables need to be airy to stay readable, and airy is the thing being avoided.
*/
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-variant-numeric: tabular-nums;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--gap-tight) var(--gap);
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    background: var(--page);
    border-bottom: 1px solid var(--line-strong);
}

tbody td {
    height: var(--row-height);
    padding: 0 var(--gap);
    border-bottom: 1px solid var(--line);
}

tbody tr:nth-child(even) {
    background: var(--stripe);
}

/*
    Offerings and Worksheets mark a row's status this way — an inactive offering,
    or a worksheet that has been delivered (which in this app means delivered OR
    posted, since WorksheetStatus is ordered and Posted implies Delivered; see
    Worksheet.Delivered). Same specificity as the stripe and hover rules above and
    below (0,1,2 each), so SOURCE ORDER is what makes a status row outrank a plain
    stripe while hover still gives feedback on top of it: after the stripe rule,
    before hover. tbody tr.selected is later still, so a selected status row shows
    the selection.
*/
tbody tr.status-inactive {
    background: var(--status-inactive-wash);
}

tbody tr.status-delivered {
    background: var(--status-delivered-wash);
}

tbody tr:hover {
    background: var(--hover);
}

/*
    Row selection, and the row the keyboard is on. FullRowSelect was how every
    list in the desktop app behaved; aria-selected is what carries it to assistive
    technology, so the styling hangs off that rather than off a class somebody has
    to remember to keep in step.
*/
tbody tr[aria-selected="true"] {
    background: var(--accent-wash);
}

/*
    The same, for the grids QuickGrid renders. It builds its own <tr> and offers no
    way to put an attribute on it — RowClass is the only hook there is — so those
    carry a class instead. The rule above stays for every table this application
    writes itself.
*/
tbody tr.selected {
    background: var(--accent-wash);
}

/* Numbers right, so digits line up under each other and are comparable. */
.numeric {
    text-align: right;
}

/* ----------------------------------------------------------------- grids -- */

/*
    QuickGrid's own markup, dressed in this application's clothes.

    Neither stylesheet the package ships is linked. One is scoped CSS, which
    arrives only through the .styles.css bundle and brings every other component
    library's along with it; the other is a theme with its own opinion about
    padding, which is the one thing this file exists to decide. What is left to do
    is the handful of rules its header needs — the table itself already inherits
    everything above.
*/

.grid-toolbar {
    display: flex;
    align-items: baseline;
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.grid-toolbar label {
    margin: 0;
}

.grid-toolbar input {
    width: 18rem;
}

/* Waiting, and having nothing to show, both belong under the table. */
.grid-status {
    margin: var(--gap) 0;
}

/*
    The "Copy table" button every list grid opens with — see gridClipboard.js.
    Pushed to the toolbar's far side so it does not compete with the search box
    for the same corner, and dimmed rather than removed while there is nothing
    rendered to copy: a button that vanished would read as the capability being
    gone rather than momentarily unavailable.
*/
.grid-copy {
    margin-left: auto;
}

.grid-copy:disabled {
    color: var(--ink-faint);
    cursor: default;
}

.grid-copy:disabled:hover {
    background: var(--surface);
}

.quickgrid .col-header-content {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
}

/*
    A sortable header is a <button> — which is right, because clicking it does
    something and a keyboard has to be able to reach it. It just must not look like
    one sitting in a header cell.
*/
.quickgrid button.col-title {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
    width: 100%;
    height: auto;
    padding: 0;
    font: inherit;
    font-weight: 600;
    color: inherit;
    text-align: left;
    background: none;
    border: 0;
    border-radius: 0;
    cursor: pointer;
}

.quickgrid button.col-title:hover {
    background: none;
    text-decoration: underline;
}

.quickgrid .col-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/*
    Which way a sorted column is sorted. Drawn in borders rather than fetched as an
    image, so it takes the ink colour and costs no request. The box is always the
    same size whether or not there is a triangle in it, so sorting a column does
    not change its width.
*/
.quickgrid .sort-indicator {
    position: relative;
    flex: none;
    width: 8px;
    height: 8px;
}

.quickgrid th.col-sort-asc .sort-indicator::after,
.quickgrid th.col-sort-desc .sort-indicator::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 0;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
}

.quickgrid th.col-sort-asc .sort-indicator::after {
    border-bottom: 5px solid var(--ink-muted);
}

.quickgrid th.col-sort-desc .sort-indicator::after {
    border-top: 5px solid var(--ink-muted);
}

/*
    The cell that opens the row, and the row's one tab stop. A real button, because
    that is what it is — but drawn as the value it shows, so the table still reads
    as a table rather than as a column of buttons.
*/
.row-open {
    height: auto;
    padding: 0;
    font: inherit;
    color: var(--accent);
    text-align: left;
    background: none;
    border: 0;
    border-radius: 0;
    cursor: pointer;
}

.row-open:hover {
    background: none;
    text-decoration: underline;
}

/*
    Every other cell on a row that can be selected — see DataGridColumn.CellContent.
    Block and full height so the click target is the whole cell, not just the text
    baseline; tbody td sets no vertical padding, so 100% already matches the row.
*/
.row-select {
    display: block;
    height: 100%;
    cursor: pointer;
}

/*
    A row that has been deleted, on a list showing them. Dimmed, with the number
    struck through — two signals rather than one, because dimming alone reads as
    "disabled" and a strikethrough alone survives at any contrast. Colour is
    deliberately not doing the work: this is a state, not a warning.

    The strikethrough is on the identifying cell rather than on the row, and that
    is not cosmetic. A text-decoration set on an ancestor propagates to every
    descendant and *cannot be turned off* by one — putting it on the <tr> would
    draw a line through the Restore button that undoes the deletion.

    The identifying cell is the first column on all four lists that use this —
    worksheet number, offering number, customer number, email address — which is
    why :first-child is enough and no list needs its own rule.
*/
tbody tr.deleted {
    color: var(--ink-faint);
}

tbody tr.deleted td:first-child {
    text-decoration: line-through;
}

/*
    The button that undoes it, on the row it undoes. Drawn as a small button
    rather than as a link, unlike .row-open, because it acts rather than
    navigates and the row already has one tab stop that opens things.
*/
.row-action {
    height: auto;
    padding: 0 calc(var(--gap) / 2);
    font: inherit;
    font-size: var(--text-small);
}

/*
    QuickGrid's paginator. Its four buttons hold no text at all — they are drawn
    entirely by the theme that is not linked — so the arrows are here. Each one
    already carries an aria-label, which is what actually says where it goes.
*/
.paginator {
    display: flex;
    align-items: center;
    gap: var(--gap);
    margin-top: var(--gap);
}

.pagination-text {
    color: var(--ink-muted);
}

.paginator nav {
    display: flex;
    gap: var(--gap-tight);
    margin-left: auto;
}

.paginator nav button {
    width: var(--control-height);
    padding: 0;
}

.paginator nav button[disabled] {
    color: var(--ink-faint);
    cursor: default;
}

.paginator .go-first::before {
    content: "«";
}

.paginator .go-previous::before {
    content: "‹";
}

.paginator .go-next::before {
    content: "›";
}

.paginator .go-last::before {
    content: "»";
}

/* ----------------------------------------------------------------- forms -- */

label {
    display: block;
    margin-bottom: 2px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    height: var(--control-height);
    padding: 0 6px;
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
}

textarea {
    height: auto;
    padding: 4px 6px;
}

input[type="checkbox"] {
    width: auto;
    height: auto;
    margin-right: var(--gap-tight);
}

input[readonly],
textarea[readonly],
input:disabled,
select:disabled {
    color: var(--ink-muted);
    background: var(--page);
}

.field {
    margin-bottom: var(--gap);
}

/*
    A named group of fields — the GroupBox the desktop forms fenced their sections
    off with: "Main Contact" on frmEditCustomer, and the two around its child
    grids. A customer form without them is one undifferentiated column of boxes,
    and which box belongs to the customer and which to the address it is filed
    under stops being visible.

    A real <fieldset> and <legend> rather than a div and a heading, because the
    grouping is then announced rather than only drawn: a screen reader reads the
    legend before the fields inside it.
*/
.subform {
    margin-bottom: var(--gap-wide);
    padding: var(--gap-wide);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.subform > legend {
    padding: 0 var(--gap);
    font-weight: 600;
}

/*
    A row of tick boxes under one caption — the three that make up an address
    type. The block, bold label rule above is for a box with a name over it, and
    these are the other thing: the words sit beside their box and belong to it,
    so they read as choices rather than as three more fields.
*/
.checkboxes label {
    display: inline-flex;
    align-items: center;
    margin-right: var(--gap-wide);
    font-weight: 400;
}

/*
    Choosing a file. The browser draws its own button inside this input and sizes
    it itself, so the full-width, fixed-height rule above is undone rather than
    fought with.
*/
.upload {
    margin-bottom: var(--gap);
}

.upload input[type="file"] {
    width: auto;
    height: auto;
    padding: 4px;
}

/* --------------------------------------------------------------- buttons -- */

button,
.button {
    display: inline-block;
    height: var(--control-height);
    padding: 0 14px;
    font: inherit;
    color: var(--ink);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--hover);
}

button[type="submit"],
.button-primary {
    color: var(--accent-ink);
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}

button[type="submit"]:hover,
.button-primary:hover {
    background: var(--accent-dark);
}

/*
    The button that deletes something. Red is the only place in this application
    where colour carries meaning on its own, so it is never the only signal — the
    prompt it sits in has already said in words what is about to happen, and the
    button is named for the action rather than "Yes".
*/
.button-danger {
    color: var(--accent-ink);
    background: var(--danger);
    border-color: var(--danger);
    font-weight: 600;
}

.button-danger:hover {
    background: var(--danger-dark);
}

/*
    A module's row of buttons, above whatever it acts on. Every screen in the
    desktop app had one — the four along the bottom of frmUsers, the five on
    frmWorksheets — and they are all the same shape, so this is one rule rather
    than one per module.

    A disabled button is dimmed rather than removed. Which actions a screen offers
    is part of how a user learns it, and one that appears only once the right row
    is selected cannot be found by looking.
*/
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
    margin-bottom: var(--gap-wide);
}

button:disabled,
.button:disabled {
    color: var(--ink-faint);
    background: var(--page);
    border-color: var(--line);
    cursor: default;
}

button:disabled:hover,
.button:disabled:hover {
    background: var(--page);
}

/* -------------------------------------------------------------- messages -- */

.problem,
.notice {
    margin: var(--gap) 0;
    padding: var(--gap) var(--gap-wide);
    border: 1px solid;
    border-radius: var(--radius);
}

.problem {
    color: var(--danger);
    background: var(--danger-wash);
    border-color: var(--danger-line);
}

.notice {
    background: var(--warning-wash);
    border-color: var(--warning-line);
}

/* The validation summary is a list of problems; it needs no bullets. */
.problem ul {
    margin: 0;
    padding-left: var(--gap-wide);
}

.muted {
    color: var(--ink-muted);
}

/*
    The "next: N" suggestion beside a New Worksheet / New Offering number box —
    see WorksheetEditor and OfferingEditor. Informational, not a value the field
    carries, so it sits beside the input rather than inside it.
*/
.suggested-number {
    margin-left: var(--gap);
    color: var(--ink-muted);
    font-size: 0.9em;
}

/* ----------------------------------------------------------------- cards -- */

/*
    The home page: the six buttons frmMain opened its modules with, as a grid of
    targets big enough to hit without aiming. This is the one place in the
    application that is deliberately not dense — it is a menu, read once at the
    start of a session, not a working surface.
*/
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: var(--gap-wide);
    max-width: 60rem;
}

.card {
    display: block;
    padding: var(--gap-wide);
    color: inherit;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.card:hover {
    border-color: var(--accent);
    background: var(--hover);
}

.card strong {
    display: block;
    margin-bottom: var(--gap-tight);
    color: var(--accent);
}

.card span {
    color: var(--ink-muted);
    font-size: var(--text-small);
}

/* ----------------------------------------------------- the account pages -- */

/*
    Signing in, signing out and setting a password. These render before there is a
    shell to put them in — no navigation, nothing to navigate to — so they get a
    card in the middle of an empty page instead.
*/
.account {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--gap-wide);
}

.account-card {
    width: 100%;
    max-width: 22rem;
    padding: var(--gap-section);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.account-card h1 {
    margin-bottom: var(--gap-section);
    text-align: center;
    letter-spacing: 0.04em;
}

.account-card button {
    width: 100%;
    margin-top: var(--gap-wide);
}

/* ---------------------------------------------------------- busy and gone -- */

/*
    The busy indicator the shared components use. Defined here so that every screen
    that waits looks the same while it does, and so that there is one answer to
    "what does waiting look like" rather than one per module.
*/
.busy {
    display: inline-block;
    width: 14px;
    height: 14px;
    vertical-align: -2px;
    border: 2px solid var(--line-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/*
    Anyone who has turned motion down has said they do not want this. Hold the
    ring still rather than removing it — it is the only sign the screen is doing
    something.
*/
@media (prefers-reduced-motion: reduce) {
    .busy {
        animation: none;
    }
}

/*
    The ring with its message beside it, which is what BusyIndicator renders. The
    ring alone says something is happening; the words say what, and they are the
    half a screen reader can use.
*/
.busy-line {
    display: inline-flex;
    align-items: center;
    gap: var(--gap);
    color: var(--ink-muted);
}

/*
    WorkingOverlay.razor's own overlay — the one "is it doing something" for
    opening a record or acting on a row, over the top of whatever list screen
    asked. Fixed to the viewport rather than the grid: the click that started
    this can be a toolbar button above the grid or a row inside it, and the
    overlay covers the whole working area either way.

    Rendered the instant WorkingOverlay.Working flips true, but invisible for
    the first 200ms — the delay is entirely this animation-delay, not a C#
    timer, and it is why a fast action never flashes it: Working flips back to
    false and the element is gone before the browser would ever have painted
    it visible. It still takes pointer events from the moment it renders
    (opacity does not affect hit-testing), which is the second half of the
    double-activation guard WorkingOverlay.RunAsync is the first half of.
*/
.working-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(0 0 0 / 15%);
    opacity: 0;
    animation: working-overlay-in 0.15s ease-out 0.2s forwards;
}

.working-overlay .busy-line {
    padding: var(--gap) var(--gap-wide);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 8px 32px rgb(0 0 0 / 25%);
}

@keyframes working-overlay-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/*
    working.js's own half — the WaitCursor for the browser -> SignalR -> server
    hop before .working-overlay above can even exist. See that file's remarks
    on what sets and clears it.
*/
html.working-pending {
    cursor: progress;
}

/*
    A dropped circuit already has its own dialog (#components-reconnect-modal)
    over the page. A server-rendered .working-overlay cannot know the circuit
    went — its clearing happens in a finally that a dropped circuit never
    reaches — so this is what stops one being stranded, visibly stuck, behind
    the reconnect dialog. working.js sets data-circuit-down on every state but
    "hide"; see that file for why "hide" is the only one that means the
    circuit is back.
*/
html[data-circuit-down] .working-overlay {
    display: none;
}

/*
    Blazor's own bar for an error inside a circuit, which is a different failure
    from the one the ErrorBoundary catches: by the time this shows, the circuit is
    already unusable and reloading is the only way on. Blazor unhides it; it is
    hidden here so it does not sit on every page.
*/
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: var(--gap) var(--gap-wide);
    color: var(--danger);
    background: var(--warning-wash);
    border-top: 1px solid var(--warning-line);
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}

/* --------------------------------------------------------------- dialogs -- */

/*
    The 15 modal windows of the desktop app become <dialog>. Focus trapping, Esc
    to close and the backdrop are the element's own; what is here is the shape,
    which ModalDialog fills in. The reconnect dialog is a <dialog> too and picks
    these up without being one of the fifteen.
*/
dialog {
    padding: 0;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 8px 32px rgb(0 0 0 / 25%);
}

/*
    ModalDialog's own shape, which the reconnect overlay below is deliberately not
    given. A dialog is as wide as what is in it, up to the window: the worksheet
    editor is the case that forces a ceiling, because its line grid is eleven
    columns and left to itself the dialog would grow past the right-hand edge of
    the screen and take the Save button with it. Capped rather than fixed, so the
    delete prompt and the item picker stay the size of their own contents instead
    of all being sized for the largest one.

    The title and the buttons then stay put and the body between them scrolls,
    because the alternative is a dialog whose Save button is below the fold on a
    long worksheet — the one button the user is looking for.
*/
.app-dialog[open] {
    display: flex;
    flex-direction: column;
    max-width: min(96vw, 1400px);
    max-height: 92vh;
    overflow: hidden;
}

dialog::backdrop {
    background: rgb(0 0 0 / 35%);
}

.dialog-title {
    padding: var(--gap) var(--gap-wide);
    font-weight: 600;
    background: var(--page);
    border-bottom: 1px solid var(--line);
}

.dialog-body {
    /* The scrolling half of the rule above: this is the part that gives. */
    overflow: auto;
}

/*
    Same fix as .shell-content-inner: a sticky grid header inside a scrolling
    dialog body pins to the padding box, so padding directly on .dialog-body
    leaves a transparent strip above the header with rows sliding past behind
    it. The padding moves to this inner wrapper (see ModalDialog.razor) so the
    scroll container's edge has nothing sitting above the header.
*/
.dialog-body-inner {
    padding: var(--gap-wide);
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--gap);
    padding: var(--gap) var(--gap-wide);
    background: var(--page);
    border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------- reconnect -- */

/*
    A dropped circuit. This is the failure mode of Blazor Server that a user will
    actually meet — a laptop lid closing, a wifi handover, an App Service restart —
    and if nothing says so the screen simply stops responding to clicks, which
    reads as the application having broken.

    The classes are Blazor's: it puts one of components-reconnect-{show,retrying,
    failed,paused,resume-failed} on the dialog and drives everything from there,
    including the countdown it writes into #components-seconds-to-next-attempt.
    Each message is hidden by default and shown by exactly one of those states.
*/
#components-reconnect-modal {
    max-width: 24rem;
    padding: var(--gap-section);
    text-align: center;
}

.components-reconnect-first-attempt-visible,
.components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible,
.components-pause-visible,
.components-resume-failed-visible,
.components-reconnect-rejected-visible,
.components-rejoining-animation {
    display: none;
}

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-rejected .components-reconnect-rejected-visible {
    display: block;
}

#components-reconnect-modal .busy {
    width: 20px;
    height: 20px;
    margin: 0 auto var(--gap-wide);
}

#components-reconnect-modal button {
    margin-top: var(--gap-wide);
}

/*
    The overlay's failed/rejected messages each promise a browser draft, which is
    only true when editorDraft.js's last write actually succeeded — see
    ReconnectOverlay.razor's own remarks. .draft-promise-fallback only exists on
    the failed-state message, which needs a replacement sentence; the
    rejected-state message reads fine with its draft clause simply gone.
*/
.draft-promise-fallback {
    display: none;
}

html[data-draft-storage-failed] .draft-promise {
    display: none;
}

html[data-draft-storage-failed] .draft-promise-fallback {
    display: inline;
}

/* --------------------------------------------------------------- modules -- */

/*
    The row of controls above a grid — search box, filter, and the buttons that
    act on the selected row. This is frmWorksheets' own top strip and frmItems'
    after it: everything on one line, labels beside their boxes rather than above
    them, and the buttons left-aligned, directly after the search and filter
    controls, on every module page (ta-m668f).

    Wraps rather than scrolls. On a narrow window the buttons drop to a second
    line and stay reachable, where a horizontal scrollbar would hide the Delete
    button behind a gesture nobody makes on a form.
*/
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap);
    margin-bottom: var(--gap);
}

/* Labels sit beside their control here, not over it. */
.toolbar label {
    margin: 0;
}

.toolbar input[type="search"] {
    width: 18rem;
}

.toolbar select {
    width: auto;
}

/*
    A checkbox that belongs to the toolbar rather than to a form — "Show deleted",
    on each of the four lists that has one. The label wraps the box so the words
    are part of the hit target, which on a strip of buttons is the difference
    between a control that can be pressed and one that has to be aimed at.
*/
.toolbar-check {
    display: inline-flex;
    gap: calc(var(--gap) / 2);
    align-items: center;
}

/* The running totals under the line grid. */
.totals {
    font-size: var(--text-small);
}

/*
    The worksheet header — three blocks of fields side by side: what identifies
    the worksheet, where the load comes from, where it goes. frmWorksheet grouped
    them the same way and in the same order, because that is the order the office
    fills them in.

    auto-fit rather than three fixed columns, so a narrow window stacks them
    instead of squeezing every box down to something unreadable.
*/
.form-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0 var(--gap-section);
}

/* The first heading in each block sits against the top, not a line below it. */
.form-columns h2:first-child {
    margin-top: 0;
}

/*
    frmEditItem's thirteen boxes (ItemEditor.razor), two columns wide instead
    of one, with narrower inputs than the full-width default above. Explicit
    columns rather than .form-columns' auto-fit: that grid widens itself off
    the worksheet header's own wide content, and .app-dialog[open] sizes to
    its content, so an auto-fit grid measured against this dialog — which has
    nothing that wide — can settle on one column instead of two.

    Column-wise, not row-wise (the same choice as the markup): the left block
    is UPC through Pack, the right is Size through List Price, so DOM order
    stays frmEditItem's own tab order (0-12 top to bottom) here and in the
    one-column fallback below, ta-h8s4f.
*/
.item-editor-columns {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    gap: 0 var(--gap-section);
}

.item-editor-columns .field {
    width: 16rem;
}

/* The seven InputNumber boxes — narrower than a text box needs to be. */
.item-editor-columns .field-narrow {
    width: 8rem;
}

@media (max-width: 720px) {
    .item-editor-columns {
        grid-template-columns: 1fr;
    }

    .item-editor-columns .field,
    .item-editor-columns .field-narrow {
        width: auto;
    }
}

/*
    The lifecycle boxes, on one line within each group. A fieldset because the
    boxes in a group are one question about one worksheet — a screen reader
    announces the legend with each box, so "Progress: Delivered" rather than a
    bare "Delivered" floating between a delivery date and a grid. Two of these
    sit on the screen: Progress holds the three ordered stages, Paperwork holds
    Printed alone, and each carries its own hint line explaining why it behaves
    the way it does.
*/
.lifecycle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap-wide);
    margin: var(--gap-wide) 0;
    padding: var(--gap) var(--gap-wide);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.lifecycle legend {
    padding: 0 var(--gap-tight);
    font-weight: 600;
}

.lifecycle-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25em;
    height: 1.25em;
    margin-right: var(--gap-tight);
    border-radius: 50%;
    background: var(--line);
    font-size: 0.85em;
    font-weight: 600;
}

.lifecycle-hint {
    flex-basis: 100%;
    margin: 0;
}

.lifecycle-stamp {
    margin-left: var(--gap-tight);
    color: var(--ink-muted);
    font-size: 0.85em;
}

/*
    A checkbox and its words, as one target. The global rule makes every label a
    block above its control, which is right for a text box and wrong for this —
    here the label is the thing you click.
*/
.checkbox {
    display: inline-flex;
    align-items: center;
    margin: 0;
    font-weight: normal;
    white-space: nowrap;
}

/*
    A box inside a grid cell. The three editable columns on a worksheet line are
    all numeric and all short, so they are sized to their content rather than
    stretched to the column: a quantity box wide enough for a UPC makes the grid
    twice as wide as the numbers in it.
*/
input.cell {
    width: 7rem;
    height: calc(var(--row-height) - 4px);
    padding: 0 4px;
    text-align: right;
}

/*
    No spinner on any type="number" box left in the app (ta-s4zx6) — the six
    grid cells above are type="text" now and never had one to begin with. The
    rest is ItemEditor's seven fields, CustomerEditor's customer number and the
    List Price prompt: hiding the arrows is only half of "take the arrows out"
    without formFieldNav.js's own wheel guard, which stops the value changing
    under a hidden arrow the same way it stops it under a visible one.
*/
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

/*
    The container the Excel-style range clipboard listens on. tabindex="-1" makes
    it a valid focus target for a click on a read-only cell — see
    lineGridClipboard.js — without adding an extra Tab stop; the boxes inside it
    already are ones.
*/
.line-grid-clipboard {
    outline: none;
}

/*
    A cell inside the current range selection, on either line grid. Distinct from
    .selected (a highlighted row) and from :focus (one box) because a range can
    span many cells across many rows, none of which is "the" focused or selected
    one — see RangePaste and lineGridClipboard.js.
*/
.range-cell.range-selected,
input.cell.range-selected {
    background: var(--accent-wash);
}

/*
    Taking a line off the worksheet. Drawn like the cell that opens a row rather
    than like a button, so a grid of ten lines is not a column of ten buttons —
    but in the danger colour, because it is the one control in the table that
    destroys something.
*/
.row-remove {
    height: auto;
    padding: 0;
    font: inherit;
    color: var(--danger);
    background: none;
    border: 0;
    border-radius: 0;
    cursor: pointer;
}

.row-remove:hover {
    background: none;
    text-decoration: underline;
}

/*
    A per-line action that is not destructive — same link-like shape as
    .row-remove, minus the danger colour, so the offering line grid's List
    Price action does not read as another way to delete the row.
*/
.row-action {
    height: auto;
    padding: 0;
    font: inherit;
    color: var(--accent);
    background: none;
    border: 0;
    border-radius: 0;
    cursor: pointer;
}

.row-action:hover {
    background: none;
    text-decoration: underline;
}

/* -------------------------------------------- offering line grid (ta-wjgh9) -- */

/*
    Everything from here down is scoped under .offering-line-grid, so it touches
    only the offering editor's own line grid — the worksheet line grid and every
    other table in the app keep the widths and padding above untouched
    (boundary 4).
*/
.offering-line-grid th,
.offering-line-grid td {
    padding: 0 4px;
}

.offering-line-grid th {
    white-space: normal;
}

/* Description is the one column allowed to wrap rather than force the grid wider. */
.offering-line-grid .wrap-cell {
    white-space: normal;
    width: 14ch;
}

.offering-line-grid input.cell.cell-qty {
    width: 8ch;
}

/*
    Cost, FOB Sell and Del Sell are decimal(18,4) and bind with four decimals
    ("30.0000" in DevSeed) — wide enough for "1234.5678" plus Chromium's own
    number spinner, not the narrower box the shared input.cell rule gives the
    worksheet grid's whole-dollar columns.
*/
.offering-line-grid input.cell.cell-money {
    width: 11ch;
}

/*
    UPC and Description stay put while the rest of the row scrolls sideways
    (boundary 3). Both pin to .dialog-body — the sticky header's own scroll
    container, see the note on thead th above — rather than to any wrapper of
    this grid's own, since .line-grid-clipboard declares no overflow of its own
    (boundary 3, and the CSS text test that pins it). UPC carries a fixed width
    so Description's left offset is a known constant instead of a guess.
*/
.offering-line-grid .freeze-upc {
    position: sticky;
    left: 0;
    width: 14ch;
    min-width: 14ch;
}

.offering-line-grid .freeze-description {
    position: sticky;
    left: 14ch;
}

/*
    Opaque backgrounds on the frozen body cells: a <td> carries none of its own,
    so without this the rows scrolling underneath would show through. Every
    token here is an opaque hex in all three themes (app.css ~l.72-187).
*/
.offering-line-grid tbody td.freeze-upc,
.offering-line-grid tbody td.freeze-description {
    background: var(--surface);
}

.offering-line-grid tbody tr:nth-child(even) td.freeze-upc,
.offering-line-grid tbody tr:nth-child(even) td.freeze-description {
    background: var(--stripe);
}

.offering-line-grid tbody tr:hover td.freeze-upc,
.offering-line-grid tbody tr:hover td.freeze-description {
    background: var(--hover);
}

/*
    Frozen HEADER cells must paint above both the frozen body cells (implicit
    stacking order — tbody comes after thead in the DOM) and every plain header
    cell, which thead th already puts at z-index 1 on its own top-pinning. A
    frozen header pins on two axes at once — top from thead th, left from here —
    so it needs to outrank that z-index too.
*/
.offering-line-grid thead th.freeze-upc,
.offering-line-grid thead th.freeze-description {
    position: sticky;
    left: 0;
    z-index: 2;
}

.offering-line-grid thead th.freeze-description {
    left: 14ch;
}

/*
    The two per-line actions, as small icon buttons instead of the words
    "List Price…"/"Remove". .row-action and .row-remove above still carry the
    link-like shape, colour and hover every other consumer of those classes uses
    (DataGridActionColumn's own action column, WorksheetEditor's Remove) — this
    only tightens the box around the glyph, on this grid alone.
*/
.offering-line-grid .row-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    font-size: var(--text-small);
}
