/* ==========================================================================
   InvoGrid — base stylesheet

   The visual language is deliberately Kitwell's: same CSS-variable theming,
   same [data-theme] switch on <html>, same header lockup, same component
   vocabulary. The two are sibling internal tools and should read as a family.
   This is InvoGrid's own copy of it, not a shared file — nothing here is
   loaded from, or has to stay byte-identical to, the other application.

   Where it differs, and why:
     - The accent is indigo rather than blue, so the two tools are told apart
       at a glance without leaving the family.
     - The header carries a search box and an Upload button, and from 1150px,
       the same breakpoint as Kitwell's, the menu is a row of its own under
       them.
     - There is a document/data split-pane vocabulary Kitwell has no need for.
   ========================================================================== */

:root {
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --radius: 10px;
    --radius-sm: 7px;
    --tap: 44px;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;

    --shadow: 0 1px 2px rgb(15 23 42 / 8%), 0 2px 8px rgb(15 23 42 / 6%);
}

/* --- Light theme (default) ------------------------------------------------ */
[data-theme="light"] {
    --bg: #f1f5f9;
    --bg-raised: #ffffff;
    --bg-sunken: #e2e8f0;
    --bg-hover: #f8fafc;
    --text: #0f172a;
    --text-muted: #52627a;
    --border: #cbd5e1;
    --border-strong: #94a3b8;

    --accent: #4338ca;
    --accent-text: #ffffff;
    --accent-hover: #3730a3;
    --accent-soft: #e0e7ff;

    --ok: #15803d;
    --ok-soft: #dcfce7;
    /* Amber-800 rather than amber-700: on the soft amber background the lighter
       shade measures 4.42:1, just under the 4.5:1 needed for normal text. */
    --warn: #854d0e;
    --warn-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;

    --focus: #4338ca;

    /* What a modal lays over the page behind it. A token rather than a fixed
       colour because a scrim is one of the few things that cannot be the same
       in both themes: its whole job is to sit *darker* than the page, and
       slate-900 over a dark page does not. */
    --scrim: rgb(15 23 42 / 55%);

    color-scheme: light;
}

/* --- Dark theme ----------------------------------------------------------- */
[data-theme="dark"] {
    --bg: #0b1120;
    --bg-raised: #172033;
    --bg-sunken: #0f172a;
    --bg-hover: #1e293b;
    --text: #f1f5f9;
    --text-muted: #a3b1c6;
    --border: #33415c;
    --border-strong: #64748b;

    --accent: #a5b4fc;
    --accent-text: #10132e;
    --accent-hover: #c7d2fe;
    --accent-soft: #312e81;

    --ok: #4ade80;
    --ok-soft: #14532d;
    --warn: #fbbf24;
    --warn-soft: #52350a;
    --danger: #f87171;
    --danger-soft: #601616;
    /* Sky-300 rather than sky-400: on the deep soft-blue background the darker
       shade measures 4.42:1, just under 4.5:1 for normal text. */
    --info: #7dd3fc;
    --info-soft: #0c4a6e;

    --focus: #c7d2fe;

    /* Nearly black, and more of it. The light theme's slate-900 is *lighter*
       than this theme's own page background, so reused here it would dim
       nothing and wash the page slightly blue instead. */
    --scrim: rgb(2 6 16 / 70%);

    color-scheme: dark;
}

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* The browser's own `[hidden] { display: none }` lives in the user-agent
   stylesheet, so any author rule setting `display` beats it — and `.btn` sets
   `display: inline-flex`. This is the one place `!important` is the right tool:
   `hidden` means hidden, and no component should have to opt in. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 17px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 var(--space-3); }

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

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 100;
    background: var(--accent); color: var(--accent-text);
    padding: var(--space-3) var(--space-4); border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

.container {
    width: 100%;
    max-width: 1200px;
    margin-inline: auto;
    padding-inline: var(--space-4);
}

/* The document-facing screens — the three queues, the document list and record,
   the dashboard — opt into this.
   1200px is a measure for reading prose, and none of those screens is prose:
   they are a scan beside a form, or a table of six columns that has to stay
   readable without wrapping every cell onto three lines. 1760px is about as
   wide as a line of table text stays scannable, and it leaves a margin on a
   1920 monitor rather than running edge to edge. Forms inside keep their own
   `max-width`, so nothing here stretches a column of text boxes. */
.container-wide { max-width: 1760px; }

.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-size: 0.86em; }
.nowrap { white-space: nowrap; }
.break { word-break: break-word; }

/* A multi-line value shown as written — request headers, a JSON body — scrolling
   rather than stretching the row when it is long. */
.pre-wrap { display: block; white-space: pre-wrap; max-height: 24rem; overflow: auto; }
.text-danger { color: var(--danger); }

/* --- Header and navigation ------------------------------------------------ */
.site-header {
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: var(--space-3);
    min-height: 60px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

/* On a phone the search box has a row of its own under the brand: squeezed
   between the logo and the buttons there is not room to read what was typed. */
.header-search {
    order: 3;
    flex: 1 0 100%;
    margin: 0;
    padding-bottom: var(--space-2);
}
.header-search .input { min-height: 40px; }

.header-upload { white-space: nowrap; }

@media (min-width: 640px) {
    .header-search {
        order: 0;
        flex: 1 1 12rem;
        max-width: 26rem;
        margin-left: var(--space-3);
        padding-bottom: 0;
    }
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    color: var(--text);
    padding-block: var(--space-2);
}

/* The logo is the link home; the wordmark next to it is not. */
.brand-home {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
}
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The IG monogram, shown until a logo is uploaded. */
.brand-mark {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.brand-name { font-size: 1.02rem; }

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap); height: var(--tap);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
}

.nav-toggle-bars { display: grid; gap: 4px; }
.nav-toggle-bars span {
    display: block; width: 20px; height: 2px;
    background: currentColor; border-radius: 2px;
}

.primary-nav {
    display: none;
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: var(--space-3) var(--space-4) var(--space-4);

    /* The open menu hangs off a sticky header, so it does not scroll away with
       the page. Without a height of its own, anything past the bottom of the
       screen is unreachable. --header-h is measured and written by app.js when
       the menu opens; 60px is the header's min-height and the fallback. dvh so
       a phone's collapsing address bar does not hide the last item. */
    max-height: calc(100vh - var(--header-h, 60px));
    max-height: calc(100dvh - var(--header-h, 60px));
    overflow-y: auto;

    /* Scrolling to the end of the menu must not then scroll the page behind. */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.primary-nav.is-open { display: block; }

.nav-list {
    list-style: none;
    margin: 0 0 var(--space-3);
    padding: 0;
    display: grid;
    gap: var(--space-1);
}

.nav-link {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

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

.nav-link.is-active {
    background: var(--accent-soft);
    color: var(--text);
    box-shadow: inset 3px 0 0 var(--accent);
}

.nav-count { margin-left: var(--space-2); }

/* --- User menu ------------------------------------------------------------ */
/* A <details> too, so signing out never depends on script. */
.user-menu { position: relative; }
.user-menu-toggle {
    display: grid;
    place-items: center;
    width: var(--tap); height: var(--tap);
    border-radius: 50%;
    cursor: pointer;
    list-style: none;
}
.user-menu-toggle::-webkit-details-marker { display: none; }
.user-menu[open] > .user-menu-toggle .avatar { box-shadow: 0 0 0 2px var(--accent); }

.user-menu-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 60;
    width: 16rem;
    max-width: calc(100vw - 2 * var(--space-4));
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
    box-shadow: var(--shadow);
}
.user-menu-panel form { margin: 0; }

.user-menu-who {
    display: grid;
    line-height: 1.3;
    margin: 0 0 var(--space-2);
    padding: var(--space-2) var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}
.user-menu-name { font-weight: 600; }
.user-menu-role { font-size: 0.82rem; color: var(--text-muted); }

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    min-height: var(--tap);
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.menu-item:hover { background: var(--bg-hover); color: var(--text); }

.avatar {
    display: grid; place-items: center;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--bg-sunken);
    color: var(--text);
    font-weight: 700;
    flex: 0 0 auto;
}

/* --- Navigation groups ---------------------------------------------------- */
/* A <details> element: an accordion in the drawer, a drop-down on the bar. One
   structure, and it works with JavaScript switched off. */
.nav-group summary { list-style: none; cursor: pointer; }
.nav-group summary::-webkit-details-marker { display: none; }

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 100%;
}

/* The disclosure triangle, wherever a <details> is used as one, so the shape
   means the same thing everywhere. */
.caret {
    width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid currentColor;
    flex: 0 0 auto;
    transition: transform 120ms ease;
}
details[open] > summary .caret { transform: rotate(180deg); }

.nav-sublist {
    list-style: none;
    margin: var(--space-1) 0 var(--space-2);
    padding: 0 0 0 var(--space-4);
    display: grid;
    gap: 2px;
    border-left: 2px solid var(--border);
}
.nav-sublink { font-weight: 500; }

