﻿/* ============================================================
   components.css — Buttons, cards, badges, forms, tables
   Built against the real tokens extracted from the Claude
   Design mockups.
   ============================================================ */

/* ── Card ── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
}

/* ── Sticky save bar ────────────────────────────────────────────
   For long forms where the save button would otherwise sit metres below
   the fold. A card variant, so it lives here beside .card.

   STICKY TO THE TOP, not the bottom, and that was measured rather than
   assumed. A bottom-sticky bar does NOT pull itself up into view: sticky
   only holds an element that is already on screen from leaving, so a bar
   at the end of a 1,470px form stayed 1,200px below the fold and pinned
   nothing — verified in the browser before this was rewritten.

   Sticking under the topbar (69px, itself sticky at z-index 40) keeps the
   button in reach for the whole scroll, which is the entire point: the
   complaint was "I never saw a Save button and assumed it autosaved".

   z-index 30 sits over page content but under the topbar (40) and
   dropdowns (100), so nothing it scrolls past can cover it and it can
   never cover a menu.

   Two things break it silently: it must be a child of a wrapper that
   spans the whole form, and no ancestor may pick up `overflow`.

   ONLY LIFTS WHEN THERE IS SOMETHING TO SAVE. Sticky plus a heavy shadow
   in the resting state made it read as a card hovering over the page for
   the whole visit — a settings page is saved almost all of the time, so
   the floating treatment was showing permanently in order to say nothing.
   Clean, it is an ordinary inline row at the top of the form; dirty, it
   pins under the topbar and lifts.

   The BUTTON stays present and pressable in both states — it is never
   hidden on "not dirty". Hiding it would reintroduce the original
   complaint ("I never saw a Save button"), and FormSaveBar deliberately
   keeps it enabled for the person who just wants to press Save again to
   be sure.

   Switching static <-> sticky costs no layout shift: a sticky element
   keeps its space in normal flow and only offsets once scrolled past, so
   nothing below it moves when the state flips. */
.form-save-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    transition: box-shadow 150ms ease;
}

.form-save-bar.is-dirty {
    position: sticky;
    top: calc(69px + var(--space-3));
    z-index: 30;
    /* --shadow-lg, not --shadow-md: the latter is the purple brand glow used
       on buttons, which reads as a hover state on a container. */
    box-shadow: var(--shadow-lg);
}

@media (prefers-reduced-motion: reduce) {
    .form-save-bar { transition: none; }
}

.form-save-bar-scope {
    flex-basis: 100%;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

@media (max-width: 768px) {
    /* No flex:1 on the button — .agent-chat-fab-wrap is fixed bottom-right at
       56px, and a full-width control crowds it. Pinned to the top the bar
       never reaches the FAB, but the rule stays as a guard against someone
       later moving it back down. */
    .form-save-bar.is-dirty {
        top: calc(69px + var(--space-2));
    }
}

/* ── Document status bar ────────────────────────────────────────
   Invoice / quote / purchase order builders. Replaces a status badge
   buried in the breadcrumb plus a separate lock banner — two places
   saying overlapping things — with one row that states the status and
   what it means for what you can do. */
.doc-status-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
}

/* A locked document is a statement of fact, not a warning — muted rather
   than alarming. Nothing has gone wrong; it just can't be edited. */
.doc-status-bar.is-locked {
    border-left-color: var(--color-text-muted);
    background: var(--color-bg);
}

.doc-status-bar-badge {
    flex-shrink: 0;
}

.doc-status-bar-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.doc-status-bar-lock {
    color: var(--color-text-muted);
    flex-shrink: 0;
    margin-left: auto;
}

.card-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-4);
}

/* Used by Account Settings — 4 equal cards side by side above ~900px
   instead of stacking full-width at a narrow max-width, which left most
   of the page as unused background on anything wider than a phone. */
.account-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    align-items: start;
    max-width: 1160px;
}

@media (max-width: 900px) {
    .account-settings-grid {
        grid-template-columns: 1fr;
    }
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.card-link {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-primary);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);

    /* REQUIRED, because this project has no global box-sizing reset — the same
       reason .dropdown-item carries this line, and the same failure.
       A <button> gets border-box from the UA stylesheet and an <a> does not, so
       `class="btn" style="width:100%"` fitted its container as a button and
       burst out of it as a link, by exactly the horizontal padding plus the two
       1px borders. Only the anchors were ever wrong, which is why it read as one
       odd button rather than a rule that was missing.

       Ten of them: the converted quote's "View invoice INV-0123" and, more
       visibly, the full-width links on Confirm email, Accept invitation, Reset
       password and Register complete — pages somebody sees before they have an
       account. Buttons are unaffected; they were already border-box. */
    box-sizing: border-box;

    padding: 10px var(--space-5);
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    cursor: pointer;
    white-space: nowrap;
    font-family: var(--font-family);
    text-decoration: none;
}

    .btn:disabled,
    .btn.disabled {
        opacity: 0.6;
        cursor: not-allowed;
        pointer-events: none;
    }

.btn-primary {
    background: var(--color-primary);
    color: var(--color-primary-text);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-brand);
}

    .btn-primary:hover:not(:disabled) {
        background: var(--color-primary-hover);
        border-color: var(--color-primary-hover);
    }

/* A faint tint, NOT --color-surface. This used to be the card white, so a
   secondary button on a card was white on white — contrast 1.00 against its
   own card, findable only by its hairline border.
   The fill has to clear BOTH surfaces one of these can land on: the card
   (#ffffff) and the app shell (--color-bg #f6f7fb). --color-border-light
   looks right on a card but is FAINTER than white against the shell (1.04 vs
   1.07), which would only have moved the problem onto the list pages, where
   the export buttons sit straight on the shell. --color-control clears both.
   Its border has to be a step darker again or it vanishes into the fill,
   hence --color-border-strong.

   All THREE properties matter, and the label most of all. A neutral fill was
   solving the visibility problem while creating a second one: gray fill under
   a --color-text-secondary label is the same grammar as a disabled input
   (--color-bg under --color-text-disabled), so these read as fields you
   weren't allowed to edit. Note that a lighter fill than this one is fine
   elsewhere in the industry — the weight comes from a full-strength label and
   a defined edge, not from how dark the fill is. */
.btn-secondary {
    background: var(--color-control);
    color: var(--color-control-text);
    border-color: var(--color-border-strong);
}

    /* Steps DOWN a shade. It used to step to --color-bg, which is lighter than
       the resting state now and would have brightened on hover. */
    .btn-secondary:hover:not(:disabled) {
        background: var(--color-control-hover);
    }

.btn-danger {
    background: var(--color-danger);
    color: var(--color-white);
    border-color: var(--color-danger);
}

    .btn-danger:hover:not(:disabled) {
        background: #c01f1f;
    }

.btn-warning {
    background: var(--color-warning);
    color: var(--color-white);
    border-color: var(--color-warning);
}

/* "Reset filters" — needs to be spottable next to a row of plain
   btn-secondary controls, but a solid btn-danger reads as too heavy
   for a non-destructive action. Tinted outline splits the difference. */
.btn-outline-danger {
    background: var(--color-surface);
    color: var(--color-danger);
    border-color: var(--color-danger-light);
}

    .btn-outline-danger:hover:not(:disabled) {
        background: var(--color-danger-light);
        border-color: var(--color-danger);
    }

.btn-success {
    background: var(--color-success);
    color: var(--color-white);
    border-color: var(--color-success);
}

    .btn-success:hover:not(:disabled) {
        background: #15803d;
        border-color: #15803d;
    }

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border-color: transparent;
}

    .btn-ghost:hover:not(:disabled) {
        background: var(--color-bg);
    }

/* Ghost variant tinted red — for inline "Remove" actions in a file/photo
   list row, where a full btn-outline-danger border would be too heavy
   next to plain-text "Preview"/"Download" ghost buttons. */
.btn-ghost-danger {
    background: transparent;
    color: var(--color-danger);
    border-color: transparent;
}

    .btn-ghost-danger:hover:not(:disabled) {
        background: var(--color-danger-light);
    }

.btn-sm {
    padding: 6px var(--space-3);
    font-size: var(--font-size-sm);
}

.btn-lg {
    padding: var(--space-3) var(--space-8);
    font-size: var(--font-size-lg);
}

/* currentColor, not white. Hardcoded white only ever showed up on the primary
   button it was written against — on .btn-secondary, .btn-ghost and anywhere
   sitting on a card it rendered white-on-white, so the busy state of those
   buttons was a label change and an invisible spinner. Inheriting the button's
   own text colour makes one rule right on every variant, including any added
   later. */
.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Form Inputs ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* A label repeated on every row of a repeating form (the recipe editor).
   Above the stacking breakpoint the first row's labels read as column
   headers and the repeats are noise; below it, .form-row collapses to one
   column and every row after the first would otherwise be unlabelled
   boxes. */
@media (min-width: 769px) {
    .bom-repeat-label {
        display: none;
    }
}

.form-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.form-control {
    padding: 11px var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    background: var(--color-surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100%;
    font-family: var(--font-family);
    box-sizing: border-box; /* critical — width:100% includes padding+border */
}

/* iOS SAFARI ZOOMS THE WHOLE PAGE when you focus an input whose font is under
   16px, and then leaves it zoomed -- you pinch back out, tap the next field,
   and it happens again. --font-size-sm is 14px, so that was every text box in
   the product on an iPhone.

   The till already knew this: .pos-tender-input carries a 16px literal and a
   "never lower this" note beside it. Nothing had applied the same rule to the
   other 170-odd inputs. Measured at 320px: 54 inputs under 16px on the invoice
   list alone.

   Only at phone widths, so desktop density is untouched. Width is unaffected
   either way -- .form-control is width:100% with box-sizing:border-box -- so
   this costs a couple of pixels of height and nothing else. */
@media (max-width: 768px) {
    .form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px;
    }
}

    .form-control:focus {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px var(--color-primary-light);
    }

    .form-control:disabled {
        background: var(--color-bg);
        color: var(--color-text-disabled);
    }

/* ── End-of-form save bar ──────────────────────────────────
   A second commit point for long forms, where the header button has scrolled
   out of reach by the time the form is finished.

   position:sticky with bottom:0 rides the viewport while content remains and
   then settles into the flow at the end. Worth knowing: sticky on this app was
   once silently dead because overflow-x:hidden on an ancestor turns it into a
   scroll container, so if this ever stops following the scroll, look there
   first rather than at this rule.

   The right padding keeps the button clear of the floating Nova launcher, which
   is fixed to the bottom-right and would otherwise sit on top of it. */
.page-save-bar {
    position: sticky;
    bottom: var(--space-3);
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-top: var(--space-5);
    padding: var(--space-3) var(--space-4);
    padding-right: 84px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(16, 24, 40, 0.10);
}

@media (max-width: 640px) {
    .page-save-bar {
        /* No launcher reservation needed here: the message and button wrap to
           their own lines on the LEFT, and the launcher is bottom-right, so
           they never share space. Padding for it just left dead white space
           under the button. */
        padding-right: var(--space-4);
    }
}

/* ── Currency-prefixed inputs ──────────────────────────────
   The symbol is a REAL FLEX ITEM, not an absolutely positioned overlay whose
   clearance the input has to guess.

   Every one of these used to be a relative wrapper plus
   `padding-left: calc(12px + <symbol>.Length ch + 8px)`, which takes the
   CHARACTER COUNT of the symbol as a stand-in for its rendered WIDTH. That
   holds for "$" and almost nothing else. Measured at 14px Inter: "$" is 8.99px
   and 1ch is 8.83px, so it fits — but "₨" is ONE character that renders
   17.94px wide, so the formula reserved 8.83px, the text began at 28.83px and
   the symbol ended at 29.94px, and the amount started INSIDE the symbol:
   "₨0.00" with no gap. Every wide symbol does this (₹ ₩ ₫), and so would any
   multi-character code.

   Flex removes the arithmetic: the symbol occupies exactly its own width and
   the input starts after it, whatever the currency. The wrapper carries the
   border so the pair reads as one control, and :focus-within reproduces what
   .form-control:focus would have done. */
.currency-field {
    display: flex;
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

    .currency-field:focus-within {
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px var(--color-primary-light);
    }

    .currency-field > .currency-field-symbol {
        display: flex;
        align-items: center;
        padding-left: var(--space-4);
        padding-right: 6px;
        color: var(--color-text-muted);
        font-size: var(--font-size-sm);
        white-space: nowrap;
        user-select: none;
        pointer-events: none;
    }

    /* The input gives up its own chrome: the wrapper is the control now. */
    .currency-field > .form-control {
        flex: 1 1 auto;
        min-width: 0;
        border: none;
        background: transparent;
        padding-left: 0;
    }

        .currency-field > .form-control:focus {
            border-color: transparent;
            box-shadow: none;
        }

        .currency-field > .form-control:disabled {
            background: transparent;
        }

    .currency-field:has(> .form-control:disabled) {
        background: var(--color-bg);
    }

.form-control-with-icon {
    position: relative;
}

    .form-control-with-icon .form-control {
        padding-right: 44px;
    }

.form-icon-toggle {
    position: absolute;
    right: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--color-text-muted);
    background: none;
    border: none;
    display: flex;
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-danger);
}

/* ONE HEIGHT FOR EVERY CONTROL THAT SHARES A ROW.

   .form-control and .custom-select-trigger declare identical padding, border,
   font size and box-sizing, and still came out different heights, because each
   one derives its height from its own content: an input from its text's line
   box, the trigger from its flex line, and a date input from whatever Chrome
   reserves for the picker icon. Measured on the invoice filter bar: Search 43,
   Status 40, From and To 45.

   The bar is align-items:flex-end, so the controls DID line up along the
   bottom -- and the labels above them therefore sat at three different
   heights, like a staircase. That is what reads as broken.

   Phone widths made it worse, not better. The 16px rule above lifts every
   input so iOS will not zoom the page, and deliberately does not include the
   trigger, which is a button and cannot trigger that zoom. Correct for its own
   purpose, and it widened the gap on exactly the screens where the row is
   tightest.

   44px because that is the touch-target minimum this app already applies to
   .btn at phone widths, so the controls and the buttons beside them now agree
   too. min-height rather than height, so a control whose content genuinely
   needs more room can still have it. */
.form-control,
.custom-select-trigger {
    min-height: 44px;
}

/* The one that needs capping rather than raising: Chrome gives a date input
   extra internal height for its picker icon. 44px still leaves 20px of content
   box, which clears the 16px font the rule above gives it on a phone. */
input.form-control[type="date"] {
    height: 44px;
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* ── Select — styled to match .form-control ── */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
    cursor: pointer;
}

    select.form-control:focus {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px var(--color-primary-light);
    }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* TWO CARDS SIDE BY SIDE THAT STACK ON A PHONE.

   Exists as a class because the alternative does not work: this was an inline
   `display:grid; grid-template-columns:1fr 1fr`, and an inline style cannot be
   overridden by a media query, so the pair could never collapse. At a 320px
   layout the two action cards on the inventory item page resolved to tracks of
   227px and 203px and ran 148px off the side of the page.

   minmax(0, 1fr), not 1fr. `1fr` means `minmax(auto, 1fr)`, and auto floors a
   track at its content's min-content width -- so a track that cannot fit does
   not shrink, it pushes the page sideways, which is half of what happened
   here. The media query is the other half: at phone widths two columns of
   these are too narrow to be worth having at any track size. */
