/* Payables bill import (Bill import LIVE slice U). Kept in its own file (not styles.css) so
   this slice's commit cannot sweep up a parallel session's uncommitted styles.css edits;
   tokens come from the same :root palette. Two views inside #room-ap: a dropzone + upload
   queue, and a composer (source bill left, draft Purchase voucher right). No live Tally
   write here: every ledger label reads "pending", never "matched". */

.ap-view[hidden] { display: none; }

/* Dropzone */
.ap-drop {
  margin-top: 18px; border: 2px dashed var(--line); border-radius: 12px;
  background: var(--surface-2); padding: 34px 24px; text-align: center;
  transition: border-color .18s ease, background .18s ease;
}
.ap-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.ap-drop-ico {
  width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center;
  font-size: var(--text-xl); font-weight: 800;
}
.ap-drop h3 { margin: 0 0 4px; font-size: var(--text-lg); font-weight: 700; }
.ap-drop p { margin: 0 0 14px; font-size: var(--text-sm); color: var(--muted); }
.ap-drop-formats { margin-top: var(--space-3); font-size: var(--text-xs); color: var(--muted); }

/* Queue */
.ap-queue-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 10px; }
.ap-queue-head h2 { margin: 0; font-size: var(--text-md); font-weight: 700; }
.ap-queue-empty { color: var(--muted); font-size: var(--text-base); padding: 10px 2px; }
.ap-queue-empty[hidden] { display: none; }
.ap-queue { display: flex; flex-direction: column; gap: 10px; }