/* Desktop navigation ------------------------------------------------------- */
/* From 1150px the menu is a second row of the header, under the brand, search
   and account controls: eleven destinations do not share one row with those at
   any common width. Below the breakpoint it is a drawer, which cannot wrap and
   is the same control phones use. */
@media (min-width: 1150px) {
    .nav-toggle { display: none; }

    /* Block padding is a mobile tap-target concern; on a desktop the row's own
       min-height does that job. */
    .brand { padding-block: 0; }

    .primary-nav {
        display: block;
        position: static;
        order: 4;
        flex: 1 0 100%;
        background: none;
        border: 0;
        border-top: 1px solid var(--border);
        box-shadow: none;
        padding: 0;

        /* The drawer's own scroll, undone: here the nav is part of the header,
           so a max-height would clip the drop-downs. */
        max-height: none;
        overflow: visible;
    }

    .nav-list {
        display: flex;
        flex-wrap: wrap;
        align-items: stretch;
        gap: var(--space-1);
        margin: 0;
    }

    .nav-item { flex: 0 0 auto; }

    .site-header .btn,
    .brand-name { white-space: nowrap; }

    .nav-link { min-height: 42px; padding-inline: var(--space-3); white-space: nowrap; }

    /* The underline sits at the foot of the bar rather than under the text, so
       it reads as an underline for the whole row instead of a strike through
       the descenders. */
    .nav-link.is-active {
        box-shadow: inset 0 -3px 0 var(--accent);
        background: transparent;
    }

    .nav-item-group { position: relative; }

    /* The panel floats over the page rather than pushing the bar taller. */
    .nav-group > .nav-sublist {
        position: absolute;
        top: calc(100% + 4px);
        left: 0;
        z-index: 50;
        min-width: 15rem;
        margin: 0;
        padding: var(--space-2);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--bg-raised);
        box-shadow: var(--shadow);
    }

    /* The last group sits at the right-hand end of the row, where a panel
       opening rightwards would leave the screen. */
    .nav-item-group:last-child > .nav-group > .nav-sublist { left: auto; right: 0; }

    .nav-group-toggle { width: auto; }

    /* A group is rendered `open` when the current page is inside it, so the
       menu shows where you are. On a phone that expands an accordion, which is
       the point. Here the panel floats, so an auto-opened one would land on top
       of the page just navigated to. :focus-within rather than a class, so this
       still works with JavaScript off. */
    .nav-group[data-nav-autoopen]:not(:focus-within) > .nav-sublist { display: none; }
}

/* --- Main ----------------------------------------------------------------- */
main.container { padding-block: var(--space-5) var(--space-6); }

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}
.page-head h1 { margin-bottom: var(--space-1); }
.page-head p { margin: 0; }

.section-title {
    margin: var(--space-6) 0 var(--space-3);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* --- Cards ---------------------------------------------------------------- */
.card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow);
}

.card-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

/* A card that is itself the link — the synced-data index, one per record
   type. `.card` alone is not a link target's shape: block-level, no
   underline, and a hover state to say it is clickable at all. */
.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease;
}
.card-link:hover, .card-link:focus-visible {
    border-color: var(--accent);
}
.card-link h3 { margin-top: 0; }

.notice-card { border-left: 4px solid var(--accent); }

/* Status cards: a coloured edge rather than a coloured panel, so the text
   inside keeps the page's normal contrast. */
.card-ok     { border-left: 4px solid var(--ok); }
.card-warn   { border-left: 4px solid var(--warn); }
.card-danger { border-left: 4px solid var(--danger); }

.plain-list { margin: 0; padding-left: var(--space-4); }
.plain-list li + li { margin-top: var(--space-1); }

/* --- Sub-navigation ------------------------------------------------------- */
.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.subnav-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: var(--space-2) var(--space-3);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.subnav-link:hover { color: var(--text); }
.subnav-link.is-active { color: var(--text); border-bottom-color: var(--accent); }

/* --- Stats ----------------------------------------------------------------
   Compact by intent. These are a glanceable summary above the day's work, not
   the point of the page.

   auto-fit rather than auto-fill: a row with fewer cards than it has room for
   should stretch across the width rather than leave a gap at the right. */
.stat-grid {
    display: grid;
    gap: var(--space-2);
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    margin-bottom: var(--space-4);
}

.stat-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border-strong);
    border-radius: var(--radius);
    padding: var(--space-3);
    display: grid;
    gap: 2px;
    align-content: start;
}

.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 0.85rem; line-height: 1.35; color: var(--text-muted); }

.stat-card.stat-danger { border-left-color: var(--danger); }
.stat-card.stat-danger .stat-value { color: var(--danger); }
.stat-card.stat-warn { border-left-color: var(--warn); }
.stat-card.stat-warn .stat-value { color: var(--warn); }
.stat-card.stat-info { border-left-color: var(--info); }
.stat-card.stat-ok { border-left-color: var(--ok); }

/* --- Tables --------------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.96rem;
}

.table th, .table td {
    padding: var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table thead th {
    background: var(--bg-sunken);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    position: sticky;
    top: 0;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-hover); }
.table-compact th, .table-compact td { padding: var(--space-2) var(--space-3); }

/* Room to breathe, once there is room to give.
   The tight padding above is a phone measurement: on a 1920 monitor the same
   table reads as a wall, and the rows a reviewer is scanning for run together.
   Nothing changes below 1150px — the same breakpoint the navigation bar uses,
   so a screen has either the desktop treatment throughout or none of it. */
@media (min-width: 1150px) {
    .table { font-size: 1rem; }
    .table th, .table td { padding: var(--space-3) var(--space-4); }
    .table-compact th, .table-compact td { padding: var(--space-2) var(--space-3); }

    /* A queue is read down its rows rather than across them, so the row
       separators earn a little more space than the columns do. */
    .table tbody th, .table tbody td { line-height: 1.45; }
}

/*
 * Column widths, stated rather than left to the browser.
 *
 * `table-layout: auto` gives the widest column whatever is left, which on the
 * queues means the "what is outstanding" sentence takes two thirds of the page
 * and the supplier — the thing being scanned for — is squeezed into three
 * wrapped lines. These say what each column is *for* instead, and are applied
 * per screen rather than globally, because a width that suits a queue is wrong
 * for the pipeline log.
 *
 * They are `min-width` on the cell rather than `width` on a <col>: a table in
 * `.table-wrap` can scroll sideways, so a minimum is honoured and a percentage
 * is negotiated away.
 */
.col-tight   { width: 1%; white-space: nowrap; }
.col-narrow  { min-width: 7rem; }
.col-date    { min-width: 8rem; white-space: nowrap; }
.col-name    { min-width: 16rem; }
.col-wide    { min-width: 22rem; }

/* The one exception to "no fixed widths": a description column is the reason
   the table is wide at all, and it should take what is left over. */
.col-grow { width: 100%; }

/* Money reads as a column of figures, so it lines up on the right and uses
   tabular digits — a column of amounts whose decimal points wander is a column
   nobody can add up by eye. */
.table .amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.row-muted td { opacity: 0.62; }
.cell-sub { font-size: 0.85rem; color: var(--text-muted); }
.empty { text-align: center; color: var(--text-muted); padding: var(--space-6) !important; }

/* The actions column: one or more buttons in the last cell of a row.
 *
 * The cell stays a table-cell. Anything that takes it out of table layout —
 * `display: flex` in particular — stops it stretching to the row height, and
 * since the row separator is a border-bottom on the cell, its line is then
 * drawn short of the others. Inline layout means `gap` does not apply, hence
 * the margin.
 */
td.actions { white-space: nowrap; vertical-align: middle; }
td.actions > * { vertical-align: middle; }
td.actions > * + * { margin-left: var(--space-1); }

.inline-form { display: inline; margin: 0; }

/* --- Stage indicator (Prompt 46) -------------------------------------------
   The same six-phase track on the document page and all three review queues,
   so "where is this" reads the same way everywhere. A line of dots joined by
   a rule; done phases and the connector before them turn ok-green, the
   current phase is coloured by what it means (accent while it is still
   in-flight, warn when it wants a person, ok once it is settled) and carries
   the actual status word rather than the phase's generic one, upcoming
   phases stay flat. Ignored/deleted/failed do not try to guess a position on
   the happy path — the whole track stays flat and the specific state is a
   badge beside it instead. */
.stage-track {
    display: flex;
    margin-bottom: var(--space-1);
}

.stage-step {
    flex: 1 1 0;
    position: relative;
    text-align: center;
    padding-top: 15px;
}

.stage-step:not(:first-child)::before {
    content: '';
    position: absolute;
    top: 6px;
    right: 50%;
    width: 100%;
    height: 2px;
    background: var(--border);
}

.stage-step.is-done:not(:first-child)::before { background: var(--ok); }

.stage-dot {
    display: block;
    position: absolute;
    top: 0;
    left: calc(50% - 6px);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-raised);
    border: 2px solid var(--border);
}

.stage-step.is-done .stage-dot { background: var(--ok); border-color: var(--ok); }

.stage-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.stage-step.is-current .stage-dot { border-width: 3px; left: calc(50% - 7px); width: 14px; height: 14px; }
.stage-step.is-current .stage-label { color: var(--text); font-weight: 700; }