.card-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-5);
}

@media (max-width: 768px) {
    .card-pair {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* A form row that ends in a small action (Remove, Clear). .form-row is a
   2-column grid, so a third child silently wraps onto its own line BELOW the
   inputs — which is what made the bill-of-materials Remove link look detached
   from its row. This gives the action its own auto-width column so it sits
   inline, and `align-items:end` lines the button up with the input baselines
   rather than the labels above them. */
.form-row.form-row-with-action {
    grid-template-columns: 2fr 1fr auto;
    align-items: end;
    /* .form-row's `gap` is BETWEEN COLUMNS only, and neither it nor .form-group
       carries a bottom margin — every other .form-row in the app is a one-off
       that adds its own inline margin. This one REPEATS (one per bill-of-
       materials line), so with nothing here the rows rendered edge to edge and
       the inputs read as a single block rather than a list. */
    margin-bottom: var(--space-3);
}

@media (max-width: 600px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Stacked on mobile the action can't sit inline, so let it sit under its
       own row and align right instead of stretching full width. */
    .form-row.form-row-with-action {
        grid-template-columns: 1fr;
    }

    .form-row.form-row-with-action > :last-child {
        justify-self: end;
    }
}

/* ── Password Strength Meter — from the Auth mockup ── */
.password-strength {
    display: flex;
    gap: var(--space-1);
    margin-top: var(--space-2);
}

.password-strength-bar {
    height: 4px;
    flex: 1;
    border-radius: var(--radius-full);
    background: var(--color-border);
}

    .password-strength-bar.filled-weak {
        background: var(--color-danger);
    }

    .password-strength-bar.filled-medium {
        background: var(--color-warning);
    }

    .password-strength-bar.filled-strong {
        background: var(--color-success);
    }

.password-strength-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    margin-top: var(--space-1);
}

    .password-strength-label.weak {
        color: var(--color-danger);
    }

    .password-strength-label.medium {
        color: var(--color-warning);
    }

    .password-strength-label.strong {
        color: var(--color-success);
    }

/* ── Badges / Status Pills ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    /* A status pill exists to be read at a glance, so it must never wrap:
       squeezed beside a long message, "Can't read it" came out as three
       stacked words in a tall ragged blob. Every badge in the app carries a
       short label from a fixed vocabulary, so there is nothing here long
       enough to overflow instead. */
    white-space: nowrap;
}

/* One credit note on the invoice page: the whole row is the link. */
.credit-note-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-border);
    color: inherit;
    text-decoration: none;
}
.credit-note-row:hover { background: var(--color-bg-hover, transparent); }

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.badge-success {
    background: var(--color-success-light);
    color: var(--color-success-text);
}

    .badge-success .badge-dot {
        background: var(--color-success);
    }

.badge-warning {
    background: var(--color-warning-light);
    color: var(--color-warning-text);
}

    .badge-warning .badge-dot {
        background: var(--color-warning);
    }

.badge-danger {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
}

    .badge-danger .badge-dot {
        background: var(--color-danger);
    }

.badge-info {
    background: var(--color-info-light);
    color: var(--color-info-text);
}

    .badge-info .badge-dot {
        background: var(--color-info);
    }

.badge-neutral {
    background: var(--color-border-light);
    color: var(--color-text-secondary);
}

.badge-nova {
    background: var(--color-primary-light);
    color: var(--color-primary-hover);
}

/* ── Nova inline highlights (summary + chat) ──
   Nova wraps a handful of standout words/figures in these — see
   Helpers/NovaMarkdown.cs for how the plain-text {{good}}...{{/good}} tags
   become these <mark> elements. */
.nova-hl {
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-weight: var(--font-weight-semibold);
}

.nova-hl-good {
    background: var(--color-success-light);
    color: var(--color-success-text);
}

.nova-hl-bad {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
}

.nova-hl-warn {
    background: var(--color-warning-light);
    color: var(--color-warning-text);
}

.nova-hl-info {
    background: var(--color-info-light);
    color: var(--color-info-text);
}

/* The summary is prompted for a bold headline, not a markdown heading — but
   the model reaches for "#" often enough that an unstyled h1 would render at
   browser-default size and dwarf the card it sits in. Cheaper to make a stray
   heading harmless than to rely on the prompt alone. */
.nova-summary-body h1,
.nova-summary-body h2,
.nova-summary-body h3,
.nova-summary-body h4 {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--space-2);
    line-height: 1.4;
}

/* ── Table ── */
.table-container {
    overflow-x: auto;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
}

    .app-table th {
        text-align: left;
        padding: var(--space-3) var(--space-4);
        font-size: var(--font-size-xs);
        font-weight: var(--font-weight-semibold);
        color: var(--color-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        border-bottom: 1px solid var(--color-border);
    }

    .app-table td {
        padding: var(--space-4);
        font-size: var(--font-size-md);
        color: var(--color-text-primary);
        border-bottom: 1px solid var(--color-border-light);
        vertical-align: middle;
    }

    .app-table tbody tr:hover {
        background: var(--color-bg);
    }

    .app-table tbody tr.clickable {
        cursor: pointer;
    }

.table-primary-text {
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

/* Mobile: tables collapse to clean cards */
@media (max-width: 768px) {
    .app-table thead {
        display: none;
    }

    .app-table, .app-table tbody, .app-table tr, .app-table td {
        display: block;
        width: 100%;

        /* border-box is not the default here. This app has no global reset (see
           reset.css for why that is being left alone for now), so `width: 100%`
           plus the row's 9px padding and 1px border came to 100% PLUS 20px.
           On the dashboard that card is overflow-x:hidden, so the last 19px of
           every row -- the right-aligned amount -- was cut off with no way to
           scroll to it. Measured at 320px: a 314px row inside a 295px card. */
        box-sizing: border-box;
    }

        .app-table tr {
            border: 1px solid var(--color-border);
            border-radius: var(--radius-lg);
            margin-bottom: var(--space-3);
            padding: var(--space-3);
            background: var(--color-surface);
        }

        .app-table td {
            border: none;
            padding: var(--space-2) 0;

            /* LABEL LEFT, VALUE RIGHT, ON ONE LINE. Stacking the label above
               the value made a six-column row six lines tall, so a single
               month of a profit and loss filled half a phone screen and the
               table became a scroll. Side by side halves that and reads like
               a receipt, which is what a row of figures is. */
            display: flex;
            justify-content: space-between;
            align-items: baseline;
            gap: var(--space-4);

            /* A long unbroken value -- an email address, a reference -- is one
               flex item next to a nowrap label, and without this it pushes the
               card wider than the screen instead of wrapping.
               break-word, NOT anywhere: anywhere also shrinks the cell's
               min-content width, which let the flex row squeeze a normal cell
               into a sliver and hyphenate real words down it. */
            overflow-wrap: break-word;

            /* The desktop cells carry inline text-align:right to line the
               money column up under its heading. In a stacked card there is
               no column and no heading, and the inline style dragged BOTH the
               label and the value to the right edge, leaving the first cell
               alone on the left and the card looking ragged. Only an
               !important can beat an inline style, and it is confined to this
               media query. */
            text-align: left !important;
        }

            .app-table td::before {
                content: attr(data-label);
                font-size: var(--font-size-xs);
                font-weight: var(--font-weight-semibold);
                color: var(--color-text-muted);
                text-transform: uppercase;
                white-space: nowrap;
            }

            /* A cell with nothing to label -- an actions column, a chevron --
               would otherwise render an empty ::before that still takes its
               gap and pushes the content off-centre. */
            .app-table td:not([data-label])::before {
                content: none;
            }

            /* THE CELL THAT NAMES THE ROW IS THE HEADING OF ITS OWN CARD --
               the name, the month, the item -- so it gets the weight, takes
               the full width and drops its label, the same shape the expense
               and invoice cards use.
               That is USUALLY the first cell, but not always: a table with a
               select-all checkbox or an expander arrow puts a control there,
               and promoting that gave a bold empty block for a heading while
               the real name was squeezed into a narrow right-hand column. So
               the second selector takes the first LABELLED cell when an
               unlabelled control leads the row. */
            .app-table td[data-label]:first-child,
            .app-table td:not([data-label]):first-child + td[data-label] {
                display: block;
                font-weight: var(--font-weight-bold);
                font-size: var(--font-size-md);
                color: var(--color-text-primary);
                padding-bottom: var(--space-3);
            }

                .app-table td[data-label]:first-child::before,
                .app-table td:not([data-label]):first-child + td[data-label]::before {
                    content: none;
                }
}

/* ── Cost mode: one value, two meanings ──
   A segmented pair that says what the number beside it IS, modelled on the
   till's amount/percent pair (.pos-discount-mode). Two money INPUTS that
   rewrite each other is the thing this replaces: there is one box to fill,
   and the toggle names it. Sized for the 40px .form-control rather than the
   till's 56px controls. */
.cost-mode {
    display: inline-flex;
}

.cost-mode-btn {
    min-width: 62px;
    min-height: 32px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
}

.cost-mode-btn:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.cost-mode-btn:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    margin-left: -1px; /* one shared border, not two touching */
}

.cost-mode-btn.is-active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #fff;
    position: relative; /* keep the active edge above its neighbour */
}

/* The arithmetic, spelled out under the box. Not an input: it is the echo
   that makes a total typed into a per-unit box look wrong while it is being
   typed, which is the whole point of showing it. */
.cost-mode-echo {
    margin-top: var(--space-2);
    margin-bottom: var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* ── Catalogue desktop/mobile split ── */
.catalogue-desktop-table {
    display: block;
}

.catalogue-mobile-cards {
    display: none;
}

@media (max-width: 768px) {
    .catalogue-desktop-table {
        display: none;
    }

    .catalogue-mobile-cards {
        display: block;
        padding: var(--space-4);
    }
}

/* ── Catalogue mobile card ── */
.catalogue-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-3);
    cursor: pointer;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

    .catalogue-card:hover {
        border-color: var(--color-primary);
        box-shadow: var(--shadow-sm);
    }

    .catalogue-card:last-child {
        margin-bottom: 0;
    }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    /* Same reason as .drawer-overlay: this centres its modal, so without it a
       modal with a text box in it centres against a height the keyboard is
       covering the bottom of. See app.js. */
    bottom: var(--viewport-bottom-inset, 0px);
    background: rgba(20, 20, 35, 0.5);
    /* +10 so confirm dialogs always sit ABOVE the slide-in drawer
       (both used to share --z-modal and DOM order decided — dialogs
       opened from a page could hide behind the drawer on mobile) */
    z-index: calc(var(--z-modal) + 10);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

/* A confirm dialog always sits above whatever opened it — including
   another modal. Without this, two .modal-overlay elements share a
   z-index and DOM order decides, so a confirm opened from a modal
   declared later in the page renders UNDERNEATH it and looks like
   nothing happened. See ConfirmDialog.razor. */
.modal-overlay.is-confirm {
    z-index: calc(var(--z-modal) + 20);
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    max-width: 520px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    /* 90vh as before on a roomy screen, but never taller than the overlay, so
       a shrunken overlay (keyboard up) actually constrains it instead of
       letting it overflow past the keyboard with its own scrollbar. */
    max-height: min(90vh, 100%);
    overflow-y: auto;
    /* REQUIRED, and it was missing. This project has no global box-sizing
       reset (see the note in pos.css), so max-height above was capping the
       CONTENT box and the painted box came out 48px taller than the cap --
       the padding on this very rule. Measured at 375x480: a 432px cap
       rendering a 480px box, which swallowed the overlay's own 12px gap and
       put the modal flush against all four screen edges with its action row
       pushed below the fold. */
    box-sizing: border-box;
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-5);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

/* ON A PHONE THE ACTION ROW IS A FOOTER, pinned to the bottom of the modal
   the way .drawer-footer is pinned to the bottom of a drawer.

   A .modal scrolls its own content (overflow-y:auto), and with the keyboard up
   there is very little of it on screen: measured at 375x480 on the receive
   stock dialog, 480px of content in a 282px window, with Cancel and Receive
   stock sitting 174px below the bottom edge. They were reachable, by scrolling
   INSIDE the modal -- which nobody does, because a modal that fills the screen
   edge to edge does not look like a thing that scrolls. The buttons read as
   missing.

   Phone only. A desktop modal has the room, and this changes how every modal
   in the app is framed, so it goes where the problem is.

   The negative margins pull the strip out to the modal's padding edges so the
   content scrolls underneath it rather than beside it, and the matching
   padding puts the buttons back where they were. They depend on .modal's
   padding being --space-8, which one rule above decides. */
@media (max-width: 768px) {
    /* The modal's own bottom padding has to go, and the strip supplies it
       instead. Sticky resolves against the scrollport, and the bottom padding
       is INSIDE that: left on, the row parks 24px short of the bottom edge
       while scrolled content carries on showing underneath it. Measured.

       :has, so this only applies to a modal that HAS a strip to supply the
       padding back. Without it a modal with no action row (the file preview is
       today's only one, and it sets padding:0 anyway) would lose its bottom
       gap and sit flush against its own edge. */
    .modal:has(> .modal-actions) {
        padding-bottom: 0;
    }

    .modal-actions {
        position: sticky;
        bottom: 0;
        margin: var(--space-4) calc(-1 * var(--space-8)) 0;
        padding: var(--space-4) var(--space-8) var(--space-8);
        background: var(--color-surface);
        border-top: 1px solid var(--color-border-light);
    }
}

/* ── Alert ── */
.alert {
    padding: var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    border: 1px solid transparent;
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
}

.alert-success {
    background: var(--color-success-light);
    color: var(--color-success-text);
    border-color: #a7e9bd;
}

.alert-warning {
    background: var(--color-warning-light);
    color: var(--color-warning-text);
    border-color: #fde29a;
}

.alert-danger {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
    border-color: #f6c4c4;
}

.alert-info {
    background: var(--color-info-light);
    color: var(--color-info-text);
    border-color: #bcd6fb;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(360px, calc(100vw - 2 * var(--space-4)));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-sm);
    animation: toast-in .2s ease-out;
}

.toast svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-success {
    background: var(--color-success-light);
    color: var(--color-success-text);
    border-color: #a7e9bd;
}

.toast-error {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
    border-color: #f6c4c4;
}

.toast-text {
    flex: 1;
}

.toast-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: .6;
    font-size: var(--font-size-lg);
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}

.toast-dismiss:hover {
    opacity: 1;
}

@keyframes toast-in {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-8);
    flex-wrap: wrap;
    gap: var(--space-4);
}

.page-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-extrabold);
    color: var(--color-text-primary);
}

.page-subtitle {
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--color-text-muted);
}

.empty-state-icon-wrap {
    width: 56px;
    height: 56px;
    background: var(--color-primary-light);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-5);
    color: var(--color-primary);
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-desc {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-5);
    line-height: var(--line-height-relaxed);
}

/* ── Stats Grid ── */
/* auto-fit: however many cards a page has (3 on Expenses, 4 on
   Invoices), they share one row on desktop instead of wrapping */
