/* =========================================================================
   Border Clear — design system
   =========================================================================

   Organised as tokens first, then primitives, then components. Every class the
   templates already use is still here; the ones added for the rebuilt screens
   are grouped under their own headings.

   Two decisions worth stating because they are not obvious:

   No web fonts. The application is offline-first by design — it runs on the
   client's own hardware and nothing is meant to leave the host — so a stylesheet
   that reaches for fonts.googleapis.com would both break that promise and fail
   at a depot with no line out. The stack below resolves to SF Pro on macOS and
   Segoe UI Variable on Windows, which are good faces; the character comes from
   the scale, the weights and the spacing rather than from a download.

   Semantic colour is separate from the brand accent. The accent is plum, on
   violet-slate neutrals; the states are blue, amber, green and red. (The
   structure is AfriClear's; Border Clear's palette and corners are its own.) A dashboard whose "working" colour is
   also its brand colour cannot show state at a glance, which is the one thing a
   queue screen is for.
   ========================================================================= */

/* Tokens ------------------------------------------------------------------ */

:root {
    color-scheme: light;

    /* Neutrals, biased slightly violet so they sit with the plum accent. */
    --ink:            #16141F;
    --ink-2:          #2C2838;
    --muted:          #5F5A6E;
    --muted-2:        #878297;
    --line:           #E2E0EA;
    --line-strong:    #CAC6D6;
    --bg:             #F3F2F8;
    --surface:        #FFFFFF;
    --surface-2:      #F9F8FC;
    --surface-sunk:   #EDEBF3;

    /* Brand. Used for identity and primary action, never for state. */
    --accent:         #5B3A8C;
    --accent-strong:  #432A6B;
    --accent-soft:    #EEE8F7;
    --accent-ink:     #2C1A4A;

    /* Text that sits *on* the accent, and the top bar's own ground.
       Both exist because the accent inverts between themes and these must not.
       Reusing --accent-strong for the bar gave a light teal bar with white text in
       dark mode — about 1.9:1, unreadable — and the same for primary buttons. */
    --on-accent:      #FFFFFF;
    --topbar:         #211833;
    --topbar-ink:     #FFFFFF;

    /* State. Each one has to be distinguishable from the others at a glance. */
    --info:           #245FA6;
    --info-soft:      #E4EDF8;
    --ok:             #1B7048;
    --ok-soft:        #E3F1E9;
    --warn:           #97600A;
    --warn-soft:      #FBEFD9;
    --danger:         #AC2A22;
    --danger-soft:    #FAE7E5;

    /* Legacy aliases, so nothing that referenced the old names breaks. */
    --border:         var(--line);
    --accent-dark:    var(--accent-strong);
    --error:          var(--danger);
    --error-bg:       var(--danger-soft);
    --success:        var(--ok);
    --success-bg:     var(--ok-soft);
    --warning:        var(--warn);
    --warning-bg:     var(--warn-soft);
    --text:           var(--ink);

    /* Type */
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text",
            "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono",
            Menlo, Consolas, "Liberation Mono", monospace;

    --t-2xs: 0.6875rem;   /* 11 */
    --t-xs:  0.75rem;     /* 12 */
    --t-sm:  0.8125rem;   /* 13 */
    --t-md:  0.9375rem;   /* 15 — base */
    --t-lg:  1.0625rem;   /* 17 */
    --t-xl:  1.3125rem;   /* 21 */
    --t-2xl: 1.625rem;    /* 26 */
    --t-3xl: 2rem;        /* 32 */

    /* Space, on a 4px base */
    --s-1: 0.25rem;  --s-2: 0.5rem;   --s-3: 0.75rem;  --s-4: 1rem;
    --s-5: 1.5rem;   --s-6: 2rem;     --s-7: 2.5rem;   --s-8: 3rem;

    --r-sm: 5px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;

    --e-1: 0 1px 2px rgba(33, 24, 51, .06);
    --e-2: 0 1px 2px rgba(33, 24, 51, .06), 0 4px 12px -4px rgba(33, 24, 51, .10);
    --e-3: 0 2px 4px rgba(33, 24, 51, .06), 0 12px 32px -8px rgba(33, 24, 51, .18);

    --dur-fast: 120ms;
    --dur:      200ms;
    --dur-slow: 340ms;
    --ease:     cubic-bezier(.2, .8, .2, 1);

    /* Placeholders. Derived from the ink and the surface so they follow the theme
       without a second definition — see ThemeTokensTest on why that matters. */
    --skeleton-base:  color-mix(in srgb, var(--ink) 9%, var(--surface));
    --skeleton-sheen: color-mix(in srgb, var(--ink) 18%, var(--surface));

    --shell: 1240px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --ink:          #ECEAF3;
        --ink-2:        #D1CDE0;
        --muted:        #A6A1B7;
        --muted-2:      #817C93;
        --line:         #2C2838;
        --line-strong:  #403A50;
        --bg:           #100E16;
        --surface:      #191621;
        --surface-2:    #1E1A28;
        --surface-sunk: #14111B;

        --accent:       #B39BE0;
        --accent-strong:#C8B5EE;
        --accent-soft:  #271E3B;
        --accent-ink:   #DCD0F5;

        /* The accent is light here, so what sits on it must be dark. The bar stays
           dark in both themes: it is chrome, not state. */
        --on-accent:    #1B1130;
        --topbar:       #15111F;
        --topbar-ink:   #ECEAF3;

        --info:         #7BA7DE;
        --info-soft:    #142335;
        --ok:           #57BC8A;
        --ok-soft:      #10291E;
        --warn:         #D9A441;
        --warn-soft:    #2C2110;
        --danger:       #E88379;
        --danger-soft:  #331715;

        --e-1: 0 1px 2px rgba(0, 0, 0, .4);
        --e-2: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px -4px rgba(0, 0, 0, .5);
        --e-3: 0 2px 4px rgba(0, 0, 0, .4), 0 12px 32px -8px rgba(0, 0, 0, .65);
    }
}

/* The same palette, chosen rather than inherited.
   These declarations are a copy of the ones above, and they have to be: a media
   query cannot be a member of a selector list, so "the system asks for dark" and
   "a person asked for dark" cannot share one rule. ThemeTokensTest compares the
   two bodies and fails the build if they drift. */
:root[data-theme="dark"] {
    color-scheme: dark;

    --ink:          #ECEAF3;
    --ink-2:        #D1CDE0;
    --muted:        #A6A1B7;
    --muted-2:      #817C93;
    --line:         #2C2838;
    --line-strong:  #403A50;
    --bg:           #100E16;
    --surface:      #191621;
    --surface-2:    #1E1A28;
    --surface-sunk: #14111B;

    --accent:       #B39BE0;
    --accent-strong:#C8B5EE;
    --accent-soft:  #271E3B;
    --accent-ink:   #DCD0F5;

    /* The accent is light here, so what sits on it must be dark. The bar stays
       dark in both themes: it is chrome, not state. */
    --on-accent:    #1B1130;
    --topbar:       #15111F;
    --topbar-ink:   #ECEAF3;

    --info:         #7BA7DE;
    --info-soft:    #142335;
    --ok:           #57BC8A;
    --ok-soft:      #10291E;
    --warn:         #D9A441;
    --warn-soft:    #2C2110;
    --danger:       #E88379;
    --danger-soft:  #331715;

    --e-1: 0 1px 2px rgba(0, 0, 0, .4);
    --e-2: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px -4px rgba(0, 0, 0, .5);
    --e-3: 0 2px 4px rgba(0, 0, 0, .4), 0 12px 32px -8px rgba(0, 0, 0, .65);
}

/* Reset and base ---------------------------------------------------------- */

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

/* `display` rules below (buttons, flex children) would otherwise beat the
   hidden attribute, leaving "hidden" controls on screen. */
[hidden] { display: none !important; }

/*
 * The background belongs on the root element, not only on the body.
 *
 * A body background propagates to the canvas and looks identical — right up to
 * the moment the browser has to paint a frame without the body. Between two
 * navigations Chrome paints a base background it takes from the *root* element,
 * and a transparent root means white. This is the fix; the cross-document view
 * transition that used to sit at the foot of this file was not, and made it worse
 * by fading that white frame out over the new page — see the note down there.
 *
 * `color-scheme` is the other half of it and is already set on `:root` in both
 * palettes; the meta in `fragments/theme` carries it before this file has even
 * been parsed.
 */
html {
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    margin: 0 0 var(--s-8);
    font-family: var(--font);
    font-size: var(--t-md);
    line-height: 1.55;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.011em;
    text-wrap: balance;
}

h1 { font-size: var(--t-2xl); font-weight: 650; letter-spacing: -0.02em; }
h2 { font-size: var(--t-lg);  font-weight: 620; }
h3 { font-size: var(--t-md);  font-weight: 620; }

p { margin: 0 0 var(--s-3); }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

code, kbd, samp, .mono { font-family: var(--font-mono); font-size: 0.92em; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* Utilities --------------------------------------------------------------- */

.muted  { color: var(--muted); }
.small  { font-size: var(--t-sm); }
.tiny   { font-size: var(--t-xs); }
.nums   { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.stack   { display: flex; flex-direction: column; gap: var(--s-3); }
.row     { display: flex; align-items: center; gap: var(--s-3); }
.row--wrap { flex-wrap: wrap; }
.spacer  { flex: 1 1 auto; }

/* Top bar ----------------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    padding: var(--s-3) var(--s-5);
    background: var(--topbar);
    color: var(--topbar-ink);
    box-shadow: var(--e-2);
}

.topbar__title {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    font-weight: 650;
    font-size: var(--t-md);
    letter-spacing: -0.01em;
    color: var(--topbar-ink);
    text-decoration: none;
    /* A two-word name, so it never breaks across two lines: between 560px — where
       the title becomes the mark alone — and about 660px it did, and a two-row bar
       pushed the whole page down. Not shrinking is the other half of that: the nav
       beside it already wraps and drops its optional links when space runs out. */
    white-space: nowrap;
    flex: none;
}

.topbar__title::before {
    content: "";
    width: 0.5rem; height: 1.05rem;
    border-radius: 2px;
    background: linear-gradient(180deg, #C9B5F2, var(--accent));
}

/* `margin-left: auto` rather than the bar's `space-between`, which only splits two
   children evenly. The drawer's hamburger is a third, and with it the bar put the
   title in the middle of the page. */
.topbar__nav { display: flex; align-items: center; gap: var(--s-4); margin-left: auto; }

.topbar__nav a {
    color: var(--topbar-ink);
    font-size: var(--t-sm);
    text-decoration: none;
    opacity: .9;
    transition: opacity var(--dur-fast) var(--ease);
}
.topbar__nav a:hover { opacity: 1; color: var(--topbar-ink); text-decoration: underline; }

/* Appearance control.

   Three states rather than two, because "follow the system" is the honest default
   and a two-way switch cannot express it: somebody whose laptop turns dark at
   sunset should not have to come back here at sunset.

   Hidden without JavaScript. The control writes to localStorage and stamps the
   root element, so with scripting off it would be three buttons that do nothing —
   worse than no control at all. The boot script in the head sets `data-js` before
   first paint, so this appears with the page rather than jumping in after it.

   The bar is dark in both themes, so these can key off white regardless. */
.themer {
    display: none;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: var(--r-full);
    background: rgba(255, 255, 255, .10);
}
:root[data-js] .themer { display: inline-flex; }

.themer__opt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-radius: var(--r-full);
    background: transparent;
    color: var(--topbar-ink);
    /* .6 measured 4.17:1 against the bar — over the 3:1 an icon needs, under the
       4.5:1 everything else on this page clears. Cheap to just clear it. */
    opacity: .72;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease),
                opacity var(--dur-fast) var(--ease);
}
.themer__opt:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.themer__opt[aria-pressed="true"] { opacity: 1; background: rgba(255, 255, 255, .22); }
.themer__opt:focus-visible { outline: 2px solid var(--topbar-ink); outline-offset: 1px; }
.themer__opt svg { width: 15px; height: 15px; display: block; }

/* Shell and cards --------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
    margin: var(--s-5) auto;
    padding: var(--s-5);
    max-width: var(--shell);
}

.card--narrow { max-width: 720px; }
.card--flush  { padding: 0; overflow: hidden; }

.card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-4);
}

.card--error {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
    background: var(--surface);
}
/* The heading sat directly on the first problem box — h2 carries no margin of its
   own and the list carries none above it. */
.card--error > h2 { color: var(--danger); margin-bottom: var(--s-4); }

.card--collapsible { padding: 0; }
.card--collapsible > details > *:not(summary) { padding: 0 var(--s-5) var(--s-5); }

.card__summary {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-4) var(--s-5);
    cursor: pointer;
    list-style: none;
    border-radius: var(--r-lg);
    transition: background var(--dur-fast) var(--ease);
}
.card__summary::-webkit-details-marker { display: none; }
.card__summary:hover { background: var(--surface-2); }

.card__summary::before {
    content: "";
    width: 0.5rem; height: 0.5rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform var(--dur) var(--ease);
    flex: none;
}
details[open] > .card__summary::before { transform: rotate(45deg); }

/* Buttons ----------------------------------------------------------------- */

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: 0.5rem 0.9rem;
    font: inherit;
    font-size: var(--t-sm);
    font-weight: 560;
    line-height: 1.2;
    color: var(--on-accent);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--r-md);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease),
                transform var(--dur-fast) var(--ease);
}

button:hover, .button:hover { background: var(--accent-strong); color: var(--on-accent); }
button:active, .button:active { transform: translateY(1px); }

button:disabled, .button[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

.button--secondary {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
}
.button--secondary:hover { background: var(--surface-2); color: var(--ink); }

.button--danger { background: var(--danger); color: var(--on-accent); }
.button--danger:hover { background: color-mix(in srgb, var(--danger) 82%, #000); }

.button--link, .button--link-dark, .button--link-danger {
    background: none;
    border: none;
    padding: 0.25rem 0.35rem;
    color: var(--accent);
    font-weight: 550;
    text-decoration: none;
}
.button--link:hover { background: var(--accent-soft); color: var(--accent-strong); }
.button--link-dark { color: var(--ink-2); }
.button--link-dark:hover { background: var(--surface-sunk); color: var(--ink); }
.button--link-danger { color: var(--danger); }
.button--link-danger:hover { background: var(--danger-soft); color: var(--danger); }

/* The same box as the control it stands beside — same vertical padding, same line
   box, same border — because a helper that is three pixels shorter than its input
   reads as a mistake on every field it appears on. */
.button--lookup {
    padding: 0.5rem 0.65rem;
    line-height: 1.55;
    font-size: var(--t-sm);
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--line);
}
.button--lookup:hover { background: var(--accent-soft); color: var(--accent-ink); }

/* The topbar's sign-out sits inside a form; keep it looking like nav. */
.topbar .button--link { color: var(--topbar-ink); opacity: .9; }
.topbar .button--link:hover { background: rgba(255,255,255,.14); color: var(--topbar-ink); }

/* Action rows -------------------------------------------------------------

   Every action on the detail screen is its own POST — its own URL, its own
   confirm — so what looks like a row of buttons is really a row of forms. A form
   is block-level, and `.actions` had no rule at all, so they stacked one per line
   down the right of the card header and touched each other.
   ------------------------------------------------------------------------- */

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--s-2);
}

/* The wrapper is scaffolding for the POST; it should take the size of its button
   and contribute nothing else. */