.stage-step.is-current.stage-tone-accent .stage-dot { border-color: var(--accent); background: var(--accent-soft); }
.stage-step.is-current.stage-tone-warn .stage-dot { border-color: var(--warn); background: var(--warn-soft); }
.stage-step.is-current.stage-tone-ok .stage-dot { border-color: var(--ok); background: var(--ok-soft); }
.stage-step.is-current.stage-tone-danger .stage-dot { border-color: var(--danger); background: var(--danger-soft); }

.stage-terminal-badge { margin-top: var(--space-2); display: inline-block; }

@media (min-width: 640px) {
    .stage-label { font-size: 0.78rem; }
}

/* --- Badges and chips ----------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--bg-sunken);
    color: var(--text);
    white-space: nowrap;
}

.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); }
.badge-muted { background: var(--bg-sunken); color: var(--text-muted); }

/* A numbered explanation — "what happens next" on the upload page. Ordinary
   list numbering, given room to breathe: the point is that it is read once,
   understood, and never looked at again. */
.steps {
    margin: 0 0 var(--space-3);
    padding-left: var(--space-5);
    display: grid;
    gap: var(--space-2);
    font-size: 0.92rem;
}

.steps li { padding-left: var(--space-1); }

.meta-list {

    list-style: none;
    margin: 0 0 var(--space-3);
    padding: 0;
    display: grid;
    gap: var(--space-1);
    font-size: 0.92rem;
}

/* --- Buttons -------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--tap);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-raised);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover { background: var(--bg-hover); color: var(--text); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }

.btn-warning { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.btn-danger  { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }

.btn-sm { min-height: 38px; padding: var(--space-1) var(--space-3); font-size: 0.9rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding-inline: var(--space-5); }
.btn-block { width: 100%; }
.btn-icon .btn-label { display: none; }

/* In the drawer there is room for the label; on the bar there is not. */
@media (max-width: 1149px) {
    .btn-icon .btn-label { display: inline; }
}

/* --- Forms ---------------------------------------------------------------- */
.form { max-width: 720px; }
.form.card { max-width: 720px; }

/* A form that is a whole pane rather than a column of boxes on a page, so it
   is not capped at the width of one. */
.form-full { max-width: none; }

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

.field-row {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}
@media (min-width: 640px) {
    .field-row { grid-template-columns: 1fr 1fr; }
}

.label { display: block; font-weight: 600; margin-bottom: var(--space-1); }

.input {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: var(--space-2) var(--space-3);
    font: inherit;
    font-size: 1rem;                 /* >=16px stops iOS zooming on focus */
    color: var(--text);
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.input:focus { border-color: var(--accent); }
.input.has-error { border-color: var(--danger); background: var(--danger-soft); }

select.input { appearance: auto; }
textarea.input { min-height: 120px; resize: vertical; }

.field-hint { margin: var(--space-1) 0 0; font-size: 0.86rem; color: var(--text-muted); }
.field-error { margin: var(--space-1) 0 0; font-size: 0.88rem; font-weight: 600; color: var(--danger); }

.input-with-button { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: stretch; }
.input-with-button .input { flex: 1 1 12rem; min-width: 0; }

/* A short answer — a number of minutes, a code — should not get a box the
   width of the card. The pair still wraps on a narrow screen. */
.input-with-button.compact { max-width: 24rem; }
.btn-inline { white-space: nowrap; border: 1px solid var(--border); }

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    min-height: var(--tap);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.checkbox:hover { background: var(--bg-hover); }
.checkbox input[type="checkbox"] {
    width: 22px; height: 22px;
    margin-top: 2px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-4);
    margin: 0 0 var(--space-4);
}
.fieldset legend { padding-inline: var(--space-2); font-weight: 700; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

/* A form inside .form-actions is a wrapper around one button (each POST needs
   its own form and CSRF token), so it must not add layout of its own. */
.form-actions > form { margin: 0; }

/*
 * Filter bars come in two shapes: unlabelled boxes and ones with visible labels
 * above each control. Both have to put every control on the same bottom edge,
 * which is why this aligns to flex-end rather than centring — centring lines up
 * the middles of columns of different heights, so a submit button with no label
 * above it floats above the boxes beside it.
 */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: flex-end;
    margin-bottom: var(--space-4);
}
.filter-bar .field { margin-bottom: 0; flex: 1 1 180px; }
.filter-bar .btn { flex: 0 0 auto; }

/* Six filters rather than two, so the free-text box gets its own line on a
   narrow screen and the hints under the boxes do not shove the row apart. */
.filter-bar .field-wide { flex: 1 1 100%; }
.filter-bar .field-hint { margin-bottom: 0; }
.filter-bar .filter-actions {
    display: flex;
    gap: var(--space-2);
    flex: 0 0 auto;
    align-self: flex-start;
    padding-top: 1.9rem; /* clears the label row beside it */
}

/* --- Flash messages ------------------------------------------------------- */
.flash-stack { display: grid; gap: var(--space-2); margin-bottom: var(--space-4); }

.flash {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--border-strong);
    background: var(--bg-raised);
    font-weight: 500;
    transition: opacity 220ms ease, transform 220ms ease;
}

.flash.is-leaving { opacity: 0; transform: translateY(-4px); }

.flash-success { background: var(--ok-soft); border-left-color: var(--ok); color: var(--ok); }
.flash-error   { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger); }
.flash-warning { background: var(--warn-soft); border-left-color: var(--warn); color: var(--warn); }
.flash-info    { background: var(--info-soft); border-left-color: var(--info); color: var(--info); }

.flash-close {
    background: none; border: 0; cursor: pointer;
    font-size: 1.4rem; line-height: 1; color: inherit; opacity: 0.7;
    min-width: 32px; min-height: 32px;
}
.flash-close:hover { opacity: 1; }

/* --- Auth screens --------------------------------------------------------- */
.body-centred {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    background: var(--bg);
    padding: var(--space-4);
}

.auth-shell { width: 100%; max-width: 430px; display: grid; gap: var(--space-4); justify-items: center; }

.auth-card {
    width: 100%;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex; align-items: center; gap: var(--space-2);
    margin-bottom: var(--space-5);
    font-weight: 700; font-size: 1.1rem;
}

.auth-title { margin-bottom: var(--space-1); }
.auth-subtitle { color: var(--text-muted); margin-bottom: var(--space-5); font-size: 0.95rem; }
.auth-help { margin: var(--space-4) 0 0; font-size: 0.88rem; text-align: center; }

.theme-toggle-standalone { border: 1px solid var(--border); background: var(--bg-raised); }

/* A moon carved out of a disc: filled in dark, crescent in light. */
.theme-icon {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: inset -6px -3px 0 0 var(--bg-raised);
}
[data-theme="dark"] .theme-icon { box-shadow: none; }

/* --- Error pages ---------------------------------------------------------- */
.error-page { text-align: center; padding-block: var(--space-6); }
.error-status { font-size: 3rem; font-weight: 800; color: var(--text-muted); margin: 0; line-height: 1; }

/* --- Footer --------------------------------------------------------------- */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--bg-raised);
    padding-block: var(--space-4);
    font-size: 0.85rem;
}
.footer-inner { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: space-between; }
.footer-brand { display: grid; gap: 2px; }
.footer-brand a { color: inherit; }

/* --- Branding -------------------------------------------------------------
   The logo is constrained by height and never by width, so it keeps its
   proportions whatever shape it is; max-width stops a very wide wordmark from
   pushing the navigation off the bar. object-fit: contain letterboxes rather
   than stretches, which is the whole point. */

.brand-logo-wrap { display: inline-flex; align-items: flex-end; }

/* Logo and wordmark side by side on the same baseline — the text aligns with
   the bottom of the logo rather than its middle, which is what makes the pair
   read as one lockup instead of two loose objects. */
.brand-stack {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    min-width: 0;
}

.brand-logo {
    display: block;
    height: 34px;
    width: auto;
    max-width: 190px;
    object-fit: contain;
}

/* The wordmark's own line box carries space under the baseline; trimming it is
   what lines the text bottom up with the foot of the logo. */
.brand-stack .brand-name { line-height: 1; padding-bottom: 2px; }

/* Both variants ship in the markup and CSS picks: the theme can change without
   a page load, so the server cannot know which one to send. Where only one was
   uploaded it is used for both — one logo is better than none, and it is then
   the only .brand-logo present, so nothing hides it. */
[data-theme="light"] .brand-logo-dark,
[data-theme="dark"]  .brand-logo-light { display: none; }