/* Deliberately still 190px. Raising it to 240 did stop the overflow, but it
   bought the room by dropping a column: five cards became three and two, and a
   set of figures meant to be read across in one glance turned into two rows.
   The number giving up a few points of type is the cheaper trade, so the fit
   is done in script instead - see fitStatValues in app.js. */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-8);
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 641px) and (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* A query container, so the value inside can size itself against THIS CARD
   rather than the viewport. It also stops an unbreakable number widening the
   card: inline-size containment means the card's width comes from the grid
   track and nothing the content does can argue with it. */
.stat-card {
    container-type: inline-size;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: 3px solid var(--color-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
}

/* A stat card that FILTERS the list under it. Reusable: any page whose
   summary cards correspond to a filter can swap the div for a button and add
   this class.

   A <button> so it is reachable by keyboard and announced as an action -- a
   clickable div is neither. Everything here from `all: unset` onwards is
   undoing the button defaults that would otherwise fight .stat-card: the
   centred text, the inherited-but-not-really font, and the border. */
.stat-card-filter {
    font: inherit;
    color: inherit;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

    /* --shadow-sm, not --shadow-md: the latter is the strong brand glow meant
       for buttons, and three of them lifting at once reads as a toolbar. */
    .stat-card-filter:hover {
        border-color: var(--color-primary);
        box-shadow: var(--shadow-sm);
    }

    /* focus-visible, not focus: a mouse click should not leave a ring behind
       on a card somebody is only reading. */
    .stat-card-filter:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }

    /* The card whose filter is currently on. Reads as pressed rather than as
       hovered, so it survives the pointer moving away -- and aria-pressed
       carries the same fact to a screen reader. */
    .stat-card-filter.is-active {
        border-color: var(--color-primary);
        box-shadow: inset 0 0 0 1px var(--color-primary);
        background: var(--color-primary-light);
    }

    /* Says what the click will do, without taking a row of its own on mobile.
       Hidden from assistive tech because aria-pressed and the button role
       already say it, and "Click to filter" read aloud after every figure is
       noise. */
    .stat-card-hint {
        font-size: var(--font-size-xs);
        color: var(--color-text-muted);
        margin-top: var(--space-2);
    }

    .stat-card-filter.is-active .stat-card-hint {
        color: var(--color-primary);
        font-weight: var(--font-weight-medium);
    }

    .stat-card.accent-primary {
        border-top-color: var(--color-primary);
    }

    .stat-card.accent-danger {
        border-top-color: var(--color-danger);
    }

    .stat-card.accent-success {
        border-top-color: var(--color-success);
    }

    .stat-card.accent-warning {
        border-top-color: var(--color-warning);
    }

    /* Value text picks up the same accent colour as the top border —
       scoped to these modifier classes so it doesn't touch the many
       other .stat-card usages (Invoices/Expenses/Cheques/Reports) that
       don't opt into an accent. */
    .stat-card.accent-primary .stat-card-value {
        color: var(--color-primary);
    }

    .stat-card.accent-danger .stat-card-value {
        color: var(--color-danger);
    }

    .stat-card.accent-success .stat-card-value {
        color: var(--color-success);
    }

    .stat-card.accent-warning .stat-card-value {
        color: var(--color-warning);
    }

/* Drawer-width variant: two tighter columns instead of the page grid's
   auto-fit, since a drawer is ~440px and the full-size cards would stack
   into one very tall column. */
.stats-grid.compact {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

    .stats-grid.compact .stat-card {
        padding: var(--space-4);
    }

    .stats-grid.compact .stat-card-value {
        font-size: clamp(15px, 12cqi, 22px);
        --stat-value-max: 22px;
        --stat-value-min: 12px;
    }

    .stats-grid.compact .stat-card-icon {
        width: 28px;
        height: 28px;
    }

    .stats-grid.compact .stat-card-header {
        margin-bottom: var(--space-2);
    }

@media (max-width: 640px) {
    .stats-grid.compact {
        grid-template-columns: 1fr 1fr;
    }
}

/* A stat card that navigates. Resets the button defaults so it renders
   identically to its non-clickable siblings, then adds the affordance. */
button.stat-card.is-clickable {
    font: inherit;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

    button.stat-card.is-clickable:hover {
        border-color: var(--color-primary);
        box-shadow: var(--shadow-sm);
        transform: translateY(-1px);
    }

    button.stat-card.is-clickable:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.stat-card-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--color-primary-light);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .stat-card-icon.danger {
        background: var(--color-danger-light);
        color: var(--color-danger);
    }

    .stat-card-icon.success {
        background: var(--color-success-light);
        color: var(--color-success);
    }

    .stat-card-icon.warning {
        background: var(--color-warning-light);
        color: var(--color-warning);
    }

.stat-card-label {
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.stat-card-value {
    /* THE FALLBACK, not the mechanism. fitStatValues measures the real text
       and writes an exact size inline, which beats this. What it cannot do is
       run before the first paint, or at all if script is off - so this keeps a
       card readable in the meantime by scaling with the card's own width
       (11cqi is 11% of it). The ceiling is the original 28px.

       It cannot react to how LONG a number is: CSS has no way to measure text,
       so on its own a wide card renders 28px whether it holds "0" or sixteen
       digits. That is exactly the gap the script closes. */
    font-size: clamp(18px, 11cqi, 28px);
    /* Read by fitStatValues, so the ceiling and floor live in one place. */
    --stat-value-max: 28px;
    --stat-value-min: 14px;
    font-weight: var(--font-weight-extrabold);
    color: var(--color-text-primary);
    line-height: var(--line-height-tight);
    /* Digits all one width, so a ticking figure does not jiggle. */
    font-variant-numeric: tabular-nums;
}

.stat-card-trend {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-2);
}

    .stat-card-trend.up {
        color: var(--color-success);
    }

    .stat-card-trend.down {
        color: var(--color-danger);
    }

/* ── Layout helpers ── */
.col-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.layout-2col {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
    align-items: start;
}

@media (max-width: 1024px) {
    .layout-2col {
        grid-template-columns: 1fr;
    }
}

.divider {
    border: none;
    border-top: 1px solid var(--color-border-light);
    margin: var(--space-5) 0;
}

/* ── Pagination ── */
.pagination-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border-light);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.pagination-info {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.pagination-page {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* ── Auth Layout ── */
.auth-shell {
    min-height: 100vh;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.auth-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
}

.auth-logo-full {
    height: 100px;
    width: auto;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-10);
    width: 100%;
    max-width: var(--auth-card-max-width);
    box-shadow: var(--shadow-lg);

    /* width:100% PLUS 32px of padding, because this app has no global
       border-box (see reset.css). The card came out 329px wide inside a 296px
       column, sat at x=-5, and scrolled the page sideways -- on the login and
       sign-up screens, which are the first two things anyone ever sees on a
       phone. The .form-control rule below already opted in for the same
       reason, one level down. */
    box-sizing: border-box;
}

/* The plan buttons on sign-up carry "Growth Monthly" and "$35.00/month ·
   30-day free trial" in one row, and .btn is white-space:nowrap, so at 320px
   the price ran 86px past the edge of the screen. Nothing on an auth card is
   so short that keeping it on one line is worth losing it off the side. */
.auth-card .btn {
    white-space: normal;
}

.auth-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-extrabold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.auth-subtitle {
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    margin-bottom: var(--space-8);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.auth-footer-text {
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-6);
}

    .auth-footer-text a {
        color: var(--color-primary);
        font-weight: var(--font-weight-medium);
    }

/* ── Auth fixes ── */

/* Prevent inputs overflowing their container on any screen size */
.auth-card .form-control {
    width: 100%;
    box-sizing: border-box;
}

/* Mobile auth card — remove the card shadow and padding on very
   small screens so it fills the viewport naturally */
@media (max-width: 480px) {
    .auth-shell {
        padding: var(--space-4);
        justify-content: flex-start;
        padding-top: var(--space-10);
    }

    .auth-card {
        padding: var(--space-6);
        border-radius: var(--radius-lg);
        box-shadow: none;
        border: 1px solid var(--color-border);
    }

    .auth-title {
        font-size: var(--font-size-xl);
    }
}

/* ── Business picker cards (SelectBusiness.razor) ── */
.business-picker-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    text-align: left;
    color: var(--color-text-primary);
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

    .business-picker-card:hover:not(:disabled) {
        border-color: var(--color-primary);
        box-shadow: var(--shadow-sm);
    }

    .business-picker-card:disabled {
        opacity: 0.6;
        cursor: default;
    }

.business-picker-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-md);
}

.business-picker-avatar-add {
    background: var(--color-border-light);
    color: var(--color-text-muted);
    font-size: var(--font-size-lg);
}

.business-picker-name {
    display: block;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
}

.business-picker-role {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.business-picker-add {
    border-style: dashed;
}

/* ── Business logo placeholder (Business Settings) ── */
.business-logo-placeholder {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-lg);
    background: var(--color-primary);
    color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    flex-shrink: 0;
    overflow: hidden;
}

/* ── File drop zone (drag-and-drop upload) ── */
.file-drop-zone {
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    transition: all var(--transition-fast);
}

    .file-drop-zone.drag-over {
        border-color: var(--color-primary);
        background: var(--color-primary-light);
    }

    .file-drop-zone.disabled {
        opacity: 0.7;
    }

.file-drop-zone-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: var(--space-5) var(--space-4);
    cursor: pointer;
    color: var(--color-text-muted);
    text-align: center;
}

    .file-drop-zone.disabled .file-drop-zone-label {
        cursor: not-allowed;
    }

    .file-drop-zone-label svg {
        color: var(--color-text-muted);
        margin-bottom: 2px;
    }

.file-drop-zone-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

    .file-drop-zone-text strong {
        color: var(--color-primary);
        font-weight: var(--font-weight-semibold);
    }

.file-drop-zone-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* ── Attached file list row (receipts/photos/logo) ── */
.attached-file-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    margin-bottom: var(--space-2);
}

.attached-file-thumb {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    overflow: hidden;
    cursor: pointer;
}

    .attached-file-thumb img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .attached-file-thumb svg {
        color: var(--color-text-muted);
    }

.attached-file-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    cursor: pointer;
}

/* ── File preview modal (image/PDF lightbox) ── */
.file-preview-modal {
    max-width: min(720px, 92vw);
    width: 100%;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 88vh;
}

.file-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.file-preview-name {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-body {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: var(--space-4);
    overflow: auto;
}

.file-preview-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.file-preview-frame {
    width: 100%;
    height: 70vh;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-white);
}

.file-preview-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    color: var(--color-text-muted);
    padding: var(--space-6);
}

/* ── Skeleton loading state ── */
.skeleton-card {
    background: linear-gradient(90deg, var(--color-border-light) 25%, var(--color-border) 50%, var(--color-border-light) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s infinite;
    border-radius: var(--radius-lg);
    border: none;
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* ── Searchable Select ── */
.searchable-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-modal); /* above drawer overlay */
    max-height: 220px;
    overflow-y: auto;
    padding: var(--space-2);
}

.searchable-select-option {
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

    .searchable-select-option:hover,
    .searchable-select-option.highlighted {
        background: var(--color-primary-light);
        color: var(--color-primary);
    }

.searchable-select-empty {
    padding: var(--space-4) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-align: center;
}

/* ── Slide-in Drawer Panel ── */
.drawer-overlay {
    position: fixed;
    inset: 0;
    /* The drawer is height:100% of this, so this is where the footer with Save
       in it stops. 0 on Chrome, where the viewport meta has already shrunk the
       layout viewport for the keyboard; the keyboard's own height on iOS,
       where it has not and the footer was behind it. See app.js. */
    bottom: var(--viewport-bottom-inset, 0px);
    background: rgba(20, 20, 35, 0.4);
    z-index: var(--z-modal);
    display: flex;
    justify-content: flex-end;
}

.drawer {
    background: var(--color-surface);
    width: 480px;
    max-width: 100vw;
    /* NOT 100vh, and not a vh unit at all. 100vh is the viewport WITHOUT the
       mobile browser's chrome, so on a phone the bottom ~90px of the drawer
       sat underneath the address bar and the nav buttons. That is the drawer
       FOOTER, which is where Save and Cancel live — reported as "you can't
       see the save button when you create a customer on mobile".

       100% inherits from .drawer-overlay, which is position:fixed inset:0 and
       therefore always exactly the layout viewport: correct when the chrome is
       showing, correct when it is hidden, and correct when the on-screen
       keyboard shrinks it (see the interactive-widget setting on the viewport
       meta in App.razor). A vh/svh/dvh unit gets at most two of those three. */
    height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: drawer-slide-in 0.22s ease;
}

@keyframes drawer-slide-in {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-6) var(--space-8);
    border-bottom: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

.drawer-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

.drawer-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-text-muted);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

    .drawer-close:hover {
        background: var(--color-bg);
        color: var(--color-text-primary);
    }

.drawer-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-8);
    padding-right: var(--space-12); /* 40px — inputs breathe away from edge */
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    box-sizing: border-box;
}

    /* Blazor component host elements inside drawer must not
   constrain height — they should grow with their content */
    .drawer-body > * {
        flex-shrink: 0;
        min-height: 0;
    }

.drawer-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-12) var(--space-5) var(--space-8);
    border-top: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

/* ── "Where the money stands" ────────────────────────────────
   One list on the payment panel, so nobody has to add up an invoice
   total, a payment history and a stack of cheque cards to work out what
   is still owed. See the markup note in ExpensePaymentPanel for the
   invoice that made the case. */
.money-standing {
    margin: var(--space-3) 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.money-standing-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: var(--font-size-sm);
}

    .money-standing-row dt {
        color: var(--color-text-secondary);
    }

    .money-standing-row dd {
        margin: 0;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        font-weight: var(--font-weight-medium);
        color: var(--color-text-primary);
    }

    /* Not money yet. Warning rather than success, because the one thing
       this line exists to say is that it has NOT arrived. */
    .money-standing-row.is-pending dd {
        color: var(--color-warning-text);
    }

    /* The line that says what to do about it, so it reads as the total. */
    .money-standing-row.is-shortfall {
        margin-top: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px solid var(--color-admin-border);
    }

        .money-standing-row.is-shortfall dt,
        .money-standing-row.is-shortfall dd {
            font-weight: var(--font-weight-bold);
            color: var(--color-text-primary);
        }

        /* Only the FIGURE takes the colour, not the label, which is how the
           lists beside these drawers already do it: the number is the thing
           being flagged and the words stay readable.

           Two tones on purpose. Each drawer borrows the colour its own list
           uses for the same idea, so opening an invoice from a red balance
           does not land on an amber one. Applied only above zero -- see the
           markup. */
        .money-standing-row.is-shortfall.is-chase dd {
            color: var(--color-danger);
        }

        .money-standing-row.is-shortfall.is-owed dd {
            color: var(--color-warning-text);
        }

.money-standing-note {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Profit insight panel — internal/admin accent colour */
.profit-insight-panel {
    background: var(--color-admin-bg);
    border: 1px solid var(--color-admin-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-sizing: border-box;
    width: 100%;
    /* Never clip content — height grows with content */
    overflow: visible;
    height: auto;
    min-height: 0;
}

    /* Force the cost/margin grid columns to not overflow their cells */
    .profit-insight-panel .form-group {
        min-width: 0;
    }

        .profit-insight-panel .form-group input.form-control {
            min-width: 0;
            width: 100%;
            box-sizing: border-box;
        }

.profit-insight-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.profit-insight-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    color: var(--color-admin-text);
}

.profit-insight-badge {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-admin-text);
    background: var(--color-admin-border);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
}