.actions > form { margin: 0; display: inline-flex; }

/* Pills, tags, status ----------------------------------------------------- */

.pill, .tag, .status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.55rem;
    border-radius: var(--r-full);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    background: var(--surface-sunk);
    color: var(--muted);
    border: 1px solid transparent;
}

.pills { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.pill--ok,      .tag--success { background: var(--ok-soft);     color: var(--ok); }
.pill--error,   .tag--error   { background: var(--danger-soft); color: var(--danger); }
.pill--warn,    .pill--warning,
.tag--warning                 { background: var(--warn-soft);   color: var(--warn); }
.pill--info,    .tag--info    { background: var(--info-soft);   color: var(--info); }
.pill--muted                  { background: var(--surface-sunk); color: var(--muted-2); }

/* Two tones UiText has always been able to emit and the stylesheet never had.
   `status(ERROR)` is "Stopped" in tone `danger` and `status(READY_FOR_REVIEW)` is
   "Ready to check" in tone `accent`; both fell through to the bare pill, so the two
   states a reviewer most needs to pick out of a queue were the two rendered grey.
   PillToneTest keeps the two lists in step. */
.pill--danger                 { background: var(--danger-soft);  color: var(--danger); }
.pill--accent                 { background: var(--accent-soft);  color: var(--accent-ink); }

/* A dot that carries the state without relying on colour alone. */
.pill--dot::before {
    content: "";
    width: 0.4rem; height: 0.4rem;
    border-radius: var(--r-full);
    background: currentColor;
    flex: none;
}

/* Clearance status. Named per enum so the template can keep appending. */
.status { text-transform: lowercase; }
.status--DRAFT             { background: var(--surface-sunk); color: var(--muted); }
.status--PROCESSING,
.status--SUBMITTING        { background: var(--info-soft);   color: var(--info); }
.status--READY_FOR_REVIEW  { background: var(--accent-soft); color: var(--accent-ink); }
.status--FLAGGED           { background: var(--warn-soft);   color: var(--warn); }
.status--APPROVED,
.status--SUBMITTED         { background: var(--ok-soft);     color: var(--ok); }
.status--REJECTED,
.status--ERROR,
.status--SUBMISSION_ERROR  { background: var(--danger-soft); color: var(--danger); }

/* Alerts ------------------------------------------------------------------ */

.alert {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-size: var(--t-sm);
    margin: 0 0 var(--s-4);
}

/* The box's padding is the space around the text. A paragraph's own bottom margin
   is added to it and nothing balances it at the top, which left every alert's text
   sitting one step above centre. */
.alert p { margin: 0; }

/* The processing alert carries a note and, once the stream answers, a progress
   block under it. The default row would stand the bar beside the sentence. */
.alert--stack { flex-direction: column; align-items: stretch; }

.alert--success { background: var(--ok-soft);     border-color: color-mix(in srgb, var(--ok) 25%, transparent);     color: var(--ok); }
.alert--error   { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); color: var(--danger); }
.alert--warning { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 25%, transparent);   color: var(--warn); }
.alert--live    { background: var(--info-soft);   border-color: color-mix(in srgb, var(--info) 25%, transparent);   color: var(--info); }

/* Settings ---------------------------------------------------------------- */

.settings__head { margin-bottom: var(--s-4); }
.settings__head h1 { margin-bottom: var(--s-2); }

.setting-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

.setting {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-4);
}

.setting__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
}
.setting__label { margin: 0; font-size: 1.05rem; }
.setting__description { margin: var(--s-2) 0 0; }
.setting__source { margin: var(--s-2) 0 0; }
.setting__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-3);
    margin-top: var(--s-3);
}
.setting__actions form { margin: 0; }

/* Consignment profiles ---------------------------------------------------- */

.profiles__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
}
.profiles__head .settings__head { flex: 1 1 24rem; margin-bottom: 0; }
.setting__label a { color: inherit; text-decoration: none; }
.setting__label a:hover { color: var(--accent); }

/* The agent defaults: what every profile is laid over. Read, not edited. */
.profiles__agent { margin-top: var(--s-6); padding-top: var(--s-5); border-top: 1px solid var(--line); }
.profiles__agent h2 { margin: 0 0 var(--s-2); }

.profile-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0 var(--s-5);
    margin: var(--s-3) 0 0;
}
.profile-facts > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-2);
    min-width: 0;
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--line);
}
.profile-facts dt { font-size: var(--t-sm); color: var(--ink-2); }
.profile-facts dd { display: flex; align-items: baseline; gap: var(--s-2); margin: 0; white-space: nowrap; }
.profile-facts__list { margin: 0; padding-left: 1.1rem; color: var(--ink-2); }

.profile-editor { max-width: 960px; }
.profile-section { margin-top: var(--s-5); padding-top: var(--s-5); border-top: 1px solid var(--line); }
.profile-section h2 { margin: 0 0 var(--s-2); }
.profile-section__title { margin: var(--s-5) 0 var(--s-2); }

/* A checkbox and its sentence on one line. `label` is a block with a heavier weight
   for a field's name; this is an answer, so it reads as body text. */
.check { display: flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-2); font-weight: 450; }
.check input { flex: none; }
/* The name of a group of controls that has no single control to label. */
.field__label { display: block; margin-bottom: var(--s-1); font-size: var(--t-sm); font-weight: 560; }

/*
 * One default per row: the field, its value, how hard it applies, and the reason a
 * reviewer reads beside it. Four columns on a desk, because the four are read across
 * together — "port of discharge, WDH, always, because the lane runs to Windhoek".
 */
.default-rows {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    overflow: hidden;
}
.default-rows__head, .default-row {
    display: grid;
    grid-template-columns: minmax(9rem, 1fr) minmax(12rem, 1.5fr) 7.5rem minmax(10rem, 1.3fr);
    align-items: center;
    gap: var(--s-2) var(--s-3);
    padding: var(--s-2) var(--s-3);
}
.default-rows__head {
    font-size: var(--t-2xs);
    font-weight: 620;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-2);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
}
.default-row + .default-row { border-top: 1px solid var(--line); }
.default-row__label { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.default-row--error { background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface)); }
.default-row__error { grid-column: 1 / -1; margin: 0; font-size: var(--t-sm); color: var(--danger); }

/* Save stays in reach: the form is long, and the change is usually near the bottom. */
.profile-editor__actions {
    position: sticky;
    bottom: 0;
    margin-top: var(--s-5);
    padding: var(--s-3) 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

/* On a phone: the field, then its value across the row so a place name is readable,
   then "Always" beside the reason. */
@media (max-width: 720px) {
    .default-rows__head { display: none; }
    .default-row { grid-template-columns: 7.5rem minmax(0, 1fr); }
    .default-row__label, .default-row > :nth-child(2) { grid-column: 1 / -1; }
}

/* Live connection indicator ----------------------------------------------- */

.live {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: var(--t-xs);
    font-weight: 560;
    padding: 0.15rem 0.6rem;
    border-radius: var(--r-full);
    background: rgba(255, 255, 255, .16);
    color: var(--topbar-ink);

    /* Sized to the resting label, so the pill the page ships with and the "Live"
       it settles on occupy the same slot and nothing beside them moves.

       Every filter on the list is a fresh page load and so a fresh connection. The
       pill used to arrive saying "Connecting…" and become "Live" one frame later:
       measured off a screen recording, 108px to 54px, which shifted the whole nav
       row left and back inside 33 milliseconds on every single filter change.

       Deliberately not sized to the longest label. "Reconnecting…" and
       "Disconnected" do widen this, and should — they are exceptional, and a pill
       that changes size when the connection actually drops is telling the truth
       about something worth noticing. What had to stop was the routine case
       announcing itself. */
    min-width: 3.6rem;
}
.live::before {
    content: "";
    width: 0.45rem; height: 0.45rem;
    border-radius: var(--r-full);
    background: currentColor;
    flex: none;
}
.live--idle::before { opacity: .5; }
.live--live::before { background: #6EE7A8; animation: pulse 2s var(--ease) infinite; }
.live--down::before { background: #F5A3A3; }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .45; transform: scale(.82); }
}

/* Tables ------------------------------------------------------------------ */

table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }

thead th {
    text-align: left;
    font-size: var(--t-2xs);
    font-weight: 620;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-2);
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

tbody td {
    padding: var(--s-3);
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.row--muted td { color: var(--muted); }

.tablewrap { overflow-x: auto; border-radius: var(--r-md); }

/* Forms ------------------------------------------------------------------- */

label { display: block; font-size: var(--t-sm); font-weight: 560; margin-bottom: var(--s-1); }

input[type="text"], input[type="date"], input[type="number"],
input[type="password"], input[type="search"], select, textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    font: inherit;
    font-size: var(--t-sm);
    /* Stated rather than left to the browser, because a select does not resolve it
       the way an input does: the input takes the inherited line box and the select
       falls back to the user agent's `normal`, which is shorter. A date filter and
       a state filter standing in the same row came out 40.1px and 35px tall. */
    line-height: 1.55;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    transition: border-color var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease);
}

/*
 * The chevron, drawn rather than left to the browser.
 *
 * A native select's arrow is painted inside the control's own inset, which is not
 * the inset the date field's calendar button uses — so the two controls beside each
 * other in the filter row had their icons at visibly different distances from the
 * right edge. `appearance: none` is what makes that inset ours to set, and it takes
 * the arrow with it, so one has to be supplied.
 *
 * Two hard-stopped gradients, not an SVG. A data URI cannot carry `currentColor`,
 * so it would need one copy per theme and both dark blocks would have to hold it —
 * the second definition ThemeTokensTest exists to discourage. This follows the ink
 * colour on its own, in every theme, from one declaration.
 *
 * Each gradient is a 1.5px band across a 5px box: the first running "\", the second
 * "/", laid side by side to make the "v". The right one sits at the same 0.65rem as
 * the calendar button; the left one is one box further in. The right padding keeps a
 * long state name from running underneath them.
 */
/* Chrome gives the date field's inner field wrapper a padding of its own — 1px top
   and bottom — which made a date 2px taller than everything else on the row, and 2px
   taller than every plain text input in the application besides. Cleared here so one
   height covers the lot rather than the date field keeping a private one.

   The wrapper, not `::-webkit-datetime-edit` around it: measured, clearing the outer
   one changes nothing and only this one gives back the 2px. */
input[type="date"]::-webkit-datetime-edit-fields-wrapper { padding-top: 0; padding-bottom: 0; }

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 1.9rem;
    background-repeat: no-repeat;
    background-image:
        linear-gradient(45deg,  transparent 0 calc(50% - 0.75px), currentColor 0 calc(50% + 0.75px), transparent 0),
        linear-gradient(135deg, transparent 0 calc(50% - 0.75px), currentColor 0 calc(50% + 0.75px), transparent 0);
    background-size: 5px 5px;
    background-position: right calc(0.65rem + 5px) center, right 0.65rem center;
}

input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
    border-color: var(--muted-2);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 4.5rem; }

input[aria-invalid="true"], .input--missing {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger-soft) 55%, var(--surface));
}

fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); }
legend { font-size: var(--t-sm); font-weight: 560; padding: 0 var(--s-2); }

.field { margin-bottom: var(--s-4); min-width: 0; }
.field__control { display: flex; gap: var(--s-2); align-items: flex-start; }
.field__control > :first-child { flex: 1 1 auto; min-width: 0; }

/*
 * The lookup magnifier.
 *
 * A helper beside a field, not the page's action. It was a filled accent block with
 * an emoji in it: louder than the value it sits next to, and painted in whatever
 * colours the platform's emoji font ships rather than the theme's. Drawn in
 * `currentColor` and given the field's own border, it reads as part of the control
 * and follows light and dark without a second definition — the same reason the
 * select's chevron is drawn rather than supplied as a data URI.
 */
.field__lookup {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: var(--t-sm);
    /* Built from the parts the inputs are built from — 0.5rem of padding either
       side, a 1.55 line box and a 1px border — so the square is exactly a control
       tall rather than approximately one. */
    width:  calc(1.55em + 1rem + 2px);
    height: calc(1.55em + 1rem + 2px);
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
}
.field__lookup svg { width: 15px; height: 15px; display: block; }

/* The calendar button carries a native date input for showPicker() to open. It has to
   be rendered for that to work, so it is made invisible rather than display: none,
   and sits under the button so the picker opens beside it. */
.field__lookup[data-date-picker] { position: relative; }
.field__date-picker {
    position: absolute;
    inset: auto 0 0 auto;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

/* Save and the additional-fields toggle, on one row. */
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.field__lookup:hover:not(:disabled) {
    color: var(--accent);
    background: var(--surface-2);
    border-color: var(--accent);
}
.field__lookup:disabled { opacity: .45; }

/* The note under a control.
   A `p`'s own margin is nothing above and one step below, which puts a note nearer
   the label of the next question than the control it explains. Reversed here: tight
   to what it belongs to, and the gap between one question and the next is the
   field's to carry. */
.field__help {
    margin: var(--s-2) 0 0;
    font-size: var(--t-sm);
    color: var(--muted);
}
/* A note that says something could not be done — a rate SARS would not give. */
.field__help--error { color: var(--danger); }

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0 var(--s-4);
}
.field-grid--compact { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.required::after { content: " *"; color: var(--danger); }

.edit-form { margin: 0; }
.inline-form, .form--detached { display: inline; margin: 0; }

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    margin-bottom: var(--s-4);
}
.filters label { margin-bottom: var(--s-1); color: var(--muted); }
.filters__check { align-self: center; }
.filters__check label { display: flex; align-items: center; gap: var(--s-2); margin: 0; }
.filters__actions { display: flex; gap: var(--s-2); align-items: center; margin-left: auto; }

.intake-choice { display: flex; gap: var(--s-4); align-items: center; }
.intake-choice label { display: flex; align-items: center; gap: var(--s-2); margin: 0; }

/* Empty states ------------------------------------------------------------ */

.empty {
    padding: var(--s-7) var(--s-5);
    text-align: center;
    color: var(--muted);
    font-size: var(--t-sm);
}

/* Progress ---------------------------------------------------------------- */

.progress {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    font-size: var(--t-sm);
}
.progress__documents { font-weight: 560; }
.progress__time, .progress__note { color: var(--muted); }

/* A determinate bar, driven by --value (0–100). */
.meter {
    position: relative;
    height: 6px;
    border-radius: var(--r-full);
    background: var(--surface-sunk);
    overflow: hidden;
}
/* Registered so `--value` is a percentage the browser can interpolate rather than
   an unknown token it can only swap. Without this the scale below jumps. */
@property --value {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

.meter__fill {
    position: absolute; inset: 0 auto 0 0;
    width: 100%;
    /* Scaled rather than resized. This is the element that repaints most often on
       the whole application — once per page window, on every open queue row — and
       `width` puts each of those through layout. A transform does not. */
    transform: scaleX(var(--value, 0));
    transform-origin: left center;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), #47A9AE);
    transition: transform var(--dur-slow) var(--ease);
    will-change: transform;
}

/* Indeterminate: we know it is working, not how far along. */
.meter--busy .meter__fill {
    width: 35%;
    transform: none;
    animation: slide 1.4s var(--ease) infinite;
}
@keyframes slide {
    0%   { transform: translateX(-110%); }
    100% { transform: translateX(320%); }
}