@media (min-width: 1150px) {
    /* 176px, not 128.
       A wordmark logo is commonly 4:1 or wider, and at 36px tall that wants
       144px. The old 128px cap did not distort it — `object-fit: contain`
       letterboxes rather than squashes — but it silently drew a 4:1 logo at 32px
       instead of 36 and left a strip of empty box between it and the wordmark.
       176px clears everything up to about 4.8:1 at full height, and the wordmark
       beside it is separately capped, so the bar still cannot reach two rows. */
    .brand-stack-logo .brand-logo { height: 36px; max-width: 176px; }

    /* Item for item with the menu: same size, same weight, standing on the same
       line. max-width is the safety net — APP_NAME is whatever the operator
       typed, and an unbounded wordmark is the one thing in this bar that could
       put it back on two rows. */
    .brand-stack .brand-name {
        font-size: inherit;
        font-weight: 600;
        line-height: 1;
        padding-bottom: 0;
        max-width: 12rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* --- Two blocks side by side ----------------------------------------------
   For a pair of sections where one is narrow by nature and the other is not —
   the dashboard's stage tally beside its recent-activity list. Stacked below
   the desktop breakpoint, and the first column takes a third, because a table
   of "stage, count" does not get better with more room and the one beside it
   does. `minmax(0, …)` on both, so a wide cell inside cannot push the grid
   past the page. */
.wide-split { display: grid; gap: var(--space-4); }
.wide-split > * { min-width: 0; }
.wide-split .section-title:first-child { margin-top: 0; }

@media (min-width: 1150px) {
    .wide-split { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-items: start; }
}

/* --- Spacing between blocks that are not cards ----------------------------
   .card carries only a bottom margin, so a card that follows something else
   sits flush against it. */
.card + .section-title { margin-top: var(--space-5); }

/* --- The document / data split --------------------------------------------
   The scan on one side, what was read off it on the other. Comparing the two is
   the entire job, so they go side by side wherever there is room and stack
   where there is not: scrolling between a figure and the number it should match
   is how transposition errors get missed.

   The breakpoint is higher than the navigation's 900px: two useful columns need
   more width than a menu does. The form takes the larger share, because a page
   of A4 stops being easier to read somewhere around 700px and a six-column
   line editor does not. The scan stays put while the form scrolls past, and
   scrolls within itself when what is on its tab is taller than the window. */
.doc-split {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
    margin-bottom: var(--space-4);
}

@media (min-width: 1100px) {
    .doc-split { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: start; }

    .doc-pane-scan {
        position: sticky;
        top: calc(var(--header-h, 60px) + var(--space-4));
        max-height: calc(100dvh - var(--header-h, 60px) - var(--space-6));
        overflow-y: auto;
    }
}

.doc-pane {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    min-width: 0;
}

.doc-pane h3 { margin-top: 0; }
.doc-pane h3 + h3 { margin-top: var(--space-5); }

/* The embedded PDF, on its tab of a document's page. */
.pdf-frame {
    display: block;
    width: 100%;
    height: 60vh;
    min-height: 380px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
}

/* The transcription, keeping the document's own line breaks and column spacing
   — which is what makes a line-item table still read as a table. `.json-view`
   is the same box for the synced-data viewer's raw-record dump: a scrollable,
   monospaced pane is exactly what a pretty-printed JSON blob wants too. */
.ocr-text, .json-view {
    margin: 0;
    padding: var(--space-3);
    max-height: 60vh;
    overflow: auto;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    tab-size: 4;
}

/* §55: the transcription as an editable box.

   Monospaced and tab-sized to match `.ocr-text` above, because it is the same
   text — a correction typed in a proportional font against a transcription
   read in a monospaced one is a correction made against a different-looking
   document. `resize: vertical` because a thirty-page transcription needs more
   than twenty rows and a page that will not let somebody see what they are
   editing is a page they will edit wrongly. */
.ocr-editor {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
    tab-size: 4;
    resize: vertical;
    min-height: 12rem;
}

/* --- Fields shown rather than edited ------------------------------------- */
.field-readonly { margin-bottom: var(--space-3); }
.field-readonly .label { margin-bottom: 0; font-size: 0.82rem; color: var(--text-muted); font-weight: 600; }

.field-value {
    display: block;
    min-height: 1.6em;
    padding: 2px 0;
    font-size: 1.02rem;
    word-break: break-word;
}

/* --- The scan viewer -------------------------------------------------------
   What a reviewer looks at, and by default it is **the page image rather than
   the PDF**.

   The images already exist: every document is rendered to one PNG per page
   before anything is read, and those are the images the model itself was shown.
   Serving one is a same-origin `<img>` the browser paints immediately, where
   the `<object>` boots a whole PDF viewer with its own toolbar, its own
   scrolling and its own idea of zoom inside a box a third of the screen wide.
   The PDF is still one click away underneath, for the times the render is not
   enough — a signature to squint at, a second page to flick to quickly.

   Two sizes and no more: fit the width of the pane, or the image's own pixels
   with the box scrolling. A zoom slider is a control nobody uses twice; "make
   it big enough to read the handwriting" is the whole requirement.
   ========================================================================== */

.scan { display: flex; flex-direction: column; gap: var(--space-3); min-height: 0; }

.scan-stage {
    flex: 1 1 auto;
    min-height: 0;
    /* Enough to read an A4 page at a glance when the pane is not the flex
       parent — a stacked phone layout, or the duplicate screen's full-width
       card. The flex rule above wins wherever the pane sets a height. */
    height: 72vh;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    /* The strip and the page arrows are in-page anchors and scroll this box;
       the reduced-motion block at the end of this file turns it off again for
       anybody who has asked their system for less movement. */
    scroll-behavior: smooth;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* A page scrolled to sits at the top of the box rather than jammed against its
   edge, and a multi-page document reads as separate sheets rather than a roll. */
.scan-page + .scan-page { margin-top: var(--space-3); }
.scan-page { scroll-margin-top: var(--space-2); }

.scan-page {
    display: block;
    width: 100%;
    /* A ceiling, for the screens where the viewer is a full-width card rather
       than half a split — the duplicate comparison, chiefly. A sheet of A4
       stretched across 1700px is not easier to read, it is a stretch of the
       neck; 52rem is about where a scanned page stops gaining from more width.
       Lifted by "actual size", which is the control for reading the small
       print. */
    max-width: 52rem;
    height: auto;
    margin-inline: auto;
    /* White whatever the theme: a scan of white paper on a dark ground reads
       as a hole in the page. */
    background: #ffffff;
}

/* Actual size: the image keeps its own pixels and the box scrolls both ways.
   `max-width: none` is the load-bearing half — the reset gives every image a
   width ceiling, and without lifting it "actual size" silently does nothing. */
.scan-stage.is-actual { display: block; }
.scan-stage.is-actual .scan-page { width: auto; max-width: none; margin-inline: 0; }

.scan-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    justify-content: space-between;
}

.scan-nav { display: flex; align-items: center; gap: var(--space-2); }
.scan-count { font-size: 0.88rem; color: var(--text-muted); white-space: nowrap; }

/* A page picker only worth showing past two pages; below that the arrows are
   quicker than aiming at a thumbnail. Ordinary in-page anchors, so it still
   works with no script — which is why these are links and not buttons. */
.scan-strip { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-1); }

.scan-strip a {
    flex: 0 0 auto;
    display: block;
    padding: 2px;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    line-height: 0;
}

.scan-strip a img { display: block; width: 54px; height: auto; background: #ffffff; }
.scan-strip a[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.scan-pdf { display: grid; gap: var(--space-2); }
.scan-pdf .pdf-frame { height: 68vh; }

/* --- Per-field issues ------------------------------------------------------
   Every note, every unresolved match and every uncertain reading is drawn on
   the field it is about. The banner this replaces listed four sentences at the
   top of a screen with forty inputs below it, which left the reviewer to work
   out which four boxes were meant — the part of the job the machine can do.

   Two tones and no more: `danger` stands between this document and Clear Books,
   `warn` is worth a look and may well turn out to be right. Both are drawn the
   same way, with a colour variable swapped, so a field cannot be marked in a
   way the reader has to learn.
   ========================================================================== */

.is-flagged {
    --flag: var(--warn);
    --flag-soft: var(--warn-soft);
}

.is-flagged-danger {
    --flag: var(--danger);
    --flag-soft: var(--danger-soft);
}

/* The rule down the left edge is the thing seen at a glance; the colour on the
   input's own border is what confirms which control it means when two fields
   sit side by side in a `.field-row`. */
.field.is-flagged {
    padding-left: var(--space-3);
    border-left: 3px solid var(--flag);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.field.is-flagged > .input,
.field.is-flagged .input { border-color: var(--flag); }

.flag-label { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }

/* The word, not just a colour: colour alone is not a signal somebody with a
   colour vision deficiency receives, and this is the whole point of the
   screen. */
.flag-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--flag-soft, var(--warn-soft));
    color: var(--flag, var(--warn));
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* The fallbacks matter: both of these are used in a couple of places that are
   not inside a `.is-flagged` — a heading for the line-item table, a chip in the
   index — and a `var()` with nothing behind it resolves to nothing at all. */
.flag-notes {
    list-style: none;
    margin: var(--space-1) 0 0;
    padding: 0;
    display: grid;
    gap: 2px;
    font-size: 0.86rem;
    line-height: 1.4;
    color: var(--flag, var(--warn));
}

.flag-notes li { display: flex; gap: var(--space-2); }

/* A drawn triangle rather than a typed "!". Generated content is read out by
   some screen readers, and "exclamation mark" before every note is noise on top
   of a message that already says what is wrong — while the word in `.flag-tag`
   beside the label carries the meaning for anybody who cannot see the colour. */
.flag-notes li::before {
    content: "";
    flex: 0 0 auto;
    width: 0;
    height: 0;
    margin-top: 0.32em;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 7px solid currentColor;
}

/* A flagged cell in the line-item table. The rule goes on the cell rather than
   the input so a whole-row problem — a line total that does not follow from
   the quantity — has somewhere to be drawn. */
.table td.is-flagged {
    box-shadow: inset 3px 0 0 var(--flag);
    /* The flat colour first for anything without `color-mix`: a stronger tint
       than intended is still a correct signal, where no tint at all is not. */
    background: var(--flag-soft);
    background: color-mix(in srgb, var(--flag-soft) 45%, transparent);
}

.table td.is-flagged .input { border-color: var(--flag); }
.table td .flag-notes { font-size: 0.8rem; margin-top: var(--space-1); }

/* A flagged line-item slot (`.line-slot`, Prompt 52, now Prompt 56's grid cell)
   is marked by the rules beside `.line-grid` further down. */

/* A field jumped to should not land under the sticky header. */
.field, .table td { scroll-margin-top: calc(var(--header-h, 60px) + var(--space-4)); }

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

/* A long form: the ordinary `.field` spacing is chosen for a handful of fields
   on a settings screen. */
.form-full .field { margin-bottom: var(--space-2); }
.form-full .input { padding-block: var(--space-1); }
.form-full h3 { margin-bottom: var(--space-2); }
.form-full h3 + p.field-hint { margin-top: calc(var(--space-2) * -1 + var(--space-1)); }

/* `.field-row` is two columns by default; three dates or four totals want to
   keep going rather than wrap in pairs. */
@media (min-width: 640px) {
    .field-row:has(> .field:nth-child(3)) { grid-template-columns: repeat(3, 1fr); }
    .field-row:has(> .field:nth-child(4)) { grid-template-columns: repeat(4, 1fr); }
}

/* --- Supplier and project controls --------------------------------------- */

/* The project-mode radios and "New project" on one line, so the button is
   there whichever of the three allocation modes is chosen. */
.project-mode-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

/*
 * The supplier picker. `.input-with-button .input`'s `flex: 1 1 12rem` never
 * reaches this field: `data-combo` (app.js) wraps the real `<select>` in a
 * `.combo` div, and that div is the flex item, sized by its placeholder text.
 * Widened here for this field only; a short code elsewhere wants the narrower
 * default.
 */
#field-supplier_name_raw .input-with-button .combo { flex: 1 1 32rem; min-width: 0; }

/* How the match was made, directly beneath the picker and small enough to
   read as a footnote to it. */
.supplier-note {
    margin: var(--space-1) 0 0;
    font-size: 0.76rem;
    line-height: 1.3;
    color: var(--text-muted);
}
.supplier-note .badge { padding: 0 6px; font-size: 0.68rem; }

/* The green mark an accepted check leaves on its field. */
.flag-tag-resolved {
    --flag: var(--ok);
    background: var(--ok-soft);
    color: var(--ok);
}

/* Project allocation's three radios: stacked, and on one line from the width
   `.field-row` itself widens at. */
.project-mode-options {
    display: flex;
    flex-direction: column;
}
@media (min-width: 640px) {
    .project-mode-options {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        column-gap: var(--space-5);
    }
}

/* A small "?" disc, hover- and keyboard-focusable, holding the description an
   inline `<span>` used to carry. Kept outside the `<label>` it sits beside —
   nested inside it, clicking the disc would also toggle the label's own radio,
   which is not what hovering it for a tooltip is asking for. */
.tooltip {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-sunken);
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
}
.tooltip:hover,
.tooltip:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    outline: none;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    z-index: 40;
    left: 50%;
    bottom: calc(100% + var(--space-2));
    transform: translateX(-50%);
    width: max-content;
    max-width: 18rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: 0.82rem;
    font-weight: 400;
    line-height: 1.4;
    text-align: left;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease;
    pointer-events: none;
}
.tooltip:hover::after,
.tooltip:focus-visible::after {
    opacity: 1;
    visibility: visible;
}

/* Net, VAT and gross are read-only computed displays, not inputs a reviewer
   can override — see §22. Styled to look it: the same box, quietly inactive. */
.input-computed {
    background: var(--bg-sunken);
    color: var(--text-muted);
    cursor: default;
}

/* Prompt 55. The figure the document prints for this total, beside the box's
   title — the target the Total Adjustment reconciles to — and a pale red glow
   on the box when it is not exactly that. The glow always carries a `title`
   and screen-reader text naming what it differs from (partials/total-box). */
.total-ocr {
    margin-left: var(--space-1);
    font-weight: 400;
    font-size: 0.85em;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* One figure per line in a table cell — the Totals check's differences. */
.cell-line { display: block; white-space: nowrap; }

.input-computed.total-mismatch {
    border-color: color-mix(in srgb, var(--danger) 45%, var(--border, transparent));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
    cursor: help;
}

/* --- The combobox — Prompt 21 -----------------------------------------------
   A progressive enhancement over an ordinary <select>: `app.js` wraps one
   marked `data-combo`, keeps it as the actual form control (visually hidden
   the same way `.sr-only` is, not `display:none`, so a required field still
   validates and the native control still works if the script fails to run),
   and drives it from a text input a reviewer can type into. Typing filters
   the list; choosing an option is the only way the real <select>'s value
   changes, so the field can never hold a value that was not already in it. */
.combo { position: relative; }

.combo-select {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.combo-input { cursor: text; }

/* Rendered on `document.body` and positioned in fixed coordinates by script —
   not inside `.combo` — so it is never clipped by an ancestor's own scrolling
   box, chiefly `.table-wrap` around the line-item table. */
.combo-list {
    position: fixed;
    z-index: 60;
    margin: 0;
    padding: var(--space-1) 0;
    list-style: none;
    max-height: 16rem;
    overflow-y: auto;
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.combo-option {
    padding: var(--space-2) var(--space-3);
    font-size: 0.95rem;
    cursor: pointer;
    line-height: 1.35;
}

.combo-option:hover,
.combo-option.is-active { background: var(--bg-hover); }
.combo-option[aria-selected="true"] { font-weight: 600; }

.combo-empty { color: var(--text-muted); font-style: italic; cursor: default; }
.combo-empty:hover { background: none; }

/* --- "New project" modal — Prompt 33 ---------------------------------------
   The first inline-create-via-modal in the app, so nothing to match: styled
   from the same `.card`/`.field`/`.btn` primitives every other panel uses. */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--scrim);
}

.modal {
    width: 100%;
    max-width: 26rem;
    margin: 0;
    max-height: calc(100vh - 2 * var(--space-4));
    overflow-y: auto;
}

.modal h3 { margin-top: 0; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

/* A <details> whose summary is the button that opens it. The marker is removed
   because the button already says what it does, and a disclosure triangle
   beside "Create in Clear Books" reads as decoration rather than as a control. */
details.fieldset > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.fieldset > summary::-webkit-details-marker { display: none; }
details.fieldset[open] > summary { margin-bottom: var(--space-4); }

/* Editable line items. The inputs sit flush in their cells so the table still
   reads as a table rather than as a wall of boxes, and the numeric columns stay
   narrow enough that the description keeps the width it needs. */
.table td > .input,
.table td > textarea.input {
    width: 100%;
    min-width: 0;
    padding: var(--space-1) var(--space-2);
}

.table td.amount > .input { text-align: right; font-variant-numeric: tabular-nums; }

/* The description column holds more than any other field on this screen —
   product code, full description, spec — and 3.2rem (about two lines) was
   cramped for it. Taller by default; still resizable for the rare line that
   needs more. */
.table td > textarea.input { resize: vertical; min-height: 5.4rem; }

/* The line editor. Each line is one `.line-item` holding two rows of
   controls, in one column template shared by every item so the columns read
   straight down the page:

     .line-main     Description | Qty | Unit | Net | VAT | Gross | X
     .line-pickers  Project | Account code | VAT rate | Quick pick

   The description takes what the fixed columns leave. `min-width` on the grid,
   rather than a media query, decides when a narrower pane scrolls inside
   `.table-wrap`: the pane beside the scan is about half the window. */
.line-grid {
    --line-cols: minmax(12rem, 1fr) 4.5rem 6.5rem 6.5rem 6.5rem 6.5rem 1.9rem;
    --line-gap: var(--space-1);
    min-width: 47rem;
    font-size: 0.96rem;
}

.line-grid-head,
.line-main {
    display: grid;
    grid-template-columns: var(--line-cols);
    column-gap: var(--line-gap);
    align-items: start;
}

.line-grid-head {
    padding: var(--space-2);
    background: var(--bg-sunken);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.line-grid-head .amount { text-align: right; padding-inline: var(--space-2); }

.line-item { padding: var(--space-2); border-top: 1px solid var(--border); }
.line-item:first-child { border-top: 0; }
.line-item:hover { background: var(--bg-hover); }

.line-pickers {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 1.9rem;
    column-gap: var(--line-gap);
    align-items: start;
    margin-top: var(--space-1);
}
.line-grid-quickpick .line-pickers { grid-template-columns: repeat(3, minmax(0, 1fr)) 9.5rem 1.9rem; }

/* One box (and any flag notes under it) in a grid cell. `min-width: 0` so a
   long value shortens the box rather than widening the column. */
.line-slot { min-width: 0; scroll-margin-top: calc(var(--header-h, 60px) + var(--space-4)); }
.line-slot .input:not(.combo-select) { min-width: 0; padding-inline: var(--space-2); }
.line-slot.amount .input { text-align: right; font-variant-numeric: tabular-nums; }
.line-slot .flag-notes { font-size: 0.8rem; margin-top: var(--space-1); }

/* The description holds more than any other field on this screen — product
   code, full description, spec — so it stays a textarea, and resizable. */
.line-slot-desc textarea.input { resize: vertical; min-height: 4.2rem; }

/* A flagged slot: the same mark `.table td.is-flagged` gives a table cell. */
.line-slot.is-flagged {
    box-shadow: inset 3px 0 0 var(--flag);
    background: var(--flag-soft);
    background: color-mix(in srgb, var(--flag-soft) 45%, transparent);
}
.line-slot.is-flagged .input { border-color: var(--flag); }

/* Project is only asked for in Per line allocation, but its slot is always in
   the layout: hidden by *visibility*, so Account code and VAT rate stay
   exactly where they are whichever allocation is chosen. Needed as an
   override, because `[hidden]` is `display: none !important` (top of file).
   `visibility: hidden` also takes the combobox out of the tab order. */
.line-slot-project[hidden] { display: block !important; visibility: hidden; }

/* The Total Adjustment's note is a direct child of the item, not of the
   description slot, so it spans the whole grid. */
.line-item.row-adjustment { background: var(--bg-sunken); }
.line-note { margin: var(--space-1) 0 0; }

.line-add { padding: var(--space-2); border-top: 1px solid var(--border); }

/* A small X, not a full button: the row already carries a quick pick and two
   pickers, and a `.btn` would be the loudest thing in it. */
.line-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-raised);
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}
.line-remove:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* Typed arithmetic that cannot be worked out, or a Unit that cannot be
   derived, leaves the field as it was and marks it with a glow rather than a
   standing border: it is not a check, and it clears on the next keystroke
   (`app.js` strips the class on `input`). */
@keyframes line-calc-error-glow {
    from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 55%, transparent); }
    to   { box-shadow: 0 0 0 0 transparent; }
}
.line-grid .input.line-calc-error {
    border-color: var(--danger);
    animation: line-calc-error-glow 900ms ease-out;
}

