:root {
    --ink: #212c27;
    --muted: #546259;
    --query-hint: #68746d;
    --paper: #f6f5ee;
    --panel: #fffefa;
    --line: #cdd4c9;
    --order-divider: color-mix(in srgb, var(--line) 60%, var(--panel));
    --action: #662483;
    --tint: #efe6f3;
    --danger: #8e3024;
    --warning: #f8edd3;
    --s: 4px;
    --m: 8px;
    --l: 16px;
    --xl: 24px;
    --xxl: 32px;
    --radius: 12px;
    --control-radius: 8px;
    --compact: 12px;
    --wide: 48px;
    --field-gap: var(--m);
    --field-step: var(--l);
    --group-step: var(--xl);
    --section-step: var(--xxl);
    --action-gap: var(--compact);
    --icon-inset: var(--compact);
    --icon-size: var(--l);
    --select-reserve: calc(var(--icon-inset) + var(--icon-size) + var(--m));
    --info-bg: #edf2f7;
    --info-ink: #324c65;
    --neutral-bg: #edf0ed;
    --success-bg: #eaf3ec;
    --success-ink: #28523a;
    --warning-ink: #664a12;
    --error-bg: #f9ece9;
    --dialog-width: 480px;
    --focus-ring: 3px;
    --backdrop: #18201bb5;
    --result-bg: #f3eff5;
    --touch: 44px;
    --shadow: 0 6px 20px #18201b0a;
    --text: 16px;
    --small: 14px;
    --large: 22px;
    --display: clamp(30px, 4vw, 48px);
    --serif: Georgia, serif
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font: var(--text)/1.45 system-ui, sans-serif
}

.masthead,
main {
    padding: var(--l) clamp(var(--l), 3vw, var(--wide))
}

.masthead {
    display: flex;
    align-items: center;
    gap: var(--xl);
    border-bottom: 1px solid var(--line);
    background: var(--panel)
}

.brand {
    font: bold var(--large) var(--serif);
    white-space: nowrap
}

.brand span,
.environment {
    font: var(--small) system-ui;
    color: var(--muted)
}

nav,
.tabs,
.row,
.heading,
.filters {
    display: flex;
    align-items: center;
    gap: var(--m);
    flex-wrap: wrap
}

nav {
    flex: 1
}

a {
    color: var(--action);
    text-underline-offset: .2em
}

nav a,
.btn,
button,
.pill,
summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
    padding: var(--m) var(--l);
    border-radius: var(--radius);
    cursor: pointer
}

nav a {
    text-decoration: none
}

nav a[aria-current],
.tabs [aria-pressed=true] {
    background: var(--tint);
    font-weight: 650
}

main {
    max-width: 1600px;
    margin: auto
}

.environment {
    margin: 0
}

h1,
h2,
h3,
p {
    margin: 0
}

h1,
h2 {
    font-family: var(--serif);
    line-height: 1.15
}

h1 {
    font-size: var(--display)
}

h2 {
    font-size: var(--large)
}

button,
.btn,
.pill {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--ink);
    font: inherit;
    text-decoration: none
}

.primary {
    background: var(--action);
    color: var(--panel);
    border-color: var(--action)
}

.btn .download-icon { flex-shrink: 0; }

button:hover,
.btn:hover {
    box-shadow: inset 0 0 0 1px var(--action)
}

button:active {
    transform: translateY(1px)
}

:focus-visible {
    outline: var(--focus-ring) solid var(--action);
    outline-offset: 2px
}

.quiet {
    border: 0
}

.pill {
    background: var(--tint);
    color: var(--action)
}

.heading {
    gap: var(--action-gap);
    justify-content: space-between;
    margin: 0
}

.heading>* {
    margin: 0
}

.desk {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(290px, 1fr);
    gap: var(--xl);
    align-items: start
}

.tabs {
    margin: 0
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: var(--m)
}

.product {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 3lh 1lh;
    gap: var(--s);
    align-items: start;
    line-height: 1.25;
    text-align: left;
    padding: var(--l);
    box-shadow: var(--shadow)
}

.product strong {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    overflow-wrap: anywhere;
    font-weight: 600;
}

.product span {
    color: var(--muted);
    font-variant-numeric: tabular-nums
}

.panel,
dialog {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--xl);
    box-shadow: var(--shadow);
    margin: 0
}

.cart {
    gap: var(--field-step);
    position: sticky;
    top: var(--m);
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 16px)
}