.spinner {
    width: 1rem; height: 1rem;
    border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    border-radius: var(--r-full);
    animation: spin 700ms linear infinite;
    flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeletons, for content that is on its way. */
.skeleton {
    /* Mixed off the ink rather than painted with --surface-sunk. Sunk against a card
       is #101A1C on #141E20 in dark mode — a four-value difference, which is to say
       invisible: the first version rendered a row with nothing at all between the
       two party names. Mixing with the ink inverts with the theme by construction. */
    background: linear-gradient(90deg,
        var(--skeleton-base) 25%,
        var(--skeleton-sheen) 37%,
        var(--skeleton-base) 63%);
    background-size: 400% 100%;
    border-radius: var(--r-sm);
    animation: shimmer 1.4s ease-in-out infinite;
    color: transparent !important;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Stagger.

   Thirty-five fields shimmering in lockstep read as one big pulsing block rather
   than as many separate values arriving — the eye takes a synchronised pulse as a
   single object. Offsetting them turns it back into activity.

   Every delay is negative on purpose. A positive one leaves an element sitting
   static until its turn comes round, which looks like the animation failed to
   start; a negative one begins it part-way through, so everything is already
   moving on the first frame. The offsets are fractions of the 1.4s cycle.

   Keyed on position rather than set per element: the alternative is an index in
   the markup, and a template that counts its own fields to decorate them is a
   template doing the stylesheet's job. */

/* Two placeholders in the same line — an exporter and a consignee, or the bars of
   a pending block — should not move together. */
.skeleton ~ .skeleton { animation-delay: -0.35s; }
.skeleton ~ .skeleton ~ .skeleton { animation-delay: -0.70s; }

/* A form of them. Five buckets is enough: past that the eye stops reading it as a
   sequence and the extra rules buy nothing. */
.field-grid > .field:nth-child(5n + 2) .skeleton { animation-delay: -0.28s; }
.field-grid > .field:nth-child(5n + 3) .skeleton { animation-delay: -0.56s; }
.field-grid > .field:nth-child(5n + 4) .skeleton { animation-delay: -0.84s; }
.field-grid > .field:nth-child(5n + 5) .skeleton { animation-delay: -1.12s; }

/* And down a list of rows, where alternating is enough to break the block up. */
.queue__list > li:nth-child(even) .skeleton,
.results > .result:nth-child(even) .skeleton { animation-delay: -0.70s; }
.queue__list > li:nth-child(even) .skeleton ~ .skeleton,
.results > .result:nth-child(even) .skeleton ~ .skeleton { animation-delay: -1.05s; }

/* A skeleton standing in for one value rather than a whole block.
   Sized in `ch` so the shimmer is roughly as wide as the thing it stands for; the
   three widths exist so a column of them does not look like a table of identical
   bars, which reads as a rendering fault rather than as work in progress. */
.skeleton--line {
    display: inline-block;
    height: 0.85em;
    vertical-align: -0.1em;
}
.skeleton--sm { width: 7ch; }

/* A whole section on its way. */
.skeleton-block { display: flex; flex-direction: column; gap: var(--s-2); margin: var(--s-4) 0; }
.skeleton-block .skeleton--line { height: 0.9rem; }

/* An input whose value is still being read. The control keeps its border and its
   size — it is a field, not a gap — and only its interior says "coming".

   Both classes in the selector, deliberately. `input[type="text"]` sets a background
   colour and is more specific than a bare class, so `.skeleton` alone lost: the
   fields rendered with no shimmer at all and the only visible effect was the
   disabled control's own grey, which is what "locked" already looked like. */
.skeleton.skeleton--field {
    border-radius: var(--r-md);
    background-color: var(--skeleton-base);
    background-image: linear-gradient(90deg,
        var(--skeleton-base) 25%,
        var(--skeleton-sheen) 37%,
        var(--skeleton-base) 63%);
    background-size: 400% 100%;
}
.skeleton--md { width: 12ch; }
.skeleton--lg { width: 17ch; }

/* Dialogs ----------------------------------------------------------------- */

.dialog {
    width: min(560px, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--e-3);
}
.dialog--wide { width: min(820px, calc(100vw - 2rem)); }

/* A dialog and its backdrop, both ways.

   `dialog-in` alone animated the opening and let the closing snap, which reads as
   the dialog having been dismissed by something other than the button that was
   pressed. Doing it with transitions rather than a second keyframe needs three
   things that only recently became answerable in CSS: `display` and `overlay` have
   to be told to wait for the transition (`allow-discrete`), and the entry state has
   to come from `@starting-style`, because an element that has just been given
   `display: block` has no previous value to transition from. */
.dialog, .dialog::backdrop {
    transition: opacity var(--dur) var(--ease),
                transform var(--dur) var(--ease),
                display var(--dur) allow-discrete,
                overlay var(--dur) allow-discrete;
    opacity: 0;
}
.dialog { transform: translateY(6px) scale(.99); }
.dialog[open] { opacity: 1; transform: none; }
.dialog[open]::backdrop { opacity: 1; }

@starting-style {
    .dialog[open] { opacity: 0; transform: translateY(6px) scale(.99); }
    .dialog[open]::backdrop { opacity: 0; }
}

.dialog::backdrop { background: rgba(22, 17, 32, .45); backdrop-filter: blur(2px); }

.dialog__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--line);
}
.dialog form, .dialog > div:not(.dialog__head):not(.dialog__actions) { padding: var(--s-4) var(--s-5); }

/* The children that are neither a div nor a form — the search label, the hint, the
   result list, the empty note — matched nothing above and so were inset by nothing.
   The search input ran border to border and the hint under it started to the left of
   the heading above it. Margin rather than padding on the list, so the scrollbar
   stays inside the inset instead of riding the dialog's edge. */
.dialog > .tariff-search { margin: var(--s-4) var(--s-5) 0; }
.dialog > p  { margin-left: var(--s-5); margin-right: var(--s-5); }
.dialog > ul { margin-left: var(--s-5); margin-right: var(--s-5); margin-bottom: var(--s-4); }
/* A label and a control written straight into a dialog — "What are these goods?" and
   its box in the tariff lookup — are the only children this list did not cover, and
   they ran to both edges while the prose above them was inset. The width is stated
   because a full-width control with side margins overflows by exactly those margins. */
.dialog > label, .dialog > input { margin-left: var(--s-5); margin-right: var(--s-5); }
.dialog > input { width: calc(100% - 2 * var(--s-5)); }

/* A count belongs at the far end from the buttons rather than crowded against them. */
.dialog__actions > span:first-child { margin-right: auto; }
.dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-5);
    border-top: 1px solid var(--line);
    background: var(--surface-2);
}

/* Road manifest ledger ---------------------------------------------------- */

/* The claim button beside the manifest box. Wraps under the box on a phone rather
   than squeezing it to a few characters of a fifteen-character number. Stretched to
   the box's height: `.field__control` aligns to the top, and a button's 1.2 line box
   left it a few pixels short of an input's 1.55 beside it. */
.field__control--wrap { flex-wrap: wrap; align-items: stretch; }
.field__control--wrap > :first-child { flex-basis: 14rem; }

.ledger { display: flex; flex-direction: column; gap: var(--s-5); }
.ledger > .alert { margin: 0; }
.ledger__section { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.ledger__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2) var(--s-3);
}
.ledger__head h3 { margin: 0; }

.ledger-day { display: flex; align-items: center; gap: var(--s-1); }
.ledger-day__input { width: auto; }

.ledger-list {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    max-height: 30vh;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}
.ledger-empty { margin: 0; }

/*
 * One line of the book: the number, who and when, the clearances on it, and the one
 * thing that can be done with it. Named areas so a phone can put the button beside
 * the number and the rest underneath, instead of four columns fighting for 340px.
 */
.ledger-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "number meta count action";
    align-items: center;
    gap: var(--s-1) var(--s-3);
    padding: var(--s-2) var(--s-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
}
.ledger-row > button { grid-area: action; }

/* The number already in the intake box, so reopening the ledger shows where the
   agent is rather than a list with nothing to say which line is theirs. */
.ledger-row--current { border-color: var(--accent); background: var(--accent-soft); }

/* The second press. The ring is the selected-row ring the lookup dialogs use. */
.ledger-row--confirm {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "number" "confirm";
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.ledger-row__number {
    grid-area: number;
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--accent-ink);
}
.ledger-row__meta { grid-area: meta; min-width: 0; overflow-wrap: anywhere; }
.ledger-row__meta:empty { display: none; }
.ledger-row__count { grid-area: count; white-space: nowrap; }

.ledger-confirm { grid-area: confirm; display: flex; flex-direction: column; gap: var(--s-3); }
.ledger-confirm p { margin: 0; color: var(--ink-2); }
.ledger-confirm__note { margin: 0; }
.ledger-confirm__note input { margin-top: var(--s-1); }
.ledger-confirm__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); }

.ledger-book { border-top: 1px solid var(--line); padding-top: var(--s-4); }
.ledger-book summary { cursor: pointer; font-size: var(--t-sm); font-weight: 560; color: var(--ink-2); }
.ledger-book__body { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-3); }
.ledger-book__body p { margin: 0; }
.ledger-book__fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); }
.ledger-book__fields label { flex: 1 1 12rem; margin: 0; }
.ledger-book__fields input { margin-top: var(--s-1); }

@media (max-width: 560px) {
    /* The dialog already scrolls at this width. A list scrolling inside it is two
       scrollbars for one thumb, and a row half-hidden behind the second. */
    .ledger-list { max-height: none; overflow: visible; }
    /* No row gap, so an unclaimed number's empty meta and count rows take no room;
       the lines that do have text carry their own space. */
    .ledger-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "number action" "meta meta" "count count";
        row-gap: 0;
    }
    .ledger-row__meta, .ledger-row__count { margin-top: var(--s-1); }
    .ledger-row--confirm {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "number" "confirm";
    }
}

/* Toasts ------------------------------------------------------------------ */