.profit-insight-desc {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-4);
    line-height: var(--line-height-relaxed);
}

/* Mobile — full screen drawer.
   Breakpoint matches the 768px used by the table/card and page-header
   splits elsewhere, so the drawer doesn't stay a narrow floating panel
   next to full-width mobile card rows in the 641-768px range. */
@media (max-width: 768px) {
    .drawer {
        width: 100vw;
        border-radius: 0;
    }

    .drawer-header {
        padding: var(--space-5) var(--space-6);
    }

    .drawer-body {
        padding: var(--space-6);
    }

    .drawer-footer {
        padding: var(--space-4) var(--space-6);
    }
}

/* end of components.css */

/* ── Page header — wrap on mobile ── */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

        .page-header > div:last-child {
            display: flex;
            flex-wrap: wrap;
            gap: var(--space-2);
            align-items: center;
        }

            .page-header > div:last-child > div:first-child {
                flex: 1;
                min-width: 140px;
            }

                .page-header > div:last-child > div:first-child input {
                    width: 100% !important;
                }

        .page-header .btn-primary {
            flex-shrink: 0;
        }
}

/* ── Customer desktop/mobile split ── */
.customer-desktop-table {
    display: block;
}

.customer-mobile-cards {
    display: none;
}

@media (max-width: 768px) {
    .customer-desktop-table {
        display: none;
    }

    .customer-mobile-cards {
        display: block;
        padding: var(--space-4);
    }
}

/* ── Expense desktop/mobile split ── */
.expense-desktop-table {
    display: block;
}

.expense-mobile-cards {
    display: none;
}

@media (max-width: 768px) {
    .expense-desktop-table {
        display: none;
    }

    .expense-mobile-cards {
        display: block;
        padding: var(--space-4);
    }
}

/* ── ExpensePaymentPanel component fix ── */
/* Blazor renders components as wrapper elements — ensure they
   never get overflow:hidden or a constrained height in the drawer */
.drawer-body .profit-insight-panel {
    overflow: visible;
    height: auto;
}

/* ── Custom Select ── */
.custom-select-trigger {
    width: 100%;
    padding: 11px var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    background: var(--color-surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-align: left;
    font-family: var(--font-family);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-sizing: border-box;
}

    .custom-select-trigger:focus,
    .custom-select-trigger.open {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px var(--color-primary-light);
    }

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-modal);
    max-height: 240px;
    overflow-y: auto;
    padding: var(--space-2);
}

/* A BOTTOM SHEET ON A PHONE, not a dropdown hanging off the field.

   This used to be `max-height: 160px`, on the reasoning that a shorter panel
   would fit inside .drawer-body's scrollport. It does not, and the cap was
   measured doing harm: at 375x812, keyboard DOWN, the expense Paid to list was
   173px tall with the drawer body cutting it off 119px in, showing 2.5 of 7
   suppliers. With the keyboard up at 375x480 and the browser having done its
   own thing (it scrolls the FIELD into view; it has no idea a panel is about
   to open under it) the same list rendered with ZERO pixels inside the
   scrollport. You typed and nothing appeared.

   The room below a field is simply not there once a keyboard has taken ~330px:
   the drawer body is 350px tall, this panel needs 177px of it, so only a field
   in the top third of a form could ever have shown a list. Pinned to the
   bottom edge instead, the panel always gets the same room wherever the field
   sits, it is no longer clipped by any scrollport, and it opens next to the
   thumb. The report picker and the notification panel already do this; these
   were the only panels left hanging off their trigger.

   bottom is the keyboard inset rather than 0: see the note in app.js for why
   the viewport meta only covers Chrome for that. Both properties fall back to
   the pre-existing behaviour if the script never ran.

   The field is scrolled clear of the sheet by revealPickerField, which the
   components call once on open. CSS cannot do that half.

   AND pointer:coarse, which the first version of this missed. The problem a
   sheet solves is a HEIGHT problem: an on-screen keyboard takes a third of the
   screen and there is no room left under the field. Gating it on width alone
   caught something else entirely -- a desktop window narrowed past 768px,
   which has no keyboard and plenty of height -- and turned every ordinary
   dropdown there into a full-width panel pinned to the bottom of the window,
   so it stopped reading as a dropdown at all. Reported, and fair.

   coarse is the honest proxy for "a touch device, so a keyboard will cover the
   bottom of the screen when one appears". A narrow desktop window is fine, and
   keeps the dropdown anchored under its field where it belongs. */
@media (max-width: 768px) and (pointer: coarse) {
    .custom-select-dropdown,
    .searchable-select-dropdown {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: var(--viewport-bottom-inset, 0px);
        width: auto;
        max-width: none;
        max-height: calc(var(--viewport-visible-height, 100vh) * 0.45);
        /* Here and not on the base rule. This cap is a SHARE OF THE SCREEN,
           and the half it does not take is the room the field above has to
           live in, so it has to mean the painted box: without this the panel
           came out 13px taller than the cap, its own padding. On desktop the
           cap is a flat 220px where that difference buys nothing and changing
           it would move every dropdown for no reason. */
        box-sizing: border-box;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
        /* Clear of the iPhone home bar when there is no keyboard holding the
           sheet up off the bottom edge. */
        padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
        -webkit-overflow-scrolling: touch;
    }
}

.custom-select-option {
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background var(--transition-fast);
}

    .custom-select-option:hover {
        background: var(--color-primary-light);
        color: var(--color-primary);
    }

    .custom-select-option.selected {
        background: var(--color-primary-light);
        color: var(--color-primary);
        font-weight: var(--font-weight-semibold);
    }

/* ── Invoice desktop/mobile split ──
   cheque-* aliases exist so Cheques.razor doesn't have to wear
   invoice-* class names; both share the same rules. */
.invoice-desktop-table,
.cheque-desktop-table {
    display: block;
}

.invoice-mobile-cards,
.cheque-mobile-cards {
    display: none;
}

@media (max-width: 768px) {
    .invoice-desktop-table,
    .cheque-desktop-table {
        display: none;
    }

    .invoice-mobile-cards,
    .cheque-mobile-cards {
        display: block;
        padding: var(--space-4);
    }
}

/* ── Badge danger (for Overdue) ── */
.badge-danger {
    background: var(--color-danger-light);
    color: var(--color-danger-text);
}

/* ── Invoice Builder Layout ── */
.invoice-builder-layout {
    display: grid;

    /* minmax(0, 1fr), NOT 1fr. A bare `1fr` means minmax(AUTO, 1fr), and auto
       floors the track at its content's min-content width -- so a track that
       cannot fit its contents does not shrink, it pushes the page sideways.
       Measured at 320px: the track computed to 346px inside a 320px viewport
       and every builder scrolled horizontally. The same trap is fixed below on
       the header grid and the bank grid; between them the page went from 47px
       of horizontal overflow to none. */
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: var(--space-6);
    align-items: start;
}

.invoice-builder-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);

    /* A grid item's min-width is auto, which is min-content -- so freeing the
       TRACK above is not enough on its own; the item would still refuse to
       shrink and would simply overflow the track instead of the page. */
    min-width: 0;
}

.invoice-builder-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    min-width: 0;   /* same reason as .invoice-builder-main */
    position: sticky;
    top: calc(var(--topbar-height) + var(--space-5));
}

.invoice-builder-header-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 170px 310px;
    gap: var(--space-4);
    align-items: start;
}

/* Read-only state for issued/sent/paid/void invoices — the API
   rejects edits, so make the form visibly inert */
/* Locked (non-draft) invoice cards — inert, but text should stay
   fully readable. Only the input chrome gets a muted background;
   dimming the whole card's opacity made the invoice hard to read. */
.card.locked {
    pointer-events: none;
    user-select: none;
}

/* LINKS STILL WORK. pointer-events:none above is a blunt instrument: it is
   there to stop a locked document being typed into, and it also killed every
   link inside the card. "View customer details" on an overdue invoice is
   exactly the question an overdue invoice provokes -- whose number do I ring
   -- and it was dead. Every anchor inside these cards (invoice, quote and
   purchase order builders) navigates somewhere else; not one of them edits
   the document, so re-enabling the lot is safe rather than a list to keep in
   step. Check that still holds before adding an <a> that acts. */
.card.locked a {
    pointer-events: auto;
}

    .card.locked .form-control,
    .card.locked textarea,
    .card.locked .invoice-toggle-btn:not(.active) {
        background: var(--color-bg);
    }

/* ── Expandable table rows ───────────────────────────────────────────
   A parent row that opens to show what it is made of (the By customer
   tables on the trade-ins and sold-items reports). The caret is its own
   button because the row's first cell already holds a link, and two
   click targets on one row means one of them silently wins. */
.row-expand-btn {
    background: none; border: none; cursor: pointer; padding: 0;
    margin-right: var(--space-2); width: 14px; line-height: 1;
    color: var(--color-text-muted); vertical-align: middle;
}
.row-expand-btn:hover { color: var(--color-primary); }
.row-expand-caret {
    display: inline-block; font-size: var(--font-size-md);
    transition: transform 120ms ease;
}
.row-expand-caret.is-open { transform: rotate(90deg); }
/* Keeps names aligned whether or not a row can open, and indents children. */
.row-expand-spacer {
    display: inline-block; width: 14px; margin-right: var(--space-2);
}
.row-expand-hint {
    margin-left: var(--space-2); font-size: var(--font-size-xs);
    color: var(--color-text-muted); font-weight: var(--font-weight-normal);
}
.row-expand-child > td {
    background: var(--color-bg);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}
.row-expand-child > td:first-child { padding-left: var(--space-5); }

/* Line items */
.invoice-line-header {
    display: grid;
    grid-template-columns: 1fr 70px 90px 70px 100px 36px;
    gap: var(--space-2);
    padding: 0 var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.invoice-line-list {
    margin-bottom: var(--space-4);

    /* Gaps between the lines, because the zebra stripe cannot always supply
       them. A discount or trade-in line paints its OWN background, which beats
       the stripe, so two trade-ins in a row were two identical tinted blocks
       touching each other and reading as one line with twice the fields.

       The gap is what does the work, not the outline below it: the card behind
       is white, so a gap reads as a white channel between two tinted blocks
       whatever colour they are, while a --color-border-light outline is nearly
       invisible ON a tint and only helps the plain rows. */
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* One group = the line row + its discount toggle, so the
   zebra stripe covers both as a single visual unit */
.invoice-line-group {
    padding: var(--space-3);
    border-radius: var(--radius-md);

    /* And an outline, for the same reason as the gap: on a phone the row wraps
       onto three lines, so where one line ends and the next begins stops being
       obvious from the shape of it. */
    border: 1px solid var(--color-border-light);
}

    .invoice-line-group:nth-child(even) {
        /* brand-tinted stripe — --color-bg was too close to white */
        background: var(--color-primary-light);
    }

.invoice-line-row {
    display: grid;
    grid-template-columns: 1fr 70px 90px 70px 100px 36px;
    gap: var(--space-2);
    align-items: start;
}

/* Summary */
.invoice-summary-row {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.invoice-summary-total {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

/* Toggle buttons (% / £) — cheque-* alias for Cheques.razor */
.invoice-toggle-btn,
.cheque-toggle-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
}

    .invoice-toggle-btn.active,
    .cheque-toggle-btn.active {
        background: var(--color-primary);
        color: var(--color-white);
    }

    /* A LINE BETWEEN THE SEGMENTS. With two buttons the active fill was enough
       to read the split; with three, the two inactive ones ran together into
       what looked like one wide label. The border sits on every button after
       the first, so a group of any size divides itself. */
    .invoice-toggle-btn + .invoice-toggle-btn,
    .cheque-toggle-btn + .cheque-toggle-btn {
        border-left: 1px solid var(--color-border);
    }

    /* The divider would otherwise draw a grey line down the edge of the filled
       segment, and against the primary colour it reads as a seam rather than
       as a separator. Removed on the active button and on the one after it,
       which are the only two edges that touch the fill. */
    .invoice-toggle-btn.active,
    .invoice-toggle-btn.active + .invoice-toggle-btn,
    .cheque-toggle-btn.active,
    .cheque-toggle-btn.active + .cheque-toggle-btn {
        border-left-color: transparent;
    }

/* ── Cheques page filter bar ──────────────────────────────────────────
   Desktop keeps the wrapping row it has always been. Under 720px that row
   was the problem: four fixed-width controls (150/150/160/160) plus a search
   box that grows, wrapping into ragged rows of two-and-a-bit with a half-empty
   line at the end. On top of that every control carries an invisible label
   spacer, there only to bottom-align the unlabelled ones against the labelled
   ones on desktop, which on a phone is just dead space between mismatched
   rows.

   So on a phone it becomes a plain two-column grid: the things that deserve
   the full width take it, the four that pair up naturally sit two per row,
   and the invisible spacers are dropped entirely. */
.cheque-filters {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    flex-wrap: wrap;
    width: 100%;
}

.cheque-filter {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cheque-filter-grow {
    flex: 1;
    min-width: 160px;
}

.cheque-filter-control {
    width: 150px;
}

.cheque-filter-control-wide {
    width: 160px;
}

/* Holds "Written / not banked yet" on one line in BOTH places it appears --
   the closed trigger and the open list, whose rows are inset further. Measured
   at 206px for the list row; 216 leaves room for the trigger's chevron and for
   a font that renders a shade wider. Later than .cheque-filter-control and
   equal in specificity, so it wins on order. */
.cheque-filter-control-status {
    width: 216px;
}

.cheque-filter-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
}

.cheque-filter-label-spacer {
    font-size: var(--font-size-xs);
    opacity: 0;
}

.cheque-filter-push {
    flex: 1;
}

@media (max-width: 768px) {
    /* SELECTOR SHAPE IS DELIBERATE, same trick as .report-picker-field below.
       `.page-header > div:last-child` (line ~2319) already sets display:flex
       on mobile for every page header's control group, and this filter bar is
       that last child. A bare `.cheque-filters` loses to it on specificity, so
       the grid-template-columns below applied while display stayed flex --
       which is worse than either, because the columns are then ignored and the
       controls wrap exactly as raggedly as before. Measured that way round
       first. Matching `div.cheque-filters` under the same ancestor ties the
       specificity, and this block sits later in the file, so it wins on order.

       768px, not a breakpoint of its own: that is where .page-header itself
       turns into a column, and a filter bar that reflowed at a different width
       would leave a band where the header had stacked but the filters had not. */
    .page-header > div.cheque-filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: end;
        gap: var(--space-3) var(--space-2);
    }

        /* The segmented view toggle, the search box and the reset button each
           read as their own thing, so each gets its own full-width line. */
        .cheque-filters .cheque-filter-full {
            grid-column: 1 / -1;
        }

        .cheque-filters .cheque-filter-grow {
            min-width: 0;
        }

        .cheque-filters .cheque-filter-control,
        .cheque-filters .cheque-filter-control-wide,
        .cheque-filters .cheque-filter-control-status {
            width: 100%;
        }

        /* Both halves of a pair must size to the column, not to their content,
           or a date input keeps its intrinsic width and leaves a gap. */
        .cheque-filters .form-control {
            width: 100%;
        }

        .cheque-filters .cheque-toggle-btn {
            flex: 1;
        }

        .cheque-filters .cheque-filter-label-spacer,
        .cheque-filters .cheque-filter-push {
            display: none;
        }
}

/* Bank details grid */
.invoice-bank-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
}

/* An IBAN is one unbreakable 24-character token, so min-content for this grid
   is however wide that string renders -- no amount of track freeing helps
   unless the string itself is allowed to break. It is an account number, not
   prose: breaking it mid-token is correct and is what every bank does on a
   statement. */
.invoice-bank-grid > * {
    overflow-wrap: anywhere;
}

.invoice-bank-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: var(--font-weight-semibold);
    margin-bottom: 2px;
}