.ap-qrow {
  display: grid; grid-template-columns: 34px minmax(0,1.4fr) minmax(0,1fr) auto auto;
  align-items: center; gap: var(--space-4); padding: 14px 16px; background: var(--raised);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  transition: box-shadow .14s ease;
}
.ap-qrow:hover { box-shadow: var(--lift); }
.ap-qico {
  width: 34px; height: 34px; border-radius: 8px; background: var(--surface-2);
  display: grid; place-items: center; color: var(--accent-ink); font-size: var(--text-xs); font-weight: 800;
}
.ap-qmeta { min-width: 0; }
.ap-qmeta .fname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-qmeta .vend { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-0-5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-qamt { text-align: right; font-family: var(--mono-font); font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.ap-qamt .lab { display: block; font-family: var(--ui-font); font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; margin-bottom: var(--space-0-5); }

.ap-pill { display: inline-flex; align-items: center; gap: var(--space-1-5); font-size: var(--text-xs); font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.ap-pill .pip { width: 6px; height: 6px; border-radius: 50%; }
.ap-pill.reading { background: var(--surface-2); color: var(--muted); }
.ap-pill.reading .pip { background: var(--muted); animation: ap-pulse 1.1s ease-in-out infinite; }
.ap-pill.ok { background: var(--accent-soft); color: var(--accent-ink); }
.ap-pill.ok .pip { background: var(--positive); }
.ap-pill.warn { background: rgba(180,83,9,.10); color: var(--warn); }
.ap-pill.warn .pip { background: var(--warn); }
.ap-pill.error { background: var(--risk-soft); color: var(--risk); }
.ap-pill.error .pip { background: var(--risk); }
@keyframes ap-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.ap-qerror { grid-column: 1 / -1; font-size: var(--text-sm); color: var(--risk); margin-top: -4px; }

.link-back { border: none; background: none; color: var(--accent-ink); font: inherit; font-weight: 600; font-size: var(--text-sm); cursor: pointer; padding: 0; }
.link-back:hover { text-decoration: underline; }

/* Composer */
.ap-composer { display: grid; grid-template-columns: minmax(0,0.82fr) minmax(0,1.18fr); gap: 18px; margin-top: 18px; align-items: start; }
@media (max-width: 1080px) { .ap-composer { grid-template-columns: 1fr; } }

.ap-bill { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); margin: 0 20px 20px; }
.ap-bill-top { padding: 14px 16px; background: var(--surface-2); border-bottom: 1px dashed var(--line); }
.ap-bill-top .vend { font-weight: 800; font-size: var(--text-md); letter-spacing: -.01em; }
.ap-bill-top .vsub { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-0-5); }
.ap-bill-meta { display: flex; gap: var(--space-5); flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.ap-bill-meta .k { color: var(--muted); display: block; text-transform: uppercase; letter-spacing: .03em; font-size: var(--text-2xs); font-weight: 700; }
.ap-bill-lines { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.ap-bill-lines th, .ap-bill-lines td { padding: 8px 16px; text-align: left; }
.ap-bill-lines th { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); }
.ap-bill-lines td.n, .ap-bill-lines th.n { text-align: right; font-family: var(--mono-font); font-variant-numeric: tabular-nums; }
.ap-bill-lines tr + tr td { border-top: 1px solid var(--line); }
.ap-stock-resolve-row td { padding: 0 16px 12px; background: var(--surface-2); }
.ap-bill-tot { display: flex; justify-content: space-between; padding: 12px 16px; border-top: 2px solid var(--line); font-weight: 700; }
.ap-bill-tot .v { font-family: var(--mono-font); font-size: var(--text-md); }

.ap-extract { margin: 0 20px 20px; }
.ap-extract-h { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin-bottom: var(--space-2); }
.ap-kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: var(--text-sm); }
.ap-kv .k { color: var(--muted); }
.ap-kv .v { text-align: right; font-family: var(--mono-font); font-variant-numeric: tabular-nums; }
.ap-kv .v.txt { font-family: var(--ui-font); text-align: right; }

.ap-warnings { margin: 0 20px 20px; padding: 10px 12px; border: 1px solid var(--risk-line); border-left: 3px solid var(--risk); background: var(--risk-soft); border-radius: 8px; font-size: var(--text-sm); color: var(--ink); }
.ap-warnings ul { margin: 4px 0 0; padding-left: 18px; }
.ap-warnings[hidden] { display: none; }

/* Resolve row (Bill import LIVE slice R): vendor -> Tally ledger match basis, honest states only. */
.ap-resolve { margin: 0 20px 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.ap-resolve-head { margin-bottom: var(--space-1-5); }
.ap-resolve-label { font-weight: 700; font-size: var(--text-base); }
.ap-resolve-detail { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-0-5); }
.ap-resolve.not-found { border-color: var(--risk); background: var(--risk-soft); }
.ap-candidates, .ap-mapping { display: grid; gap: 7px; margin: 12px 20px; }
.ap-mapping-highlight { animation: ap-mapping-highlight 1.2s ease; }
@keyframes ap-mapping-highlight { 0%, 100% { box-shadow: none; } 25%, 75% { box-shadow: 0 0 0 3px var(--accent-soft); } }
.ap-resolve .ap-candidates { margin: 12px 0; }
.ap-candidate { display: block; width: 100%; text-align: left; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.ap-candidate.selected, .ap-candidate:hover { border-color: var(--accent); background: var(--accent-soft); }
.ap-route-choice { margin: 12px 0; padding: var(--space-3); border: 1px solid var(--warn); border-radius: 7px; background: rgba(180,83,9,.06); }
.ap-route-choice-title { font-size: var(--text-sm); font-weight: 700; margin-bottom: var(--space-2); }
.ap-route-choice .ap-candidates { margin: 0; }
.ap-route-candidate { display: grid; gap: 3px; }
.ap-route-candidate-label { font-weight: 700; }
.ap-route-candidate-detail { color: var(--muted); font-size: var(--text-xs); }
.ap-route-tension { margin-bottom: var(--space-3); }
.ap-stock-resolve { display: grid; gap: var(--space-2); padding: 11px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.ap-stock-resolve.suggest { border-color: var(--warn); background: rgba(180,83,9,.06); }
.ap-stock-resolve.not-found { border-color: var(--risk); border-left: 3px solid var(--risk); background: var(--risk-soft); }
.ap-stock-resolve-head { display: flex; align-items: center; gap: var(--space-2); }
.ap-stock-item { font-size: var(--text-sm); font-weight: 700; color: var(--ink); }
.ap-stock-detail { font-size: var(--text-xs); color: var(--muted); }
.ap-stock-not-found { font-size: var(--text-sm); font-weight: 700; color: var(--risk); }
.ap-stock-search { display: grid; gap: var(--space-1-5); }
.ap-stock-search input { width: 100%; box-sizing: border-box; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; }
.ap-stock-results { display: grid; gap: var(--space-1); max-height: 160px; overflow: auto; }
.ap-stock-candidate { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.ap-stock-candidate-score { flex: none; color: var(--muted); font-family: var(--mono-font); font-size: var(--text-xs); }
.ap-picker-label { display: grid; gap: 5px; color: var(--ink-soft); font-size: var(--text-sm); font-weight: 650; }
.ap-ledger-input, .ap-tax-treatment { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; }
.ap-ledger-results { display: grid; gap: var(--space-1); max-height: 160px; overflow: auto; }
.ap-search-helper, .ap-confirm-reason { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--muted); }
.ap-saved { margin-top: 10px; color: var(--accent-ink); font-size: var(--text-sm); font-weight: 700; animation: ap-saved-in .22s ease-out; }
@keyframes ap-saved-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .ap-saved { transition: none; }
  .ap-pill.reading .pip, .ap-mapping-highlight, .ap-saved { animation: none; }
  .ap-mapping-highlight { box-shadow: 0 0 0 3px var(--accent-soft); }
}

/* Allocation table + reconciliation */
.ap-alloc-wrap { padding: 0 20px 20px; }
.ap-alloc { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.ap-alloc th { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.ap-alloc th.n, .ap-alloc td.n { text-align: right; font-family: var(--mono-font); font-variant-numeric: tabular-nums; }
.ap-alloc td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.ap-alloc tr:hover td { background: var(--surface-2); }
.ap-alloc .led { font-weight: 650; }
.ap-alloc .sub { color: var(--muted); font-size: var(--text-xs); margin-top: 1px; }
.ap-alloc tr.tax td { color: var(--ink-soft); }

.ap-recon { margin: 16px 20px 20px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; transition: border-color .3s ease; }
.ap-recon.balanced { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.ap-recon-bar { display: flex; align-items: stretch; }
.ap-recon-side { flex: 1; padding: 12px 16px; text-align: center; }
.ap-recon-side .k { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.ap-recon-side .v { font-family: var(--mono-font); font-variant-numeric: tabular-nums; font-size: var(--text-lg); font-weight: 650; margin-top: var(--space-1); }
.ap-recon-mid { width: 64px; display: grid; place-items: center; background: var(--surface-2); }
.ap-recon.balanced .ap-recon-mid { background: var(--accent-soft); }
.ap-recon-check { width: 30px; height: 30px; border-radius: 50%; background: var(--muted); display: grid; place-items: center; color: #fff; font-weight: 800; transition: background .2s ease; }
.ap-recon.balanced .ap-recon-check { background: var(--positive); }
.ap-recon-foot { padding: 9px 16px; border-top: 1px solid var(--line); font-size: var(--text-sm); font-weight: 700; text-align: center; color: var(--muted); background: var(--surface); }
.ap-recon.balanced .ap-recon-foot { color: var(--accent-ink); background: var(--accent-soft); }

.ap-pending-note { margin: 0 20px 20px; font-size: var(--text-xs); color: var(--muted); font-style: italic; }

/* Book to Tally (Bill import LIVE slice W): enabled only once the party ledger resolves
   confident; the why-blocked / result states render inline, never hover-only. */
.ap-book { margin: 0 20px 20px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.ap-book-head { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.ap-book-blocked { font-size: var(--text-sm); color: var(--muted); }
.ap-book-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ap-book-label { font-size: var(--text-sm); font-weight: 650; color: var(--ink-soft); }
.ap-book-input { flex: 1 1 160px; min-width: 140px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: var(--text-base); }
.ap-book-input:disabled { opacity: .6; }
.ap-book-hint { margin: 8px 0 0; font-size: var(--text-xs); color: var(--muted); }
.ap-book-reason { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--risk); }
.ap-book .ap-pill { margin-top: 10px; }
.ap-duplicate-warning { display: grid; gap: 7px; margin-top: 10px; padding: 10px; border: 1px solid var(--warn); border-radius: 6px; background: rgba(180,83,9,.10); font-size: var(--text-sm); color: var(--ink); }
.ap-duplicate-voucher { color: var(--ink-soft); }