.toasts {
    position: fixed;
    right: var(--s-4);
    bottom: var(--s-4);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-width: 240px;
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    background: var(--ink);
    color: var(--surface);
    font-size: var(--t-sm);
    box-shadow: var(--e-3);
    pointer-events: auto;
    animation: toast-in var(--dur) var(--ease);
}
.toast--ok    { background: var(--ok); color: #fff; }
.toast--error { background: var(--danger); color: #fff; }
.toast--leaving { animation: toast-out var(--dur) var(--ease) forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* Stages ------------------------------------------------------------------ */

.stage { padding: 0; }

.stage__strip {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.stage__title { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.stage__rerun { margin-left: auto; }
.stage > *:not(.stage__strip) { padding-left: var(--s-5); padding-right: var(--s-5); }
.stage > *:last-child { padding-bottom: var(--s-5); }

.stage__flags { display: flex; flex-direction: column; gap: var(--s-1); padding-top: var(--s-3); }
.stage__invoice { padding-top: var(--s-4); }
/* The invoice's own heading sat directly on the first line's card. */
.stage__invoice > h3 { margin-bottom: var(--s-3); }

.field-flag { margin: 0; }

/* A flag under a field had no tone at all: `field-flag--` + the severity was being
   written onto every one of them and matched nothing, so INFO, WARNING and ERROR
   read identically. Named in upper case to match the severity enum, which is the
   convention the status pills already follow. */
.field-flag--INFO    { color: var(--info); }
.field-flag--WARNING { color: var(--warn); }
.field-flag--ERROR   { color: var(--danger); }
.flag-link {
    display: inline-flex;
    align-items: flex-start;
    gap: var(--s-2);
    padding: 0.3rem 0.5rem;
    background: var(--warn-soft);
    color: var(--warn);
    border: none;
    border-radius: var(--r-sm);
    font-size: var(--t-sm);
    font-weight: 500;
    text-align: left;
    white-space: normal;
    cursor: pointer;
}
.flag-link:hover { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.flag-decision { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.flag-decision__code { width: 9.5em; padding: 2px 6px; font: inherit; }

/* A question put as a recommendation: the answer declared, then the others considered. */
.recommend { min-width: 16em; max-width: 34em; margin-bottom: 6px; }
.recommend__answer { padding: 8px 10px; border: 1px solid var(--line, #d8dde3); border-left: 3px solid var(--ok, #2f7d4f); border-radius: 4px; }
.recommend__label { display: block; font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted, #5b6672); }
.recommend__value { display: block; overflow-wrap: anywhere; }
.recommend__source { display: block; font-size: 0.82rem; color: var(--muted, #5b6672); }
.recommend__why { margin: 4px 0 6px; font-size: 0.82rem; overflow-wrap: anywhere; }
.recommend__accept { padding: 4px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.recommend__others { margin-top: 6px; font-size: 0.9rem; }
.recommend__others summary { cursor: pointer; }
.recommend__others ul { list-style: none; margin: 6px 0 0; padding: 0; }
.recommend__others li { padding: 6px 10px; border: 1px solid var(--line, #d8dde3); border-radius: 4px; margin-bottom: 6px; }

/* Line items -------------------------------------------------------------- */

.line {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-4);
    margin-bottom: var(--s-3);
    background: var(--surface);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.line:hover { border-color: var(--line-strong); box-shadow: var(--e-1); }
.line__header { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.line__actions { display: flex; gap: var(--s-2); align-items: center; margin-left: auto; }
.line__why { margin-top: var(--s-2); }

.line-grouping { color: var(--muted); }

/* The entry's own lines, beside the rows they were built from.
   Sticky, because it is a reference while a reviewer works down forty editable
   rows; its own scrollbar, because an invoice can carry more lines than a screen
   holds.

   Measured against the space this section actually has rather than the window's
   width: the document pane beside it opens and closes, and a window wide enough
   for two columns is not the same question as this column being wide enough for
   them. Narrower than that, it is an ordinary block above the rows — the reading
   order it had when it was a table across the top. */
.stage__invoice { container-type: inline-size; }
.lines-layout__lines { min-width: 0; }
.declared { margin-bottom: var(--s-3); }

/* No grip until there are two columns to divide. */
.lines-layout__grip { display: none; }

@container (min-width: 46rem) {
    .lines-layout {
        display: grid;
        /* The reviewer's own width, kept in their browser by lines-resize.js, with
           the rail's original width as the fallback and a floor so it cannot be
           dragged into a sliver. */
        grid-template-columns: minmax(0, 1fr) auto minmax(11rem, var(--rail-width, 21rem));
        gap: var(--s-3);
        align-items: start;
    }
    .lines-layout__grip {
        display: block;
        align-self: stretch;
        width: 7px;
        min-height: 3rem;
        border-radius: var(--r-sm);
        background: var(--line);
        cursor: col-resize;
        touch-action: none;
    }
    .lines-layout__grip:hover,
    .lines-layout__grip:focus-visible,
    .lines-layout__grip[data-dragging] { background: var(--accent); }
    .declared {
        position: sticky;
        top: var(--s-4);
        max-height: calc(100vh - 6rem);
        overflow: auto;
        margin-bottom: 0;
    }
}

.declared {
    /* The table scrolls inside the rail rather than pushing the page sideways: on a
       narrow screen its five columns want more width than the column it sits in. */
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-sunk);
    /* No side padding on the panel: the selected row is painted edge to edge, and a
       row that stops short of the panel's own edge reads as a box inside a box. The
       inset moves onto the things inside it, so the text still lines up. */
    padding: var(--s-3) 0;
}
.declared__head, .declared > p, .declared__add { padding-left: var(--s-3); padding-right: var(--s-3); }
.declared__table th:first-child, .declared__table td:first-child { padding-left: var(--s-3); }
.declared__table th:last-child, .declared__table td:last-child { padding-right: var(--s-3); }
/* Figures line up under one another and read as a column of money. */
.num { text-align: right; font-variant-numeric: tabular-nums; }

.declared__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); }
.declared__head h4 { margin: 0; }
/* Shares of the rail rather than fixed rem, because the rail is a share of the
   section and the section is a share of a window with a document pane that opens
   and closes. Fixed widths that fit at one width spill into the next column at
   another, which is what "DESCRIPTION" over "ORIGIN" was. */
.declared__table { font-size: var(--t-sm); width: 100%; table-layout: fixed; }
.declared__table th, .declared__table td {
    vertical-align: top;
    padding-left: 0;
    padding-right: var(--s-1);
    overflow-wrap: anywhere;
}
/* The headings wrap rather than clip: "Description" over two lines still reads,
   and "Descr." does not. */
/* Centred over their columns: five short words across a narrow panel read as a
   row of labels this way, where left-aligned they drift away from the figures
   under them. The values keep their own alignment — text left, money right. */
.declared__table th { font-size: var(--t-xs); letter-spacing: .04em; white-space: normal; text-align: center; }
.declared__table th:nth-child(1), .declared__table td:nth-child(1) { width: 7%; }
.declared__table th:nth-child(2), .declared__table td:nth-child(2) { width: 28%; }
.declared__table th:nth-child(3), .declared__table td:nth-child(3) { width: 14%; }
.declared__table th:nth-child(4), .declared__table td:nth-child(4) { width: 25%; }
.declared__table th:nth-child(5), .declared__table td:nth-child(5) { width: 20%; }
.declared__table th:nth-child(6), .declared__table td:nth-child(6) { width: 6%; }
/* A code and a figure are read as one thing, so they never break across lines. */
.declared__table code, .declared__table .num { white-space: nowrap; }
.declared__what { overflow-wrap: anywhere; }

/* The row is how a line is opened, so it behaves like one thing rather than a
   number that happens to be a link. */
.declared__table tbody tr { cursor: pointer; }
.declared__table tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.declared__table tbody tr.is-open { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.declared__table tbody tr.is-open .declared__no a { color: var(--ink); font-weight: 600; }

.declared__state { text-align: center; }
.declared__mark { font-weight: 700; line-height: 1; }
.declared__mark--problem { color: var(--warn); }
.declared__mark--checked { color: var(--ok); }

.declared__add { margin-top: var(--s-3); }
.declared__add button { width: 100%; }
.declared__table code { font-size: inherit; }
.declared__no a { display: inline-block; color: var(--muted); text-decoration: none; }
.declared__no a:hover { color: var(--accent); text-decoration: underline; }
/* Two lines of description and then an ellipsis: the full text is on the row's
   own title, and the point of this column is which line, not the wording. */
.declared__what span:first-child {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}


/* Provenance and evidence ------------------------------------------------- */

/*
 * Where a value came from, and the way to say it was read wrong.
 *
 * One quiet line. This was a 13px semibold sentence, then a link button carrying a
 * button's padding, then a disclosure — three lines of chrome under every field, on
 * a form with twenty of them. The information is worth keeping and was never worth
 * that much of the page, so the whole row now sits at the smallest size in the scale
 * and in the muted colour, and the eye passes over it until it is wanted.
 */
.provenance {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--s-1) var(--s-3);
    margin-top: var(--s-2);
    font-size: var(--t-xs);
    color: var(--muted);
}
.provenance__chosen { font-weight: 500; color: var(--muted); }

/* An action, so it stays findable and keyboard-reachable rather than being revealed
   on hover — a reviewer on a touch screen has no hover to give it. Quiet instead. */
.provenance__wrong {
    padding: 0;
    font-size: var(--t-xs);
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: none;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: color-mix(in srgb, var(--muted) 45%, transparent);
}
.provenance__wrong:hover {
    color: var(--accent);
    background: none;
    text-decoration-color: currentColor;
}

/* Its own line, so opening it never reflows the row above it. */
.provenance__more { flex: 1 0 100%; }
.provenance__more summary { cursor: pointer; }
.provenance__more ul { margin: var(--s-2) 0 0; padding-left: var(--s-4); }

.snippet {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    background: var(--surface-sunk);
    border-radius: var(--r-sm);
    padding: var(--s-2) var(--s-3);
    color: var(--muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* The confidence bar. Green while the answer stands on its own, amber once the
   server says it does not — the same two states the sentence beside it names, in a
   form that also carries how far from the line it fell. */
.classify__meter { margin: var(--s-2) 0 var(--s-3); }
.meter--low .meter__fill { background: var(--warn); }

/*
 * The classification panel, laid out the way the browser extension lays out the
 * same answer.
 *
 * Every part of this existed and none of it had been spaced: the sections ran into
 * each other, the summaries were the browser's own, and the General Rules reasoning
 * was a bare `dl` — a term, then the user agent's 40px indent, then the text, six
 * times over. That is the machine's working shown to the person deciding whether to
 * agree with it.
 */
.classify {
    font-size: var(--t-sm);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    margin-top: var(--s-4);
    padding-top: var(--s-4);
    border-top: 1px solid var(--line);
}

/* The head's own rhythm rather than a margin on the block below it: the panel is a
   flex column now and owns the gaps between its parts. */
.classify__head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s-2);
}
.classify > * { margin: 0; }
/* The same code, in the same face and weight as a search result's — it is the
   answer to the same question, arrived at a different way. */
.classify__code {
    font-family: var(--font-mono);
    font-size: var(--t-lg);
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--accent-ink);
}
.classify__confidence { color: var(--muted); }
.classify__description { color: var(--ink-2); line-height: 1.45; }
.classify__list { margin: 0; padding-left: var(--s-4); display: flex; flex-direction: column; gap: var(--s-1); }

/*
 * A foldable section: the extension's `reveal`.
 *
 * A rule above it and a quiet upper-case summary, so four of them in a column read
 * as four sections rather than as four sentences. The marker is drawn rather than
 * typed — a `▸` in the content is a character that inherits the summary's letter
 * spacing and sits on its baseline, which is why it looked like punctuation.
 */
.classify__block {
    margin: 0;
    border-top: 1px solid var(--line);
    padding-top: var(--s-3);
}
.classify__block > summary {
    cursor: pointer;
    font-size: var(--t-xs);
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--s-2);
}
.classify__block > summary::-webkit-details-marker { display: none; }
.classify__block > summary::before {
    content: "";
    flex: none;
    width: 0; height: 0;
    border-left: 4px solid currentColor;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transition: transform var(--dur-fast) var(--ease);
}
.classify__block[open] > summary::before { transform: rotate(90deg); }
.classify__block > summary:hover { color: var(--ink-2); }
.classify__block[open] > summary { margin-bottom: var(--s-3); }

/* The section's own text, indented to the summary's words rather than to its
   marker, so a fold reads as belonging to the heading above it. */
.classify__block > :not(summary) { margin-left: calc(var(--s-2) + 4px); }

/*
 * The General Rules working, as banded rows.
 *
 * A `dl` renders as a term and then an indented definition, which for six rows of
 * reasoning is a column of orphaned headings. Banded key/value pairs are what the
 * extension uses and what this actually is. The bands come from `nth-child(4n)`
 * over the flat `dt, dd, dt, dd` sequence — a grid has no rows to stripe.
 */
.classify__reasoning {
    display: grid;
    grid-template-columns: minmax(8rem, max-content) 1fr;
    gap: 0;
    margin: 0;
    border-radius: var(--r-md);
    overflow: hidden;
    font-size: var(--t-xs);
}
.classify__reasoning > * { margin: 0; padding: var(--s-2) var(--s-3); }
.classify__reasoning > :nth-child(4n + 1),
.classify__reasoning > :nth-child(4n + 2) { background: var(--surface-sunk); }
.classify__reasoning > dt { color: var(--muted); }
.classify__reasoning > dd { color: var(--ink-2); overflow-wrap: anywhere; }

/* The note above the rulings, and the one that says they are being translated. */
.classify__block > p.muted { margin: 0 0 var(--s-2); line-height: 1.45; }
.classify__detail { margin-top: var(--s-2); }

/* The shortlist an undecided answer was choosing between. Chips that are a reading
   of the evidence rather than links, so they take the chip's shape without its
   pointer or its hover. */
.classify--undecided { display: flex; flex-direction: column; gap: var(--s-2); }
.classify__label {
    margin: 0 0 var(--s-1);
    font-size: var(--t-xs);
    font-weight: 600;
    color: var(--muted);
}
.chips--static .chip { cursor: default; }
.chips--static .chip:hover { background: var(--surface-sunk); border-color: var(--line); color: inherit; }

/* Where the product information came from. Links, because the whole value of a
   source is going and reading it — they were rendered as `title — url`, which is a
   URL somebody has to select and paste. */
.sources { list-style: none; margin: var(--s-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-1); }
.sources a { font-size: var(--t-xs); overflow-wrap: anywhere; }

/* Binding rulings -----------------------------------------------------------

   One card per EU ruling, brought across from the browser extension's `.mini`.
   They were a bullet list of one joined string each — `8708.30 · DE · REF (de) —
   description` — which is the whole of the evidence for a classification rendered
   as a run-on line, in German, on a screen where somebody is deciding whether to
   agree with the machine.
   -------------------------------------------------------------------------- */

.minis { list-style: none; margin: var(--s-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }

.mini {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-3);
    background: var(--surface-2);
    font-size: var(--t-xs);
    line-height: 1.45;
}

.mini__top {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-bottom: var(--s-1);
}

.mini__ref {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--ink);
}

/* Pushed to the end of the row, so "show original" sits where the eye already
   goes for a control rather than trailing the country. */
.mini__original { margin-left: auto; flex: none; font-size: var(--t-2xs); font-weight: 500; }

.mini__extra { margin-top: var(--s-1); color: var(--muted); }

/* The original, when somebody asks for it. Set apart so it is never mistaken for
   the translation sitting above it — a machine's reading of the evidence and the
   evidence itself must not look alike. */
.mini__source {
    margin-top: var(--s-2);
    padding-top: var(--s-2);
    border-top: 1px dashed var(--line-strong);
    color: var(--muted);
}

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

.tariff-search { display: flex; gap: var(--s-2); }
.tariff-results, .code-results, .client-results {
    max-height: 46vh;
    overflow-y: auto;
    margin-top: var(--s-3);
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    /* Blockifying a list item does not remove its marker, so `display: flex` on the
       list left a bullet beside every result, sitting in the 40px the user agent
       indents a list by. */
    list-style: none;
    padding: 0;
}
/*
 * One result, as the browser extension draws one.
 *
 * The extension's panel and this dialog answer the same question against the same
 * tariff book, and they looked like two products. They share the palette already —
 * `extension/src/css/panel.css` copies the token block and `ExtensionTokenParityTest`
 * fails the build if the two drift — but every component below the tokens was
 * written twice, and only one of them was designed. This is the extension's `.result`
 * brought across: a card, its parts stacked with air between them, rather than one
 * line of run-together text.
 *
 * Hover is a raised edge, not a fill. It was the accent border and the accent-soft
 * background, which is exactly what `is-selected` uses — so the row under the mouse
 * and the row the keyboard had landed on were indistinguishable, and the apply button
 * would act on the one that was not glowing.
 */
.tariff-result, .code-result, .client-result {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    padding: var(--s-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease),
                background var(--dur-fast) var(--ease);
}
.tariff-result:hover, .code-result:hover, .client-result:hover {
    border-color: var(--line-strong);
    box-shadow: var(--e-1);
}

/* The code, at the size the thing being chosen deserves. It was body weight beside
   the description, so the row read as a sentence with a number in it rather than as
   a code with its description underneath. */
.tariff-result__head { display: flex; align-items: center; gap: var(--s-2); }
.tariff-result__code {
    font-family: var(--font-mono);
    font-size: var(--t-lg);
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--accent-ink);
}

/* The statistical unit, as a pill at the end of the head row: it is a fact about the
   code rather than part of its description, and `kg` set as muted body text beside a
   sentence disappears into it. */
.tariff-result__unit {
    margin-left: auto;
    flex: none;
    padding: 2px var(--s-2);
    border-radius: var(--r-full);
    border: 1px solid var(--line);
    background: var(--surface-sunk);
    font-size: var(--t-2xs);
    color: var(--muted);
}

.tariff-result__description {
    font-size: var(--t-sm);
    color: var(--ink-2);
    line-height: 1.45;
}

/* Where the code sits in the book. Two steps below the description on purpose —
   it runs to three or four lines on a deep heading and was competing with it. */
.tariff-result__ancestry {
    font-size: var(--t-2xs);
    color: var(--muted);
    line-height: 1.4;
}

.code-result__note, .client-result__address {
    font-size: var(--t-xs); color: var(--muted);
}

/*
 * A place or CPC row: code, name, then what kind of thing it is.
 *
 * The three were bare siblings with no rule between them, so `UTN`, `Upington` and
 * `city · za` ran together as `UTNUpingtoncity · za` — and the monospace went on the
 * name, which is prose, rather than on the code, which is the part being chosen.
 */
.code-result { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-1) var(--s-3); }
.code-result__code {
    flex: none;
    min-width: 4.5ch;
    font-family: var(--font-mono);
    font-weight: 620;
    color: var(--accent-ink);
}
.code-result strong { font-weight: 560; }
.code-result__note { margin-left: auto; }
.code-result__duty, .code-result__common {
    font-size: var(--t-xs);
    background: var(--surface-sunk);
    border-radius: var(--r-sm);
    padding: 0.1rem 0.4rem;
}
.code-result__common { color: var(--accent-ink); background: var(--accent-soft); }
/* Copy the digits. Small and quiet at the end of the head row: it is the second
   thing anybody does with a result, behind choosing it. */
.tariff-result__copy {
    flex: none;
    padding: 2px var(--s-2);
    font-size: var(--t-2xs);
    border-radius: var(--r-full);
}

/* A row on its way. No pointer and no hover, because there is nothing under it to
   choose yet — a placeholder that lights up when the mouse crosses it is claiming
   to be a result. */
.tariff-result--loading { cursor: default; }
.tariff-result--loading:hover { border-color: var(--line); box-shadow: none; }

/* The bars inside one, at the sizes the extension uses: a code, then two lines of
   description at different lengths so the block reads as text rather than as a
   rendering fault. */
.skeleton--code { height: 18px; width: 96px; }
.skeleton--wide { width: 100%; }
.skeleton--mid  { width: 72%; }

.tariff-result__rates { display: flex; flex-wrap: wrap; gap: var(--s-1); }

/*
 * A duty rate, as the extension draws one.
 *
 * The two spans inside had nothing between them and no rule to separate them, so
 * every rate rendered as one word: `General15%`, `SADCfree`, `EU / UK9%`. Six of
 * them in a row, and the reviewer is reading duty rates off a declaration screen.
 * The gap is the fix; the rest is the extension's chip — a full radius, its own
 * border, the regime upper-cased and spaced so the eye separates label from figure
 * before it reads either, and the figure in the mono face every other number on
 * this screen uses.
 */
.rate {
    display: inline-flex;
    align-items: baseline;
    gap: var(--s-1);
    padding: 2px var(--s-2);
    border-radius: var(--r-full);
    background: var(--surface-sunk);
    border: 1px solid var(--line);
    font-size: var(--t-2xs);
}
.rate__name {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}
.rate__value { font-family: var(--font-mono); color: var(--ink); }
/*
 * The short code follows the name in the markup with nothing between the two, so
 * they read as one word — "INDUSTRIAL POWER" and the code "INDUSTRIAL" came out as
 * `INDUSTRIAL POWERINDUSTRIAL`, which is not a company anyone can recognise. Same
 * fault one line down, where `Customs 00498414` and `VAT 4210258465` ran together.
 */
.client-result__short {
    margin-left: var(--s-2);
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 500;
    color: var(--muted);
}

.client-result__codes {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1) var(--s-3);
    margin: var(--s-2) 0 0;
    font-size: var(--t-xs);
    font-family: var(--font-mono);
    color: var(--muted);
}
.client-result__warn { color: var(--warn); }

/* The address is stored with its line breaks and client-lookup.js sets it as
   textContent specifically so they survive without markup from the data reaching the
   page. It says a CSS rule keeps them; there was no such rule, so all four lines ran
   together into one. */
.client-result__address { white-space: pre-line; margin: var(--s-1) 0 0; }
.tariff-empty { color: var(--muted); padding: var(--s-4); text-align: center; }
.suggestions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }

/* States the scripts set ---------------------------------------------------

   Every class below was already being added by JavaScript and matched no rule, so
   the behaviour ran and showed nothing. They are grouped here because they share
   that history rather than a place on the page.
   ------------------------------------------------------------------------- */

/*
 * Which row the arrow keys or a click have landed on, in all three lookup dialogs.
 *
 * Without it the dialogs were unusable by keyboard and misleading by mouse: the
 * apply button enabled itself and nothing on screen said what would be applied. The
 * inset ring is what separates "selected" from ":hover", which already takes the
 * accent border and the soft background.
 */
.tariff-result.is-selected,
.code-result--selected,
.client-result--selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}

/*
 * Where a jump landed.
 *
 * live.js scrolls the field into view, forces a reflow to restart the animation and
 * removes the class after 1800ms — all of which worked, invisibly. A ring rather
 * than a background so nothing moves, and it fades rather than blinking.
 */
@keyframes field-focus {
    0%   { box-shadow: 0 0 0 0   color-mix(in srgb, var(--accent) 60%, transparent); }
    15%  { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 28%, transparent); }
    100% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent)  0%, transparent); }
}
.field-focus {
    border-radius: var(--r-md);
    animation: field-focus 1.8s var(--ease);
}

/*
 * An edit that was carried across a reload while the server's value moved too.
 *
 * This is the one state here that a reviewer must not miss: their value is in the
 * box, and it is no longer based on what the server now holds. Warn rather than
 * danger — nothing is broken, but it wants a decision.
 */
.input--conflict {
    border-color: var(--warn);
    background: color-mix(in srgb, var(--warn-soft) 55%, var(--surface));
}

/* Filled from the client register rather than read off a document, so the reviewer
   can see which boxes the lookup just wrote. */
.input--from-master {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line-strong));
    background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}