#lines {
    overflow: auto;
    min-height: 0
}

.settle {
    display: grid;
    gap: var(--field-step);
    border-top: 1px solid var(--line);
    padding-top: var(--l)
}

.settle .pay {
    flex: 1
}

.settle .heading strong { font-weight: 700; }

.settle .heading {
    font-size: var(--large)
}

.item,
.sale { padding: var(--m) 0; }
.item:not(:last-child) { border-bottom: 1px solid var(--order-divider); }
.sale {
    border-bottom: 1px solid var(--line)
}

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

.order-lines {
    container-type: inline-size;
    display: grid;
    grid-template-columns: minmax(0, 1fr) calc(3 * var(--touch) + 2 * var(--action-gap)) minmax(6ch, max-content);
    column-gap: var(--m);
    align-content: start;
}
#lines:not(:has(.item)) { display: block; }
.item {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "product product" "controls amount";
    align-items: center;
    gap: var(--s) var(--l);
}
.item-edit { display: contents; }
.item-product { grid-area: product; display: flex; flex-direction: column; min-width: 0; }
.item-name { overflow-wrap: anywhere; font-weight: 400; }
.item-detail { grid-area: detail; color: var(--muted); font-size: var(--small); font-variant-numeric: tabular-nums; }
.item-amount { grid-area: amount; font-weight: 550; }
.item-controls { grid-area: controls; display: flex; gap: var(--action-gap); }
.item-controls button {
    display: grid;
    place-items: center;
    width: var(--touch);
    height: var(--touch);
    padding: 0;
}
.item-controls button:focus-visible { outline-offset: calc(-1 * var(--focus-ring)); }
@container (min-width: 320px) {
    .item { column-gap: var(--m); grid-template-columns: subgrid; grid-template-areas: "product controls amount"; }
    .item-product { margin-inline-end: var(--m); }
}
@media (min-width: 1024px) {
    .desk { grid-template-columns: minmax(0, 1.8fr) minmax(410px, 1fr); }
}

.mobile,
[hidden] {
    display: none !important
}

.narrow {
    max-width: 560px;
    margin: 0 auto
}

.columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--l)
}

label {display: block;}

input:not([type=hidden]):not([type=checkbox]),
select,
textarea {
    display: block;
    margin-top: var(--field-gap);
    width: 100%;
    max-width: 100%;
    min-height: var(--touch);
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--m);
    padding: var(--m) var(--icon-inset);
    font: inherit
}

input[type=checkbox] {
    width: 20px;
    height: 20px;
    vertical-align: middle
}

.filters {
    align-items: flex-end
}

.filters label {
    flex: 1 1 140px;
    margin: 0
}

dl {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--m)
}

dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums
}

.scroll {
    overflow: auto
}

table {
    border-collapse: collapse;
    width: 100%
}

td,
th {
    text-align: left;
    padding: var(--compact) var(--l);
    border-bottom: 1px solid var(--line)
}

.notice,
#connect,
.errorlist {
    padding: var(--l);
    background: var(--warning);
    border-radius: var(--m)
}

.errorlist,
[role=alert] {
    color: var(--danger)
}

dialog {
    width: min(var(--dialog-width), calc(100vw - var(--xxl)));
    margin: auto
}

dialog::backdrop {
    background: var(--backdrop)
}

.row {
    margin: 0
}

button:disabled {
    background: var(--paper);
    color: var(--muted);
    border-color: var(--line);
    cursor: default
}

summary {
    justify-content: flex-start;
    text-decoration: underline
}

.mobilebar {
    z-index: 2
}

@media(max-width:720px) {
    .masthead {
        gap: var(--m);
        flex-wrap: wrap;
        padding: var(--m) var(--l)
    }

    .masthead nav {
        order: 3;
        flex: 1 0 100%;
        gap: 0;
        justify-content: space-between
    }

    nav a {
        font-size: var(--small);
        padding: var(--m)
    }

    .masthead form {
        margin-left: auto
    }

    main {
        padding-bottom: 90px
    }

    .desk,
    .columns {
        display: block
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr))
    }

    .cart {
        display: none
    }

    .cart.open {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 4;
        margin: 0;
        max-height: 100dvh;
        border-radius: 0
    }

    .cart.open #lines {
        flex: 1
    }

    .mobile:not([hidden]) {
        display: inline-flex !important
    }

    .mobilebar {
        position: fixed;
        bottom: var(--m);
        left: var(--l);
        right: var(--l);
        box-shadow: var(--shadow);
        min-height: 52px
    }

    .panel {
        padding: var(--l)
    }



    h1 {
        overflow-wrap: anywhere
    }

    .product {
        padding-block: var(--compact)
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--m)
}