.invoice-bank-value {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* Mobile — stack columns */
@media (max-width: 900px) {
    .invoice-builder-layout {
        grid-template-columns: 1fr;
    }

    .invoice-builder-sidebar {
        position: static;
    }

    .invoice-builder-header-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    /* The column headings are a table header, and a table header only works
       above a table. On a phone the row wraps, so it was switched off — and
       nothing replaced it. Every cell now carries its own data-label and
       prints it above itself instead. */
    .invoice-line-header {
        display: none;
    }

    /* Six equal tracks, and each cell claims the span it needs:

         [ ------------- description ------------- ]
         [   qty   ][   unit   ][    tax    ]
         [ ---------- AMOUNT ---------- ][  x  ]

       Previously this was five tracks on one line, which on a 360px phone
       left about 55px per field — too narrow to read a price back, let alone
       tell which box was which. !important because the purchase order sets
       its columns inline (it grows a seventh for the converted amount) and an
       inline style beats a stylesheet. */
    .invoice-line-row {
        grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
        gap: var(--space-2);
        align-items: start;
    }

        .invoice-line-row > div:first-child {
            grid-column: 1 / -1;
        }

        .invoice-line-row > div[data-label] {
            grid-column: span 2;
        }

        /* The amount gets its own line, because it is the number being
           checked. The remove button keeps the last track beside it. */
        .invoice-line-row > div[data-label="Amount"] {
            grid-column: 1 / 6;
        }

        /* :not([data-label]) so this can only ever mean the remove cell. The
           amount is also last on some rows and must keep its own span. */
        .invoice-line-row > div:last-child:not([data-label]) {
            grid-column: 6 / 7;
        }

        .invoice-line-row > div[data-label]::before {
            content: attr(data-label);
            display: block;
            font-size: 10px;
            font-weight: var(--font-weight-semibold);
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: var(--color-text-muted);
            margin-bottom: 2px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /* Label on the left, total on the right, on a rule of its own so the
           line reads as a subtotal rather than one more cramped cell. The
           inline padding-top aligns the figure with the inputs beside it on
           desktop; here there is nothing beside it. */
        .invoice-line-row > div[data-label="Amount"] {
            display: flex;
            flex-wrap: wrap;
            align-items: baseline;
            justify-content: space-between;
            gap: var(--space-2);
            font-size: var(--font-size-lg);
            margin-top: var(--space-1);
            padding-top: var(--space-2) !important;
            border-top: 1px dashed var(--color-border);
        }

            .invoice-line-row > div[data-label="Amount"]::before {
                margin-bottom: 0;
                font-size: 11px;
            }

    .invoice-bank-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ── Dashboard ── */
.dashboard-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
}

@media (max-width: 1100px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }
}

.pnl-breakdown-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    align-items: start;
}

@media (max-width: 900px) {
    .pnl-breakdown-grid {
        grid-template-columns: 1fr;
    }
}

.dashboard-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

/* Cash flow bar chart (pure CSS) */
.cashflow-chart {
    display: flex;
    align-items: flex-end;
    gap: var(--space-3);
    height: 170px;
}

.cashflow-month {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-width: 0;
}

.cashflow-bars {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
}

.cashflow-bar {
    width: 12px;
    max-width: 22%;
    border-radius: 4px 4px 0 0;
    transition: height 0.35s ease;
}

    .cashflow-bar.invoiced {
        background: var(--color-warning);
    }

    .cashflow-bar.income {
        background: var(--color-primary);
    }

    .cashflow-bar.expense {
        background: #b8bdf5; /* lighter brand tint */
    }

.cashflow-label {
    margin-top: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Cheques-in-transit widget */
.transit-pill {
    flex: 1;
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    min-width: 0;
}

    .transit-pill.incoming {
        background: var(--color-success-light);
    }

    .transit-pill.outgoing {
        background: var(--color-warning-light);
    }

.transit-pill-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
}

.transit-pill-value {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-top: 2px;
}

.transit-pill.incoming .transit-pill-value {
    color: var(--color-success-text);
}

.transit-pill.outgoing .transit-pill-value {
    color: var(--color-warning-text);
}

.transit-pill-sub {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.transit-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border-light);
    text-decoration: none;
    font-size: var(--font-size-sm);
}

    .transit-row:last-child {
        border-bottom: none;
    }

    .transit-row:hover {
        background: var(--color-bg);
    }

.transit-row-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    flex-shrink: 0;
}

    .transit-row-icon.in {
        background: var(--color-success-light);
        color: var(--color-success-text);
    }

    .transit-row-icon.out {
        background: var(--color-warning-light);
        color: var(--color-warning-text);
    }

/* Activity feed avatar */
.activity-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    flex-shrink: 0;
}


/* Month/year jump picker above the Orbit card — a native
   <input type="month"> styled to read as a bold page title,
   so users aren't limited to stepping one month at a time. */
.orbit-month-input {
    font-family: var(--font-family);
    font-size: 20px;
    font-weight: var(--font-weight-extrabold);
    color: var(--color-text-primary);
    border: 1px solid transparent;
    background: transparent;
    text-align: center;
    cursor: pointer;
    min-width: 190px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

    .orbit-month-input:hover {
        background: var(--color-bg);
        border-color: var(--color-border);
    }

    .orbit-month-input:focus-visible {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px var(--color-primary-light);
    }

/* ── Orbit cashflow card ── */
/* NOTE: chart containers must keep overflow VISIBLE — overflow:hidden
   clips Chart.js tooltips in this project */
.orbit-donut-wrap {
    position: relative;
    overflow: visible;
    flex-shrink: 0;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-primary-light) 0%, transparent 72%);
}

.orbit-donut-compact {
    width: 120px;
    height: 120px;
}

.orbit-donut-full {
    width: 280px;
    height: 280px;
    margin: 0 auto var(--space-4);
}

/* The centre label sits in a CIRCLE, so the space available to a line of text
   depends on how far that line is from the middle — a chord, not the hole's
   full diameter. On the compact card the hole is 86px across but only 65px
   wide where the value line actually sits, and a A$2,058 rendered 74px wide,
   overhanging the ring by about 4px each side.
   Hence a tight line-height: pulling the two lines toward the centre buys more
   width than any padding change can, because the chord widens fastest there. */
.orbit-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
    padding: 12%;
    line-height: 1.1;
    transition: opacity 120ms ease;
    /* A wrapped currency amount inside a donut reads as two unrelated numbers;
       better to keep it on one line and size it to fit. */
    white-space: nowrap;
}

/* Set while a donut slice is hovered, so the canvas-drawn tooltip is not read
   through this overlay. Opacity rather than display:none: the hole keeps its
   size, so nothing around it shifts as the pointer crosses the ring. */
.orbit-center-hidden {
    opacity: 0;
}

.orbit-center-value {
    font-size: 24px;
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-primary);
    line-height: 1.15;
}

/* One notch down from the full card's 24px. 18px overflowed the compact hole
   at four significant digits, and a shop with five-figure monthly takings is
   not unusual — this leaves room for one more digit rather than fitting
   today's number exactly. */
.orbit-center-value-sm {
    font-size: var(--font-size-md);
}

.orbit-center-sub {
    font-size: var(--font-size-base);
    color: var(--color-text-muted);
}

/* The sub-line is the LOWER of the two, so it sits where the chord has already
   started narrowing again — at 15px "of A$2,063" left barely 4px spare, and a
   five-figure total would have run onto the ring. */
.orbit-donut-compact .orbit-center-sub {
    font-size: var(--font-size-xs);
}

/* The full donut did NOT have room to spare, whatever the note above used to
   claim. That was written when the sub-line was a bare total; it now names the
   month ("of A$44,612 raised in October"), and nowrap meant a five-figure
   amount ran straight out of the hole and under the ring, half of it unreadable
   on top of the green. The AMOUNT still must not break — a wrapped currency
   figure reads as two numbers, which is what nowrap was for — but the words
   after it have no such claim, and there are no spaces inside the amount for a
   break to land in.

   The width is a percentage of the already-12%-padded box, so it tracks the
   donut at every size. It has to clear the chord at the LOWEST line of the
   wrapped block, not at the centre, which is why it is well under the hole's
   full diameter. */
.orbit-donut-full .orbit-center-sub {
    white-space: normal;
    max-width: 76%;
}

.orbit-label {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

/* Compact variant */
.orbit-compact {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-7);
    cursor: pointer;
    transition: box-shadow var(--transition-normal), border-color var(--transition-normal),
        transform var(--transition-normal);
}

    .orbit-compact:hover {
        border-color: var(--color-primary);
        box-shadow: var(--shadow-md);
        transform: translateY(-2px);
    }