/* The card a feedback report is about, so "the Frame lines card" is not something
   the reviewer has to go and find. */
.feedback-linked {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent);
    border-radius: var(--r-lg);
}

/* Documents --------------------------------------------------------------- */

.add-documents { margin-top: var(--s-4); }
.add-documents__note { color: var(--muted); font-size: var(--t-sm); }
.doc__type-note { color: var(--muted); font-size: var(--t-xs); }

/* Feedback ---------------------------------------------------------------- */

.feedback-launcher {
    position: fixed;
    right: var(--s-4);
    bottom: var(--s-4);
    z-index: 50;
    border-radius: var(--r-full);
    box-shadow: var(--e-2);
}
/* The body between the head and the actions.

   Its left and right padding comes from the shared `.dialog > div` rule, which is
   the point of wrapping it: the heading and the two questions used to be bare
   children of the dialog, and `h2` and `label` are not in the list of element types
   that rule pads. One column with one gap owns the vertical rhythm, so the parts
   below can stop carrying margins that had to be kept in step by hand. */
.feedback__body { display: flex; flex-direction: column; gap: var(--s-4); }

/* Each question reads as a label above its control rather than a line of text with
   a box after it. */
.feedback__body > label { display: flex; flex-direction: column; gap: var(--s-2); }

.feedback__choices { display: flex; flex-wrap: wrap; gap: var(--s-4); }
.feedback__choices label { display: flex; align-items: center; gap: var(--s-2); }
.feedback__selection { font-size: var(--t-sm); color: var(--muted); }
.feedback__corrected { margin: 0; }
.feedback__link { font-size: var(--t-xs); margin: 0; }
.feedback__sent { color: var(--ok); }

/* Responsive -------------------------------------------------------------- */

@media (max-width: 900px) {
    .card { margin: var(--s-4) var(--s-3); padding: var(--s-4); border-radius: var(--r-md); }
    .card__header { flex-direction: column; align-items: stretch; }
    .filters__actions { margin-left: 0; width: 100%; }
    .stage__strip { flex-wrap: wrap; }
    .stage__rerun { margin-left: 0; }
    .topbar { padding: var(--s-3) var(--s-4); }
    .topbar__nav { gap: var(--s-3); }
}

@media (max-width: 640px) {
    body { font-size: var(--t-sm); }
    h1 { font-size: var(--t-xl); }
    .field-grid { grid-template-columns: 1fr; }
    .toasts { left: var(--s-3); right: var(--s-3); }
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dashboard ---------------------------------------------------------------
   The queue screen. Everything here is about scanning: the eye should land on
   the band, then the state, then the file, and stop as soon as it has found the
   row it wants. Nothing competes with that. */

.board { max-width: var(--shell); margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-8); }

.board__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-5);
}
.board__head h1 { font-size: var(--t-3xl); }
.board__subtitle { margin: var(--s-1) 0 0; }
.board__settled { margin-top: var(--s-5); text-align: center; }

/* Stat tiles */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--s-3);
    margin-bottom: var(--s-6);
}

.stat {
    display: flex;
    flex-direction: column;
    gap: var(--s-1);
    padding: var(--s-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
    text-decoration: none;
    color: var(--ink);
    position: relative;
    overflow: hidden;
    transition: transform var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease),
                border-color var(--dur) var(--ease);
}
.stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--e-2);
    border-color: var(--line-strong);
    color: var(--ink);
}

/* A colour rail rather than a coloured tile: the number stays legible and the
   state is still readable at a glance from across a desk. */
.stat::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--muted-2);
}
.stat--attention::before { background: var(--warn); }
.stat--working::before   { background: var(--info); }
.stat--ready::before     { background: var(--ok); }
.stat--settled::before   { background: var(--muted-2); }

.stat__value {
    font-size: var(--t-3xl);
    font-weight: 660;
    line-height: 1;
    letter-spacing: -0.03em;
}
.stat--attention .stat__value { color: var(--warn); }
.stat--working   .stat__value { color: var(--info); }
.stat--ready     .stat__value { color: var(--ok); }

.stat__label {
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Queue */

.queue { margin-bottom: var(--s-6); }

.queue__head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
    padding-left: var(--s-1);
}
.queue__head h2 { font-size: var(--t-md); letter-spacing: 0.01em; }

.queue__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }

.qrow {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
    transition: transform var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease);
}
.qrow:hover { transform: translateX(2px); box-shadow: var(--e-2); border-color: var(--line-strong); }

.qrow__link {
    display: grid;
    grid-template-columns: minmax(140px, auto) minmax(0, 1fr) minmax(0, 22rem) auto auto;
    align-items: center;
    gap: var(--s-4);
    padding: var(--s-3) var(--s-4);
    text-decoration: none;
    color: inherit;
}

.qrow__who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.qrow__file { font-weight: 620; font-size: var(--t-sm); }
.qrow__parties { font-size: var(--t-sm); color: var(--muted); }

.qrow__meta { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.qrow__blocking { font-size: var(--t-sm); font-weight: 560; color: var(--warn); }

.qrow__progress { display: flex; flex-direction: column; gap: var(--s-1); }
.qrow__progress .meter { width: 100%; }

.qrow__age { white-space: nowrap; }

.qrow__go {
    color: var(--muted-2);
    font-size: var(--t-lg);
    transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.qrow:hover .qrow__go { transform: translateX(3px); color: var(--accent); }

/* A row the machine is working on gets a moving edge, so "still going" is
   visible without reading the caption. */
.qrow--working { border-color: color-mix(in srgb, var(--info) 30%, var(--line)); }

/* Nothing waiting */

.queue-empty { text-align: center; padding: var(--s-8) var(--s-5); }
.queue-empty__mark {
    width: 3rem; height: 3rem;
    margin: 0 auto var(--s-4);
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: var(--ok-soft);
    color: var(--ok);
    font-size: var(--t-xl);
    animation: mark-in var(--dur-slow) var(--ease);
}
@keyframes mark-in { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
.queue-empty h2 { margin-bottom: var(--s-2); }
.queue-empty .button { margin-top: var(--s-4); }

@media (max-width: 900px) {
    .qrow__link { grid-template-columns: 1fr auto; grid-auto-rows: auto; gap: var(--s-2); }
    .qrow__state { grid-column: 1; }
    .qrow__age { grid-column: 2; grid-row: 1; text-align: right; }
    .qrow__who, .qrow__meta { grid-column: 1 / -1; }
    .qrow__go { display: none; }
    .board__head { flex-direction: column; align-items: stretch; gap: var(--s-3); }
}
.queue__more { margin: var(--s-2) 0 0; padding-left: var(--s-1); }

/* A section that has not been read yet ------------------------------------

   Shown in place of the form, not around it. The reviewer's question is "can I work
   on this yet", and a disabled form full of half-merged values answers it badly.
   ------------------------------------------------------------------------- */

.stage__waiting { padding: var(--s-2) 0 var(--s-4); }

.stage__waiting-title {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin: 0 0 var(--s-2);
    font-weight: 560;
    color: var(--ink-2);
}
.stage__waiting-title .spinner { color: var(--info); }
.stage__waiting-note { margin: 0 0 var(--s-3); max-width: 56ch; }

/* Clearance search --------------------------------------------------------

   The list screen is the find-it tool, so the search box is the largest thing on
   it and everything else is a way of narrowing what it returns. Rows rather than
   a table: nine columns did not survive a phone, and the columns that mattered
   (who, what state, how old) were the three easiest to lose in the middle.
   ------------------------------------------------------------------------- */

.finder { margin: 0 0 var(--s-4); padding: var(--s-4); }

.finder__line { display: flex; gap: var(--s-2); align-items: center; }

.finder__input {
    flex: 1 1 auto;
    min-width: 0;
    font-size: var(--t-md);
    padding: var(--s-3) var(--s-4);
}

.finder__more { margin: var(--s-3) 0 0; }
.finder__more > summary {
    cursor: pointer;
    font-size: var(--t-sm);
    color: var(--muted);
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
}
.finder__more > summary::-webkit-details-marker { display: none; }
.finder__more > summary::before {
    content: "▸";
    transition: transform var(--dur-fast) var(--ease);
}
.finder__more[open] > summary::before { transform: rotate(90deg); }
.finder__more > summary:hover { color: var(--ink-2); }

.finder__grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-3);
    align-items: flex-end;
    margin-top: var(--s-3);
}
.finder__grid label { display: block; margin-bottom: var(--s-1); color: var(--muted); font-size: var(--t-sm); }
.finder__grid input, .finder__grid select { margin: 0; }
.finder__actions { display: flex; align-items: center; gap: var(--s-3); margin-left: auto; }

/* Which columns a search is narrowed to.

   A fieldset, because that is what a set of checkboxes answering one question is,
   and the legend is what a screen reader reads before the first box. Its own
   border and padding are removed: the disclosure around it is already the box. */
.finder__fields {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2) var(--s-4);
    margin: var(--s-3) 0 0;
    padding: 0;
    border: 0;
}

/* The label wraps its box, so the words are part of the target rather than
   something to aim past on the way to a 13px square. */
.finder__field {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    margin: 0;
    font-size: var(--t-sm);
    color: var(--ink-2);
    cursor: pointer;
}
.finder__field input { margin: 0; cursor: pointer; }
.finder__field:hover { color: var(--ink); }

/* The state filters. Chips rather than a select, because the four states anybody
   filters by are worth one click, and a select hides which one is on. */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    margin-bottom: var(--s-4);
}
.chip {
    display: inline-flex;
    align-items: center;
    padding: var(--s-2) var(--s-4);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: var(--surface);
    color: var(--ink-2);
    font-size: var(--t-sm);
    font-weight: 520;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-2); color: var(--ink); }
.chip--on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}
.chip--on:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }

.results__count { margin: 0 0 var(--s-3); }

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }

.result {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
    transition: transform var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease);
}
.result:hover { transform: translateX(2px); box-shadow: var(--e-2); border-color: var(--line-strong); }

.result__link {
    display: grid;
    grid-template-columns: minmax(130px, auto) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, auto) auto auto;
    align-items: center;
    gap: var(--s-4);
    padding: var(--s-3) var(--s-4);
    text-decoration: none;
    color: inherit;
}

.result__who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result__file { font-weight: 620; font-size: var(--t-sm); }
.result__parties { font-size: var(--t-sm); color: var(--muted); }

.result__ship { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result__counts { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1); }
.result__when { white-space: nowrap; }

.result__go {
    color: var(--muted-2);
    font-size: var(--t-lg);
    transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.result:hover .result__go { transform: translateX(3px); color: var(--accent); }

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-4);
    margin-top: var(--s-5);
}

/* Clearance detail --------------------------------------------------------- */

.detail__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin: var(--s-2) 0 0; }
.detail__meta > span:not(.status):not(.tag)::before { content: "·"; margin-right: var(--s-3); color: var(--muted-2); }
.detail__meta > span:first-child::before, .detail__meta .status::before { content: none; margin: 0; }

/* Problems. Titled by what happened, led by what to do, with the original
   message folded away for whoever is diagnosing rather than clearing. */
.problems { list-style: none; margin: 0 0 var(--s-4); padding: 0; display: flex; flex-direction: column; gap: var(--s-3); }

/* One inset all round. It was 12px top and bottom against 16px left and right,
   which reads as a box that has slipped upwards. */
.problem {
    padding: var(--s-4);
    border-radius: var(--r-md);
    background: var(--danger-soft);
    border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent);
}
.problem__title { font-weight: 620; color: var(--danger); margin-bottom: var(--s-1); }
.problem__action { font-size: var(--t-sm); color: var(--ink-2); }
.problem__where { display: flex; gap: var(--s-3); margin-top: var(--s-2); }
.problem__detail { margin-top: var(--s-3); }
.problem__detail summary { cursor: pointer; }

/* The snippet is a paragraph, so it brought a bottom margin into a box that
   already has padding — 24px under the last line against 16px over the first. */
.problem__detail .snippet { margin: var(--s-2) 0 0; }

.flag-kind { font-weight: 560; }

/* The blocker. The one panel on the detail screen that must not look like the
   others: it is the answer to "why can I not send this yet". */