/* The transcription beside the scan scrolls on its own rather than stretching
   the pane: on a long document it is several screens of text and the reviewer
   wants the PDF to stay where it is. */
.doc-pane .ocr-text { max-height: 22rem; overflow-y: auto; }

/* --- The prompt editor ---------------------------------------------------- */

/* A prompt is several screens of prose with structure that matters — headings,
   bullet rules, a JSON example. Monospaced so the example lines up, and tall,
   because scrolling a four-line box to read four kilobytes is how a rule gets
   edited out by accident. */
.prompt-editor {
    min-height: 60vh;
    resize: vertical;
    line-height: 1.5;
    tab-size: 2;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}

/* The variable panel: each one opens to show what it holds today. */
details.fieldset > summary .cell-sub { display: block; margin-top: 2px; }
details.fieldset + details.fieldset { margin-top: calc(var(--space-3) * -1 + var(--space-4)); }

/* The capability list on the users screen. A tick rather than a bullet: the
   list is "what this role can do", and every line is a yes. */
.tick-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--space-2);
}

.tick-list li {
    position: relative;
    padding-left: 1.4em;
    line-height: 1.4;
}

.tick-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.42em;
    width: 0.5em;
    height: 0.8em;
    border: solid var(--accent);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* A radio row reads the same as a checkbox row — a control, a bold name, and a
   sentence of what choosing it means. */
