/* Purchasing: bills, receipts, suppliers, purchase orders (modules/purchasing.js). Tokens only.
   Builds on money.css (doc-layout, line editor, totals). */

/* lines: the amount is an input on bills, so it sits level with qty and unit cost */
.pu-line .line-amt { padding-top: 0; font-weight: 400; }
.pu-line select.line-kind { max-width: 160px; }
.pu-line .pu-unit { max-width: 90px; min-height: 28px; padding: 2px 8px; font-size: var(--fs-xs); }
.pu-po-line .line-amt { padding-top: 8px; font-weight: 600; }

/* taxes as printed */
.pu-taxes { gap: var(--s2); }
.pu-tax-row { display: grid; grid-template-columns: 110px 140px auto; gap: var(--s2); align-items: center; }
.pu-tax-row select { min-height: 36px; padding: 6px 10px; border: 1px solid var(--border-input); border-radius: var(--r-sm); background: var(--surface); color: inherit; font: inherit; }
.pu-tax-row .input { min-height: 36px; padding: 6px 10px; border: 1px solid var(--border-input); border-radius: var(--r-sm); background: var(--surface); width: 100%; text-align: right; }
.pu-note { margin: 0; font-size: var(--fs-sm); }

/* status, problems and the "doesn't add up" warning */
.pu-status { display: inline-flex; gap: var(--s1); flex-wrap: wrap; }
.pu-actions { flex-wrap: wrap; gap: var(--s2); }
.pu-problems { margin: 0; padding-left: var(--s5); font-size: var(--fs-sm); display: flex; flex-direction: column; gap: 2px; }
.pu-problems .block { color: var(--danger); }
.pu-problems .warn { color: var(--warning); }
.pu-mismatch { display: flex; gap: var(--s2); align-items: flex-start; margin-top: var(--s2); padding: var(--s3); border-radius: var(--r-sm); background: var(--warning-soft); color: var(--text); font-size: var(--fs-sm); }
.pu-mismatch svg { color: var(--warning); flex: none; margin-top: 2px; }
.pu-mismatch .btn { margin-top: var(--s2); }
.totals-row.pu-diff.bad { color: var(--danger); font-weight: 600; }
.pu-billed { gap: 2px; font-size: var(--fs-sm); margin-top: var(--s1); }

/* the bill itself: a photo or a PDF */
.pu-receipt { margin: 0; display: flex; flex-direction: column; gap: var(--s1); }
.pu-receipt img { width: 100%; max-height: 420px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); }
.pu-receipt.pdf { flex-direction: row; align-items: center; gap: var(--s3); padding: var(--s2) 0; }
.pu-file { display: none; }

/* purchase order from material requests */
.pu-po-requests .list-row { flex-wrap: wrap; }
.pu-po-requests .qty { font-weight: 700; min-width: 64px; }
.pu-po-requests .grow { min-width: 160px; }
.pu-vendor-pick { min-width: 200px; margin: 0; }

/* Release 1: tax use, trucks, price variances, closed periods, receiving, committed cost */
.pu-line-warn { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; margin-top: var(--s1); font-size: var(--fs-sm); color: var(--text); }
.pu-line-warn svg { color: var(--warning); flex: none; }
.pu-partial { font-size: var(--fs-sm); color: var(--warning); }
.pu-variances { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s3); border-radius: var(--r-sm); background: var(--warning-soft); }
.pu-problems .ok { color: var(--text-muted); }
.pu-lock { display: inline-flex; color: var(--text-muted); }
.rcv-lines { display: flex; flex-direction: column; gap: var(--s2); }
.rcv-line { display: grid; grid-template-columns: 1fr 110px; gap: var(--s2); align-items: center; }
.rcv-line input { width: 100%; }

@media (max-width: 640px) {
  .pu-tax-row { grid-template-columns: 1fr 1fr auto; }
  .pu-vendor-pick { width: 100%; }
  .rcv-line { grid-template-columns: 1fr 90px; }
}