.blocker {
    border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
    border-left: 4px solid var(--warn);
    border-radius: var(--r-md);
    background: var(--warn-soft);
    padding: var(--s-4);
    margin-bottom: var(--s-4);
}
.blocker__title { font-size: var(--t-md); color: var(--warn); }
.blocker__note { margin: var(--s-1) 0 0; color: color-mix(in srgb, var(--warn) 80%, var(--ink)); }
.blocker__list { margin: var(--s-3) 0 0; padding-left: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.blocker__list li { color: var(--ink-2); }
.blocker__jump {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: var(--s-2);
    border-radius: var(--r-sm);
    color: inherit;
    font: inherit;
    /* The base `button` rule sets `nowrap`, which is right for a label like "Save
       consignment details" and wrong here: this button is a field name over a
       sentence, and inheriting nowrap ran the sentence off the side of the card
       where it was clipped mid-word. `.flag-link` opts out for the same reason. */
    white-space: normal;
    cursor: pointer;
}
.blocker__jump:hover { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.blocker__field { display: block; font-weight: 620; font-size: var(--t-sm); }
.blocker__why { display: block; font-size: var(--t-sm); color: var(--muted); }

.progress-block { display: flex; flex-direction: column; gap: var(--s-2); width: 100%; }

/* Upload ------------------------------------------------------------------ */

.dropzone {
    position: relative;
    display: grid;
    place-items: center;
    padding: var(--s-7) var(--s-4);
    margin-bottom: var(--s-3);
    border: 2px dashed var(--line-strong);
    border-radius: var(--r-lg);
    background: var(--surface-2);
    cursor: pointer;
    text-align: center;
    transition: border-color var(--dur) var(--ease),
                background var(--dur) var(--ease),
                transform var(--dur) var(--ease);
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone--over {
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: scale(1.005);
}

/* The real input stays in the DOM and keeps working without JavaScript; it is
   only hidden once there is a zone forwarding to it. */
.dropzone__input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone__mark {
    width: 2.5rem; height: 2.5rem;
    margin: 0 auto var(--s-3);
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: var(--t-xl);
    font-weight: 400;
    transition: transform var(--dur) var(--ease);
}
.dropzone--over .dropzone__mark { transform: scale(1.12); }

.dropzone__lead { font-weight: 560; margin: 0 0 var(--s-1); }
.dropzone__hint { margin: 0; }
.dropzone__browse { color: var(--accent); text-decoration: underline; }
.dropzone__note { margin: var(--s-2) 0 0; color: var(--warn); }

.filelist { list-style: none; margin: 0 0 var(--s-4); padding: 0; display: flex; flex-direction: column; gap: var(--s-1); }
.filelist__item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    animation: file-in var(--dur) var(--ease);
}
@keyframes file-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.filelist__name { font-size: var(--t-sm); font-weight: 500; min-width: 0; }

/* New clearance ------------------------------------------------------------

   An intake form: filled top to bottom in one pass, unlike the queue, which is
   scanned. So the rhythm is the whole design here — one step between a control and
   its own note, a bigger one between one question and the next. Without it the
   labels, controls and notes all sat the same distance apart and the form read as
   one undifferentiated column of rows.
   ------------------------------------------------------------------------- */

.intake__head { margin-bottom: var(--s-6); }
.intake__head p { margin: var(--s-2) 0 0; max-width: 64ch; }

.intake .field { margin-bottom: var(--s-5); }

/* The zone and the list it fills are one field. The space between them belongs to
   them; the space after them belongs to the field. */
.intake .dropzone { margin-bottom: 0; }
.intake .filelist { margin: var(--s-3) 0 0; }

/* Side by side the two fields need no bottom margin of their own — and stacked at a
   narrow width they need one, which is what the row gap is. Stated on the grid so
   there is one number either way rather than a margin that has to be cancelled. */
.intake .field-grid { gap: var(--s-5) var(--s-4); margin-bottom: var(--s-5); }
.intake .field-grid .field { margin-bottom: 0; }

/* No margin above: the last field already leaves a step, and the rule wants the
   same air on both sides of it. */
.intake__actions {
    padding-top: var(--s-5);
    border-top: 1px solid var(--line);
}
.intake__note { margin: var(--s-3) 0 0; max-width: 64ch; }

@media (max-width: 560px) {
    /* The bar wrapped to two lines and pushed the page down. The mark stays as the
       way back to the queue, the link text goes, and the nav keeps only what cannot
       be reached from the page below it. */
    .topbar { padding: var(--s-2) var(--s-3); gap: var(--s-2); }
    .topbar__title { font-size: 0; gap: 0; }
    .topbar__title::before { width: 0.55rem; height: 1.3rem; }
    /* Wrapping is the fallback, not the plan: at 375px the nav still ran past the
       right edge and took "Sign out" with it, and a control you cannot reach is
       worse than a bar that is two rows tall. */
    .topbar__nav { gap: var(--s-2); row-gap: var(--s-1); font-size: var(--t-xs); flex-wrap: wrap; justify-content: flex-end; }
    .topbar__nav a { white-space: nowrap; }

    /* Nav links that duplicate a button on the page below. Dropping them is what
       keeps the bar to one row; the action is still one thumb away. */
    .topbar__optional { display: none; }

    /* The word "Live" is the least of what this says; the dot carries it. */
    .live { font-size: 0; gap: 0; padding: 0.3rem; }
    .themer__opt { width: 1.5rem; height: 1.5rem; }
    .themer__opt svg { width: 13px; height: 13px; }
    .live { padding: 0.1rem 0.4rem; font-size: var(--t-2xs); min-width: 0; }
    .board { padding: var(--s-4) var(--s-3) var(--s-7); }
    .board__head h1 { font-size: var(--t-2xl); }
    .stat { padding: var(--s-3); }
    .stat__value { font-size: var(--t-2xl); }

    /* Six columns do not fit a phone.
       `display: contents` on the name block so the file number and the parties can
       take separate rows: side by side at this width the exporter truncated to
       "ROBERTBOSCH(PTY)LTD. →…", which is the half of the row that identifies it. */
    .result__link {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: var(--s-2) var(--s-3);
        padding: var(--s-3);
    }
    .result__who { display: contents; }
    .result__file    { grid-row: 1; grid-column: 1; }
    .result__state   { grid-row: 1; grid-column: 2; justify-self: end; }
    .result__parties { grid-row: 2; grid-column: 1 / -1; white-space: normal; overflow: visible; }
    .result__note    { grid-row: 3; grid-column: 1 / -1; }
    .result__ship    { grid-row: 4; grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: var(--s-3); }
    .result__counts  { grid-row: 5; grid-column: 1; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .result__when    { grid-row: 5; grid-column: 2; justify-self: end; align-self: end; }
    .result__go { display: none; }

    .finder { padding: var(--s-3); }
    .finder__line { flex-wrap: wrap; }
    .finder__input { flex: 1 1 8rem; padding: var(--s-2) var(--s-3); }
    .finder__actions { margin-left: 0; }
    .chips { gap: var(--s-1); }
    .chip { padding: var(--s-2) var(--s-3); }
}

/* Sign-in screen ----------------------------------------------------------

   The one screen shown to somebody who is not yet anybody, so it is the one screen
   that has to introduce the application rather than assume it. Two halves: a stage
   that carries the brand and a small loop of the machine working, and a panel that
   carries the form and nothing else.

   The stage keeps its dark petrol ground in both themes, for the same reason the top
   bar does — it is chrome, not state — so its colours are literals rather than
   tokens. Adding tokens for a surface that never inverts would mean a third copy of
   them in each dark block, which is the duplication ThemeTokensTest exists to
   discourage. Everything in the panel follows the theme normally.

   All of the motion here is decorative, and the global prefers-reduced-motion rule
   stops every animation in the file at one frame — which for these means the pack is
   drawn read and the light stops drifting. That is the right resting state, so
   nothing further is needed for it.
   ------------------------------------------------------------------------- */

.auth-page { margin: 0; }

.auth {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
}

/* The stage --------------------------------------------------------------- */

.auth__stage {
    position: relative;
    display: flex;
    align-items: flex-end;
    padding: var(--s-8) clamp(var(--s-5), 4vw, var(--s-8));
    overflow: hidden;
    /* Aubergine, the top bar's own ground, deepening to the plum accent. */
    background: linear-gradient(158deg, #140E21 0%, #2A1D45 54%, #1A1230 100%);
    color: #ECEAF3;
    /* A stacking context of its own, so the negative z-indexes below stay inside the
       stage instead of sliding behind the page. */
    isolation: isolate;
}

/*
 * Drifting light.
 *
 * Three soft radial pools rather than one: a single blob reads as a gradient that
 * somebody forgot to finish, and three at different sizes never quite repeat, which
 * is what stops a 34-second loop from looking like a 34-second loop.
 *
 * Inset past the edges by a quarter so the drift never walks a pool's hard cut-off
 * into view, and blurred on top of that because the pools are cheap and the blur is
 * what makes them look like light rather than paint.
 */
.auth__aurora {
    position: absolute;
    inset: -25%;
    z-index: -2;
    background:
        radial-gradient(38% 42% at 22% 26%, rgba(179, 155, 224, .55), transparent 70%),
        radial-gradient(30% 36% at 80% 20%, rgba(201, 181, 242, .30), transparent 70%),
        radial-gradient(44% 48% at 64% 84%, rgba(91, 58, 140, .45), transparent 72%);
    filter: blur(18px);
    animation: auth-drift 34s var(--ease) infinite alternate;
}

@keyframes auth-drift {
    0%   { transform: translate3d(-3%, -2%, 0) scale(1); }
    50%  { transform: translate3d(4%, 3%, 0)   scale(1.08); }
    100% { transform: translate3d(-2%, 4%, 0)  scale(1.03); }
}

/* The survey grid. Faint enough to be texture rather than pattern, masked so it
   fades out before it reaches the text, and drifting by exactly one cell so the
   loop has no seam. */
.auth__grid {
    position: absolute;
    inset: 0;
    z-index: -1;
    background-image:
        linear-gradient(rgba(255, 255, 255, .055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .055) 1px, transparent 1px);
    background-size: 34px 34px;
    -webkit-mask-image: radial-gradient(122% 104% at 34% 18%, #000 34%, transparent 78%);
            mask-image: radial-gradient(122% 104% at 34% 18%, #000 34%, transparent 78%);
    animation: auth-grid 26s linear infinite;
}

@keyframes auth-grid { to { background-position: 34px 34px, 34px 34px; } }

/*
 * The pack being read.
 *
 * The loop is the product in one gesture: a beam passes down the sheet, each line
 * fills in behind it, and a tick lands when the last one is done. Nine seconds,
 * which is long enough that it never feels like a spinner.
 *
 * The lines fill with `scaleX` rather than an animated width — width is a layout
 * property and animating six of them forever would relayout the sheet sixty times a
 * second for the life of the page.
 */
.auth__doc {
    position: absolute;
    z-index: -1;
    top: clamp(var(--s-6), 13vh, 7rem);
    right: clamp(var(--s-4), 5vw, 4rem);
    width: min(20rem, 46%);
    padding: var(--s-4);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: var(--r-lg);
    background: rgba(255, 255, 255, .06);
    box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .7);
    /* Its own entrance rather than the shared one: `auth-rise` ends at
       `transform: none`, which would take the tilt with it. */
    transform: rotate(-3deg);
    animation: auth-doc-in var(--dur-slow) var(--ease) both;
    animation-delay: 160ms;
}

@keyframes auth-doc-in {
    from { opacity: 0; transform: rotate(-3deg) translateY(14px); }
    to   { opacity: 1; transform: rotate(-3deg); }
}

.auth__doc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding-bottom: var(--s-3);
    margin-bottom: var(--s-4);
    border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.auth__doc-tag {
    width: 44%;
    height: 9px;
    border-radius: var(--r-full);
    background: rgba(236, 234, 243, .5);
}

.auth__doc-chip {
    width: 3.4rem;
    height: 1.05rem;
    border-radius: var(--r-full);
    background: rgba(201, 181, 242, .22);
    border: 1px solid rgba(201, 181, 242, .38);
}

.auth__doc-body { display: flex; flex-direction: column; gap: var(--s-3); }

/* Each line's width and delay. AfriClear set these as inline style attributes, which
   Border Clear's Content-Security-Policy does not allow. */
.auth__doc-line:nth-child(1) { --i: 0; --w: 94%; }
.auth__doc-line:nth-child(2) { --i: 1; --w: 71%; }
.auth__doc-line:nth-child(3) { --i: 2; --w: 88%; }
.auth__doc-line:nth-child(4) { --i: 3; --w: 62%; }
.auth__doc-line:nth-child(5) { --i: 4; --w: 83%; }
.auth__doc-line:nth-child(6) { --i: 5; --w: 48%; }

.auth__doc-line {
    display: block;
    width: var(--w, 100%);
    height: 7px;
    border-radius: var(--r-full);
    background: linear-gradient(90deg, rgba(201, 181, 242, .85), rgba(236, 234, 243, .32));
    transform-origin: left center;
    animation: auth-line 9s var(--ease) infinite;
    animation-delay: calc(var(--i, 0) * 340ms);
}

@keyframes auth-line {
    0%   { transform: scaleX(0); opacity: 0; }
    8%   { opacity: .92; }
    26%  { transform: scaleX(1); opacity: .92; }
    76%  { transform: scaleX(1); opacity: .92; }
    92%  { transform: scaleX(1); opacity: 0; }
    100% { transform: scaleX(0); opacity: 0; }
}

.auth__doc-foot {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding-top: var(--s-4);
    margin-top: var(--s-4);
    border-top: 1px solid rgba(255, 255, 255, .12);
}

/* The payoff. Green rather than the accent, because "checked" is a state and the
   accent is not allowed to carry state anywhere else in the application either. */
.auth__doc-tick {
    flex: none;
    width: 22px;
    height: 22px;
    color: #6FE3B0;
    animation: auth-tick 9s var(--ease) infinite;
}

@keyframes auth-tick {
    0%, 42%  { opacity: 0; transform: scale(.6); }
    52%      { opacity: 1; transform: scale(1.14); }
    59%      { opacity: 1; transform: scale(1); }
    82%      { opacity: 1; transform: scale(1); }
    92%, 100%{ opacity: 0; transform: scale(1); }
}

.auth__doc-bar {
    width: 52%;
    height: 7px;
    border-radius: var(--r-full);
    background: rgba(111, 227, 176, .38);
    transform-origin: left center;
    animation: auth-line 9s var(--ease) infinite;
    animation-delay: 2s;
}

/* The beam. Taller than it looks: most of its height is the fade above the bright
   edge, so what reads on screen is the leading line and a wake behind it. */
.auth__doc-beam {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 44%;
    pointer-events: none;
    /* The resting state, which is what a reader who has asked for reduced motion
       gets: the pack drawn already read, with nothing sweeping over it. The
       keyframes take the opacity back over while the animation is running. */
    opacity: 0;
    background: linear-gradient(180deg,
        transparent 0%,
        rgba(201, 181, 242, .10) 58%,
        rgba(201, 181, 242, .40) 92%,
        rgba(226, 214, 250, .55) 100%);
    animation: auth-beam 9s var(--ease) infinite;
}

@keyframes auth-beam {
    0%       { transform: translateY(-100%); opacity: 0; }
    5%       { opacity: 1; }
    36%      { transform: translateY(245%); opacity: 1; }
    44%, 100%{ transform: translateY(245%); opacity: 0; }
}

/* What the stage says ------------------------------------------------------ */

.auth__pitch { position: relative; max-width: 30rem; }

.auth__mark {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    margin: 0 0 var(--s-5);
    font-size: var(--t-sm);
    font-weight: 620;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: rgba(236, 234, 243, .82);
    animation: auth-rise var(--dur-slow) var(--ease) both;
}

/* The same mark the top bar uses, so the application is recognisable from the
   screen before the top bar exists. */
.auth__mark::before {
    content: "";
    width: 0.5rem;
    height: 1.15rem;
    border-radius: 2px;
    background: linear-gradient(180deg, #C9B5F2, #5B3A8C);
}

.auth__claim {
    margin: 0 0 var(--s-4);
    font-size: clamp(var(--t-2xl), 3.4vw, 2.6rem);
    font-weight: 640;
    line-height: 1.12;
    letter-spacing: -0.025em;
    text-wrap: balance;
    color: #FFFFFF;
    animation: auth-rise var(--dur-slow) var(--ease) both;
    animation-delay: 60ms;
}

.auth__points {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    font-size: var(--t-sm);
    color: rgba(236, 234, 243, .78);
    animation: auth-rise var(--dur-slow) var(--ease) both;
    animation-delay: 120ms;
}

.auth__points li {
    display: flex;
    align-items: baseline;
    gap: var(--s-3);
}

/* A drawn tick rather than a bullet or an SVG per line: two borders on a rotated
   box, which follows the type size and needs no markup. */
.auth__points li::before {
    content: "";
    flex: none;
    width: 0.36rem;
    height: 0.62rem;
    margin-top: 0.1rem;
    border-right: 1.5px solid #C9B5F2;
    border-bottom: 1.5px solid #C9B5F2;
    transform: rotate(42deg);
}

.auth__appearance {
    position: absolute;
    top: var(--s-5);
    right: var(--s-5);
    z-index: 1;
}

@keyframes auth-rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

/* The form ---------------------------------------------------------------- */

.auth__panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-8) clamp(var(--s-4), 4vw, var(--s-7));
    background: var(--bg);
}

.auth__form {
    width: 100%;
    max-width: 23rem;
    animation: auth-rise var(--dur-slow) var(--ease) both;
    animation-delay: 80ms;
}

/* The spacing the plain form did not have. A label's own margin is one step, which
   is the gap between a label and its input; the gap between one field and the next
   has to be bigger than that or the two read as one block of four rows. `.field`
   already carries it, so the fields use it rather than restating it here. */
.auth__head { margin-bottom: var(--s-6); }
.auth__head h1 { font-size: var(--t-2xl); }
.auth__head p { margin: var(--s-2) 0 0; }

/* Full width and taller than a toolbar button. This is the only action on the
   screen; it does not stand in a row with anything, so the one-height rule the
   filter controls follow has nothing to be consistent with here. */
.auth__submit {
    width: 100%;
    margin-top: var(--s-2);
    padding: 0.65rem 1rem;
    font-size: var(--t-md);
    box-shadow: var(--e-1);
}

.auth__foot {
    margin: var(--s-6) 0 0;
    padding-top: var(--s-4);
    border-top: 1px solid var(--line);
}

/* Narrower --------------------------------------------------------------- */

@media (max-width: 960px) {
    /* One column, stage on top. It keeps the mark and the claim; the points and the
       pack are what a 400px-tall band has no room for, and the claim is the half
       that was doing the work. */
    .auth { grid-template-columns: 1fr; min-height: 0; }

    .auth__stage {
        align-items: flex-start;
        padding: var(--s-7) var(--s-5) var(--s-6);
    }

    .auth__doc, .auth__points { display: none; }
    .auth__claim { font-size: var(--t-2xl); }
    .auth__claim br { display: none; }
    .auth__pitch { max-width: none; padding-right: 6rem; }
    .auth__panel { padding: var(--s-6) var(--s-5) var(--s-8); }
}

@media (max-width: 560px) {
    .auth__stage { padding: var(--s-5) var(--s-4); }
    .auth__mark { margin-bottom: var(--s-4); }
    .auth__claim { font-size: var(--t-xl); }
    .auth__appearance { top: var(--s-4); right: var(--s-4); }
    .auth__pitch { padding-right: 5rem; }
    .auth__panel { padding: var(--s-5) var(--s-4) var(--s-7); }
    .auth__head { margin-bottom: var(--s-5); }
}


/* Busy and pending states ---------------------------------------------------
   Three places the interface used to say nothing while it worked: a form posting,
   a lookup fetching, and a long list laying itself out. */

/* The button that started something. Disabled by live.js on the tick after the
   submit, so the control is still valid when its own form is serialised. */
button.is-busy {
    position: relative;
    cursor: progress;
    /* Not `opacity`: the disabled rule already dims it, and stacking the two makes
       the label unreadable at exactly the moment it says what is happening. */
    padding-left: calc(var(--s-4) + 1.1rem);
}
button.is-busy::before {
    content: "";
    position: absolute;
    left: var(--s-3);
    top: 50%;
    margin-top: -.5rem;
    width: 1rem; height: 1rem;
    border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    border-radius: var(--r-full);
    animation: spin 700ms linear infinite;
}

/* A results list showing the previous query while a newer one is in flight. The
   rows stay readable — they are probably still right — but they stop looking
   settled. */
[aria-busy="true"] {
    opacity: .55;
    transition: opacity var(--dur-fast) var(--ease);
}

/* Forty line-item forms is a great deal of layout for a page that re-renders
   itself. Off-screen ones are skipped until they are scrolled near; the size hint
   keeps the scrollbar honest while they are. */
.line {
    content-visibility: auto;
    contain-intrinsic-size: auto 420px;
}

/* `details` opened and closed with no motion at all, so a card unfolding read as
   the page having jumped. Only the summary's marker and the card's own shadow are
   animated — animating the height of a block containing forty forms would be the
   expensive thing this file has otherwise avoided. */
.card--collapsible > details > summary { transition: background var(--dur-fast) var(--ease); }
.card--collapsible > details[open] > summary { background: var(--surface-sunk); }

/* Cross-document view transitions, removed.

   They were added to hide a white flash between two documents, and the flash was
   real: the root element had no background, so the colour a browser paints before
   the new document has styles was white. The rule above `body` fixes that at the
   source now.

   What the transition did in the meantime was make the symptom worse rather than
   better. Measured off a screen recording: a uniform white layer over the whole
   viewport at 81% opacity, decaying over 149ms. A frame of white is one frame; a
   cross-fade from white is a fifth of a second, and the eye reads the second as a
   fault. It also only happened on the first navigation of the three in that
   recording — the one taken while the previous page was still loading, which is
   where a transition is interrupted and falls back.

   Left out rather than tuned, because with the background fixed there is nothing
   here for it to hide: the browser's own paint holding keeps the old page on
   screen until the new one has painted, and these pages answer in under 100ms. */

/* Sections drawer ----------------------------------------------------------

   The panel behind the hamburger. Built on `details`, so `open` is the element's
   own state and every rule below hangs off it — there is no class for a script to
   forget to remove, and the thing works before any script has run.
   ------------------------------------------------------------------------- */

.navdrawer { flex: none; }

/* The button. A `summary` is a list item by default, which draws a marker beside
   the icon and indents it; both user agents need telling separately. */
.navdrawer__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: var(--r-md);
    color: var(--topbar-ink);
    cursor: pointer;
    list-style: none;
    opacity: .9;
    transition: background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.navdrawer__toggle::-webkit-details-marker { display: none; }
.navdrawer__toggle:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.navdrawer[open] .navdrawer__toggle { background: rgba(255, 255, 255, .18); opacity: 1; }
.navdrawer__toggle svg { width: 17px; height: 17px; display: block; }

/* Over everything, including the top bar it hangs from — the bar is `z-index: 40`
   and a panel that slid out underneath it would lose its first two entries. */
.navdrawer__scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(22, 17, 32, .38);
    animation: drawer-fade var(--dur) var(--ease);
}

.navdrawer__panel {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 51;
    width: min(280px, 82vw);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--s-4) var(--s-3) var(--s-6);
    overflow-y: auto;
    background: var(--surface);
    color: var(--ink);
    border-right: 1px solid var(--line);
    box-shadow: var(--e-3);
    animation: drawer-in var(--dur) var(--ease);
}

/* A heading for a handful of links, so "Master data" is not mistaken for one. */
.navdrawer__group {
    margin: var(--s-4) 0 var(--s-1);
    padding: 0 var(--s-3);
    font-size: var(--t-2xs);
    font-weight: 620;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted-2);
}
.navdrawer__group:first-child { margin-top: var(--s-2); }

.navdrawer__link {
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    font-size: var(--t-sm);
    color: var(--ink-2);
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.navdrawer__link:hover { background: var(--surface-sunk); color: var(--ink); text-decoration: none; }

/* Where you already are. A rail rather than a fill, so the section reads as
   marked rather than as selected and about to be opened again. */
.navdrawer__link--on {
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 560;
    box-shadow: inset 2px 0 0 var(--accent);
}

/* The page behind a drawer fixed to the viewport must not slide past underneath
   it; set by nav.js, because `details` cannot reach the root element itself. */
.nav-open, .nav-open body { overflow: hidden; }

@keyframes drawer-in  { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes drawer-out { from { transform: translateX(100%); }  to { transform: none; } }
@keyframes drawer-fade { from { opacity: 0; } to { opacity: 1; } }

/* The registers --------------------------------------------------------------

   One row per company, on the grid `.result__link` already sets and with its own
   columns: a clearance row leads with a file number and a state, and a company has
   neither. What identifies one is the name and the first line of its address —
   571 exporter names in the client's data appear more than once, and 148 of those
   carry more than one customs code.
   ------------------------------------------------------------------------- */

.register-row {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.1fr) auto minmax(0, auto) auto;
}

.register-row__who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.register-row__name { font-weight: 560; font-size: var(--t-sm); }

.register-row__short {
    font-family: var(--font-mono);
    font-size: var(--t-2xs);
    color: var(--muted);
}

.register-row__address { display: block; }

.register-row__codes {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: var(--t-xs);
}

/* Not a missing value but a rejected one — about 40% of the codes in the export
   are placeholders and are dropped at import. Warn, because it is something to go
   and find rather than something broken. */
.register-row__warn { color: var(--warn); }

.register-row__country { white-space: nowrap; font-variant-numeric: tabular-nums; }
.register-row__marks { display: flex; align-items: center; gap: var(--s-1); }

/* The company drawer ---------------------------------------------------------

   Rendered by the server when the URL names a company, which is why there is no
   hidden state here: the panel is present or it is not. It slides in from the
   right, over the list, and the list stays where it was so that closing it puts
   the reviewer back on the row they opened.
   ------------------------------------------------------------------------- */

.drawer__scrim {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(22, 17, 32, .34);
    animation: drawer-fade var(--dur) var(--ease);
}

.drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 61;
    width: min(520px, 100vw);
    display: flex;
    flex-direction: column;
    padding: var(--s-5);
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--e-3);
    animation: drawer-out var(--dur) var(--ease);
}