.brand img {
    object-fit: contain
}

/* Structural rhythm belongs to the container. */
main { display: grid; align-content: start; gap: var(--group-step); }
main > *, .columns > .panel, .panel > *, .dialog h2, .dialog p { margin-block: 0; }
.panel:not(.cart):not(details):not(.filters), .form-stack, .form-section, .section-intro, .flow, .dialog-body, .desk > section {
    display: grid; gap: var(--field-step); align-content: start; min-width: 0;
}
.panel > a.btn, .form-stack > button, .flow > button { justify-self: start; }
.narrow { width: min(100%, 560px); margin-inline: auto; }
.columns { align-items: start; }
.field { display: grid; gap: var(--field-gap); }
.field > input:not([type=hidden]), .field > select, .field > textarea { margin-top: 0; }
.hint { color: var(--muted); font-size: var(--small); }
.hint ul, .errorlist { margin: 0; padding-inline-start: var(--xl); }
.form-stack label:has(input[type=checkbox]) { min-height: var(--touch); display: flex; align-items: center; gap: var(--m); }
input[type=checkbox] { flex: none; margin: 0; accent-color: var(--action); }

details[open] > .form-stack { margin-top: var(--l); }
.panel > .heading, .panel > .tabs, .panel > .row { margin: 0; }
.panel > dl { margin: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%, 160px),1fr)); gap: var(--l); }
.filters > select, .filters > input[type=search] { margin: 0; }
.filters input::placeholder, .filters select:has(option:checked[value=""]) { color: var(--query-hint); opacity: 1; }
.filters option { color: var(--ink); }
.filters .filter-date { position: relative; }
.filter-date span { position: absolute; top: var(--s); left: var(--icon-inset); color: var(--muted); font-size: var(--small); pointer-events: none; }
.filters .filter-date input { padding-top: var(--xl); padding-bottom: var(--s); }
.filters:has(.filter-date:not([hidden])) > :is(select,input) { align-self: stretch; }
#filterResults { display: grid; gap: var(--field-step); min-width: 0; }
#filterResults > * { margin-block: 0; }
#filterRetry { justify-self: start; }
.filters button { justify-self: start; }
.sale { min-height: var(--touch); }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-size: var(--small); }
button, .btn, nav a { border-radius: var(--control-radius); }
[aria-busy=true] { color: var(--muted); }
.destructive { background: var(--danger); color: var(--panel); border-color: var(--danger); }

.empty-state { color: var(--muted); padding-block: var(--l); }
.dialog { padding: 0; max-height: calc(100dvh - var(--xxl)); color: var(--ink); }
.dialog[open] { display: flex; flex-direction: column; }
.dialog-head, .dialog-body, .dialog-actions { padding: var(--xl); }
.dialog-head { border-bottom: 1px solid var(--line); }
.dialog-body { overflow-y: auto; }
.dialog-body > p:first-child { color: var(--muted); }
.dialog-body [role=alert]:empty, .form-stack [role=alert]:empty { display: none; }
.dialog-head, .dialog-actions { flex: none; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--action-gap); border-top: 1px solid var(--line); }
.dialog-head strong, .amount-result strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-result { display: flex; justify-content: space-between; align-items: baseline; padding: var(--l); background: var(--result-bg); border-radius: var(--control-radius); }
.amount-result strong { font-size: var(--large); }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--group-step); align-items: stretch; }
.gallery-wide { grid-column: 1 / -1; }
@media(max-width:720px) {
    .columns { display: grid; grid-template-columns: 1fr; }
    .dialog-head, .dialog-body, .dialog-actions { padding: var(--l); }
    .dialog-actions { display: grid; grid-template-columns: 1fr; }
    .dialog-actions > button { width: 100%; }
}
main > .dialog { margin: auto; }
main > .narrow { margin-block: 0; }
.gallery > .panel { margin: 0; }