.checkbox input[type="radio"] {
    width: 22px; height: 22px;
    margin-top: 2px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.checkbox .cell-sub { display: block; margin-top: 2px; }

/* A form with three short fields and nothing else on the page. Full width
   would put the label a hand's width from its box on a desktop. */
.form-narrow { max-width: 32rem; }

/* The activity feed: a time on the left, what happened on the right. A table
   would be three columns of which one is always short and one is always long,
   which reads worse than it sounds. */
.feed { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: grid; gap: var(--space-2); }

.feed-item {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--border);
    background: var(--bg-raised);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.feed-when { color: var(--text-muted); font-size: 0.88rem; flex: 0 0 auto; min-width: 9.5rem; }
.feed-what { flex: 1 1 16rem; }
.feed-what .cell-sub { display: block; }

/* A failure's structured detail, folded away inside the event row. Open by
   click rather than always visible: the history table is scanned far more often
   than any one row is read. */
.event-detail summary { cursor: pointer; }
.event-detail .meta-list { margin-top: var(--space-2); }

/* Separates the sections inside a synced-data record's expanded detail —
   InvoGrid's own additions, then the raw Clear Books record — without
   another nested card. */
.event-detail .detail-heading { margin-top: var(--space-4); margin-bottom: var(--space-1); }

/* --- Logo previews on the branding screen --------------------------------- */

/* Each preview sits on the ground its variant is *for*, not on the page's
   current theme — a dark-mode logo previewed on a light card is an invisible
   logo, and somebody would reasonably conclude the upload had failed. These two
   are therefore fixed colours rather than theme variables, which is the one
   place in this stylesheet where that is correct. */
.logo-preview {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 84px;
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.logo-preview img {
    display: block;
    max-height: 48px;
    max-width: 100%;
    width: auto;
    object-fit: contain;
}

.logo-preview-light { background: #ffffff; color: #0f172a; }
.logo-preview-dark  { background: #0b1120; color: #f1f5f9; }

/* The monogram placeholder has to flip with the ground it is standing on. */
.logo-preview-light .brand-mark { background: #4338ca; color: #ffffff; }
.logo-preview-dark  .brand-mark { background: #a5b4fc; color: #10132e; }
.logo-preview .muted { color: inherit; opacity: 0.65; }

/* A file input is a browser widget with its own idea of padding; .input's
   fixed height crops the button in some of them. */
.input[type="file"] {
    height: auto;
    padding: var(--space-2);
    line-height: 1.4;
}

/* --- The upload page — Prompt 50 --------------------------------------------
   A drop zone, and a queue of files each with its own progress.

   The zone is a <label> pointing at the file input, so clicking it opens the
   dialogue and a keyboard reaches it the same way it reaches any other label.
   Nothing here is click-only: everything the zone does, the input does too. */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-6) var(--space-4);
    margin-bottom: var(--space-4);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-hover);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

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

/* The dragged-over state. A colour change alone would be invisible to anybody
   who cannot see it, but a drag is a pointer gesture by definition — there is
   no keyboard equivalent to signal, and the input below is the keyboard path. */
.dropzone.is-over {
    border-color: var(--accent);
    border-style: solid;
    background: var(--accent-soft);
}

.dropzone-icon { font-size: 1.8rem; line-height: 1; color: var(--text-muted); }
.dropzone-lead { font-weight: 600; }
.dropzone-sub  { color: var(--text-muted); font-size: 0.92rem; }

/* The input is the accessible twin of the zone, not a duplicate control: it
   keeps its own label and hint, and both feed the same queue. */
.upload-queue {
    list-style: none;
    margin: 0 0 var(--space-4);
    padding: 0;
    display: grid;
    gap: var(--space-2);
}

.upload-item {
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    background: var(--bg-raised);
}

/* One mark per state, in the same colours the badges use, so a long queue can
   be read down the left edge without reading any of the words. */
.upload-pending   { border-left-color: var(--border-strong); }
.upload-uploading { border-left-color: var(--info); }
.upload-done      { border-left-color: var(--ok); }
.upload-duplicate { border-left-color: var(--warn); }
.upload-failed    { border-left-color: var(--danger); }

.upload-item-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* The filename takes what is left and truncates rather than wrapping: a queue
   of fifty rows whose heights depend on how long a scanner names its files is
   a queue nobody can scan. */
.upload-item-name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item-size { flex: 0 0 auto; font-size: 0.88rem; }

.upload-bar {
    margin-top: var(--space-2);
    height: 6px;
    border-radius: 999px;
    background: var(--bg-sunken);
    overflow: hidden;
}

/* Width is set from the XHR's own progress events, so this moves because bytes
   moved. There is no animation on it beyond smoothing the steps between
   events — a bar that advances on a timer is a lie about a stalled upload. */
.upload-bar-fill {
    height: 100%;
    width: 0;
    background: var(--info);
    transition: width 0.12s linear;
}

.upload-item-note {
    margin: var(--space-2) 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.upload-failed .upload-item-note { color: var(--danger); }

.upload-item-tools {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.upload-item-tools:empty { display: none; }
.upload-item-link { font-size: 0.9rem; }

.queue-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.queue-head h2 { margin: 0; }
.queue-head p  { margin: 0; }

@media (max-width: 640px) {
    .dropzone { padding: var(--space-5) var(--space-3); }

    /* The size drops below the name rather than squeezing it: on a narrow
       screen the filename is the thing being looked for. */
    .upload-item-head { flex-wrap: wrap; }
    .upload-item-name { flex-basis: 100%; }
}

/* --- Motion --------------------------------------------------------------- */

/* Somebody who has asked their operating system for less motion has asked
   every application on it, and the answer has to cover the page rather than the
   three components that happened to be remembered. This replaces two
   narrower blocks that killed the caret and the flash transitions and left the
   nav drawer, the buttons and the flash's leaving transform still moving.

   `.flash.is-leaving` also has its transform cancelled: a message that slides
   away is still motion even when the slide is instant. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }

    .flash.is-leaving { transform: none; }
}

/* ==========================================================================
   Print

   Two parts, and the distinction matters. The `.print-*` classes below style
   the dedicated print layout *on screen* — somebody looks at that page before
   they print it, and a preview that looks nothing like the output is not a
   preview. The print block at the end is the small set of changes that only
   make sense on paper.

   InvoGrid follows Kitwell here: a separate layout for anything meant to be
   printed, rather than the ordinary page with its chrome hidden. Hiding the
   navigation still ships it, and a printed record that quietly breaks when the
   menu changes is one nobody notices until a supplier queries an invoice.
   ========================================================================== */

.print-body {
    background: var(--bg-sunken);
}

/* The only chrome, and it is .no-print. Sticky so "Print this" is reachable
   from the bottom of a long summary without scrolling back up. */
.print-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}

/* A sheet of A4, near enough, so what is on screen is what comes out. */
.print-sheet {
    width: 100%;
    max-width: 210mm;
    min-height: 260mm;
    margin: var(--space-5) auto;
    padding: 16mm 14mm;
    background: #ffffff;
    color: #0f172a;
    box-shadow: var(--shadow);
}

.print-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-5);
    border-bottom: 2px solid #0f172a;
}

.print-brand { display: flex; align-items: flex-end; gap: var(--space-3); min-width: 0; }

/* Same aspect-ratio-safe treatment as the header: a height, an automatic
   width, and a ceiling so a very wide logo cannot push the date off the sheet. */
.print-logo {
    display: block;
    height: 40px;
    width: auto;
    max-width: 220px;
    object-fit: contain;
}

.print-wordmark { font-size: 1.15rem; font-weight: 700; line-height: 1; padding-bottom: 2px; }

.print-meta {
    display: grid;
    gap: 2px;
    text-align: right;
    font-size: 0.85rem;
    color: #52627a;
}

.print-title { font-size: 1.5rem; margin-bottom: var(--space-1); }
.print-subtitle { color: #52627a; margin-bottom: var(--space-5); }

.print-block { margin-bottom: var(--space-5); break-inside: avoid; }

.print-block h2 {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: #52627a;
    padding-bottom: var(--space-1);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid #cbd5e1;
}

/* The Clear Books outcome, which is what somebody printing this wants to point
   at. An indigo rule rather than a filled panel: a block of colour is a block
   of ink, and this page exists to be printed. */
.print-block-key { border-left: 4px solid #4338ca; padding-left: var(--space-4); }
.print-block-pending { border-left: 4px solid #854d0e; padding-left: var(--space-4); }

.print-pairs { display: grid; gap: var(--space-2); margin: 0; }
.print-pairs > div { display: flex; gap: var(--space-3); align-items: baseline; }

.print-pairs dt {
    flex: 0 0 12rem;
    font-weight: 600;
    color: #52627a;
}

.print-pairs dd { margin: 0; flex: 1 1 auto; min-width: 0; }

.print-pairs-totals > div { max-width: 24rem; justify-content: space-between; }
.print-pairs-totals dd { text-align: right; flex: 0 0 auto; font-variant-numeric: tabular-nums; }

.print-total {
    padding-top: var(--space-2);
    border-top: 1px solid #cbd5e1;
    font-weight: 700;
    font-size: 1.05rem;
}
.print-total dt { color: inherit; }

.table-print { font-size: 0.92rem; }
.table-print th, .table-print td { border-color: #cbd5e1; }
.table-print tr { break-inside: avoid; }

.print-list { margin: 0; padding-left: 1.2rem; }
.print-list li { margin-bottom: var(--space-1); }
.print-note-line { color: #52627a; font-size: 0.9rem; }

.print-foot {
    margin-top: var(--space-6);
    padding-top: var(--space-3);
    border-top: 1px solid #cbd5e1;
    font-size: 0.8rem;
    color: #52627a;
}

@media print {
    @page { size: A4; margin: 12mm; }

    .no-print { display: none !important; }

    /* Anything from the ordinary layout, for the day somebody prints a normal
       page — better a readable sheet than the navigation across the top of it. */
    .site-header, .site-footer, .filter-bar, .form-actions,
    .nav-toggle, .btn, .flash-stack { display: none !important; }

    html, body {
        background: #ffffff !important;
        color: #000000;
        margin: 0;
        padding: 0;
        font-size: 11pt;
    }

    /* The sheet is the page now: no shadow, no margin, no second set of edges
       inside the printer's own. */
    .print-sheet {
        max-width: none;
        min-height: 0;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .card, .table-wrap { border: 1px solid #999; box-shadow: none; }

    /* A table split over a page break repeats its headings rather than leaving
       the second half as unlabelled columns. */
    thead { display: table-header-group; }
    tr, .print-block { break-inside: avoid; }

    /* A link's href is invisible on paper, and a summary that says "see the
       document" without saying where is a dead end. */
    a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; word-break: break-all; }
}

/* --- Reference files on a document (§59) ------------------------------------
   Quieter than the document's own data on purpose: one line per file, and
   everything read off it folded away. */
.attachment-list { list-style: none; margin: 0; padding: 0; }
.attachment-list > .attachment { padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.attachment-list > .attachment:first-child { border-top: 0; padding-top: 0; }
.attachment-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.attachment .cell-sub { margin: var(--space-1) 0 0; }
.attachment form { margin-top: var(--space-2); }
.attachment-detail .meta-list { margin-top: var(--space-2); }
.attachment-detail .ocr-text { max-height: 24rem; overflow: auto; }
.attachment-add { margin-top: var(--space-3); }
.attachment-add[open] > summary { margin-bottom: var(--space-3); }

/* --- Authenticator set-up ------------------------------------------------- */

/* Dark on white in both themes: a scanner expects dark modules on a light
   ground, and the SVG carries its own white quiet zone. */
.qr-code { width: 220px; max-width: 100%; margin: var(--space-4) 0; }
.qr-code svg { display: block; width: 100%; height: auto; border-radius: 4px; }
.qr-secret { font-size: 1.05rem; letter-spacing: 0.04em; word-break: break-all; user-select: all; }
.auth-help .inline-form + .inline-form,
.auth-help .inline-form + .btn,
.auth-help .btn + .inline-form { margin-left: var(--space-2); }

/* --- Lists ---------------------------------------------------------------- */
/* The shared list: saved views, filters, a sortable table and its pages. */
.views-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.view-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.view-chip {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-raised);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}
.view-chip:hover { background: var(--bg-hover); color: var(--text); }
.view-chip.is-active { background: var(--accent-soft); border-color: var(--accent); }

.view-save > summary { list-style: none; }
.view-save > summary::-webkit-details-marker { display: none; }
.view-save[open] { flex: 1 1 100%; }
.view-save-form {
    max-width: 26rem;
    margin: var(--space-2) 0 0;
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.view-save-form .input { margin-bottom: var(--space-2); }

.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--text); text-decoration: underline; }
.sort-link.is-sorted { color: var(--text); }
/* The arrow repeats what aria-sort already says. */
.sort-link.is-sorted::after {
    content: '';
    display: inline-block;
    margin-left: 6px;
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}
.sort-link.is-asc::after { border-bottom: 5px solid currentColor; }
.sort-link.is-desc::after { border-top: 5px solid currentColor; }

/* Aligned on their labels, so a hint under one filter hangs below the row
   instead of lifting its box above the others. */
.list .filter-bar { align-items: flex-start; }

/* A list has many columns and the growing one is the one that is read, so it
   keeps a width of its own and a second line goes under rather than beside. */
.list-table th, .list-table td { padding-left: var(--space-2); padding-right: var(--space-2); }
.list-table th.col-grow { min-width: 12rem; }
.list-table td .nowrap > .cell-sub { display: block; }

.list-table [data-list-row] { cursor: pointer; }
.list-table [data-list-row]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.list-table [data-list-row]:focus { background: var(--accent-soft); }

.ql-eye {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap); height: var(--tap);
    margin: -8px 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}
.ql-eye:hover { background: var(--bg-sunken); color: var(--text); }

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.pager p { margin: 0; }
.pager-links { display: flex; align-items: center; gap: var(--space-3); }

.list-empty { text-align: center; padding: var(--space-6) var(--space-4); }

/* --- Quick-look ----------------------------------------------------------- */
.ql {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    justify-content: center;
}
.ql-backdrop { position: absolute; inset: 0; background: var(--scrim); }

.ql-box {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--bg-raised);
    box-shadow: var(--shadow);
}
.ql-box:focus { outline: none; }

.ql-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3);
    border-bottom: 1px solid var(--border);
}
.ql-name { min-width: 0; }
.ql-title { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.ql-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.ql-body { flex: 1 1 auto; min-height: 0; background: var(--bg-sunken); }
.ql-body iframe { display: block; width: 100%; height: 100%; border: 0; }
.ql-none { margin: 0; padding: var(--space-6) var(--space-4); text-align: center; }

body.ql-open { overflow: hidden; }

@media (min-width: 900px) {
    .ql { padding: 3vh 3vw; }
    .ql-box { max-width: 72rem; border-radius: var(--radius); overflow: hidden; }
}

/* --- Checks bar ----------------------------------------------------------- */
/* What is outstanding on a subject, must-fix first, beside the action it holds
   up. The edge colour repeats what the badges say in words. */
.checks-bar {
    margin-bottom: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-left: 4px solid var(--ok);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.checks-bar.has-checks { border-left-color: var(--warn); }
.checks-bar.has-must-fix { border-left-color: var(--danger); }

.checks-summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; }

.checks-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; }
.check-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-2) 0;
    border-top: 1px solid var(--border);
}
.check-message { flex: 1 1 14rem; }
.check-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }

.checks-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}
.checks-why { flex: 1 1 100%; margin: 0; }
/* A held action has to look held, or it reads as a button that does nothing. */
.checks-footer .btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }

