/* AP Bills workspace. Presentation only: layout, typography and states. Design tokens come from the ERP palette in
   app.css; .apb-ui carries them for the page and for the bill workspace inside the modal. */

.apb-ui {
  --apb-ink: var(--text, #0f172a);
  --apb-ink-2: var(--text2, #334155);
  --apb-muted: var(--muted, #64748b);
  --apb-line: var(--border, #e2e8f0);
  --apb-line-2: var(--border2, #cbd5e1);
  --apb-surface: var(--surface, #ffffff);
  --apb-canvas: var(--bg, #f8fafc);
  --apb-accent: var(--brand, #4f46e5);
  --apb-accent-d: var(--brand-d, #3730a3);
  --apb-accent-bg: var(--brand-light, #eef2ff);
  --apb-ok: #047857;
  --apb-ok-bg: #ecfdf5;
  --apb-warn: #92400e;
  --apb-warn-bg: #fffbeb;
  --apb-danger: #b91c1c;
  --apb-danger-bg: #fef2f2;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--apb-ink);
  font-size: 13px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
}
.apb-ui *, .apb-ui *::before, .apb-ui *::after { box-sizing: border-box; }
.apb-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.apb-primary, .apb-secondary, .apb-ghost, .apb-success {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.apb-primary { background: var(--apb-accent); border: 1px solid var(--apb-accent); color: #fff; }
.apb-primary:hover:not(:disabled) { background: var(--apb-accent-d); border-color: var(--apb-accent-d); }
.apb-primary--lg { height: 40px; padding: 0 18px; font-size: 13.5px; }
.apb-success { background: var(--apb-ok); border: 1px solid var(--apb-ok); color: #fff; }
.apb-success:hover:not(:disabled) { background: #065f46; border-color: #065f46; }
.apb-secondary { background: var(--apb-surface); border: 1px solid var(--apb-line-2); color: var(--apb-ink-2); }
.apb-secondary:hover:not(:disabled) { background: var(--apb-canvas); border-color: var(--apb-muted); }
.apb-ghost { background: transparent; border: 1px solid transparent; color: var(--apb-ink-2); }
.apb-ghost:hover:not(:disabled), .apb-ghost.is-on { background: var(--apb-canvas); }
.apb-ghost.is-on { border-color: var(--apb-line); }
.apb-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.apb-block-btn { width: 100%; margin-top: 10px; }
.apb-link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--apb-accent); cursor: pointer; }
.apb-danger-link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; font-weight: 600; color: var(--apb-danger); cursor: pointer; }
.apb-link { color: var(--apb-accent); font-size: 12px; font-weight: 600; text-decoration: none; }
.apb-link:hover { text-decoration: underline; }
.apb-primary:disabled, .apb-secondary:disabled, .apb-success:disabled, .apb-ghost:disabled, .apb-danger-link:disabled { opacity: .5; cursor: not-allowed; }
.apb-ui button:focus-visible, .apb-ui a:focus-visible, .apb-ui input:focus-visible, .apb-ui select:focus-visible, .apb-ui textarea:focus-visible, .apb-table-wrap:focus-visible {
  outline: 2px solid var(--apb-accent); outline-offset: 2px;
}

/* ── Register ────────────────────────────────────────────────────────── */
.apb-shell { display: flex; flex-direction: column; gap: 14px; max-width: 1280px; margin: 0 auto; padding-bottom: 28px; min-width: 0; }
.apb-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.apb-head-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.apb-head h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.015em; color: var(--apb-ink); }
.apb-head-meta { font-size: 13px; color: var(--apb-muted); }

.apb-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; overflow: hidden; }
.apb-kpi { padding: 12px 18px; border-right: 1px solid var(--apb-line); min-width: 0; }
.apb-kpi:last-child { border-right: 0; }
.apb-kpi dt { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--apb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apb-kpi dd { margin: 3px 0 0; font-size: 18px; font-weight: 700; color: var(--apb-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apb-kpi.is-overdue dd { color: var(--apb-warn); }
.apb-kpi.is-overdue { box-shadow: inset 3px 0 0 #f59e0b; }

.apb-list { background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; overflow: hidden; min-width: 0; }
.apb-list-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 0 14px; border-bottom: 1px solid var(--apb-line); }
.apb-tabs { display: flex; gap: 20px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.apb-tabs::-webkit-scrollbar { display: none; }
.apb-tab { display: inline-flex; align-items: center; gap: 7px; height: 44px; padding: 0; margin-bottom: -1px; background: none; border: 0; border-bottom: 2px solid transparent; font: inherit; font-size: 13px; font-weight: 600; color: var(--apb-muted); cursor: pointer; white-space: nowrap; }
.apb-tab:hover { color: var(--apb-ink-2); }
.apb-tab.is-active { color: var(--apb-accent); border-bottom-color: var(--apb-accent); }
.apb-tab-count { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--apb-canvas); border: 1px solid var(--apb-line); color: var(--apb-muted); }
.apb-tab.is-active .apb-tab-count { background: var(--apb-accent-bg); border-color: transparent; color: var(--apb-accent-d); }
.apb-tools { display: flex; align-items: center; gap: 8px; padding: 8px 0; flex-wrap: wrap; }
.apb-search { position: relative; display: flex; align-items: center; width: 260px; max-width: 100%; }
.apb-search > i { position: absolute; left: 11px; font-size: 12px; color: var(--apb-muted); pointer-events: none; }
.apb-search input { width: 100%; height: 34px; padding: 0 12px 0 32px; border: 1px solid var(--apb-line-2); border-radius: 8px; background: var(--apb-surface); font: inherit; font-size: 13px; color: var(--apb-ink); }
.apb-search input::placeholder { color: #94a3b8; }
.apb-filters { display: flex; flex-wrap: wrap; gap: 12px 16px; padding: 12px 14px; background: var(--apb-canvas); border-bottom: 1px solid var(--apb-line); }
.apb-filters label { display: flex; flex-direction: column; gap: 4px; min-width: 150px; font-size: 11.5px; font-weight: 600; color: var(--apb-muted); }
.apb-filters select, .apb-filters input[type="date"] { height: 32px; padding: 0 8px; border: 1px solid var(--apb-line-2); border-radius: 7px; background: var(--apb-surface); font: inherit; font-size: 13px; color: var(--apb-ink); }

/* Register ledger: fixed column widths so PO, dates and amounts never wrap; the vendor column takes the rest. */
.apb-table-wrap { overflow-x: auto; }
.apb-table { width: 100%; min-width: 960px; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.apb-col-vendor { width: auto; }
.apb-col-po { width: 132px; }
.apb-col-date { width: 112px; }
.apb-col-due { width: 136px; }
.apb-col-amount { width: 176px; }
.apb-col-status { width: 124px; }
.apb-col-action { width: 184px; }
.apb-table thead th { position: sticky; top: 0; z-index: 1; padding: 9px 14px; background: var(--apb-canvas); border-bottom: 1px solid var(--apb-line); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--apb-muted); text-align: left; white-space: nowrap; }
.apb-table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--apb-line); vertical-align: middle; color: var(--apb-ink-2); min-width: 0; }
.apb-table tbody tr:last-child td { border-bottom: 0; }
.apb-table tbody tr:hover td { background: #fafbff; }
.apb-num { text-align: right; white-space: nowrap; }
.apb-table thead .apb-num { text-align: right; }
.apb-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apb-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--apb-muted); }
.apb-sub-label { display: block; font-size: 12px; color: var(--apb-ink-2); }
.apb-muted { color: var(--apb-muted); }
.apb-small { font-size: 12px; }
.apb-mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--apb-ink-2); white-space: nowrap; }

/* Vendor and bill: name clamped to two lines; invoice, then source and document, as quieter lines */
.apb-cell-vendor { min-width: 0; }
.apb-vendor-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 600; line-height: 1.35; color: var(--apb-ink); overflow-wrap: anywhere; }
.apb-source { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin-top: 3px; }
.apb-source .apb-sub-label { flex: 1 1 auto; min-width: 0; color: var(--apb-muted); }
.apb-source .apb-link { flex: 0 0 auto; font-size: 12px; }

/* Dates, due labels and amounts */
.apb-cell-po, .apb-cell-date { white-space: nowrap; }
.apb-cell-due { white-space: nowrap; }
.apb-due-date { display: block; color: var(--apb-ink-2); }
.apb-due-note { display: block; margin-top: 2px; font-size: 12px; color: var(--apb-muted); }
.apb-due-note.is-overdue { color: var(--apb-danger); font-weight: 600; }
.apb-due-note.is-soon { color: var(--apb-warn); }
.apb-row.is-overdue .apb-cell-due .apb-due-date { color: var(--apb-danger); font-weight: 600; }
.apb-cell-amount { white-space: nowrap; }
.apb-open { display: block; font-size: 14px; font-weight: 700; color: var(--apb-ink); }
.apb-num-sub { white-space: normal; line-height: 1.4; }
.apb-amt-state { display: block; font-size: 12.5px; font-weight: 600; color: var(--apb-muted); }
.apb-amt-state--settled { color: var(--apb-ok); }

/* Bills that are not payables yet: a faint tint, so they read apart from posted payables */
.apb-row.is-bill td { background: var(--apb-canvas); }

/* Actions: one primary per row, the rest secondary or ghost, all the same height */
.apb-cell-action { white-space: nowrap; text-align: right; }
.apb-cell-action .apb-primary, .apb-cell-action .apb-secondary, .apb-cell-action .apb-ghost { height: 30px; padding: 0 11px; font-size: 12.5px; margin-left: 6px; }
.apb-cell-action .apb-primary { min-width: 76px; justify-content: center; }
.apb-empty-cell { padding: 0 !important; }
.apb-empty { padding: 40px 20px; text-align: center; }
.apb-empty strong { font-size: 13px; font-weight: 600; color: var(--apb-ink-2); }
.apb-state { padding: 32px 20px; text-align: center; color: var(--apb-muted); }
.apb-state--error { color: var(--apb-danger); }
.apb-foot { margin: 0; padding: 10px 14px; font-size: 12px; color: var(--apb-muted); background: var(--apb-canvas); border-top: 1px solid var(--apb-line); }

/* Status badges: colour only where it carries meaning */
.apb-pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #f1f5f9; color: #334155; white-space: nowrap; }
.apb-flagged { display: inline-block; margin-left: 6px; font-size: 11.5px; font-weight: 600; color: var(--apb-warn); }

/* ── Bill workspace (modal) ─────────────────────────────────────────── */
.apb-modal { width: min(1200px, 96vw) !important; max-width: 96vw !important; height: calc(100vh - 40px) !important; max-height: calc(100vh - 40px) !important; }
/* The header and footer keep their height. The body takes the rest and never scrolls as a whole; its two columns do. */
.apb-modal .mb { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.apb-form { font-size: 13px; display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.apb-workspace { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.apb-main { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 24px 24px; }
/* Each card keeps its own height, so a short column scrolls instead of squeezing the cards. */
.apb-aside > .apb-ctx { flex: 0 0 auto; }
.apb-aside {
  min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 16px 28px; background: var(--apb-canvas); border-left: 1px solid var(--apb-line);
}

.apb-sec { padding: 20px 0 6px; border-top: 1px solid var(--apb-line); }
.apb-main > .apb-notice + .apb-sec, .apb-main > .apb-sec:first-child { border-top: 0; }
.apb-sec-head { margin-bottom: 12px; }
.apb-sec-head h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--apb-ink); }
.apb-sec-note { margin: 3px 0 0; font-size: 12px; color: var(--apb-muted); }
.apb-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.apb-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.apb-label { font-size: 12px; font-weight: 600; color: var(--apb-ink-2); }
.apb-req { color: var(--apb-danger); }
.apb-input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--apb-line-2); border-radius: 8px; background: var(--apb-surface); font: inherit; font-size: 13px; color: var(--apb-ink); }
.apb-input:hover:not(:disabled) { border-color: #94a3b8; }
.apb-input:focus { border-color: var(--apb-accent); outline: none; box-shadow: 0 0 0 3px rgba(79, 70, 229, .14); }
.apb-input:disabled { background: var(--apb-canvas); color: var(--apb-muted); }
.apb-num-input { text-align: right; }
.apb-textarea { height: auto; min-height: 60px; padding: 8px 10px; resize: vertical; }
.apb-field.has-error .apb-input { border-color: var(--apb-danger); }
.apb-hint { font-size: 11.5px; color: var(--apb-muted); }
.apb-err { font-size: 11.5px; font-weight: 600; color: var(--apb-danger); }
.apb-history { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--apb-line); font-size: 12px; color: var(--apb-muted); }
.apb-history summary { cursor: pointer; font-weight: 600; color: var(--apb-ink-2); }
.apb-history ul { margin: 8px 0 0; padding-left: 18px; }

.apb-notice { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--apb-line); background: var(--apb-canvas); font-size: 12.5px; color: var(--apb-ink-2); }
.apb-notice--ok { background: var(--apb-ok-bg); border-color: #a7f3d0; color: #064e3b; }
.apb-notice--error { background: var(--apb-danger-bg); border-color: #fecaca; color: #7f1d1d; }

/* Context column cards */
.apb-ctx { background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; overflow: hidden; }
.apb-ctx-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--apb-line); }
.apb-ctx-head h3 { margin: 0; font-size: 12.5px; font-weight: 700; color: var(--apb-ink); }
.apb-ctx-body { padding: 12px 14px; font-size: 12.5px; color: var(--apb-ink-2); }
.apb-ctx-body p { margin: 0 0 6px; }
.apb-ctx-body p:last-child { margin-bottom: 0; }
.apb-ctx-empty strong { display: block; font-size: 13px; color: var(--apb-ink); }
.apb-ctx-empty p { margin: 4px 0 0; color: var(--apb-muted); }
.apb-tag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #f1f5f9; color: var(--apb-ink-2); white-space: nowrap; }
.apb-tag--block { background: var(--apb-danger-bg); color: var(--apb-danger); }
.apb-tag--review { background: var(--apb-warn-bg); color: var(--apb-warn); }
.apb-tag--clear { background: var(--apb-ok-bg); color: var(--apb-ok); }
.apb-po-id { font-size: 14px; font-weight: 700; color: var(--apb-ink); }
.apb-po-vendor { margin-top: 2px; color: var(--apb-muted); }
.apb-dl { margin: 12px 0 0; display: grid; gap: 0; }
.apb-dl > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--apb-line); }
.apb-dl > div:last-child { border-bottom: 0; }
.apb-dl dt { margin: 0; color: var(--apb-muted); }
.apb-dl dd { margin: 0; font-weight: 600; color: var(--apb-ink); text-align: right; }
.apb-dl dd small { display: block; font-size: 11px; font-weight: 400; color: var(--apb-muted); }
.apb-dl .is-key { background: var(--apb-accent-bg); margin: 4px -14px 0; padding: 9px 14px; border-bottom: 0; border-radius: 0; }
.apb-dl .is-key dd { font-size: 15px; color: var(--apb-accent-d); }
.apb-flags { margin: 0 0 6px; padding-left: 16px; color: var(--apb-warn); }
.apb-flags li { margin-bottom: 3px; }
.apb-flags .is-info { color: var(--apb-accent-d); }
.apb-ok { margin: 0; font-weight: 600; color: var(--apb-ok); }

.apb-match-list { list-style: none; margin: 10px 0 0; padding: 0; }
.apb-match { padding: 10px 0; border-top: 1px solid var(--apb-line); }
.apb-match:first-child { border-top: 0; padding-top: 0; }
.apb-match.is-block { padding-left: 10px; border-left: 3px solid var(--apb-danger); }
.apb-match-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.apb-match-top strong { font-size: 12.5px; color: var(--apb-ink); }
.apb-match-meta { margin-top: 2px; font-size: 12px; color: var(--apb-muted); }
.apb-match-note { margin-top: 3px; font-size: 12px; color: var(--apb-ink-2); }
.apb-match-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.apb-sep-dot { color: var(--apb-muted); }
.apb-ack { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--apb-ink-2); cursor: pointer; }
.apb-doc { display: flex; align-items: center; gap: 10px; min-width: 0; }
.apb-doc-icon { flex: 0 0 36px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; background: var(--apb-canvas); border: 1px solid var(--apb-line); color: var(--apb-accent); }
.apb-doc-text { display: flex; flex-direction: column; min-width: 0; }
.apb-doc-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--apb-ink); }

