/* Trade customers' area and the shared sign-in pages. Loaded after staff.css, which sets the look (colours, type,
   buttons, cards, top bar); this file only adds the pieces the staff portal doesn't have, in staff.css tokens. */

/* Top bar: business name and Sign out (right of the menu on wide screens, foot of the drawer on phones). */
.trade-who { display: flex; align-items: center; gap: 12px; }
.trade-who-name { font-weight: 500; color: var(--text-2); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1199.98px) {
    .trade-who { margin-top: auto; padding: 14px 12px; border-top: 1px solid var(--border); flex-direction: column; align-items: stretch; }
    .trade-who-name { max-width: none; color: var(--text); font-weight: 600; white-space: normal; }
    .trade-who .btn { width: 100%; min-height: var(--tap); }
}

/* Sign-in pages: the staff sign-in card, plus the "Apply for one" line under it. */
.trade-auth-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--text-2); }

/* Page heads */
.trade-page { padding-top: 28px; }
.trade-hello, .trade-head { margin-bottom: 20px; }
.trade-hello h1, .trade-head h1 { margin-bottom: 6px; }
.trade-hello p, .trade-head p { color: var(--text-2); margin: 0; max-width: 72ch; }
.trade-empty { color: var(--text-2); margin: 8px 0; }
.trade-count { color: var(--text-2); font-size: 0.875rem; margin-bottom: 8px; }
@media (max-width: 575.98px) { .trade-page { padding-top: 18px; } }

/* Balance figures: like the staff figure cards; what's owed leads in soft ROK blue. */
.trade-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.trade-figure { display: grid; gap: 2px; align-content: start; min-width: 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
.trade-figure.is-main { background: var(--primary-soft); border-color: #BBDCF0; }
.trade-figure-label { font-size: 0.8125rem; font-weight: 500; color: var(--text-2); }
.trade-figure.is-main .trade-figure-label { color: var(--primary-hover); }
.trade-figure strong { font-size: 1.625rem; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.trade-figure strong.is-good { color: var(--success); }
.trade-figure.is-main a { font-weight: 600; font-size: 0.875rem; }
.trade-over { font-size: 0.8125rem; font-weight: 600; color: var(--danger); }

/* Home shortcuts */
.trade-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.trade-tile { display: flex; gap: 14px; align-items: center; min-height: 72px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); color: var(--text); text-decoration: none; transition: border-color 0.12s ease-out, box-shadow 0.12s ease-out; }
.trade-tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); color: var(--text); text-decoration: none; }
.trade-tile i { width: 40px; height: 40px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-size: 1.05rem; }
.trade-tile strong { display: block; font-weight: 600; }
.trade-tile span { font-size: 0.875rem; color: var(--text-2); }
.trade-tile span strong { font-size: 0.9375rem; color: var(--text); }

/* Lists of orders, invoices and returns */
.trade-list { list-style: none; margin: 0; padding: 0; }
.trade-list > li { border-top: 1px solid var(--border); }
.trade-list > li:first-child { border-top: 0; }
.trade-list a { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 56px; padding: 10px 4px; color: var(--text); text-decoration: none; }
.trade-list a:hover strong { color: var(--primary); }
.trade-list strong { font-weight: 600; }
.trade-list small { display: block; color: var(--text-2); }
.trade-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trade-invoices { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); padding: 0 16px; }
.trade-list a.trade-return { min-height: 44px; padding: 4px 4px 12px 24px; color: var(--text-2); font-size: 0.875rem; }
.trade-return small { display: inline; margin-left: 6px; }