/* Where "Go to" landed. */
.is-goto-target { outline: 3px solid var(--focus); outline-offset: 3px; scroll-margin-top: 140px; }

/* --- A purchase document ---------------------------------------------------
   One page: the header with its checks, the scan beside the form, and three
   folded sections under both. */
.doc-head { margin-bottom: var(--space-4); }
.doc-back { margin: 0 0 var(--space-1); font-size: 0.9rem; }
.doc-head-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.doc-head-title { flex: 1 1 16rem; min-width: 0; }
.doc-head-title h1 { margin-bottom: var(--space-1); overflow-wrap: anywhere; }
.doc-facts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); margin: 0; }
.doc-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.doc-steps { display: flex; align-items: center; gap: var(--space-2); }
.doc-position { font-size: 0.88rem; white-space: nowrap; }
.doc-stage { max-width: 36rem; margin-top: var(--space-3); }

/* The less common actions: a <details>, so they work without script. */
.doc-menu { position: relative; }
.doc-menu > summary { list-style: none; cursor: pointer; font-weight: 700; }
.doc-menu > summary::-webkit-details-marker { display: none; }
.doc-menu-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 30;
    width: 18rem;
    max-width: calc(100vw - 2 * var(--space-4));
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
    box-shadow: var(--shadow);
}
.doc-menu-panel form { margin: 0; }
.doc-menu-label { margin: var(--space-2) 0 0; padding: 0 var(--space-3); font-size: 0.82rem; color: var(--text-muted); }
.doc-menu-delete > summary { list-style: none; }
.doc-menu-delete > summary::-webkit-details-marker { display: none; }
.doc-menu-delete form { display: grid; gap: var(--space-2); padding: var(--space-2) var(--space-3); }
.doc-menu-delete .field-hint { margin: 0; }