/* ── Footer ──────────────────────────────────────────────────────────── */
.mf.apb-modal-footer { display: flex; background: var(--apb-surface); padding: 12px 22px; border-top: 1px solid var(--apb-line); }
.apb-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; width: 100%; }
.apb-footer-left { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 auto; }
.apb-footer-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.apb-state-line { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--apb-ink-2); min-width: 0; }
.apb-state-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--apb-muted); }
.apb-state-dot.is-review { background: #f59e0b; }
.apb-state-dot.is-block { background: var(--apb-danger); }
.apb-divider { width: 1px; height: 26px; background: var(--apb-line-2); margin: 0 4px; }
.apb-footer .apb-primary, .apb-footer .apb-success { background-image: none; box-shadow: none; transform: none; color: #fff; text-shadow: none; }
.apb-footer .apb-primary { background-color: var(--apb-accent); border-color: var(--apb-accent); }
.apb-footer .apb-success { background-color: var(--apb-ok); border-color: var(--apb-ok); }
.apb-footer .apb-secondary { background-color: var(--apb-surface); color: var(--apb-ink-2); border-color: var(--apb-line-2); }
.apb-footer .apb-ghost { color: var(--apb-ink-2); }

/* ── Narrower desktop ───────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .apb-workspace { grid-template-columns: minmax(0, 1fr) 300px; }
  .apb-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apb-fields .span-3 { grid-column: 1 / -1; }
}

/* ── Phone and tablet: the context panel moves below the fields, in order ─ */
@media (max-width: 900px) {
  .apb-modal { height: auto !important; }
  .apb-modal .mb { overflow-y: auto; }
  .apb-form { flex: none; }
  .apb-workspace { flex: none; grid-template-columns: minmax(0, 1fr); }
  .apb-main { overflow: visible; padding: 6px 18px 20px; }
  .apb-aside { overflow: visible; border-left: 0; border-top: 1px solid var(--apb-line); padding: 16px 18px 22px; }
  .apb-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apb-kpi:nth-child(2) { border-right: 0; }
  .apb-kpi:nth-child(-n+2) { border-bottom: 1px solid var(--apb-line); }
  .apb-search { width: 100%; }
}
@media (max-width: 640px) {
  .apb-fields { grid-template-columns: minmax(0, 1fr); }
  .apb-fields .span-2, .apb-fields .span-3 { grid-column: auto; }
  .apb-head h1 { font-size: 18px; }
  .apb-primary--lg { width: 100%; }
  .apb-head { align-items: stretch; }
  /* Register: each bill is a card. Vendor and amount on top, PO and due, invoice date and status, then actions. */
  .apb-table { min-width: 0; table-layout: auto; }
  .apb-table colgroup, .apb-table thead { display: none; }
  .apb-table, .apb-table tbody { display: block; width: 100%; }
  .apb-table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "vendor amount" "po due" "date status" "action action"; gap: 10px 14px; align-items: start; padding: 14px 16px; border-bottom: 1px solid var(--apb-line); }
  .apb-table tbody tr:last-child { border-bottom: 0; }
  .apb-table tbody td { display: block; min-width: 0; padding: 0; border: 0; background: none !important; text-align: left; white-space: normal; }
  .apb-table tbody td.apb-num { text-align: right; }
  .apb-cell-vendor { grid-area: vendor; }
  .apb-cell-amount { grid-area: amount; text-align: right; }
  .apb-cell-po { grid-area: po; }
  .apb-cell-date { grid-area: date; }
  .apb-cell-due { grid-area: due; text-align: right; }
  .apb-cell-status { grid-area: status; justify-self: end; }
  .apb-table tbody td.apb-cell-action { grid-area: action; display: flex; gap: 8px; padding-top: 4px; text-align: left; }
  .apb-cell-po::before, .apb-cell-date::before, .apb-cell-due::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
  .apb-cell-action .apb-primary, .apb-cell-action .apb-secondary, .apb-cell-action .apb-ghost { flex: 1 1 0; justify-content: center; height: 38px; margin-left: 0; font-size: 13.5px; }
  .apb-cell-action .apb-ghost { flex: 0 0 auto; }
  .apb-cell-amount .apb-open { font-size: 16px; }
  .apb-cell-due .apb-due-note { white-space: normal; }
  .apb-row.is-bill { background: var(--apb-canvas); }
  .apb-footer-left, .apb-footer-right { width: 100%; justify-content: stretch; }
  .apb-footer-right .apb-primary, .apb-footer-right .apb-secondary, .apb-footer-right .apb-success, .apb-footer-right .apb-ghost { flex: 1 1 auto; }
  .apb-divider { display: none; }
  .mf.apb-modal-footer { flex-wrap: wrap; padding: 12px 16px; }
}

/* ── Register layouts (window.APB_REGISTER_VARIANT) ───────────────────── */
/* Ledger: a status rail on the first cell. Overdue is red, not-posted bills are amber, nothing else is coloured. */
.apb-register--ledger .apb-row.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--apb-danger); }
.apb-register--ledger .apb-row.is-bill td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.apb-register--ledger .apb-vendor-name { font-size: 13.5px; }