/* Quick receipt capture (wheel → Receipt): the captured photo preview in the allocate sheet. */
.qr-quick .qr-snap { margin: 0; display: flex; align-items: center; justify-content: center; max-height: 240px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.qr-quick .qr-snap img { max-height: 240px; max-width: 100%; object-fit: contain; }
.qr-quick .qr-snap.pdf { gap: 10px; padding: 16px; justify-content: flex-start; color: var(--text-muted); }

/* ---------- Material requests (modules/materials.js) ----------
   The request composer ("What do you need?" under the title, the price book as rows, the details
   group) and the office list (one inset group per job). modules.css still holds the original
   .mr-* rules; the ones below win where the redesign reuses a class for the tests' sake. */
.mr-page .mr-what { min-height: 52px; border-radius: 14px; padding-left: var(--s3); }
.mr-page .mr-what .search-field-input { height: 52px; font-size: var(--fs-body); }
.mr-page .mr-what:focus-within { box-shadow: 0 0 0 2px var(--accent-fill); }
.mr-composer { display: block; }
.mr-composer .mr-what { margin-bottom: var(--s4); }
.mr-composer .ios-group { margin-bottom: var(--s4); }
.mr-picks { display: block; }
.ios-row.mr-pick { min-height: var(--row); height: auto; padding: 0 0 0 var(--s4); border: 0; border-radius: 0; background: var(--surface); font-size: inherit; }
.ios-row.mr-pick[aria-pressed="true"] { border: 0; background: var(--accent-soft); font-weight: inherit; }
.ios-row.mr-pick[aria-pressed="true"] .ios-row-title { font-weight: 600; }
.mr-details[hidden] { display: none; }
.mr-form-row { cursor: default; }
label.mr-form-row { cursor: pointer; }
.mr-form-row .ios-row-body { gap: var(--s3); }
.mr-qty-row .ios-row-text { flex: 0 1 auto; }
.mr-stepper { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.mr-step { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--fill); color: var(--text); cursor: pointer; }
.mr-step:active { background: var(--fill-strong); transform: scale(.95); }
.mr-step:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: 2px; }
.mr-qty-input, .mr-unit-input, .mr-note-input { min-width: 0; height: 40px; border: 0; border-radius: 10px; background: var(--fill); color: var(--text); font: inherit; font-size: var(--fs-body); outline: none; -webkit-appearance: none; appearance: none; }
.mr-qty-input { width: 60px; text-align: center; font-weight: 600; -moz-appearance: textfield; }
.mr-qty-input::-webkit-inner-spin-button, .mr-qty-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.mr-unit-input { width: 60px; margin-left: 6px; padding: 0 var(--s2); text-align: center; }
.mr-note-input { flex: 1; width: 100%; padding: 0 var(--s3); background: transparent; padding-left: 0; }
.mr-qty-input:focus, .mr-unit-input:focus { box-shadow: 0 0 0 2px var(--accent-fill); }
.mr-note-row .ios-row-body { padding-top: 4px; padding-bottom: 4px; }
.mr-job-row .ios-row-value { max-width: 62%; color: var(--text-muted); }
.mr-job-select { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.mr-form-row input.switch { flex: none; width: 50px; height: 30px; margin-left: auto; }
.mr-page .status-card { margin-bottom: var(--s5); }
.mr-seg { margin: 0 0 var(--s4); }
.mr-scope { margin: 0 var(--s4) var(--s3); }
.ios-row-wrap.mr-row { display: block; flex-wrap: nowrap; }
.mr-row .ios-row-title { font-weight: 600; }
.mr-sub { display: flex; flex-direction: column; gap: 2px; }
.mr-sub .mr-stock { font-size: var(--fs-footnote); line-height: var(--lh-footnote); font-weight: 600; }
.mr-check { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--text-muted); color: var(--on-accent); }
.mr-check.on { border-color: var(--accent-fill); background: var(--accent-fill); }
.mr-row .ios-row[aria-pressed="true"] { background: var(--accent-soft); }
.mr-job .ios-group-header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-job-link { flex: none; color: var(--accent); font-size: var(--fs-footnote); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s2); margin: -14px calc(-1 * var(--s2)) -6px 0; }
.mr-job-link::after { content: "›"; margin-left: 3px; font-size: 1.2em; line-height: 1; }
.mr-more { margin-top: var(--s5); }
.mr-danger .ios-row { justify-content: center; }
.mr-danger .ios-row-text { align-items: center; }
.mr-trailing { display: inline-flex; align-items: center; gap: var(--s1); }
@media (max-width: 480px) {
  .mr-row .badge { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- Purchasing lists (modules/purchasing.js): home, orders, suppliers ---------- */
.pu-page .status-card { margin-bottom: var(--s5); }
.pu-sections { margin-bottom: var(--s5); }
.pu-filter { margin: 0 0 var(--s4); }
.pu-filter .tabs { display: flex; }
.pu-seg { margin: 0 0 var(--s4); }
.pu-hint { margin-top: calc(-1 * var(--s3)); }
.ios-row .pu-status { flex: none; display: inline-flex; align-items: center; gap: var(--s1); flex-wrap: nowrap; }
.ios-row .pu-status .qbo-badge-host:empty { display: none; }
.pu-avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--tile-purple); color: var(--on-tile); }
.pu-bills .ios-row-value, .pu-orders .ios-row-value { font-weight: 600; color: var(--text); }
.pu-vendor-qbo:empty { display: none; }
.pu-vendor-qbo { margin-top: var(--s2); }
.pu-danger { margin-top: var(--s2); }
.pu-danger .ios-row { justify-content: center; }
.pu-danger .ios-row-text { align-items: center; }
/* A wide screen keeps the total; a phone keeps the supplier, the status and the subtitle. */
@media (max-width: 480px) {
  .pu-bills .ios-row .qbo-badge-host, .pu-orders .ios-row .qbo-badge-host { display: none; }
  .pu-bills .ios-row-value, .pu-orders .ios-row-value { font-size: var(--fs-subhead); max-width: 34%; }
  .ios-row .pu-status .badge { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- Bill and purchase order editors: grouped cards, the action bar, a red Delete row ---------- */
.pu-doc-page .doc-layout { margin-bottom: var(--s4); }
.pu-card { border: 0; border-radius: var(--r-group); box-shadow: none; }
.pu-card > h3 { font-size: var(--fs-footnote); line-height: var(--lh-footnote); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; margin: 0 0 var(--s3); }
.pu-card .field > span { font-weight: 600; }
.pu-status-card .row:first-child strong { font-size: var(--fs-headline); }
.pu-doc-page .pu-actions .btn { flex: 1 1 auto; }
.pu-doc-page .doc-side { position: static; }
/* The status card's other actions, as rows under it. */
.pu-status-card { display: flex; flex-direction: column; gap: var(--s3); }
.pu-status-card .ios-group { margin: 0; }
.pu-status-card > .stack > .card { margin: 0; }
@media (max-width: 1000px) {
  /* One column: the status (what to do next) on top, the form, then totals and the photo, Delete last. */
  .pu-doc-page .doc-layout { display: flex; flex-direction: column; align-items: stretch; gap: var(--s4); }
  .pu-doc-page .doc-layout > .stack, .pu-doc-page .doc-side, .pu-doc-page .doc-side > .stack { display: contents; }
  .pu-doc-page .pu-status-card { order: -1; }
  .pu-doc-page .pu-after { order: 1; }
  .pu-doc-page .pu-danger-host { order: 2; }
}

/* ---------- Inventory (modules/inventory.js) ---------- */
.inv-tabs-row { margin: 0 0 var(--s5); }
.inv-tabs-row .tabs { display: flex; }
.inv-body > .status-card { margin-bottom: var(--s4); }
.inv-seg { margin: 0 0 var(--s4); }
.inv-count { margin-top: calc(-1 * var(--s3)); margin-bottom: var(--s5); }
.inv-tools { margin-top: var(--s5); }
.inv-book .ios-row-value, .inv-stock .ios-row-value { color: var(--text); font-weight: 600; }
.inv-lock { flex: none; display: inline-flex; color: var(--text-muted); }
.inv-group-total { font-size: var(--fs-footnote); font-weight: 600; color: var(--text); }
.inv-asof .ios-row-body { gap: var(--s3); }
.inv-date { margin-left: auto; height: 40px; padding: 0 var(--s3); border: 0; border-radius: 10px; background: var(--fill); color: var(--text); font: inherit; font-size: var(--fs-body); }
.inv-date:focus { outline: none; box-shadow: 0 0 0 2px var(--accent-fill); }
.inv-danger .ios-row { justify-content: center; }
.inv-danger .ios-row-text { align-items: center; }
.inv-page .focus-note { margin-bottom: var(--s4); }
@media (max-width: 480px) {
  .inv-book .ios-row-value { font-size: var(--fs-subhead); }
}
/* The line editor (money.css) on a phone or iPad: every control a finger can hit is 44pt. */
@media (pointer: coarse), (max-width: 1023px) {
  .pu-doc-page .line-row .input, .pu-doc-page .pu-tax-row select, .pu-doc-page .pu-tax-row .input { min-height: 44px; }
  .pu-doc-page .line-meta select.line-kind, .pu-doc-page .line-meta .pu-unit { min-height: 44px; padding-top: 0; padding-bottom: 0; font-size: var(--fs-subhead); }
  .pu-doc-page .line-meta { gap: var(--s2); }
}

/* supplier invoices by email (lib/supplier-mail-ui.js): the address, the email sheet, the bill's note */
.sm-address-box { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; padding: var(--s3); border-radius: var(--r-sm); background: var(--fill); }
.sm-address { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; font-size: var(--fs-sm); user-select: all; }
.sm-text summary { cursor: pointer; font-size: var(--fs-sm); color: var(--text-muted); }
.sm-text pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; font-size: var(--fs-xs); margin: var(--s2) 0 0; }
.pu-from-email { display: flex; flex-direction: column; gap: var(--s2); align-items: flex-start; margin-bottom: var(--s3); }