.drawer__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-3);
}
.drawer__title { margin: 0; font-size: var(--t-xl); }
.drawer__meta { margin: var(--s-1) 0 0; }
.drawer__close { flex: none; }

/* Where a correction stands: kept through the next import, or not yet made. Said
   before the form rather than after a save, because it is what decides whether
   somebody types here at all or goes on overtyping the value per clearance. */
.drawer__note {
    margin: 0 0 var(--s-4);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    background: var(--surface-sunk);
    color: var(--muted);
}

.drawer__body { display: flex; flex-direction: column; }

/* The parsed address components. None of them is submitted, so they are folded
   away rather than given a third of the panel. */
.drawer__more {
    margin-bottom: var(--s-4);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-2) var(--s-3);
}
.drawer__more > summary { cursor: pointer; font-size: var(--t-sm); color: var(--ink-2); }
.drawer__more[open] > summary { margin-bottom: var(--s-3); }

/* Above the fold of a long panel, so Save is reachable without scrolling back. */
.drawer__actions {
    position: sticky;
    bottom: calc(var(--s-5) * -1);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-3);
    margin: 0 calc(var(--s-5) * -1) calc(var(--s-5) * -1);
    padding: var(--s-4) var(--s-5);
    background: var(--surface);
    border-top: 1px solid var(--line);
}

/* A drawer that is most of the screen has no page left to slide over, so it stops
   pretending to be one. */
@media (max-width: 720px) {
    .drawer { width: 100vw; border-left: none; }
    .register-row { grid-template-columns: minmax(0, 1fr) auto; }
    .register-row__country, .register-row__marks, .register-row .result__go { display: none; }
}

/* =========================================================================
   The review workspace
   =========================================================================
   Three stages as destinations rather than three thousand pixels of scroll, and
   the header form in the five panels Easy Clear names.

   Everything here is progressive. `[data-workspace-on]` is set by workspace.js
   once it has found both the tabs and the sections, so with scripting off no
   section is ever hidden and the tabs stay what the markup makes them: anchors
   that jump down the page.
   ========================================================================= */

.workspace {
    display: flex;
    gap: var(--s-1);
    padding: var(--s-1);
    margin-bottom: var(--s-4);
    background: var(--surface-sunk);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    position: sticky;
    top: var(--s-2);
    z-index: 3;
}

.workspace__tab {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-full);
    color: var(--muted);
    font-size: var(--t-sm);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.workspace__tab:hover { color: var(--ink); background: var(--surface); }

.workspace__tab[aria-current="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--e-1);
}

/* The count is the reason to look, so it keeps its colour when the tab is not
   current — a tab that hides its own bad news is worse than no tab. */
.workspace__flags { font-size: var(--t-2xs); }

/* Only once the script is driving it. Before that every stage is on the page. */
:root[data-workspace-on] section.stage[data-stage-hidden] { display: none; }

/* Sticky chrome over a focused input is WCAG 2.2 SC 2.4.11 Focus Not Obscured.
   The tab strip is sticky, so anything scrolled to needs its height of padding. */
:root[data-workspace-on] { scroll-padding-top: calc(var(--s-8) + var(--s-4)); }

/* -------------------------------------------------------------------------
   Panels
   ------------------------------------------------------------------------- */

.panel { margin-bottom: var(--s-5); }

.panel__title {
    display: flex;
    align-items: baseline;
    gap: var(--s-2);
    margin: 0 0 var(--s-3);
    padding-bottom: var(--s-2);
    border-bottom: 1px solid var(--line);
    font-size: var(--t-sm);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel__count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: var(--muted-2);
}

/* Not a tick and not green: a panel whose fields all carry a value has not been
   checked by anybody, and painting it as done is the automation bias this whole
   screen is trying not to feed. It is a quieter rule, nothing more. */
.panel[data-panel-complete] .panel__title { border-bottom-color: var(--line-strong); }

/*
   The additional fields are hidden here and nowhere else.

   They are NOT hidden in the markup: with scripting off every field on this form is
   visible and editable, which is what progressive enhancement has to mean on a form
   whose values go onto a customs declaration. `data-js` is stamped by the inline boot
   script before first paint, so there is no flash — and if scripting is off, this rule
   never applies and the toggle beneath it is hidden instead.
*/
:root[data-js] .panel:not([data-extras-open]) [data-additional-field] { display: none; }

.panel__more {
    margin-top: var(--s-2);
    padding: 0;
    background: none;
    border: 0;
    color: var(--accent);
    font-size: var(--t-sm);
    font-weight: 600;
    cursor: pointer;
}

.panel__more:hover { text-decoration: underline; }