/* Vendors: one header per vendor with its open and overdue totals; the vendor name is not repeated in each row. */
.apb-register--vendors .apb-vendor-name { display: none; }
.apb-table tbody tr.apb-group th { padding: 0; background: var(--apb-surface); border-bottom: 1px solid var(--apb-line); position: static; text-transform: none; letter-spacing: 0; }
.apb-group-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; padding: 10px 14px; background: var(--apb-canvas); }
.apb-group-name { font-size: 13.5px; font-weight: 700; color: var(--apb-ink); margin-right: auto; }
.apb-group-meta, .apb-group-open { font-size: 12.5px; color: var(--apb-muted); font-weight: 600; }
.apb-group-open { color: var(--apb-ink-2); }
.apb-group-over { font-size: 12.5px; font-weight: 700; color: var(--apb-danger); }

/* Lanes: bills grouped by what needs doing, as cards. */
.apb-register--lanes { padding: 6px 14px 16px; display: grid; gap: 18px; }
.apb-lane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 2px 10px; }
.apb-lane-head h3 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--apb-ink-2); }
.apb-lane-meta { font-size: 12.5px; color: var(--apb-muted); font-weight: 600; }
.apb-lane--overdue .apb-lane-head h3 { color: var(--apb-danger); }
.apb-lane--not-posted .apb-lane-head h3 { color: var(--apb-warn); }
.apb-lane-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 12px; }
.apb-card { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; min-width: 0; }
.apb-card.is-overdue { border-color: #fecaca; }
.apb-card.is-bill { background: var(--apb-canvas); }
.apb-card-vendor { font-size: 13.5px; font-weight: 700; color: var(--apb-ink); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.apb-card-ref { margin-top: 2px; font-size: 12px; color: var(--apb-muted); }
.apb-card-amount { text-align: right; }
.apb-card-amount .apb-open { font-size: 18px; }
.apb-card-meta { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 0.9fr); gap: 8px; margin: 0; }
.apb-card-meta dt { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--apb-muted); margin: 0 0 3px; }
.apb-card-meta dd { margin: 0; font-size: 12.5px; color: var(--apb-ink-2); }
.apb-card-meta .apb-due-date { display: inline; }
.apb-card-meta .apb-due-note { display: block; margin-top: 1px; white-space: nowrap; }
.apb-card-meta dd { overflow-wrap: anywhere; min-width: 0; }
.apb-card-meta .apb-mono { white-space: normal; word-break: break-all; }
.apb-card-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--apb-line); padding-top: 10px; }
.apb-card-actions .apb-primary, .apb-card-actions .apb-secondary, .apb-card-actions .apb-ghost { height: 30px; padding: 0 11px; font-size: 12.5px; }