.orbit-compact-net {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Bounds for fitStatValues. Declared rather than inferred: the script needs a
   ceiling that does not move, and these boxes are a fixed width so the CSS
   clamp used on stat cards can do nothing for them. */
.orbit-center-value { --stat-value-max: 16px; --stat-value-min: 10px; }
.orbit-chip-value   { --stat-value-max: 20px; --stat-value-min: 11px; }
.orbit-net-value    { --stat-value-max: 28px; --stat-value-min: 14px; }
.orbit-tile-value   { --stat-value-max: 21px; --stat-value-min: 12px; }

.orbit-net-value {
    font-size: 28px;
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.orbit-compact-stats {
    display: flex;
    gap: var(--space-6);
    margin-left: auto;
    padding-left: var(--space-6);
    border-left: 1px solid var(--color-border);
}

.orbit-chip {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 64px;
}

.orbit-chip-value {
    font-size: 20px;
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

.orbit-chip-label {
    font-size: var(--font-size-base);
    color: var(--color-text-muted);
}

.orbit-view-link {
    position: absolute;
    right: var(--space-5);
    bottom: var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-primary);
    text-decoration: none;
}

/* Full variant */
.orbit-full {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(240px, 1fr);
    gap: var(--space-10);
    align-items: start;
}

.orbit-full-left {
    min-width: 0;
    padding-right: var(--space-3);
}

.orbit-full-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.orbit-legend {
    display: flex;
    justify-content: center;
    gap: var(--space-5);
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    flex-wrap: wrap;
}

    .orbit-legend > span {
        display: inline-flex;
        align-items: center;
        gap: 5px;
    }

.orbit-dot {
    width: 8px;
    height: 8px;
    border-radius: 3px;
    display: inline-block;
}

.orbit-expense-card {
    margin-top: var(--space-5);
    padding: var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.orbit-expense-bar {
    display: flex;
    height: 32px;
    border-radius: var(--radius-md);
    overflow: hidden; /* bar only — the CHART container stays visible */
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.orbit-expense-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
    overflow: hidden;
    min-width: 0;
    transition: width 0.35s ease;
}

/* Tiles (right column of full variant) */
.orbit-tile {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

    .orbit-tile:hover {
        transform: translateY(-1px);
        box-shadow: var(--shadow-md);
    }

.orbit-tile-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    background: var(--color-border-light);
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

    .orbit-tile-icon.success {
        background: var(--color-success-light);
        color: var(--color-success);
    }

    .orbit-tile-icon.primary {
        background: var(--color-primary-light);
        color: var(--color-primary);
    }

    .orbit-tile-icon.warning {
        background: var(--color-warning-light);
        color: var(--color-warning);
    }

    .orbit-tile-icon.amber {
        background: var(--color-amber-light);
        color: var(--color-amber);
    }

    .orbit-tile-icon.danger {
        background: var(--color-danger-light);
        color: var(--color-danger);
    }

    /* White badge for icons sitting on an already-tinted tile,
       so the icon chip doesn't wash out against a matching bg */
    .orbit-tile-icon.on-tint {
        background: var(--color-surface);
        box-shadow: var(--shadow-sm);
    }

.orbit-tile-body {
    flex: 1;
    min-width: 0;
}

.orbit-tile-value {
    font-size: 21px;
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-primary);
    margin-top: 2px;
    line-height: 1.2;
}

.orbit-tile-sub {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.orbit-progress {
    height: 6px;
    background: var(--color-border-light);
    border-radius: 3px;
    margin-top: var(--space-3);
    overflow: hidden;
}

.orbit-progress-fill {
    height: 100%;
    border-radius: 3px;
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
    transition: width 0.35s ease;
}

/* Responsive — stack below 768px */
@media (max-width: 768px) {
    .orbit-compact {
        flex-direction: column;
        align-items: center;
        gap: var(--space-4);
        text-align: center;
    }

    .orbit-donut-compact {
        width: 100px;
        height: 100px;
    }

        /* The donut loses 20px here but the text did not, which put the
           sub-line back on the ring — it cleared by 16px at 120px and
           overflowed by 0.6px at 100px. Both lines step down with the circle
           they sit in. */
        .orbit-donut-compact .orbit-center-value-sm {
            font-size: var(--font-size-sm);
        }

        .orbit-donut-compact .orbit-center-sub {
            font-size: 11px;
        }

    .orbit-compact-stats {
        margin-left: 0;
        padding-left: 0;
        padding-top: var(--space-4);
        border-left: none;
        border-top: 1px solid var(--color-border);
        width: 100%;
        justify-content: center;
    }

    .orbit-chip {
        align-items: center;
        min-width: 0;
        flex: 1;
    }

    .orbit-view-link {
        position: static;
        margin-top: var(--space-2);
    }

    .orbit-full {
        grid-template-columns: 1fr;
    }

    .orbit-full-left {
        padding-right: 0;
    }

    .orbit-donut-full {
        width: 220px;
        height: 220px;
    }

    /* One tile per row — a 2-column grid is too narrow for the
       label text at readable sizes and forces awkward wrapping */
    .orbit-full-right {
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
    }

    .orbit-month-input {
        min-width: 0;
        font-size: var(--font-size-lg);
    }
}

/* ── Cheque calendar ── */
.cheque-calendar-month {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    min-width: 160px;
    text-align: center;
}

.cheque-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--color-border);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.cheque-calendar-weekday {
    background: var(--color-bg);
    padding: var(--space-3);
    text-align: center;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cheque-calendar-day {
    background: var(--color-surface);
    min-height: 100px;
    padding: var(--space-2);
    cursor: pointer;
    transition: background var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    box-sizing: border-box;
}

    .cheque-calendar-day:hover {
        background: var(--color-bg);
    }

    .cheque-calendar-day.other-month {
        background: var(--color-bg);
    }

        .cheque-calendar-day.other-month .cheque-calendar-day-number {
            color: var(--color-text-disabled);
        }

    .cheque-calendar-day.today {
        box-shadow: inset 0 0 0 2px var(--color-primary);
    }

.cheque-calendar-day-number {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
}

.cheque-calendar-dots {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cheque-calendar-chip {
    display: block;
    font-size: var(--font-size-xs);
    padding: 1px var(--space-2);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .cheque-calendar-chip.incoming {
        background: var(--color-success-light);
        color: var(--color-success-text);
    }

    .cheque-calendar-chip.outgoing {
        background: var(--color-warning-light);
        color: var(--color-warning-text);
    }

    .cheque-calendar-chip.cleared {
        background: var(--color-bg);
        color: var(--color-text-muted);
    }

    .cheque-calendar-chip.attention {
        background: var(--color-danger-light);
        color: var(--color-danger-text);
        font-weight: var(--font-weight-semibold);
    }

.cheque-calendar-more {
    font-size: var(--font-size-xs);
    color: var(--color-primary);
    font-weight: var(--font-weight-medium);
}

.cheque-calendar-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: var(--radius-full);
    display: inline-block;
    flex-shrink: 0;
}

    .cheque-calendar-legend-dot.incoming { background: var(--color-success); }
    .cheque-calendar-legend-dot.outgoing { background: var(--color-warning); }
    .cheque-calendar-legend-dot.attention { background: var(--color-danger); }
    .cheque-calendar-legend-dot.cleared { background: var(--color-border); }

/* The phone view's count pills. Hidden on desktop, where the named chips
   above say more than a number can. */
.cheque-calendar-counts {
    display: none;
}

.cheque-calendar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: var(--font-weight-bold);
    line-height: 1;
    color: #fff;
    box-sizing: border-box;
}

/* The DARK -text tokens, not the mid-tone solids the legend dots use, and not
   the -light ones this view used to borrow. Three numbers decided it, measured
   against the white cell:

     -light  (what shipped)   1.07:1 - 1.17:1   fails the 3:1 WCAG asks of a
                                                non-text indicator. This is the
                                                reported bug: a pale dot nobody
                                                over forty can pick out.
     solid   (legend dots)    3.30:1 - 5.18:1   passes as a shape, but a WHITE
                                                DIGIT on the green is only
                                                3.30:1, under the 4.5:1 that
                                                11px bold text needs.
     -text   (used here)      6.57:1 - 7.31:1   passes both, because these
                                                tokens were built to carry text.

   Same hue family as the legend, so "green means incoming" still matches.
   Cleared uses muted grey rather than --color-border, which at 1.18:1 would
   have repeated the original mistake; it is present but quiet, which is what a
   settled cheque should be. */
.cheque-calendar-count.incoming {
    background: var(--color-success-text);
}

.cheque-calendar-count.outgoing {
    background: var(--color-warning-text);
}

.cheque-calendar-count.attention {
    background: var(--color-danger-text);
}

.cheque-calendar-count.cleared {
    background: var(--color-text-muted);
}

/* Mobile — cells are too tight for chip text, so the named chips give way to
   the count pills above. */
@media (max-width: 640px) {
    .cheque-calendar-day {
        min-height: 54px;
        padding: var(--space-1);
    }

    .cheque-calendar-day-number {
        font-size: var(--font-size-xs);
    }

    .cheque-calendar-weekday {
        padding: var(--space-1);
        font-size: 10px;
    }

    /* The per-cheque chips and the "+N more" go together: the counts already
       cover every cheque in the cell, so nothing is hidden by this. */
    .cheque-calendar-dots {
        display: none;
    }

    .cheque-calendar-counts {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 3px;
    }
}

/* ── Reports tab bar (segmented button group) ──
   Same visual as before (bordered, rounded, corners clipped) but
   scrolls horizontally on narrow viewports instead of clipping tabs
   off the edge — this group has 9 buttons, which never fit a phone
   width. */
.report-tabs-wrap {
    position: relative;
    max-width: 100%;
}

.report-tabs {
    display: flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    /* overflow-x here, NOT plain overflow:hidden. The hidden was for the
       rounded corners (the buttons have no radius of their own), but it
       applied at every width while the scrolling that rescues it lived only
       inside the 768px query below — so every viewport ABOVE 768px squeezed
       the buttons toward min-content and then clipped the overflow with no
       scrollbar and no way to reach the last tabs. An Owner with inventory
       renders fourteen of them. This is a desktop bug that looks like a
       mobile one. */
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

    /* Also unconditional: without it the buttons shrink instead of scrolling,
       which is what made the clipping silent. */
    .report-tabs .invoice-toggle-btn {
        flex-shrink: 0;
        white-space: nowrap;
    }

@media (max-width: 768px) {
    .report-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* Inward shadow on the right edge — a "content continues" cue
           that reads correctly regardless of which tab (active/indigo
           or inactive/white) ends up scrolled under it. */
        box-shadow: inset -10px 0 8px -8px rgba(0, 0, 0, 0.2);
    }

        .report-tabs .invoice-toggle-btn {
            flex-shrink: 0;
            white-space: nowrap;
        }

}

/* ── Report picker (/reports) ──
   Replaces the fourteen-tab segmented strip. The trigger borrows
   .custom-select-trigger so it sits beside the Period select as an equal;
   everything below is the panel, which is wider than the trigger because it
   carries a description per row. */
/* The Report control's slot in the filter row.
   flex-shrink:0 is the point of it. With the wrapper free to shrink, a row
   that was two pixels too narrow squeezed the picker to 197px rather than
   wrapping it onto its own line, so the label truncated on a screen with
   plenty of room a line below. Refusing to shrink forces the wrap instead. */
/* Takes its own row at every width, so the pills get the full page to lay out
   on and the period control sits underneath rather than competing for it. */
.report-picker-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 0 100%;
}

/* Full width now, not 300px. That width sized a single dropdown trigger; the
   control is two rows of pills, and boxing them into 300px on a 1280px screen
   wrapped five groups onto two cramped lines with the reports on three more. */
.report-picker {
    position: relative;
    width: 100%;
}

/* Wider than the trigger, and pinned to its LEFT edge so it grows rightwards
   into the page rather than off it. On the right of a wide header the panel
   would otherwise overhang the viewport; see the media query below for the
   narrow case, where it stops being wider at all. */
.report-picker-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 380px;
    max-width: calc(100vw - var(--space-6));
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-modal);
    overflow: hidden;
}

.report-picker-search {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

/* Unstyled on purpose: it is the first row of the panel, not a form field
   sitting inside one, and a bordered input here reads as a box within a box.
   The 16px floor is the same one the POS screen keeps, because anything
   smaller makes iOS zoom the page the moment it takes focus. */
.report-picker-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: none;
    font-family: var(--font-family);
    font-size: 16px;
    color: var(--color-text-primary);
}

.report-picker-search-input::placeholder {
    color: var(--color-text-muted);
}

.report-picker-list {
    max-height: 420px;
    overflow-y: auto;
    padding: var(--space-2);
}

/* Headings carry the structure, so they are allowed to be seen. They were
   --color-text-muted, the same grey as the descriptions directly under them,
   which put the label and the thing it labels at identical weight and let the
   sections blur into one list.

   Sticky, because the list scrolls: fourteen rows past the fold, the heading
   that tells you which section you are in has already gone. Sticking it means
   the answer is always on screen. The opaque background is load-bearing -- a
   transparent heading would have option rows sliding visibly under its text. */
.report-picker-group {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--color-surface);
    padding: var(--space-3) var(--space-3) 4px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

/* A rule between sections, on every heading but the first -- the first one
   would be drawing a line immediately under the search box, which already has
   its own border. */
.report-picker-group:not(:first-child) {
    margin-top: var(--space-2);
    border-top: 1px solid var(--color-border-light);
    padding-top: var(--space-3);
}

/* The pinned section is the one heading that is not a category, so it is the
   one heading allowed the brand colour. */
.report-picker-group.is-featured {
    color: var(--color-primary);
}

.report-picker-option {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: none;
    background: none;
    border-radius: var(--radius-md);
    text-align: left;
    font-family: var(--font-family);
    cursor: pointer;
    color: var(--color-text-primary);
}

/* One highlight class driven by both hover and the arrow keys, rather than a
   :hover rule plus a separate keyboard one. Two of them meant the mouse
   resting over the list lit a second row while the keyboard walked, and the
   Enter key then chose the row that was not under the pointer. */
.report-picker-option.highlighted {
    background: var(--color-primary-light);
}

.report-picker-option.current .report-picker-option-label {
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

/* Category dot. Same idiom as CustomSelect's colour dots, deliberately, so
   this is a pattern the app already has rather than a new vocabulary.

   margin-top aligns it to the LABEL's cap height, not the row: the row is two
   lines tall (label plus description) and a vertically centred dot would float
   beside the gap between them, pointing at nothing. */
.report-picker-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    margin-top: 7px;
}

.report-picker-option-main {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.report-picker-option-label {
    font-size: var(--font-size-sm);
    line-height: 1.3;
}

.report-picker-option-desc {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    line-height: 1.35;
}

.report-picker-tick {
    color: var(--color-primary);
    flex-shrink: 0;
    margin-top: 3px;
}

.report-picker-empty {
    padding: var(--space-4) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-align: center;
}

/* The report control at every width: two rows of pills, groups then reports.
   The dropdown it replaced had to be opened before it said anything; these
   rows show where you are and what else there is without being touched. */
.report-picker-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.report-picker-grouprow {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

    .report-picker-grouprow > .report-picker-pills {
        flex: 1 1 auto;
        min-width: 0;
    }

    .report-picker-grouprow > .report-picker-search-btn {
        flex: 0 0 auto;
    }

/* WRAPS on a wide screen, SCROLLS on a narrow one. A hidden horizontal scroll
   is fine under a thumb and awful under a mouse, which has no natural gesture
   for it — so width is spent on more rows here and on a scroll only where a
   drag is available. */
.report-picker-pills {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.report-picker-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    /* 44px tall including the border — the floor for a thumb, and no worse
       for a pointer. Measured, not assumed: 11px padding came out at 40. */
    padding: 13px var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    white-space: nowrap;
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

    .report-picker-pill:hover {
        border-color: var(--color-border-strong);
    }

/* The group row is the quieter of the two: it says where you are looking,
   while the row under it is what you are choosing from. */
.report-picker-pill.is-group {
    padding-top: 11px;
    padding-bottom: 11px;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    background: none;
    border-color: transparent;
}

    .report-picker-pill.is-group.current {
        color: var(--color-text-primary);
        background: var(--color-bg);
        border-color: var(--color-border);
        font-weight: var(--font-weight-semibold);
    }

.report-picker-pill.current:not(.is-group) {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

/* Same dot idiom as the panel rows, so a pill and its list entry read as the
   same report. Not .report-picker-dot itself: that one is nudged down to meet
   a two-line row's cap height, which is wrong inside a pill. */
.report-picker-chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
}

/* Search is all this button still does, so it is sized for that rather than
   for holding the current report's name. */
.report-picker-search-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

    .report-picker-search-btn:hover,
    .report-picker-search-btn.open {
        border-color: var(--color-primary);
        color: var(--color-primary);
    }

@media (max-width: 768px) {
    /* Full width of the trigger, not wider than it: on a phone "wider than the
       trigger" means "wider than the screen". The description lines stay, and
       wrap. */
    /* SELECTOR SHAPE IS DELIBERATE. `.page-header > div:last-child >
       div:first-child` (line ~1742) gives every first header control
       `flex: 1` on mobile so a row of them shares the width. That is right for
       a search box beside a button and wrong here: this control owns a row of
       quick-pick chips underneath it, and at 163px of a 375px screen the chips
       were clipped to a sliver.

       Matching `div.report-picker-field` under the same ancestors ties that
       rule's specificity, and this block sits later in the file, so it wins on
       order. A bare `.report-picker-field` loses outright, and `flex-basis`
       alone loses to both shorthands. Measured: 163px before, 335px after. */
    .page-header > div:last-child > div.report-picker-field {
        flex: 1 0 100%;
    }

    /* Narrow screens scroll the rows sideways instead of wrapping them: a wrap
       pushes the report itself further down the screen every time a group
       gains a report, and on a phone that vertical space is the scarce one.
       A drag is available here, which is what makes a hidden scrollbar fair. */
    .report-picker-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

        .report-picker-pills::-webkit-scrollbar {
            display: none;
        }

    /* PERIOD STEPPER. Prev + input + Next came to 353px against a 335px row,
       so Next wrapped onto a line of its own with the month stranded above it.
       The input carries a fixed 197px width for the desktop layout; letting it
       shrink here is what lets all three share one line. */
    .period-stepper {
        gap: var(--space-2) !important;
        flex-wrap: nowrap !important;
    }

        .period-stepper .orbit-month-input {
            flex: 1 1 auto;
            min-width: 0;
            width: auto;
        }

        .period-stepper .btn {
            flex: 0 0 auto;
        }

    .report-picker {
        width: 100%;
    }

    /* A BOTTOM SHEET, not a dropdown hanging off the trigger.

       Anchored under the trigger, the panel got whatever room happened to be
       left below it: measured on a 375x812 phone, 459px of panel showing 24%
       of a 1776px list, and less the further down the page the trigger sat.
       Pinned to the bottom edge instead, it always gets the same generous
       space no matter where the trigger is, and it opens next to the thumb
       rather than under the top of the screen. */
    .report-picker-panel {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        max-height: 85vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
        display: flex;
        flex-direction: column;
    }

    /* Fills what the sheet has rather than a fixed fraction of the screen, so
       the search row is never pushed off the top by a long list. */
    .report-picker-list {
        max-height: none;
        flex: 1 1 auto;
        min-height: 0;
        padding-bottom: var(--space-4);
    }
}

/* ── Team desktop/mobile split ── */
.team-desktop-table {
    display: block;
}

.team-mobile-cards {
    display: none;
}

@media (max-width: 768px) {
    .team-desktop-table {
        display: none;
    }

    .team-mobile-cards {
        display: block;
        padding: var(--space-4);
    }
}

/* ── Text utilities ── */
/* Small muted helper text — replaces the inline
   font-size/color pair repeated across pages. */
.text-muted-xs {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* ── Email template editors (Business settings) ──────────────
   Four editors share one card, so each header has to read as a real
   section break. Previously these were plain --font-size-sm divs, which
   looked like body copy and let the four templates blur together. */
.email-template-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-primary-light);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
}

.email-template-title {
    margin: 0;
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    /* --color-primary-hover, not --color-primary-text: the latter is white,
       meant for text ON a solid primary fill. This sits on the pale
       --color-primary-light band, so it needs the darker brand tone. */
    color: var(--color-primary-hover);
}

/* ============================================================
   Confirm dialog — structured detail rows
   Used by Nova's action previews (ConfirmDialog.ShowAsync overload
   taking ConfirmDetail rows). A \n-joined string collapses into one
   run-on paragraph in HTML, so previews get real rows instead.
   ============================================================ */
.confirm-detail-list {
    margin: 0 0 var(--space-5) 0;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    max-height: 320px;
    overflow-y: auto;
}

.confirm-detail-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}

.confirm-detail-row:last-child {
    border-bottom: none;
}

.confirm-detail-row dt {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
}

.confirm-detail-row dd {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    word-break: break-word;
}

.confirm-detail-items {
    margin: 0;
    padding-left: var(--space-4);
}

.confirm-detail-items li {
    margin-bottom: var(--space-1);
}

@media (max-width: 600px) {
    .confirm-detail-row {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }
}

/* ── Nova chat history ── */
/* Sits here rather than beside the other .agent-chat-* rules in layout.css
   purely to keep this change append-only; it is the same component. */

.agent-chat-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

.agent-chat-header-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

    .agent-chat-header-btn:hover:not(:disabled) {
        background: var(--color-bg);
        color: var(--color-text-primary);
    }

    .agent-chat-header-btn:disabled {
        opacity: 0.5;
        cursor: default;
    }

    /* The history toggle stays lit while its list is up — it's the only thing
       on screen saying why the composer below is greyed out. */
    .agent-chat-header-btn.is-active {
        background: var(--color-primary-light);
        color: var(--color-primary);
    }

.agent-chat-history {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.agent-chat-history-row {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    overflow: hidden;
}

    .agent-chat-history-row:hover {
        border-color: var(--color-primary);
    }

    /* Marks the conversation the drawer is currently in, so resuming the one
       you're already reading isn't a mystery click. */
    .agent-chat-history-row.is-current {
        border-color: var(--color-primary);
        background: var(--color-primary-light);
    }

.agent-chat-history-open {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    text-align: left;
    padding: var(--space-3) var(--space-4);
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

    .agent-chat-history-open:disabled {
        opacity: 0.6;
        cursor: default;
    }

/* Titles are generated from the opening message and run to 60 characters, so
   they clip to one line — a wrapped title would push the next chat off-screen
   and make the list impossible to scan. */
.agent-chat-history-title {
    max-width: 100%;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-chat-history-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.agent-chat-history-delete {
    flex-shrink: 0;
    width: 36px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

    .agent-chat-history-delete:hover:not(:disabled) {
        background: var(--color-danger-light);
        color: var(--color-danger);
    }

    .agent-chat-history-delete:disabled {
        opacity: 0.5;
        cursor: default;
    }

.agent-chat-history-error {
    padding: var(--space-2) 0;
    font-size: var(--font-size-xs);
    color: var(--color-danger);
}

.agent-chat-history-more {
    padding: var(--space-2) 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-align: center;
}

/* Motion overrides live at the END of this file on purpose. These selectors
   match the specificity of the rules they are switching off, so the later one
   wins — placed with the other reduced-motion rule near the top they parsed
   fine, applied nothing, and would have read as done.

   The two highest-frequency animations in the product: a skeleton on almost
   every page load, a spinner on almost every save. Held still rather than
   hidden — they are the only thing on screen saying work is happening. */
@media (prefers-reduced-motion: reduce) {
    .btn-spinner { animation: none; }
    .skeleton-card { animation: none; }
}

/* ── Bare shell (404 / error page) ──────────────────────────────
   Centres a single card on an otherwise empty page. Used only by
   BareLayout, which exists so these two pages don't depend on the app
   shell — see that file for why. */
.bare-shell {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    background: var(--color-bg);
}

.bare-card {
    width: 100%;
    max-width: 520px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
}

    .bare-card .empty-state {
        /* The card is already the padding; the empty state's own generous
           vertical rhythm would push the buttons off a short phone screen. */
        padding-top: 0;
        padding-bottom: 0;
    }

.bare-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
    color: var(--color-text-primary);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
}

/* ── Nova: the thinking panel ───────────────────────────────────
   Only ever on screen during a REAL generation — 8-13 seconds of one
   Claude call over the whole report battery. A cached summary never
   mounts this (see the gate in Dashboard.razor), which is what lets the
   motion here be generous without costing anyone time.

   Everything is transform/opacity so it composites on the GPU: this runs
   for ten seconds on a dashboard that is also loading charts, and a
   layout-thrashing animation would show up as jank in exactly the moment
   it is meant to reassure. */
.nova-thinking {
    position: relative;
    padding: var(--space-4) 0 var(--space-2);
}

/* Indeterminate, deliberately. There is no progress to report — one
   opaque call, no server-side percentage — and a bar that crept to 90%
   and stopped would be a worse lie than no bar at all. */
.nova-rail {
    position: relative;
    height: 2px;
    border-radius: 2px;
    background: var(--color-border);
    overflow: hidden;
    margin-bottom: var(--space-4);
}

.nova-rail-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 38%;
    border-radius: inherit;
    background: linear-gradient(90deg,
        transparent,
        var(--color-primary),
        color-mix(in srgb, var(--color-primary) 35%, transparent));
    animation: nova-rail-travel 1.9s cubic-bezier(.55, 0, .45, 1) infinite;
}

@keyframes nova-rail-travel {
    0%   { transform: translateX(-110%); }
    100% { transform: translateX(365%); }
}

.nova-rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.nova-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--font-size-sm);
    /* Three states share one transition so a row settling from active to
       done reads as the same object changing, not a swap. */
    transition: color 260ms ease, opacity 260ms ease;
}

    .nova-row.is-todo   { color: var(--color-text-muted); opacity: .45; }
    .nova-row.is-done   { color: var(--color-text-muted); opacity: 1; }
    .nova-row.is-active { color: var(--color-text-primary); opacity: 1; }

.nova-row-marker {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 2px solid currentColor;
    color: var(--color-border);
    transition: color 260ms ease, border-color 260ms ease;
}

    .nova-row.is-done .nova-row-marker {
        color: var(--color-primary);
        border-color: transparent;
    }

    .nova-row.is-done .nova-row-marker svg {
        width: 16px;
        height: 16px;
        /* Drawn on, not popped in — the tick arriving is the one moment of
           actual progress this panel has to show. */
        stroke-dasharray: 16;
        animation: nova-tick 340ms cubic-bezier(.2, .7, .3, 1) both;
    }

    /* Only the row being worked on breathes. Animating all four would read
       as decoration; animating one reads as attention. */
    .nova-row.is-active .nova-row-marker {
        color: var(--color-primary);
        animation: nova-marker-pulse 1.6s ease-in-out infinite;
    }

@keyframes nova-tick {
    from { stroke-dashoffset: 16; }
    to   { stroke-dashoffset: 0; }
}

@keyframes nova-marker-pulse {
    0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 40%, transparent); }
    50%      { transform: scale(1.08); box-shadow: 0 0 0 5px color-mix(in srgb, var(--color-primary) 0%, transparent); }
}