/* The relationship determines the space. Layout children have no outer margin. */
.form-stack > *, .form-section > *, .row, .tabs, .flow > *, .section-intro > *, .settle > *, .desk > section > * { margin-block: 0; }
.form-stack:has(> .action-footer), .gallery > section.panel:not(.cart):not(.filters) { gap: var(--group-step); }
.section-intro { gap: var(--compact); }
.section-intro p, .empty-state { color: var(--muted); }
.section-intro .empty-state { padding: 0; }
h3 { font: 650 var(--text)/1.45 system-ui,sans-serif; }
.row, .tabs { gap: var(--action-gap); }
.action-footer { align-self: end; }
.form-stack > .form-section { align-content: start; }
label:has(> select), label:has(> input:not([type=checkbox])) { display: grid; gap: var(--field-gap); }
label > select, label > input:not([type=hidden]):not([type=checkbox]) { margin-top: 0; }
select:not([multiple]) {
    appearance: none;
    padding-inline-end: var(--select-reserve);
    background-image: url("select-chevron.svg");
    background-size: var(--icon-size) var(--icon-size);
    background-position: right var(--icon-inset) center;
    background-repeat: no-repeat;
}
@media (forced-colors: active) {
    select:not([multiple]) { appearance: auto; background-image: none; padding-inline-end: var(--icon-inset); }
}
button:not(.product), .btn { font-weight: 550; line-height: 1.25; gap: var(--m); }
button[aria-busy=true] { cursor: progress; }
.notice, #connect, .errorlist {
    padding: var(--compact) var(--l);
    border-inline-start: var(--s) solid currentColor;
    background: var(--info-bg); color: var(--info-ink);
}
.notice.success { background: var(--success-bg); color: var(--success-ink); }
.notice.warning, #connect { background: var(--warning); color: var(--warning-ink); }
.notice.error, .errorlist { background: var(--error-bg); color: var(--danger); }
.field:has(.errorlist) { row-gap: var(--field-gap); }
.errorlist { list-style-position: inside; }
#sub:empty { display: none; }
.gallery .grid { grid-template-columns: repeat(auto-fit,minmax(min(100%, 112px),1fr)); }
@media (max-width:720px) {
    .gallery { grid-template-columns: 1fr; gap: var(--group-step); }
    main { gap: var(--field-step); }
}

.field > p { margin: 0; }
[aria-invalid=true] { border-color: var(--danger); }
.mobile-caption { display: none; }
@media (max-width: 720px) {
    .catalog-table thead {
        position: absolute; width: 1px; height: 1px; overflow: hidden;
        clip-path: inset(50%);
    }
    .catalog-table tbody { display: block; }
    .catalog-table tbody tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto;
        gap: var(--s) var(--l); padding-block: var(--compact);
        border-bottom: 1px solid var(--line);
    }
    .catalog-table td { padding: 0; border: 0; overflow-wrap: anywhere; }
    .catalog-table td:nth-child(3) { grid-area: 1 / 2; }
    .catalog-table td:nth-child(4) { grid-area: 2 / 2; }
    .catalog-table td:nth-child(2), .catalog-table td:nth-child(n+4) {
        font-size: var(--small); color: var(--muted);
    }
    .mobile-caption { display: inline; }
}