/* Products: search, then a list of products (cards on phones) */
.trade-search { position: relative; display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.trade-search > i { position: absolute; left: 16px; top: 26px; transform: translateY(-50%); color: var(--text-3); z-index: 1; }
.trade-search .form-control { flex: 1 1 220px; padding-left: 44px; }
.trade-group { flex: 0 1 220px; }
.trade-search .btn { min-height: 52px; padding: 0 22px; }
.trade-products { list-style: none; margin: 0; padding: 0 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
.trade-product { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto 110px; align-items: center; gap: 10px 14px; padding: 14px 0; border-top: 1px solid var(--border); }
.trade-product:first-child { border-top: 0; }
.trade-product-main { display: grid; gap: 2px; min-width: 0; }
.trade-product-code { font-weight: 600; }
.trade-product-desc { color: var(--text-2); overflow-wrap: anywhere; }
.trade-product-note { font-size: 0.8125rem; color: var(--text-2); }
.trade-product-note i { margin-right: 6px; color: var(--primary); }
.trade-price { text-align: right; font-weight: 600; font-size: 1.0625rem; font-variant-numeric: tabular-nums; }
.trade-price small { display: block; font-weight: 400; font-size: 0.75rem; color: var(--text-2); }
.trade-add { display: flex; gap: 8px; align-items: center; grid-column: 2 / -1; }
.trade-add .form-control { width: 80px; }

/* Basket and order lines */
.trade-basket-line { grid-template-columns: 48px minmax(0, 1fr) auto 110px auto; }
.trade-order-line { grid-template-columns: 48px minmax(0, 1fr) 110px; }
.trade-qty { display: flex; gap: 6px; align-items: center; }
.trade-qty .form-control { width: 76px; text-align: center; }
.trade-remove .btn { color: var(--danger); }
.trade-facts.trade-totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; max-width: 320px; margin: 0 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; }
.trade-totals dt { color: var(--text-2); font-weight: 400; }
.trade-totals dd { margin: 0; font-weight: 600; }

/* Order status and progress */
.trade-status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; background: #EEF1F5; color: var(--text-2); }
.trade-status.is-sent, .trade-status.is-picking { background: var(--warning-bg); color: var(--warning); }
.trade-status.is-ready, .trade-status.is-collected { background: var(--success-bg); color: var(--success); }
.trade-status.is-cancelled { background: var(--danger-bg); color: var(--danger); }
.trade-progress { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 0; margin: 0 0 16px; }
.trade-progress li { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--text-3); font-size: 0.875rem; font-weight: 500; text-align: center; }
.trade-progress li.is-done { background: var(--success-bg); border-color: var(--success-bg); color: var(--success); }
.trade-progress li.is-now { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* Statement */
.trade-opening td { color: var(--text-2); background: var(--surface-2); }

/* Account */
.trade-facts { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: 8px 18px; margin: 0; }
.trade-facts dt { color: var(--text-2); font-weight: 500; font-size: 0.875rem; }
.trade-facts dd { margin: 0; overflow-wrap: anywhere; }
.trade-contacts, .trade-requests { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.trade-requests li { display: grid; gap: 2px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.trade-requests small { color: var(--text-2); }

@media (max-width: 991.98px) {
    .trade-tiles { grid-template-columns: 1fr; }
}
@media (max-width: 767.98px) {
    .trade-figures { grid-template-columns: 1fr 1fr; }
    .trade-figure.is-main { grid-column: 1 / -1; }
    .trade-product { grid-template-columns: 48px minmax(0, 1fr) auto; }
    .trade-product .stock-mark { grid-column: 2; justify-self: start; }
    .trade-price { grid-row: 1; grid-column: 3; }
    .trade-facts { grid-template-columns: 1fr; gap: 2px; }
    .trade-facts dd { margin-bottom: 8px; }
    .trade-facts.trade-totals { grid-template-columns: 1fr auto; gap: 6px 18px; }
    .trade-totals dd { margin-bottom: 0; }
}
@media (max-width: 575.98px) {
    .trade-search .btn, .trade-group { flex: 1 1 100%; }
    .trade-products { padding: 0; background: transparent; border: 0; box-shadow: none; display: grid; gap: 12px; }
    .trade-product, .trade-product:first-child { padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
    .trade-add { grid-column: 1 / -1; }
    .trade-add .btn { flex: 1; }
    .trade-basket-line { grid-template-columns: 48px minmax(0, 1fr) auto; }
    .trade-basket-line .trade-qty { grid-column: 1 / -1; }
    .trade-basket-line .trade-price { grid-row: 1; grid-column: 3; }
    .trade-basket-line .trade-remove { grid-column: 1 / -1; justify-self: start; }
    .trade-facts.trade-totals { max-width: none; }
    .trade-progress { grid-template-columns: 1fr 1fr; }
    .trade-invoices { padding: 0 14px; }
}
/* Two cards in a row: the first card's own margin is the gap. */
.trade-page .panel.mb-4 + .panel { margin-top: 0; }
@media (max-width: 575.98px) {
    .trade .portal-table th, .trade .portal-table td { padding: 10px 6px; }
}

/* Page heads with an action (Create order) on the right; the button goes full width under the heading on phones. */
.trade-head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.trade-create { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 20px; }
@media (max-width: 575.98px) { .trade-create { flex: 1 1 100%; justify-content: center; } }

/* Header basket button: a live count; opens the basket panel (a link to the Basket page without JS). */
.trade-basket-btn { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-weight: 500; text-decoration: none; white-space: nowrap; }
.trade-basket-btn:hover, .trade-basket-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.trade-basket-btn.active { border-color: var(--primary); color: var(--primary); }
.trade-basket-btn i { color: var(--primary); }
.trade-basket-count { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.trade-basket-count[hidden] { display: none; }
@media (min-width: 1200px) { .trade-basket-btn { margin-left: 12px; } }
@media (max-width: 575.98px) {
    .trade-basket-btn { padding: 0 11px; }
    .trade-basket-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* The basket panel: a dropdown under the top bar on wider screens; a panel from the right on phones. */
.trade-basket-panel { --bs-offcanvas-width: min(420px, 92vw); background: var(--surface); color: var(--text); }
.trade-basket-panel .offcanvas-header { min-height: var(--header-h); border-bottom: 1px solid var(--border); }
.trade-basket-panel .btn-close { width: var(--tap); height: var(--tap); }
.trade-basket-panel .offcanvas-body { flex: 1 1 auto; min-height: 0; padding: 4px 16px 12px; }
.trade-basket-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface-2); }
.trade-basket-foot[hidden] { display: none; }
.trade-basket-foot .btn { min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; }
@media (min-width: 768px) {
    .trade-basket-panel.offcanvas-end {
        top: calc(var(--header-h) + 6px); bottom: auto; right: max(12px, calc((100vw - 1320px) / 2 + 12px));
        width: 420px; height: auto; max-height: calc(100vh - var(--header-h) - 24px);
        border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden;
        opacity: 0; transform: translateY(-6px); transition: opacity 0.15s ease-out, transform 0.15s ease-out, visibility 0.15s;
    }
    .trade-basket-panel.offcanvas-end.showing, .trade-basket-panel.offcanvas-end.show:not(.hiding) { opacity: 1; transform: none; }
    .trade-basket-panel.offcanvas-end.hiding { opacity: 0; transform: translateY(-6px); }
    .trade-basket-panel .offcanvas-header { min-height: 0; padding: 12px 12px 12px 16px; }
    body.trade-basket-open .offcanvas-backdrop.show { opacity: 0.12; }
}
@media (prefers-reduced-motion: reduce) { .trade-basket-panel.offcanvas-end { transition: none; } }

/* Basket lines, as the panel and the Create order popup draw them */
.trade-mini-empty { color: var(--text-2); margin: 16px 0; }
.trade-mini-lines { list-style: none; margin: 0; padding: 0; }
.trade-mini-line { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "img what sum" "img qty remove"; align-items: center; gap: 8px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.trade-mini-line.is-busy { opacity: 0.6; }
.trade-mini-line > .thumb { grid-area: img; align-self: start; width: 40px; height: 40px; }
.trade-mini-what { grid-area: what; display: grid; gap: 1px; min-width: 0; }
.trade-mini-code { font-weight: 600; }
.trade-mini-desc { font-size: 0.875rem; color: var(--text-2); overflow-wrap: anywhere; line-height: 1.3; }
.trade-mini-each { font-size: 0.8125rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.trade-mini-was { color: var(--warning); font-weight: 600; }
.trade-mini-gone { color: var(--danger); font-weight: 600; }
.trade-mini-line.is-unavailable .trade-mini-code { color: var(--text-2); text-decoration: line-through; }
.trade-mini-qty { grid-area: qty; display: flex; align-items: center; gap: 4px; }
.trade-mini-qty .btn { width: var(--tap); min-height: var(--tap); padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 1.125rem; line-height: 1; }
.trade-mini-qty .form-control { width: 64px; min-height: var(--tap); padding: 4px 6px; text-align: center; -moz-appearance: textfield; }
.trade-mini-qty .form-control::-webkit-outer-spin-button, .trade-mini-qty .form-control::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.trade-mini-sum { grid-area: sum; justify-self: end; align-self: start; font-weight: 600; font-variant-numeric: tabular-nums; }
.trade-mini-remove { grid-area: remove; justify-self: end; width: var(--tap); min-height: var(--tap); padding: 0; color: var(--text-3); border-radius: var(--radius-sm); }
.trade-mini-remove:hover, .trade-mini-remove:focus-visible { color: var(--danger); background: var(--danger-bg); }
.trade-mini-totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 0; margin: 12px 0 0; font-variant-numeric: tabular-nums; }
.trade-mini-totals[hidden] { display: none; }
.trade-mini-totals dt { font-weight: 400; color: var(--text-2); }
.trade-mini-totals dd { margin: 0; padding-left: 16px; text-align: right; font-weight: 600; }
.trade-mini-totals .is-total { padding-top: 6px; border-top: 1px solid var(--border); font-size: 1.0625rem; font-weight: 700; color: var(--text); }

/* Products: instant add */
.trade-add .btn.is-added { background: var(--success); border-color: var(--success); color: #fff; }
.trade-add-error { grid-column: 2 / -1; color: var(--danger); font-size: 0.875rem; font-weight: 500; }
.trade-add-error[hidden] { display: none; }
@media (max-width: 575.98px) { .trade-add-error { grid-column: 1 / -1; } }

/* Create order popup: like the staff sale popup; full screen below lg. */
.trade-order-modal .modal-content { background: var(--bg); }
.trade-order-modal .modal-header { background: var(--surface); align-items: flex-start; }
.trade-order-modal .modal-header .btn-close { width: var(--tap); height: var(--tap); margin: -6px -6px -6px auto; }
.trade-order-titles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; }
.trade-steps { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.trade-steps li { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-3); font-size: 0.8125rem; font-weight: 500; }
.trade-steps li span { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--border); color: var(--text-2); font-size: 0.75rem; font-weight: 700; }
.trade-steps li.is-now { background: var(--primary-soft); border-color: #BBDCF0; color: var(--primary-hover); font-weight: 600; }
.trade-steps li.is-now span { background: var(--primary); color: #fff; }
.trade-steps li.is-done { color: var(--success); }
.trade-steps li.is-done span { background: var(--success-bg); color: var(--success); }
.trade-builder { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 992px) { .trade-builder { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; } .trade-builder-side { position: sticky; top: 0; } }
.trade-builder-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.trade-builder-heading { font-size: 1rem; font-weight: 600; margin: 0 0 12px; }
.trade-builder-heading:focus { outline: none; }
.trade-side-count { margin-left: 6px; font-weight: 500; font-size: 0.875rem; color: var(--text-2); }
.trade-builder-input { position: relative; }
.trade-builder-input > i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.trade-builder-input .form-control { padding-left: 44px; }
.trade-builder-note { font-size: 0.875rem; color: var(--text-2); margin: 8px 0 4px; }
.trade-results { list-style: none; margin: 0; padding: 0; }
.trade-result { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "img main price" ". add add" ". err err"; align-items: center; gap: 8px 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.trade-result > .thumb { grid-area: img; align-self: start; width: 40px; height: 40px; }
.trade-result-main { grid-area: main; display: grid; gap: 2px; justify-items: start; min-width: 0; }
.trade-result .trade-price { grid-area: price; align-self: start; }
.trade-result-add { grid-area: add; display: flex; gap: 8px; }
.trade-result-add .form-control { width: 76px; min-height: var(--tap); text-align: center; }
.trade-result-add .btn { min-height: var(--tap); min-width: 104px; padding: 0 16px; }
.trade-result-add .btn.is-added { background: var(--success); border-color: var(--success); color: #fff; }
.trade-result .trade-add-error { grid-area: err; }
@media (min-width: 768px) {
    .trade-result { grid-template-columns: 40px minmax(0, 1fr) 96px auto; grid-template-areas: "img main price add" ". err err err"; }
}
.trade-pay { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trade-pay-option { display: flex; gap: 12px; align-items: flex-start; height: 100%; min-height: 64px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.trade-pay-option i { margin-top: 3px; color: var(--text-3); }
.trade-pay-option strong { display: block; font-weight: 600; }
.trade-pay-option small { display: block; color: var(--text-2); font-size: 0.8125rem; }
.btn-check:checked + .trade-pay-option { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.btn-check:checked + .trade-pay-option i { color: var(--primary); }
.btn-check:focus-visible + .trade-pay-option { box-shadow: 0 0 0 3px var(--primary-ring); }
.btn-check:disabled + .trade-pay-option { cursor: not-allowed; background: var(--surface-2); color: var(--text-3); }
.btn-check:disabled + .trade-pay-option small { color: var(--text-2); }
@media (max-width: 575.98px) { .trade-pay { grid-template-columns: 1fr; } }
.trade-optional { font-weight: 400; color: var(--text-2); }
.trade-builder-card fieldset { margin-top: 16px; }
.trade-optional[hidden] { display: none; }
.trade-builder-foot { background: var(--surface); justify-content: flex-end; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.trade-builder-foot > * { margin: 0; }
.trade-builder-summary { margin-right: auto !important; color: var(--text-2); font-variant-numeric: tabular-nums; }
.trade-builder-summary strong { color: var(--text); font-size: 1.0625rem; }
.trade-builder-hint { flex-basis: 100%; order: 5; text-align: right; font-size: 0.875rem; color: var(--warning); font-weight: 500; }
.trade-builder-hint[hidden] { display: none; }
.trade-builder-foot .btn { min-height: var(--tap); display: inline-flex; align-items: center; gap: 8px; padding: 0 20px; }
@media (max-width: 575.98px) {
    .trade-builder-summary { flex-basis: 100%; }
    .trade-builder-foot .btn { flex: 1 1 0; justify-content: center; }
    .trade-builder-hint { text-align: left; }
    .trade-order-modal .modal-body { padding: 12px; }
}