.nova-row-text {
    animation: nova-stage-in 300ms ease-out;
}

@keyframes nova-stage-in {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: none; }
}

/* ── Nova: how the summary arrives ──────────────────────────────
   RenderMarkdown returns a MarkupString we cannot annotate, so the
   stagger reaches into it by position. Capped at the fourth child: a long
   monthly summary must not cascade for a full second before it is
   readable. */
.nova-summary-body > * {
    animation: nova-reveal 280ms cubic-bezier(.2, .7, .3, 1) both;
}

    .nova-summary-body > *:nth-child(1) { animation-delay: 0ms; }
    .nova-summary-body > *:nth-child(2) { animation-delay: 70ms; }
    .nova-summary-body > *:nth-child(3) { animation-delay: 140ms; }
    .nova-summary-body > *:nth-child(n+4) { animation-delay: 200ms; }

@keyframes nova-reveal {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    /* The panel still says what it is doing and the rows still change
       state — only the movement goes. Removing the words as well would
       take away the one thing telling anyone that work is happening. */
    .nova-rail-fill,
    .nova-row-text,
    .nova-summary-body > * { animation: none; }

    .nova-row.is-active .nova-row-marker { animation: none; }

    .nova-row.is-done .nova-row-marker svg {
        animation: none;
        stroke-dasharray: none;
    }

    /* The rail would otherwise be an empty grey line with no indication
       anything is in flight. */
    .nova-rail-fill { width: 100%; opacity: .35; }
}

/* The elapsed clock beside Nova's progress steps. Deliberately quiet — it is
   reassurance that the turn is alive, not information to read. It earns its
   place because the model can spend 50 seconds generating with the last step's
   label still on screen, and without a moving number that is indistinguishable
   from a hang. */
.nova-elapsed {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* A link inside a clickable table row. Reads as the item's name until you
   want it, then shows it is a way out — the row still navigates in place, so
   the underline on hover is the only thing telling you this one opens its own
   tab. Colour comes from the link token so it stays legible in a table that
   is otherwise all body text. */
.link-item {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
}

    .link-item:hover,
    .link-item:focus-visible {
        text-decoration: underline;
    }

/* ── Inline field validation ─────────────────────────────────
   A failed validation used to appear only in a banner at the top of the form,
   which on a long document is off screen: pressing Save looked like it did
   nothing. The message now sits against the field, and app.js scrolls it into
   view and focuses it. */

.field-error {
    margin-top: var(--space-1);
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    line-height: 1.35;
}

/* Applied by balanceBlitz.focusFieldError to the WRAPPER, so it works for a
   custom select or a combo just as well as a bare <input>. Removed on the next
   edit, so the highlight lasts as long as the problem and no longer. */
.field-invalid input,
.field-invalid select,
.field-invalid textarea,
.field-invalid .form-control,
.field-invalid .custom-select-trigger,
.field-invalid .searchable-select-trigger {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px var(--color-danger-light);
}

/* Respect a reduced-motion preference: the point is to LAND on the field, and
   a smooth scroll is a nicety rather than the feature. */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* ── Public quote page ─────────────────────────────────────────
   The one page in this app a stranger sees. Self-contained on
   purpose: it must not inherit anything from the signed-in shell,
   because the shell assumes a user and a tenant and this page has
   neither. Plain tokens only, so it renders correctly before any
   business theme is loaded. */
.public-quote-shell {
    min-height: 100vh;
    background: var(--color-bg-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-6) var(--space-4);
    box-sizing: border-box;
}

.public-quote-main {
    width: 100%;
    max-width: 780px;
    flex: 1;
}

.public-quote-card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-7);
    box-sizing: border-box;
}