.documents-table :is(.sale-detail, button) { white-space: nowrap; }
.documents-table time { font-variant-numeric: tabular-nums; }
.documents-table .document-state { text-align: center; }
.documents-table .sale-detail, .table-sort {
    display: inline-flex; align-items: center; min-height: var(--touch);
}
.documents-table th:has(.table-sort) { padding-block: 0; }
.table-sort { gap: var(--s); color: inherit; text-decoration: none; }
.table-sort svg {
    width: 1em; height: 1em; fill: none; stroke: currentColor;
    stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
[aria-sort="ascending"] .table-sort svg { transform: scaleY(-1); }

@media (max-width: 720px) {
    .documents-table .sale-detail { display: inline-grid; align-content: center; white-space: normal; }
    .documents-table td:nth-child(2) { min-width: 9rem; }
}

/* Table and entity states share the same semantic palette as notices. */
.state-chip {
    display: inline-flex; align-items: center; justify-self: start;
    min-height: var(--xl); padding: 2px var(--m); border-radius: 2em;
    background: var(--neutral-bg); color: var(--muted);
    font-size: var(--small); font-weight: 550; line-height: 1.4;
    vertical-align: middle; white-space: normal;
}
.state-chip[data-tone=success] { background: var(--success-bg); color: var(--success-ink); }
.state-chip[data-tone=warning] { background: var(--warning); color: var(--warning-ink); }
.state-chip[data-tone=error] { background: var(--error-bg); color: var(--danger); }
.state-chip[data-tone=info] { background: var(--info-bg); color: var(--info-ink); }
.gallery { align-items: start; }
nav a, nav a[aria-current] { font-weight: 550; }
nav a[aria-current] { color: var(--action); box-shadow: inset 0 -2px var(--action); }
button.destructive { background: var(--panel); color: var(--danger); border-color: var(--line); }
.data-table thead { background: var(--paper); }
.data-table th { font-weight: 650; }
.data-table .table-sort { white-space: nowrap; gap: var(--s); }
.table-sort svg { flex: 0 0 1em; }
[aria-sort=none] .table-sort svg { opacity: .75; }
.data-table [aria-sort=ascending], .data-table [aria-sort=descending] { color: var(--action); }
.data-table th:has(.table-sort) { padding-block: 0; }
.catalog-table .empty-state, .documents-table .empty-state { text-align: start; padding: var(--xl) var(--l); }
.busy-action {
    position: relative;
    padding-inline: calc(var(--icon-size) + var(--compact));
}
.busy-action::before {
    position: absolute;
    inset-inline-start: var(--m);
    inset-block: 0;
    margin-block: auto;
}
button[aria-busy=true]::before, #filterStatus[data-state=loading]::before {
    content: ""; display: inline-block; flex: none; box-sizing: border-box;
    width: 1em; height: 1em; border: 2px solid transparent; border-radius: 50%;
}
button[aria-busy=true]::before, #filterStatus[data-state=loading]::before {
    border-color: currentColor; border-inline-end-color: transparent; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { button[aria-busy=true]::before, #filterStatus[data-state=loading]::before { animation: none; } }
#filterStatus { display: flex; gap: var(--m); align-items: center; padding: var(--l); }
#filterStatus[data-state=error] { color: var(--danger); background: var(--error-bg); }
@media (max-width: 720px) {
    .catalog-table thead {
        display: block; position: static; width: auto; height: auto; clip-path: none; overflow: visible;
    }
    .catalog-table thead tr { display: flex; flex-wrap: wrap; gap: 0 var(--m); padding-inline: var(--m); }
    .catalog-table thead th { padding: 0; border: 0; }
    .catalog-table .table-sort { font-size: var(--small); }
    .catalog-table td[colspan] { grid-column: 1 / -1; }
}
.documents-table { min-width: 56rem; table-layout: fixed; }
.documents-table th:nth-child(4) { width: 10rem; }
.documents-table td { overflow-wrap: anywhere; }
.documents-table:has(th:nth-child(7)) { min-width: 68rem; }
.documents-table th:nth-child(7) { width: 11rem; }
@media (min-width: 721px) {
    .catalog-table { table-layout: fixed; }
    .catalog-table th:first-child { width: 32%; }
}
.documents-table th:nth-child(2) { width: 13rem; }
.documents-table .sale-detail {
    display: inline-grid; align-content: center; max-width: 100%;
    white-space: normal; overflow-wrap: anywhere;
}

#paytitle { flex-wrap: nowrap; }
#payAmount { margin-inline-start: auto; }
.cash-options {
    display: grid;
    grid-auto-rows: 1fr;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--action-gap);
}
.cash-options button {
    min-height: var(--wide);
    border-radius: var(--control-radius);
    font-weight: 600;
}
.cash-options button[aria-pressed=true] {
    color: var(--action);
    background: var(--tint);
    border-color: var(--action);
}
.cash-summary {
    display: grid;
    gap: var(--m);
    padding: var(--l);
    background: var(--result-bg);
    border-radius: var(--control-radius);
}
.cash-summary p {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--m);
    font-variant-numeric: tabular-nums;
}
.cash-summary p:first-child { color: var(--muted); }
.cash-summary p > :last-child { white-space: nowrap; text-align: right; }
#changeAmount { font-size: var(--large); }
.cash-hint { color: var(--danger); font-size: var(--small); }
.cash-hint:empty { display: none; }
@media (min-width: 721px) {
    #pay:has(#cashfields:not([hidden])) .dialog-actions {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
    }
}
.cash-options button:last-child:nth-child(odd of :not([hidden])) {
    grid-column: span 2;
    justify-self: center;
    width: calc((100% - var(--action-gap)) / 2);
}