.doc-notice p:last-child, .doc-notice .form-actions:last-child { margin-bottom: 0; }

/* All three in order without script; one at a time once app.js has the tabs. */
.doc-tab + .doc-tab { margin-top: var(--space-4); }
.doc-tabs.has-tabs .doc-tab + .doc-tab { margin-top: 0; }
.doc-tab-bar { margin-bottom: var(--space-3); }
.doc-tab-note { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: 0; }

.doc-section { scroll-margin-top: calc(var(--header-h, 60px) + var(--space-4)); }
.doc-section + .doc-section { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.doc-section > h2 { margin-top: 0; font-size: 1.15rem; }
.doc-section.is-flagged { padding-left: var(--space-3); border-left: 3px solid var(--flag); }

.lock-mark { display: inline-block; color: var(--text-muted); vertical-align: -1px; }
.lock-banner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
}
.field-locked .label { margin-bottom: 0; font-size: 0.82rem; color: var(--text-muted); }
.field-locked .field-value { margin: 0; }

.kind-choice { margin-inline: 0; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 0; }
.kind-options { display: flex; flex-wrap: wrap; gap: 0 var(--space-4); }
.supplier-create { margin-top: var(--space-3); }
.totals-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.field-rate { max-width: 24rem; }

/* Saving is within reach wherever in a long form the change was made. */
.doc-save {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border);
    background: var(--bg-raised);
}
.doc-save .field-hint { margin: 0; }

.doc-fold > summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-height: var(--tap); cursor: pointer; }
.doc-fold[open] > summary { margin-bottom: var(--space-3); }
.doc-fold { scroll-margin-top: calc(var(--header-h, 60px) + var(--space-4)); }
.doc-fold-title { font-size: 1.15rem; font-weight: 700; }

.compare-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.compare-head h2 { margin: 0; font-size: 1.15rem; }
.compare-table th, .compare-table td { vertical-align: top; min-width: 10rem; }
.compare-table .compare-label { min-width: 6rem; }
.compare-table td.is-same { background: var(--ok-soft); }
.compare-table th .cell-sub { display: block; font-weight: 400; }
.compare-eye { margin-left: var(--space-2); }
.compare-answers form { margin: 0 0 var(--space-2); }
.compare-answers .btn { white-space: normal; text-align: left; }
.compare-new { display: grid; gap: var(--space-2); justify-items: start; }

/* A line's figures are named by the grid's headings, until the grid folds. */
.line-label { display: none; }

/* On a phone a line is a small form of its own: description, then the figures
   three across, then the picks one under another. Nothing scrolls sideways. */
@media (max-width: 699px) {
    .line-grid { min-width: 0; }
    .line-grid-head { display: none; }
    .line-main { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: var(--space-2); }
    .line-slot-desc { grid-column: 1 / -1; }
    .line-slot-remove { align-self: end; justify-self: end; }
    .line-label { display: block; font-size: 0.78rem; color: var(--text-muted); }
    .line-pickers,
    .line-grid-quickpick .line-pickers { grid-template-columns: 1fr; row-gap: var(--space-2); margin-top: var(--space-2); }
    .line-slot-project[hidden] { display: none !important; }
    .doc-pane { padding: var(--space-3); }
}

@media print {
    .doc-pane-scan, .doc-head-actions, .doc-save, .doc-tab-bar { display: none !important; }
}

/* --- Me ------------------------------------------------------------------- */
/* A person's own pages, designed for one hand on a phone: one column, and the
   tabs along the foot of the screen where a thumb reaches. */
.me { max-width: 40rem; margin-inline: auto; }
.me .card { overflow-wrap: anywhere; }

.me-tabs ul { display: flex; margin: 0; padding: 0; list-style: none; }
.me-tabs li { flex: 1 0 auto; }
.me-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    padding: var(--space-1) var(--space-1);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}
.me-tab.is-active { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 3px 0 var(--accent); }

.me-details { display: grid; gap: var(--space-1); margin: 0 0 var(--space-4); }
.me-details dt { font-size: 0.82rem; color: var(--text-muted); }
.me-details dd { margin: 0 0 var(--space-2); }

@media (max-width: 639px) {
    .me-tabs {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 35;
        overflow-x: auto;
        padding-bottom: env(safe-area-inset-bottom);
        border-top: 1px solid var(--border);
        background: var(--bg-raised);
    }
    body.has-me-tabs { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}

@media (min-width: 640px) {
    .me-tabs { margin-bottom: var(--space-4); overflow-x: auto; border-bottom: 1px solid var(--border); }
    .me-tab { min-height: var(--tap); padding-inline: var(--space-3); font-size: 0.95rem; }
    .me-tab.is-active { background: transparent; box-shadow: inset 0 -3px 0 var(--accent); }
}

@media print {
    .header-search, .me-tabs, .ql, .views-bar, .pager-links { display: none !important; }
}

/* --- People ---------------------------------------------------------------
   A person's record reads as label and value pairs; on a wide screen the
   labels sit in a column of their own. */
.facts { display: grid; grid-template-columns: 1fr; gap: var(--space-1) var(--space-4); margin: 0 0 var(--space-4); }
.facts dt { font-size: 0.82rem; color: var(--text-muted); }
.facts dd { margin: 0 0 var(--space-2); }
@media (min-width: 640px) {
    .facts { grid-template-columns: minmax(10rem, max-content) 1fr; }
    .facts dd { margin: 0; }
}

.pattern-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr)); gap: var(--space-2); }
.pattern-day { display: grid; gap: var(--space-1); font-size: 0.86rem; color: var(--text-muted); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { padding: var(--space-2) 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: 0; }