.public-quote-header {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.public-quote-business {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

.public-quote-number {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.public-quote-contact {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.public-quote-for {
    margin: var(--space-5) 0;
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.public-quote-banner {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-5);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.public-quote-banner-good {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

.public-quote-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

    .public-quote-table th,
    .public-quote-table td {
        padding: var(--space-3);
        border-bottom: 1px solid var(--color-border);
        text-align: left;
    }

    .public-quote-table th {
        font-size: var(--font-size-xs);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--color-text-muted);
    }

    .public-quote-table .num {
        text-align: right;
        /* Aligns the decimal points down a money column, which is the whole
           reason anyone scans one. */
        font-variant-numeric: tabular-nums;
    }

.public-quote-discount-row td {
    color: var(--color-success);
    font-size: var(--font-size-xs);
    padding-top: 0;
}

.public-quote-totals {
    margin-top: var(--space-5);
    margin-left: auto;
    max-width: 320px;
    font-size: var(--font-size-sm);
}

    .public-quote-totals > div {
        display: flex;
        justify-content: space-between;
        gap: var(--space-4);
        padding: var(--space-2) 0;
        font-variant-numeric: tabular-nums;
    }

.public-quote-total {
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-2);
    padding-top: var(--space-3) !important;
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

.public-quote-terms {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    white-space: pre-wrap;
}

.public-quote-footer {
    margin-top: var(--space-6);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.public-quote-brand {
    margin-top: var(--space-6);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.public-quote-brand-name {
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
}

@media (max-width: 640px) {
    .public-quote-card {
        padding: var(--space-5);
    }

    .public-quote-totals {
        max-width: none;
    }
}

.public-quote-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

    /* The decision is the point of the page, so the buttons are reachable
       without hunting on a phone. Full width below the fold rather than two
       small targets side by side. */
    @media (max-width: 480px) {
        .public-quote-actions {
            flex-direction: column-reverse;
        }

            .public-quote-actions .btn {
                width: 100%;
            }
    }

.public-quote-respond {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
}

/* ── Supplier quick-add (SupplierQuickAdd.razor) ───────────────
   Create a supplier without abandoning the form you are filling in.

   A QUERY CONTAINER, not a media query, because this component is dropped
   into two very different slots: a modal on the Inventory page and a 170px
   column on the item detail page. The 170px one is too narrow for a name box
   beside two buttons at ANY viewport width, so keying off the phone would
   have fixed one and left the other. What matters is the room this has. */
.supplier-quick-add {
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-2);
    /* Breathing room below too, or the stacked buttons sit right on top of
       the next field's label and the two read as one group. */
    margin-bottom: var(--space-2);
}

.supplier-quick-add-row {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

/* min-width:0 so the flex item may actually shrink. Without it an input's
   default intrinsic width is the floor, which is what pushed this row wider
   than its container in the first place. */
.supplier-quick-add-name {
    flex: 1 1 auto;
    min-width: 0;
}

.supplier-quick-add-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Not enough room for a usable name box beside the buttons. Stacking gives
   the input the same full width as every other field in the form, which is
   what made the squeezed version look broken rather than merely tight. */
@container (max-width: 380px) {
    .supplier-quick-add-row {
        flex-direction: column;
        align-items: stretch;
    }

    .supplier-quick-add-actions > .btn {
        flex: 1 1 0;
    }
}

/* ── Stock action rows (InventoryItemDetail: adjust / receive) ──
   A row of controls on a desktop card, a stack of full-width fields on a
   phone.

   These were one flex-wrap row with the widths written inline for a desktop
   layout -- 110px for the quantity, 150px for the cost, 170px for each
   picker, and the note told to fill whatever was left. Inside a 318px card
   that wrapped into ragged pairs: six controls at six different widths, three
   different left edges, and two of them sitting 6-10px out of vertical
   alignment with the control beside them. Nothing overflowed, so nothing
   looked broken enough to catch; it just looked wrong.

   A query container again, because these sit on a card whose width has
   nothing to do with the viewport's. */
.stock-action-row {
    container-type: inline-size;
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
}

/* Controls that belong together on one line even when everything stacks:
   the +/- sign toggle and the quantity it applies to. */
.stock-action-pair {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

/* TWO THRESHOLDS, because the two rows are not the same size. Adjust stock
   is a sign toggle and a note and wants about 500px; receive stock carries a
   quantity, a cost toggle, a cost, a supplier, sometimes a warehouse, a note
   and a button, which come to roughly 840-1010px with their gaps. One shared
   breakpoint would either stack the short row when it fits perfectly well, or
   leave the long one ragged -- and the long one is ragged on a DESKTOP too:
   this card sits in a two-column page, so at a 1385px viewport the row still
   only gets 508px and wrapped into six widths across five lines. */
@container (max-width: 480px) {
    /* FLEX-BASIS, not width. The widths above are inline styles, which no
       class selector can outrank -- but a flex item takes its main size from
       flex-basis whenever that is not `auto`, so this wins without reaching
       for !important. */
    .stock-action-row > * {
        flex: 1 1 100%;
        max-width: 100%;
        min-width: 0;
    }

    /* The pair keeps its line; the box inside it takes what the buttons
       leave rather than sitting at 90px with a gap after it. */
    .stock-action-grow {
        flex: 1 1 auto;
        width: auto;
    }
}

/* The long row. In practice this card never reaches 1000px, so it reads as a
   plain vertical form -- which is exactly what the same fields already look
   like in the Inventory page's receive modal, so the two surfaces finally
   agree instead of one being a form and the other a wrapped row. */
@container (max-width: 1000px) {
    .stock-action-row--wide > * {
        flex: 1 1 100%;
        max-width: 100%;
        min-width: 0;
    }
}

/* ── "Used in": the recipes that consume an item ──────────────────────────
   One row per recipe, name on the left and what a build takes on the right.
   Stacks on a narrow card rather than squeezing, because the right-hand side
   is a quantity with a unit ("0.0004 kg per build") and wrapping it mid-phrase
   reads as two facts instead of one. A CONTAINER query, like the stock action
   rows above: this card sits in a two-column page, so the room it has is not
   the room the phone has. */
.used-in-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    container-type: inline-size;
}

.used-in-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: inherit;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.used-in-row:hover {
    /* The same hover fill the app's table rows use, so a list of links inside
       a card does not pick its own shade. */
    background: var(--color-bg);
    border-color: var(--color-primary);
}

.used-in-name {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    min-width: 0;
}

.used-in-qty {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

@container (max-width: 320px) {
    .used-in-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
}

/* ── Money in and out ──────────────────────────────────────────
   The guidance block and the chart swap order at phone width: the
   guidance is what somebody reads at a supplier's counter, so it goes
   first there. Done with flex order so there is only ever one copy of
   the markup to keep in step. The banner is first in both. */
.mio {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    /* CHART SERIES COLOURS, scoped here rather than added to tokens.css.
       That file holds UI colours with a documented contrast reason each;
       these are series colours for one chart and have a different job, so
       they live where they are used instead of growing the global palette
       with names nothing else can reuse.

       ONE HUE PER KIND OF MONEY. An earlier version ran three shades of green
       for the three incoming legs and leaned on position for the rest. A ramp
       of one hue says "the same thing, more or less of it", and these are not
       the same thing: a cheque in the drawer, an invoice a customer has not
       paid, and a nine-week average are three different kinds of money with
       three different chances of turning up. They are told apart by hue now,
       and direction is carried by the axis, which was already doing that job.

       Going out splits by how much CHOICE the owner has:

         red    a cheque already written, which will be presented
         amber  a bill falling due, which can be held back if it has to be

       That is not decoration. The banner's advice is literally "hold some
       bills back", and the amber bars are the part that sentence is about.

       Amber rather than orange for the bills, because tokens.css records that
       --color-warning reads too close to --color-danger in thin bars, which
       is exactly what these are. The grey for counter sales is the one
       deliberately weak colour on the chart: it is an average, not money. */
    --mio-cheque-in: #16a34a;   /* green-600,  = --color-success */
    --mio-invoice-in: #0891b2;  /* cyan-600,   owed to you, not yet yours */
    --mio-sales: #94a3b8;       /* slate-400,  an average, not a promise */
    --mio-cheque-out: #dc2626;  /* red-600,    = --color-danger, committed */
    --mio-bill-out: #d97706;    /* amber-600,  = --color-amber, still yours to hold */
    --mio-line: #1d4ed8;        /* blue-700,   = --color-info-text */
}

/* THE VERDICT, before any number. Somebody holding a cheque book wants
   yes / careful / no first, and reads the figures second. */
.mio-banner { order: 0; border-radius: var(--radius-lg); padding: var(--space-5) var(--space-6);
    border: 1px solid transparent; }
.mio-banner-title { font-size: var(--font-size-lg); font-weight: var(--font-weight-bold);
    line-height: 1.3; }
.mio-banner-sub { font-size: var(--font-size-sm); line-height: 1.55; margin-top: 3px; }
.mio-banner--ask { background: var(--color-primary-light); border-color: var(--color-border-strong); }
.mio-banner--ask .mio-banner-title { color: var(--color-primary); }
.mio-banner--ask .mio-banner-sub { color: var(--color-text-secondary); }
.mio-banner--ok { background: var(--color-success-light); border-color: #bbf7d0; }
.mio-banner--ok .mio-banner-title { color: var(--color-success-text); }
.mio-banner--ok .mio-banner-sub { color: var(--color-success-text); opacity: 0.85; }
.mio-banner--watch { background: var(--color-amber-light); border-color: #fde68a; }
.mio-banner--watch .mio-banner-title { color: var(--color-amber-text); }
.mio-banner--watch .mio-banner-sub { color: var(--color-amber-text); opacity: 0.85; }
.mio-banner--bad { background: var(--color-danger-light); border-color: #fecaca; }
.mio-banner--bad .mio-banner-title { color: var(--color-danger-text); }
.mio-banner--bad .mio-banner-sub { color: var(--color-danger-text); opacity: 0.85; }

.mio-controls { order: 1; display: flex; flex-wrap: wrap; align-items: flex-start;
    justify-content: space-between; gap: var(--space-4); }
.mio-chart-wrap { order: 2; }
.mio-guidance { order: 3; }

.mio-balance { display: flex; flex-direction: column; gap: var(--space-2); max-width: 430px; }
.mio-balance label { font-size: var(--font-size-sm); color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold); }
.mio-balance-row { display: flex; align-items: center; gap: var(--space-2); }
.mio-cur { color: var(--color-text-secondary); font-weight: var(--font-weight-medium); }
/* 16px floor: anything smaller makes iOS zoom the page on focus, and this
   field is tapped with the keyboard up. Same rule as the POS inputs. */
.mio-balance-row .form-control { width: 190px; font-size: var(--font-size-md); }
.mio-hint { font-size: var(--font-size-xs); color: var(--color-text-muted); line-height: 1.5; }
.mio-asat { font-size: var(--font-size-xs); color: var(--color-text-secondary); line-height: 1.5; }
.mio-toggle { display: flex; gap: 4px; }

.mio-guidance { background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); padding: 0 var(--space-6) var(--space-5);
    border-top: 3px solid var(--color-border); }
/* The card carries the verdict as well as the banner, because on a phone the
   two are a scroll apart and this is the half with the numbers on it. */
.mio-guidance--ok { border-top-color: var(--color-success); }
.mio-guidance--watch { border-top-color: var(--color-amber); }
.mio-guidance--bad { border-top-color: var(--color-danger); }
.mio-guidance-title { font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary); padding: var(--space-5) 0 var(--space-4); }
.mio-guidance-empty, .mio-note { font-size: var(--font-size-sm);
    color: var(--color-text-secondary); line-height: 1.6; }
.mio-note { margin-top: var(--space-4); padding-top: var(--space-3);
    border-top: 1px solid var(--color-border); font-size: var(--font-size-xs); }

.mio-row { display: flex; justify-content: space-between; align-items: flex-start;
    gap: var(--space-5); padding: var(--space-4) 0;
    border-bottom: 1px solid var(--color-border); }
.mio-row:last-of-type { border-bottom: none; }
.mio-row-label { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mio-row-name { display: flex; align-items: center; gap: 8px;
    font-size: var(--font-size-sm); font-weight: var(--font-weight-medium);
    color: var(--color-text-primary); }
/* THE DEFINITION, not decoration. "Tightest it gets" is not a phrase anybody
   has met outside this screen, and three rows that all answer in money were
   being read as three versions of one number. */
.mio-row-why { font-size: var(--font-size-xs); color: var(--color-text-muted);
    line-height: 1.5; max-width: 58ch; }
.mio-row-value { display: flex; flex-direction: column; align-items: flex-end;
    gap: 2px; flex: 0 0 auto; }
/* The amount left on the tightest day is an ANSWER, not a caption. At
   --font-size-xs in muted grey, next to a bold date, it was the figure people
   actually needed and the one they could not read. Sized and coloured to sit
   just under .mio-big rather than down with the labels. */
.mio-row-when { font-size: var(--font-size-sm); color: var(--color-text-secondary);
    font-weight: var(--font-weight-medium); white-space: nowrap; }
.mio-row strong { white-space: nowrap; color: var(--color-text-primary); text-align: right; }
/* The answers are the point of the panel, so they are sized like answers. */
.mio-big { font-size: var(--font-size-xl); font-weight: var(--font-weight-bold);
    letter-spacing: -0.3px; }

/* VERDICT PER ROW, not per panel. The usual case is a panel that says yes to
   one thing and no to another: there is money to spend today and no date you
   can safely put on a cheque. One tint over the lot would flatten that. */
.mio-pip { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
    background: var(--color-text-muted); }
.mio-row--ok .mio-pip { background: var(--color-success); }
.mio-row--ok .mio-big { color: var(--color-success-text); }
.mio-row--warn .mio-pip { background: var(--color-amber); }
.mio-row--warn .mio-big { color: var(--color-amber-text); }
.mio-row--bad .mio-pip { background: var(--color-danger); }
.mio-row--bad .mio-big { color: var(--color-danger-text); }
.mio-bad { color: var(--color-danger); }
.mio-good { color: var(--color-success-text); }

.mio-legend { display: flex; flex-wrap: wrap; align-items: baseline;
    gap: var(--space-2) var(--space-5);
    font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.mio-legend + .mio-legend { margin-top: var(--space-2); }
.mio-legend:last-of-type { margin-bottom: var(--space-4); }
.mio-legend span { display: flex; align-items: center; gap: 6px; }
.mio-legend-head { font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary); min-width: 74px; }
.mio-dot { width: 11px; height: 11px; border-radius: 2px; display: inline-block;
    flex: 0 0 auto; }
.mio-dot-cheque-in { background: var(--mio-cheque-in); }
.mio-dot-invoice { background: var(--mio-invoice-in); }
.mio-dot-sales { background: var(--mio-sales); }
.mio-dot-cheque-out { background: var(--mio-cheque-out); }
.mio-dot-bill { background: var(--mio-bill-out); }
.mio-rule { width: 18px; height: 0; display: inline-block; flex: 0 0 auto; }
.mio-rule-sure { border-top: 3px solid var(--mio-line); }
.mio-rule-hope { border-top: 3px dashed var(--mio-invoice-in); }

/* Horizontal scroll rather than squeezing: 14 columns at phone width would
   be unreadable slivers, and a fortnight is the point of the view. */
.mio-scroll { overflow-x: auto; padding-bottom: var(--space-2); }
.mio-svg { display: block; max-width: none; }
.mio-grid { stroke: var(--color-border); stroke-width: 1; }
.mio-grid-zero { stroke: var(--color-text-muted); stroke-width: 1.5; }
.mio-ytick { font-size: 11px; fill: var(--color-text-muted); text-anchor: end; }
.mio-xtick { font-size: 11px; fill: var(--color-text-muted); text-anchor: middle; }
.mio-xtick-on { fill: var(--color-text-primary); font-weight: var(--font-weight-semibold); }
.mio-line-sure { fill: none; stroke: var(--mio-line); stroke-width: 2.5;
    stroke-linejoin: round; stroke-linecap: round; }
/* Dashed because it is a forecast. A solid second line would read as another
   fact rather than the thing you are hoping for. */
.mio-line-hope { fill: none; stroke: var(--mio-invoice-in); stroke-width: 2;
    stroke-dasharray: 5 4; stroke-linejoin: round; opacity: 0.8; }
.mio-dot-sure { fill: var(--mio-line); }
.mio-dot-under { fill: var(--color-danger); }
/* The whole column is the tap target, not the bar: a 22px bar is a miss
   waiting to happen on a phone. */
.mio-hit { fill: var(--color-text-primary); opacity: 0; cursor: pointer; }
.mio-hit:hover { opacity: 0.04; }
.mio-hit-on { opacity: 0.06; }
.mio-nobal { margin-top: var(--space-2); font-size: var(--font-size-xs);
    color: var(--color-text-muted); }

.mio-readout { margin-top: var(--space-4); padding: var(--space-4) var(--space-5);
    background: var(--color-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); min-height: 54px; }
.mio-readout-hint { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.mio-readout-head { font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm); margin-bottom: var(--space-2); }
.mio-readout-grid { display: grid; grid-template-columns: 1fr auto;
    gap: 5px var(--space-5); font-size: var(--font-size-sm); }
.mio-readout-grid span { display: flex; align-items: center; gap: 7px;
    color: var(--color-text-secondary); }
.mio-readout-grid strong { text-align: right; white-space: nowrap; }
.mio-readout-left { font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary) !important; padding-top: var(--space-2);
    border-top: 1px solid var(--color-border); }
.mio-readout-grid .mio-readout-left + strong { padding-top: var(--space-2);
    border-top: 1px solid var(--color-border); }
.mio-empty { padding: var(--space-6); text-align: center;
    color: var(--color-text-muted); font-size: var(--font-size-sm); }

@media (max-width: 768px) {
    .mio-banner { order: 0; padding: var(--space-4) var(--space-5); }
    .mio-banner-title { font-size: var(--font-size-md); }
    .mio-guidance { order: 1; padding: var(--space-5); }
    .mio-controls { order: 2; }
    .mio-chart-wrap { order: 3; }
    .mio-balance { flex: 1 1 100%; max-width: none; }
    .mio-balance-row .form-control { flex: 1; width: auto; }
    .mio-toggle { flex: 1 1 100%; }
    .mio-toggle .btn { flex: 1; }
    /* The value drops under its own label rather than being squeezed into a
       column beside a wrapping explanation. */
    .mio-row { flex-direction: column; align-items: stretch; gap: var(--space-2);
        padding: var(--space-4) 0; }
    .mio-row-value { flex-direction: row; align-items: baseline;
        justify-content: space-between; width: 100%; }
    .mio-row-why { max-width: none; }
    .mio-big { font-size: var(--font-size-lg); }
    /* The chat launcher is fixed over the bottom-right corner, and the tap
       readout is the last block on the page with its amounts right-aligned
       into exactly that spot, so tapping a date put the figures under the
       button. Room to scroll the readout clear of it: 56px of button, its
       12px offset, and some air. */
    .mio { padding-bottom: 76px; }
}

/* ── Credit note page ─────────────────────────────────────── */
.credit-note-card-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}
.credit-note-against {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-4);
}
.credit-note-lines { display: flex; flex-direction: column; }
.credit-note-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-border);
}
.credit-note-line.is-child { padding-left: var(--space-6); }
.credit-note-line.is-done { opacity: 0.6; }
.credit-note-line-pick {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    min-width: 0;
    flex: 1 1 240px;
    cursor: pointer;
}
.credit-note-line-pick input { margin-top: 3px; flex-shrink: 0; }
.credit-note-line-pick > span { display: flex; flex-direction: column; min-width: 0; }
.credit-note-line-desc {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}
.credit-note-line-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}
.credit-note-qty { width: 80px; }
.credit-note-toggle {
    display: flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.credit-note-adjustment {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto auto;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.credit-note-tax {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}
.credit-note-tax .form-control { width: 64px; }
.credit-note-outcome {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
}
.credit-note-send {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.customer-credits-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin: calc(-1 * var(--space-3)) 0 var(--space-5);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    text-decoration: none;
}
.credit-note-picker {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.credit-note-picker-list { max-height: 50vh; overflow-y: auto; }
.credit-note-outcome-title {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}
/* On a phone: description and its remove button on one row, amount and
   tax on the next. Left to auto-flow, the button ended up alone on a row. */
@media (max-width: 640px) {
    .credit-note-adjustment { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
    .credit-note-adjustment > :nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
    .credit-note-adjustment > :nth-child(4) { grid-column: 3; grid-row: 1; }
    .credit-note-adjustment > :nth-child(2) { grid-column: 1; grid-row: 2; }
    .credit-note-adjustment > :nth-child(3) { grid-column: 2 / 4; grid-row: 2; }
}

/* ── Invoices | Credit notes ─────────────────────────────── */
.doc-switch {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: var(--space-4);
}
.doc-switch a {
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    text-decoration: none;
}
.doc-switch a + a { border-left: 1px solid var(--color-border); }
.doc-switch a.active {
    background: var(--color-primary);
    color: var(--color-white);
}