/* Hidden until workspace.js can make it work. */
:root:not([data-js]) [data-js-only] { display: none !important; }

/* -------------------------------------------------------------------------
   Find a field
   ------------------------------------------------------------------------- */

.palette {
    width: min(38rem, calc(100vw - var(--s-6)));
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--e-3);
}

.palette::backdrop { background: rgb(0 0 0 / 0.35); }

.palette__form {
    display: flex;
    gap: var(--s-2);
    align-items: center;
    padding: var(--s-3);
    border-bottom: 1px solid var(--line);
}

.palette__input {
    flex: 1 1 auto;
    padding: var(--s-2) var(--s-3);
    font-size: var(--t-md);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--ink);
}

.palette__list { list-style: none; margin: 0; padding: var(--s-2); max-height: 22rem; overflow-y: auto; }

.palette__hit {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s-3);
    width: 100%;
    padding: var(--s-2) var(--s-3);
    background: none;
    border: 0;
    border-radius: var(--r-md);
    color: inherit;
    font-size: var(--t-sm);
    text-align: left;
    cursor: pointer;
}

.palette__hit:hover, .palette__hit:focus-visible { background: var(--accent-soft); }
.palette__name { font-weight: 600; }
.palette__where { color: var(--muted); font-size: var(--t-xs); white-space: nowrap; }

/* -------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------
   Same-document view transitions for the stage switch. Baseline since late 2025,
   and the fallback is that the switch simply happens — workspace.js calls the
   same function either way, so there is no branch to keep in step.

   The global prefers-reduced-motion block turns the rest off; this needs its own
   rule because a view transition is not an animation on an element. */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) { animation: none !important; }
}

@media (max-width: 640px) {
    .workspace { position: static; }
    .workspace__label { font-size: var(--t-xs); }
}

/* =========================================================================
   The document beside the fields
   =========================================================================
   A grid, not a float or a fixed panel. With no script the pane is hidden by its
   own `hidden` attribute and the fields take the full width; on a narrow screen
   the pane drops below the fields and reads as another card. Neither case needs
   a media query to undo a position.
   ========================================================================= */

/*
   One width for the whole review page, and a gutter so nothing meets the edge.

   The page's cards took their inset from `max-width` plus `margin: auto`, which
   insets nothing once the window is narrower than the shell, and the review grid
   had neither, so it ran edge to edge. Both now share one rule: the shell, or the
   window less a gutter either side, whichever is smaller.

   The shell is wider here than elsewhere because this page carries two columns — a
   forty-field form and the page it was read from. At the default 1240px the pane
   leaves the form about five hundred pixels, which is two fields to a row. Widening
   the shell for this page alone keeps the cards above aligned with the workspace
   instead of stepping out past them.
*/
body[data-page="detail"] {
    --shell: 1640px;
}

/* Both parentages, deliberately. The page's content sits inside #clearance-body,
   the region live.js swaps, and an earlier version of this rule targeted body's
   direct children instead — it matched nothing, so the cards inherited the wider
   shell and got no gutter at all. Naming both keeps it right if the wrapper ever
   moves. The stage cards inside .review__fields are not matched: they sit in a grid
   cell, and a gutter there would indent them past the stage tabs above. */
body[data-page="detail"] > :is(.card, .review),
body[data-page="detail"] > #clearance-body > :is(.card, .review) {
    width: min(var(--shell), calc(100% - 2 * var(--s-5)));
    margin-inline: auto;
}

.review {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s-4);
    align-items: start;
    margin-block: var(--s-5);
}

/* Only widen to two columns when there is room for both to be usable. Below this
   a 40-field form and a page image share nothing but crowding. */
@media (min-width: 1100px) {
    :root[data-js] .review:has(.review__doc:not([hidden])) {
        grid-template-columns: minmax(0, 1fr) minmax(22rem, 34vw);
    }
}

.review__fields { min-width: 0; }

/* The cell's edges are already the page gutter. Without this, the site's
   narrow-screen card margin (12px under 900px) indents the stage cards past the
   stage tabs directly above them. */
.review__fields > .card { margin-inline: 0; }

.review__doc {
    position: sticky;
    /* Clears the sticky stage tabs above it. */
    top: calc(var(--s-8) + var(--s-4));
    min-width: 0;
}

.viewer {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    max-height: calc(100vh - var(--s-8) * 2);
    padding: var(--s-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
}

.viewer__bar {
    display: flex;
    align-items: baseline;
    gap: var(--s-3);
    font-size: var(--t-sm);
}

.viewer__where {
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer__empty { margin: 0; padding: var(--s-5) var(--s-3); text-align: center; }

.viewer__stage { min-height: 0; overflow: auto; }

/* The box is positioned in percentages of this element, so it must be exactly as
   big as the image and no bigger — hence the grid of one cell rather than padding. */
.viewer__frame {
    position: relative;
    display: grid;
    background: var(--surface-sunk);
    border-radius: var(--r-sm);
    overflow: hidden;
}

.viewer__page { display: block; width: 100%; height: auto; }

/* Zoomed is a scale about the highlight, which only means anything when there is
   one; the button toggles it and the box keeps its place either way. */
.viewer__frame[data-viewer-zoomed] { overflow: auto; }
.viewer__frame[data-viewer-zoomed] .viewer__page { width: 180%; max-width: none; }

.viewer__box {
    position: absolute;
    border: 2px solid var(--warn);
    border-radius: 2px;
    background: color-mix(in srgb, var(--warn) 18%, transparent);
    box-shadow: 0 0 0 9999px color-mix(in srgb, var(--surface-sunk) 55%, transparent);
    pointer-events: none;
    animation: viewer-box-in var(--dur) var(--ease);
}

@keyframes viewer-box-in {
    from { opacity: 0; transform: scale(1.04); }
    to   { opacity: 1; transform: scale(1); }
}

.viewer__snippet { margin: var(--s-2) 0 0; }

@media (prefers-reduced-motion: reduce) {
    .viewer__box { animation: none; }
}


/* Border Clear's own pages ---------------------------------------------------- */
/* The waybill, manifest and usage pages, on the same shell as the workspace. Only
   what the workspace had no class for. */

.board > .card { margin: var(--s-4) 0; }

.upload-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin-top: var(--s-3); }

.table-scroll { overflow-x: auto; margin: 0 calc(-1 * var(--s-2)); padding: 0 var(--s-2); }

.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--s-2) var(--s-5);
    margin: 0;
    font-size: var(--t-sm);
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------------
   Options on every field (field-options.js)

   A field a flag asks about is marked: an amber border with a bar on its
   leading edge, and a chip in its label. The chip carries words as well as
   colour. A blocking field keeps its red (aria-invalid), which wins.
   ------------------------------------------------------------------------ */
.field--options { position: relative; }
.field--options > label { display: flex; align-items: center; gap: var(--s-2); }
.options-chip {
    margin-left: auto; border: 0; cursor: pointer; white-space: nowrap;
    font: 600 var(--t-xs) var(--font); padding: 1px var(--s-2); border-radius: var(--r-full);
    background: var(--surface-sunk); color: var(--muted);
    opacity: 0; transition: opacity var(--dur-fast) var(--ease);
}
.field--options:hover .options-chip, .field--options:focus-within .options-chip { opacity: 1; }
.field[data-field-asks] .options-chip { opacity: 1; background: var(--warn); color: var(--surface); }
.field--settled .options-chip { opacity: 1; background: var(--ok-soft); color: var(--ok); }
.field[data-field-asks] :is(input, textarea, select):not([aria-invalid="true"]) {
    border-color: var(--warn);
    box-shadow: inset 3px 0 0 var(--warn);
    background-color: color-mix(in srgb, var(--warn-soft) 45%, var(--surface));
}
.field[data-field-asks] :is(input, textarea, select):not([aria-invalid="true"]):focus {
    box-shadow: inset 3px 0 0 var(--warn), 0 0 0 3px var(--warn-soft);
}
.field--saving :is(input, textarea) { opacity: .6; }
.field--settled :is(input, textarea) { background-color: var(--ok-soft); transition: background-color var(--dur-slow) var(--ease); }

.options-pop {
    position: absolute; left: 0; top: 100%; z-index: 40;
    width: max(100%, min(28rem, calc(100vw - 2rem))); max-width: calc(100vw - 2rem);
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line-strong); border-radius: var(--r-md);
    box-shadow: 0 12px 32px -8px color-mix(in srgb, var(--ink) 30%, transparent), 0 2px 6px color-mix(in srgb, var(--ink) 10%, transparent);
    overflow: hidden; animation: options-in var(--dur-fast) var(--ease);
}
@keyframes options-in { from { opacity: 0; transform: translateY(-4px); } }
.options-pop__q { margin: 0; padding: var(--s-2) var(--s-3); font-size: var(--t-sm); font-weight: 600; background: var(--surface-sunk); border-bottom: 1px solid var(--line); }
.options-pop__wait { margin: 0; padding: var(--s-3); font-size: var(--t-sm); color: var(--muted); list-style: none; }
.options-pop__list { list-style: none; margin: 0; padding: var(--s-1); max-height: 20rem; overflow: auto; }
.option { padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); cursor: pointer; display: grid; gap: 3px; }
.option[aria-selected="true"] { background: var(--accent-soft); }
.option__value { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.option__value b { font-weight: 600; overflow-wrap: anywhere; }
.option--typed .option__value { font-family: var(--font); }
.option__tag { font: 600 10.5px var(--font); letter-spacing: .05em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--surface-sunk); color: var(--muted); }
.option__tag--agree { background: var(--ok-soft); color: var(--ok); }
.option__sources { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.option__source { font-size: var(--t-xs); padding: 0 7px; border-radius: var(--r-full); border: 1px solid var(--line-strong); color: var(--muted); }
.option__why { font-size: var(--t-xs); color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.options-pop__foot { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-3); align-items: center; padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line); font-size: var(--t-xs); color: var(--muted); }
.options-pop__keep { margin-left: auto; font-size: var(--t-xs); }
.options-note { margin: var(--s-1) 0 0; color: var(--ok); }
.options-note--bad { color: var(--danger); }
@media (prefers-reduced-motion: reduce) { .options-pop { animation: none; } .options-chip, .field--settled :is(input, textarea) { transition: none; } }

/* ------------------------------------------------------------------------
   The declaration preview (declaration-preview.html)

   The form is paper in both themes: a document looks like a document. The
   page around it follows the theme.
   ------------------------------------------------------------------------ */
.preview { max-width: 1400px; margin: 0 auto; padding-block: var(--s-5) var(--s-8); padding-left: max(var(--s-4), env(safe-area-inset-left, 0px)); padding-right: max(var(--s-4), env(safe-area-inset-right, 0px)); }
.preview__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-3) var(--s-5); align-items: flex-end; margin-bottom: var(--s-4); }
.preview__head h1 { margin: 0; font-size: var(--t-xl); }
.preview__head p { margin: var(--s-1) 0 0; }
.preview__tabs { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.preview__tabs a[data-preview-tab] { padding: var(--s-1) var(--s-3); border-radius: var(--r-full); color: var(--muted); text-decoration: none; border: 1px solid var(--line-strong); }
.preview__tabs a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.preview__body { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) 19rem; gap: var(--s-5); align-items: start; }
@media (max-width: 1100px) { .preview__body { grid-template-columns: minmax(0, 1fr); } .preview__rail { display: flex; flex-wrap: wrap; } }
.preview__rail { display: grid; gap: var(--s-3); position: sticky; top: var(--s-5); }
.preview__thumb { display: grid; place-items: end center; aspect-ratio: 595 / 822; width: 5rem; background: #FFFFFF; border: 1px solid var(--line-strong); border-radius: 3px; color: #4A4A4A; font-size: var(--t-xs); text-decoration: none; padding-bottom: 4px; position: relative; }
.preview__thumb--asks::after { content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.preview__forms { min-width: 0; display: grid; gap: var(--s-5); }
.preview__sheet { margin: 0; display: grid; gap: var(--s-1); }
.preview__sheet svg.sad { width: 100%; height: auto; display: block; box-shadow: var(--e-2); border-radius: 2px; }
svg.sad { --sad-ink: #141414; --sad-rule: #2A2A2A; --sad-label: #4A4A4A; }
.sad__paper { fill: #FFFFFF; }
.sad__rules line { stroke: var(--sad-rule); stroke-width: 0.5; }
.sad__labels text { fill: var(--sad-label); font-family: Arial, "Helvetica Neue", sans-serif; }
.sad__value { fill: var(--sad-ink); font-family: Arial, "Helvetica Neue", sans-serif; }
.sad__hit { fill: transparent; }
.sad__box { cursor: pointer; outline: none; }
.sad__box:hover .sad__hit, .sad__box:focus .sad__hit { fill: #EEE8F7; }
.sad__box--asks .sad__hit { fill: #FFF2CC; stroke: #B07408; stroke-width: 0.6; }
.sad__box--later .sad__hit { fill: url(#hatch); }
.sad__hatch-bg { fill: #FFFFFF; }
.sad__hatch { stroke: #DDDDDD; stroke-width: 2; }
.sad__box--changed .sad__value { text-decoration: underline; text-decoration-color: #7A5BB0; }
.sad__box--unmeasured .sad__value { text-decoration: underline dotted; }
.sad__watermark { font: 700 34px Arial, sans-serif; fill: rgb(20 20 20 / .07); letter-spacing: .08em; pointer-events: none; }
.preview__legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin: 0; }
.preview__legend span { display: inline-flex; gap: var(--s-2); align-items: center; }
.legend { width: 18px; height: 12px; border: 1px solid var(--line-strong); display: inline-block; border-radius: 2px; }
.legend--asks { background: #FFF2CC; border-color: #B07408; }
.legend--later { background: repeating-linear-gradient(45deg, #DDDDDD 0 2px, #FFFFFF 2px 6px); }
.legend--changed { border: 0; border-bottom: 2px solid #7A5BB0; border-radius: 0; }
.preview__code { background: var(--surface-sunk); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4); overflow: auto; max-height: 70vh; font-size: var(--t-sm); }
.preview__signoff { position: sticky; top: var(--s-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-4); display: grid; gap: var(--s-3); }
.preview__signoff h2 { margin: 0; font-size: var(--t-lg); }
.preview__questions { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); max-height: 40vh; overflow: auto; }
.preview__questions li { font-size: var(--t-sm); border-left: 3px solid var(--warn); padding: var(--s-1) var(--s-2); background: color-mix(in srgb, var(--warn-soft) 40%, transparent); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.preview__questions li.preview__question--blocking { border-left-color: var(--danger); }
.preview__stats { display: grid; grid-template-columns: 1fr auto; gap: var(--s-1) var(--s-3); margin: 0; font-size: var(--t-sm); }
.preview__stats dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.preview__changes { margin: 0; padding-left: var(--s-4); }
.preview__approve { display: grid; gap: var(--s-2); }
.preview__approve button { width: 100%; }
.preview__stamp { border: 2px solid var(--ok); color: var(--ok); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); display: grid; gap: 2px; }
.preview__stamp code { word-break: break-all; color: var(--muted); }
@media print {
    .topbar, .preview__head, .preview__rail, .preview__signoff, .preview__legend, [data-preview-pane="asycuda"], [data-preview-pane="payload"] { display: none !important; }
    .preview__body { display: block; }
    .preview__sheet { break-after: page; }
    .preview__sheet svg.sad { box-shadow: none; }
}