/* Bill window: summary strip above the fields */
.apb-strip { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 14px; margin: 0 0 16px; background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; }
.apb-strip-k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--apb-muted); margin-bottom: 2px; }
.apb-strip-cell strong { display: block; font-size: 13.5px; color: var(--apb-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apb-strip-vendor strong { font-size: 14.5px; }
.apb-strip-status { justify-self: end; }

@media (max-width: 900px) {
  .apb-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apb-strip-vendor { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .apb-register--lanes { padding: 4px 12px 8px; }
  .apb-lane-grid { grid-template-columns: minmax(0, 1fr); }
  .apb-card-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apb-table tbody tr.apb-group { display: block; padding: 0; }
  .apb-table tbody tr.apb-group th { display: block; }
  .apb-group-row { padding: 10px 14px; }
  .apb-strip { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .apb-strip-status { justify-self: start; }
}

/* ── Row menu (⋯) ─────────────────────────────────────────────────────── */
.apb-menu-btn { font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; margin-left: 6px; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 7px; color: var(--apb-muted); cursor: pointer; }
.apb-menu-btn:hover, .apb-menu-btn:focus-visible { background: var(--apb-canvas); border-color: var(--apb-line); color: var(--apb-ink-2); }
.apb-menu-panel { position: fixed; inset: auto; margin: 0; white-space: normal; min-width: 240px; max-width: min(320px, calc(100vw - 16px)); padding: 6px; background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 23, 42, .16); color: var(--apb-ink-2); }
.apb-menu-panel:not(:popover-open) { display: none; }
.apb-menu-item { display: block; width: 100%; padding: 8px 10px; background: none; border: 0; border-radius: 6px; text-align: left; font: inherit; font-size: 13px; color: var(--apb-ink-2); text-decoration: none; cursor: pointer; }
.apb-menu-item:hover, .apb-menu-item:focus-visible { background: var(--apb-canvas); outline: none; }
.apb-menu-item.is-danger { color: var(--apb-danger); }
.apb-menu-note { padding: 8px 10px 4px; font-size: 11.5px; line-height: 1.4; color: var(--apb-muted); border-top: 1px solid var(--apb-line); margin-top: 4px; }

/* ── Linked records under the bill summary ─────────────────────────────── */
.apb-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: -6px 0 16px; }
.apb-link-cell { padding: 10px 12px; background: var(--apb-surface); border: 1px solid var(--apb-line); border-radius: 10px; min-width: 0; }
.apb-link-cell .apb-link-btn { font-size: 13px; font-weight: 700; margin-right: 8px; }
.apb-link-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--apb-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apb-container { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; margin: 4px 0 0; }
.apb-container dt { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
.apb-container dd { margin: 0 0 4px; font-size: 12.5px; color: var(--apb-ink-2); font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }

/* PO allocations: one supplier invoice covering several purchase orders. */
.apb-alloc { display: grid; gap: 10px; }
.apb-input--error { border-color: var(--apb-danger); }

/* PO line cards: one per purchase order, with its own line, the invoice line, and the checks beside it. */
.apb-alloc-field .apb-alloc { display: grid; gap: 14px; }
.apb-mini-field { display: grid; gap: 4px; font-size: 11px; font-weight: 600; color: var(--apb-muted); }
.apb-mini-field > span { text-transform: uppercase; letter-spacing: .04em; }
.apb-alloc-totals { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.apb-alloc-totals td { padding: 5px 8px; text-align: left; }
.apb-alloc-totals .apb-num { text-align: right; }
.apb-ok-mark { color: var(--apb-ok); font-weight: 700; }
.apb-warn-mark { color: #b45309; font-weight: 700; }
.apb-alloc-totals { margin-top: 4px; }
.apb-alloc-totals .apb-alloc-sum td { border-top: 1px solid var(--apb-line-2); font-weight: 700; }
.apb-alloc-totals tr td:first-child { color: var(--apb-ink-2); }
@media (max-width: 720px) {
}

/* ── Purchase order lines ──────────────────────────────────────────────
   Colour means one thing: blue = the ERP / purchase order, white = a field to enter, green = matched,
   amber = needs attention, red = blocking only, grey = derived or not available. */
.apb-alloc { display: grid; gap: 12px; }
.apb-pl { border: 1px solid var(--apb-line-2); border-radius: 10px; background: var(--apb-surface); padding: 12px 14px; display: grid; gap: 10px; position: relative; }
.apb-pl.is-review { box-shadow: inset 3px 0 0 var(--apb-warn); }
.apb-pl-head { display: grid; grid-template-columns: minmax(0, 1.2fr) 84px minmax(0, 1.4fr); gap: 8px; align-items: end; }
.apb-pl-head .apb-input { background: var(--apb-accent-bg); border-color: transparent; color: var(--apb-accent-d); font-weight: 600; }
.apb-pl-head .apb-input:focus { background: var(--apb-surface); border-color: var(--apb-accent); }
.apb-pl-line select { background: var(--apb-accent-bg); border-color: transparent; color: var(--apb-accent-d); }
.apb-pl-line select:focus { background: var(--apb-surface); border-color: var(--apb-accent); }
.apb-pl-line select:disabled { background: var(--apb-canvas); color: var(--apb-muted); }
.apb-pl-select { width: 100%; height: 36px; font-size: 12.5px; }
/* ERP context read from the PO line: read-only, tinted blue. */
.apb-pl-ctx { background: var(--apb-accent-bg); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; color: var(--apb-ink-2); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.apb-pl-item-id { color: var(--apb-accent-d); font-weight: 600; }
.apb-pl-desc { color: var(--apb-ink); }
.apb-pl-facts span { display: inline-flex; gap: 5px; align-items: baseline; }
.apb-k { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
/* Entry: white fields with a clear focus ring. */
.apb-pl-invoice { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.1fr); gap: 8px; align-items: end; }
.apb-pl-invoice .apb-input { background: var(--apb-surface); border-color: var(--apb-line-2); }
.apb-pl-invoice .apb-input:focus { border-color: var(--apb-accent); box-shadow: 0 0 0 3px var(--apb-accent-bg); outline: none; }
/* Derived: grey, not white, so it reads as a result rather than an entry. */
.apb-pl-amount { background: var(--apb-canvas); border: 1px solid var(--apb-line); border-radius: 8px; padding: 7px 10px; display: grid; gap: 2px; }
.apb-pl-amount span { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
.apb-pl-amount strong { font-size: 15px; color: var(--apb-ink); font-variant-numeric: tabular-nums; text-align: right; }
.apb-pl-status { display: grid; gap: 6px; }
.apb-pl-remaining { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; font-size: 12px; color: var(--apb-muted); }
.apb-pl-remaining strong { color: var(--apb-ink-2); font-weight: 600; }
.apb-pl-remove { justify-self: end; }
.apb-pl-issue { margin: 0; font-size: 12.5px; color: var(--apb-ink); }
/* One check per row: a tone for each state. */
.apb-chk { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 6px; align-items: start; margin: 0; padding: 6px 8px; border-radius: 6px; font-size: 12.5px; color: var(--apb-ink-2); }
.apb-chk > span:first-child { line-height: 1.4; }
.apb-chk small { color: var(--apb-muted); }
.apb-chk.is-ok { background: var(--apb-ok-bg); color: var(--apb-ok); }
.apb-chk.is-ok .apb-ok-mark { color: var(--apb-ok); }
.apb-chk.is-warn { background: var(--apb-warn-bg); color: var(--apb-warn); }
.apb-chk.is-warn > span:last-child { color: var(--apb-ink); }
.apb-chk.is-unavailable { background: var(--apb-canvas); color: var(--apb-muted); border: 1px dashed var(--apb-line-2); }
.apb-chk.is-pending { color: var(--apb-muted); padding-left: 8px; }
.apb-variance { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.apb-var-title { margin: 0; display: flex; align-items: center; gap: 6px; }
.apb-var { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.apb-var > div { background: var(--apb-surface); border-radius: 6px; padding: 5px 8px; }
.apb-var dt { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
.apb-var dd { margin: 0; font-size: 13px; font-weight: 600; color: var(--apb-ink); font-variant-numeric: tabular-nums; }
.apb-var-ext { margin: 0; color: var(--apb-ink-2); }
.apb-linkbtn { justify-self: start; align-self: end; height: 32px; padding: 0 6px; background: none; border: 0; color: var(--apb-accent); font-size: 12px; font-weight: 600; cursor: pointer; }
.apb-add-po { justify-self: start; height: 32px; padding: 0 12px; font-size: 12.5px; }
/* ── Right rail cards ───────────────────────────────────────────── */
.apb-rc-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.apb-rc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: baseline; font-size: 12.5px; }
.apb-rc-row.is-block { color: var(--apb-warn); }
.apb-rc-issues { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; color: var(--apb-ink-2); }
.apb-dl--tight > div { padding: 5px 0; }
.apb-dl--tight .is-key { margin-top: 6px; }
.apb-checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.apb-checklist > li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 6px; align-items: start; }
.apb-checklist .apb-match-list { margin: 6px 0 0; }
.apb-chk.is-warn > div > span:first-child { font-weight: 600; color: var(--apb-ink); }
.apb-more { margin-top: 8px; }
.apb-more summary { cursor: pointer; font-size: 12px; color: var(--apb-muted); }
.apb-more p { margin: 6px 0 0; }
/* ── Additional references: collapsed unless one is filled ──────── */
.apb-refs { border-top: 1px solid var(--apb-line); margin-top: 6px; padding-top: 12px; }
.apb-refs > summary { cursor: pointer; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--apb-muted); }
.apb-refs > .apb-fields { margin-top: 12px; }
@media (max-width: 1180px) {
  .apb-pl-invoice { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .apb-pl-head { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .apb-pl-ref { grid-column: 1 / -1; }
  .apb-pl-invoice { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apb-pl-select { min-width: 0; width: 100%; }
}
