/* PRTY OS — Finance › Payables / Invoices / Payment Runs styles. Screen-specific layout only; reuse components.css for everything else.
   Prefix: fin- */

/* ---------- Light summary strip (not a bank period) ---------- */
.fin-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); border: 1px solid var(--line); border-radius: var(--r-3); background: var(--surface); overflow: hidden; }
.fin-strip__item { display: flex; flex-direction: column; gap: 4px; padding: 12px var(--s-4); border-left: 1px solid var(--line-soft); min-width: 0; color: inherit; transition: background var(--dur-1); }
.fin-strip__item:first-child { border-left: 0; }
.fin-strip__item.is-link:hover { background: var(--hover); }
.fin-strip__label { font-size: var(--fs-11); color: var(--text-3); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fin-strip__value { font-size: var(--fs-16); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.fin-strip__sub { font-size: var(--fs-12); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fin-note { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-12); color: var(--text-3); }
.fin-created { --c: var(--green); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: var(--s-4); padding: 6px 6px 6px 12px; border-radius: var(--r-2); border: 1px solid color-mix(in srgb, var(--c) 24%, transparent); background: color-mix(in srgb, var(--c) 7%, var(--surface)); font-size: var(--fs-13); color: var(--text-2); }
.fin-created > .icon { color: var(--c); }
.fin-created b { color: var(--text); font-weight: 600; }

/* ---------- Filters ---------- */
.fin-filters .select--compact { width: auto; min-width: 0; box-sizing: border-box; }
.fin-filters { width: 100%; display: flex; flex-direction: column; gap: var(--s-3); margin-bottom: var(--s-3); }
.fin-filters__chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.fin-filters__controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.fin-search { width: 260px; }
.fin-search .input { height: var(--h-ctl-sm); }
.fin-search .input::-webkit-search-cancel-button { filter: invert(0.6); }
.fin-supplier-menu { display: inline-flex; }
.fin-supplier-menu .popover { max-height: 360px; overflow-y: auto; }
.fin-removable .icon { color: var(--text-3); }
.fin-removable:hover .icon { color: var(--text); }

/* ---------- Table ---------- */
.fin-tablepanel { overflow: hidden; }
.fin-table th.fin-check, .fin-table td.fin-check { width: 44px; padding-right: 0; user-select: none; -webkit-user-select: none; }
.fin-table td.fin-check { cursor: default; }
.fin-table .checkbox:disabled { opacity: 0.35; cursor: not-allowed; }
.fin-table tbody tr.is-open { background: var(--press); }
.fin-table tbody tr.is-selected.is-open { background: var(--select); }
.fin-due { display: inline-flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.fin-hint { font-size: var(--fs-12); color: var(--text-3); }
.fin-amount { display: inline-flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
.fin-amount__local { font-size: var(--fs-12); color: var(--text-3); font-variant-numeric: tabular-nums; }
.fin-table tfoot td { font-size: var(--fs-12); }

/* ---------- Mobile list ---------- */
.fin-mlist { overflow: hidden; }
.fin-mlist__head { display: flex; align-items: center; gap: var(--s-1); min-height: 48px; padding: 2px var(--s-4) 2px 2px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.fin-mcheck { width: 44px; height: 44px; display: grid; place-items: center; flex-shrink: 0; }
.fin-mcheck .checkbox { width: 18px; height: 18px; }
.fin-mcheck .checkbox:disabled { opacity: 0.3; }
.fin-mrow { display: flex; align-items: center; gap: var(--s-1); min-height: 76px; padding: var(--s-2) var(--s-4) var(--s-2) 2px; border-bottom: 1px solid var(--line-soft); cursor: pointer; transition: background var(--dur-1); }
.fin-mrow:last-child { border-bottom: 0; }
.fin-mrow.is-selected { background: var(--select); }
.fin-mrow__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fin-mrow__supplier { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-mrow__sub, .fin-mrow__due { font-size: var(--fs-12); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fin-mrow__due.c-red { color: var(--red); }
.fin-mrow__side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.fin-mrow__side .fin-amount { font-weight: 500; }

/* ---------- Payment batches ---------- */
.fin-batch { border-bottom: 1px solid var(--line-soft); }
.fin-batch:last-child { border-bottom: 0; }
.fin-batch__head {
  display: grid; align-items: center; column-gap: var(--s-4); row-gap: 6px;
  grid-template-columns: 124px minmax(0, 1fr) 96px 112px 150px minmax(200px, auto);
  grid-template-areas: "toggle created count total status actions";
  min-height: 56px; padding: var(--s-2) var(--s-4) var(--s-2) var(--s-2);
}
.fin-batch__toggle { grid-area: toggle; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; border-radius: var(--r-2); justify-self: start; transition: background var(--dur-1); }
.fin-batch__toggle:hover { background: var(--hover); }
.fin-batch__toggle .icon { color: var(--text-3); }
.fin-batch__created { grid-area: created; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-batch__count { grid-area: count; white-space: nowrap; }
.fin-batch__total { grid-area: total; text-align: right; }
.fin-batch__status { grid-area: status; }
.fin-batch__actions { grid-area: actions; display: flex; justify-content: flex-end; }
.fin-batch__body { padding: 0 var(--s-4) var(--s-3) calc(var(--s-2) + 30px); }
.fin-batch__inv {
  display: grid; align-items: center; column-gap: var(--s-4); width: 100%;
  grid-template-columns: minmax(0, 1.1fr) 140px minmax(0, 1.4fr) 100px 32px;
  min-height: 38px; padding: 0 var(--s-2); text-align: left;
  border-bottom: 1px solid var(--line-soft); border-radius: var(--r-1);
  transition: background var(--dur-1);
}
.fin-batch__inv:hover { background: var(--hover); }
.fin-batch__inv .r { text-align: right; }
.fin-batch__rm { display: flex; justify-content: flex-end; }
.fin-batch__rm .btn { opacity: 0.6; }
.fin-batch__inv:hover .fin-batch__rm .btn { opacity: 1; }

/* ---------- Bank upload preview (inline) ---------- */
.fin-export { margin-top: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-2); overflow: hidden; animation: rise-in var(--dur-2) var(--ease); }
.fin-export__head { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; min-height: 40px; padding: 4px 6px 4px var(--s-4); border-bottom: 1px solid var(--line-soft); }
.fin-export .tbl th { background: var(--bg-2); }
.fin-export .tbl tfoot td { background: var(--bg-2); }
.fin-export__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; padding: var(--s-2) var(--s-4); border-top: 1px solid var(--line-soft); }
.fin-batch__foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--s-2); padding-top: var(--s-2); }

/* ---------- Sticky bulk action bar ---------- */
.fin-bar { position: sticky; bottom: var(--s-4); z-index: 30; display: flex; justify-content: center; margin-top: var(--s-5); pointer-events: none; }
.fin-bar__inner {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--s-2);
  width: min(780px, 100%); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: var(--r-3);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: rise-in var(--dur-2) var(--ease);
}
.fin-bar__summary { white-space: nowrap; color: var(--text-2); }
.fin-bar__summary b { color: var(--text); font-weight: 600; }
.fin-bar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

/* ---------- Drawer ---------- */
.fin-drawer__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.fin-drawer__amount { font-size: var(--fs-24); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.fin-drawer__fx { margin-top: calc(-1 * var(--s-4)); }
.fin-drawer__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--s-2); width: 100%; }
.fin-drawer__actions .popover { top: auto !important; bottom: calc(100% + 4px); }
.fin-pnl { display: flex; flex-direction: column; gap: 10px; padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-2); }
.fin-pnl--none { padding: var(--s-3) var(--s-4); }
.fin-pnl__top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); min-width: 0; }
.fin-pnl__nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); }
.fin-pnl__nums > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fin-history { border: 1px solid var(--line); border-radius: var(--r-3); overflow: hidden; }
.fin-history__row { display: grid; grid-template-columns: 118px minmax(0, 1fr) 72px 128px; align-items: center; gap: 10px; min-height: 36px; padding: 0 var(--s-3); border-bottom: 1px solid var(--line-soft); }
.fin-history__row:last-child { border-bottom: 0; }
.fin-history__row.is-current { background: var(--press); }
.fin-history__row .num { text-align: right; }
.fin-history__row .pill { justify-self: end; }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .fin-col-category { display: none; }
  .fin-batch__head {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "toggle status total" "created created count" "actions actions actions";
  }
  .fin-batch__status { justify-self: end; }
  .fin-batch__count { text-align: right; }
  .fin-batch__actions { justify-content: flex-start; padding-left: 8px; }
  .fin-batch__inv { grid-template-columns: minmax(0, 1fr) 120px 100px 32px; }
  .fin-batch__inv > :nth-child(3) { display: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .fin-filters__chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--page-pad)); padding: 2px var(--page-pad); }
  .fin-filters__chips::-webkit-scrollbar { display: none; }
  .fin-filters__chips .chip { height: 32px; padding: 0 12px; flex-shrink: 0; }
  .fin-search { width: 100%; }
  .fin-search .input { height: 38px; font-size: 16px; }
  .fin-filters__controls .btn--sm { --btn-h: 36px; }
  .fin-supplier-menu .popover { right: auto; max-width: calc(100vw - 32px); }

  .fin-batch__head { padding: var(--s-3) var(--s-4) var(--s-3) var(--s-2); }
  .fin-batch__actions .btn { --btn-h: 40px; }
  .fin-batch__body { padding: 0 var(--s-3) var(--s-3); }
  .fin-batch__inv { grid-template-columns: minmax(0, 1fr) auto 38px; min-height: 44px; }
  .fin-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fin-strip__item { border-left: 0; border-top: 1px solid var(--line-soft); }
  .fin-strip__item:nth-child(-n+2) { border-top: 0; }
  .fin-strip__item:nth-child(even) { border-left: 1px solid var(--line-soft); }
  .fin-batch__inv > :nth-child(2), .fin-batch__inv > :nth-child(3) { display: none; }

  .fin-bar { bottom: 0; margin: var(--s-4) calc(-1 * var(--page-pad)) 0; }
  .fin-bar__inner {
    width: 100%; flex-wrap: wrap; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding: var(--s-3) var(--page-pad) calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
  }
  .fin-bar__actions { margin-left: 0; width: 100%; }
  .fin-bar__actions .btn { flex: 1; --btn-h: 42px; font-size: var(--fs-13); }
  .fin-bar__summary { flex: 1; }

  .fin-drawer__actions .btn { --btn-h: 40px; }
  .fin-history__row { grid-template-columns: minmax(0, 1fr) 72px auto; }
  .fin-history__row > :nth-child(2) { display: none; }
}

/* ---- Finance list: one-click payment control, filters, grouped totals ---- */
.paybtn { min-height: 32px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.paybtn:focus-visible { outline: 2px solid var(--accent, #4b6bfb); outline-offset: 2px; }
.paybtn--unpaid { border-color: var(--amber, #d98a00); color: var(--amber, #a86400); }
.paybtn--unpaid:hover { background: var(--amber-soft, #fff4dc); }
.paybtn--partial { border-color: var(--amber, #d98a00); color: var(--amber, #a86400); background: var(--amber-soft, #fff4dc); }
.paybtn--saving { opacity: .7; cursor: progress; }
.paybtn--undo { border-style: dashed; font-weight: 500; color: var(--text-2, inherit); }
.paycell { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select--compact { min-height: 32px; padding: 4px 26px 4px 8px; font-size: 12px; max-width: 170px; }
.invx-filters .select--compact { width: auto; min-width: 0; box-sizing: border-box; }
.invx-filters { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.invx-totals { width: 100%; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; margin-bottom: 12px; font-size: 13px; }
@media (max-width: 720px) {
  .paybtn { min-height: 44px; padding: 8px 16px; font-size: 14px; }
  .select--compact { min-height: 44px; max-width: 100%; font-size: 14px; }
  .invx-filters .select--compact { flex: 1 1 calc(50% - 8px); width: calc(50% - 8px); }
  .invx-filters { justify-content: flex-start; }
}

/* Phone layout: each invoice becomes a stacked card so nothing scrolls sideways */
@media (max-width: 720px) {
  .fin-table, .fin-table tbody, .fin-table tr, .fin-table td { display: block; width: 100%; }
  .fin-table thead { display: none; }
  .fin-table tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .fin-table td { height: auto; padding: 5px 0; border: 0; white-space: normal; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: right !important; }
  .fin-table td::before { content: attr(data-label); flex: 0 0 38%; text-align: left; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3, #888); }
  .fin-table td[data-label="Supplier"] { justify-content: flex-start; font-size: 15px; }
  .fin-table td[data-label="Supplier"]::before { display: none; }
  .fin-table td select, .fin-table td .paycell { flex: 1 1 auto; min-width: 0; }
  .fin-table .table-wrap, .table-wrap:has(.fin-table) { overflow-x: visible; }
}

/* ---- Invoice Tracker v2: chips, row action, warning chips, columns, Bankline status ---- */
.invx-chips { width: 100%; margin-bottom: 10px; align-items: center; }
.invx-chips .chip { min-height: 32px; }
.invx-bankline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; margin: 0 0 12px; border: 1px dashed var(--line); border-radius: 8px; font-size: 13px; }
.paybtn--review { border-color: var(--line-strong, var(--line)); }
.paybtn--confirm { border-color: var(--green, #1a7f4b); color: var(--green, #1a7f4b); }
.paycell--confirm { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
.input--compact { min-height: 32px; padding: 4px 8px; font-size: 12px; max-width: 190px; }
.linkbtn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: var(--accent, #4b6bfb); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
.warncell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.warncell__reason { max-width: 240px; white-space: normal; }
.fin-tracker td { vertical-align: top; }
.fin-tracker .fin-actioncell { min-width: 96px; }
.colpicker { position: relative; display: inline-block; }
.colpicker__menu { position: absolute; z-index: 30; right: 0; top: 100%; min-width: 230px; padding: 10px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-2, 0 8px 24px rgba(0,0,0,.18)); }
.colpicker__item { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.audit-row { padding: 6px 0; border-bottom: 1px solid var(--line-soft); }

@media (max-width: 720px) {
  /* Chips: wrapped rows inside a scroller (max ~3 rows) with 44px tap targets */
  .invx-chips { max-height: 156px; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; }
  .invx-chips .chip, .page .invx-chips .chip { min-height: 44px; padding-inline: 14px; }
  .input--compact { min-height: 44px; font-size: 14px; max-width: 100%; flex: 1 1 100%; }
  .linkbtn { min-height: 44px; font-size: 14px; }
  /* Compact card per invoice: only due date, supplier, currency + amount, status, warnings and the one action */
  .fin-tracker td.fin-opt { display: none; }
  .fin-tracker tr { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 2px; align-items: center; }
  .fin-tracker td { padding: 2px 0; text-align: left !important; }
  .fin-tracker td::before { display: none; }
  .fin-tracker td[data-col="supplier"] { grid-column: 1; grid-row: 1; font-size: 15px; }
  .fin-tracker td[data-col="due"] { grid-column: 1; grid-row: 2; font-size: 12px; justify-content: flex-start; }
  .fin-tracker td[data-col="gross"] { grid-column: 2; grid-row: 1; justify-content: flex-end; text-align: right !important; font-weight: 600; }
  .fin-tracker td[data-col="currency"] { grid-column: 2; grid-row: 2; justify-content: flex-end; }
  .fin-tracker td[data-col="payment"] { grid-column: 1; grid-row: 3; justify-content: flex-start; }
  .fin-tracker td[data-col="action"] { grid-column: 2; grid-row: 3; justify-content: flex-end; }
  .fin-tracker td[data-col="warning"] { grid-column: 1 / -1; grid-row: 4; justify-content: flex-start; }
  .fin-tracker td[data-col="warning"] .t-3:only-child { display: none; }
  .warncell__reason { max-width: none; }
  .colpicker__menu { right: auto; left: 0; }
}
@media (max-width: 400px) {
  .fin-tracker tr { padding: 10px 12px; }
}

/* Mobile invoice tracker: keep the mailbox status to its headline (title + last/next sync); the full detail is on desktop */
@media (max-width: 720px) {
  [data-release-states], [data-mailbox-detail], [data-sync-detail] { display: none !important; }
}

/* ---- Invoice to event review (js/screens/finance-invoice-events.js). Prefix: ive- ---- */
.ive { min-width: 0; }
.ive-intro { margin: 0 0 var(--s-3); max-width: 70ch; }
.ive-list { display: flex; flex-direction: column; gap: var(--s-3); }
.ive-row { border: 1px solid var(--line); border-radius: var(--r-3); background: var(--surface); padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ive-row__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px var(--s-3); min-width: 0; }
.ive-row__title { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.ive-row__amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.ive-row__desc, .ive-row__event { overflow-wrap: anywhere; min-width: 0; }
.ive-row__signals { display: flex; flex-wrap: wrap; gap: 4px; }
.ive-row__evidence { margin: 0; padding-left: 18px; color: var(--text-2, inherit); }
.ive-row__cands ul { margin: 6px 0 0; padding-left: 18px; }
.ive-row__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ive-choose { display: flex; flex-direction: column; gap: var(--s-2); }
.ive-choose .select, .ive-choose .input { width: 100%; max-width: 100%; box-sizing: border-box; }
.ive-pill, .ive-chip { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; line-height: 20px; background: var(--hover); white-space: nowrap; }
.ive-pill--green { background: color-mix(in srgb, var(--green, #1a7f37) 16%, transparent); color: var(--green, #1a7f37); }
.ive-pill--amber { background: color-mix(in srgb, var(--amber, #b45309) 16%, transparent); color: var(--amber, #b45309); }
.ive-note { border-radius: 8px; padding: 8px 12px; margin-bottom: var(--s-3); font-size: 13px; overflow-wrap: anywhere; }
.ive-note.is-ok { background: color-mix(in srgb, var(--green, #1a7f37) 12%, transparent); }
.ive-note.is-err { background: color-mix(in srgb, var(--red, #c0362c) 12%, transparent); }
@media (max-width: 720px) {
  .ive-row { padding: var(--s-3); }
  .ive-row__actions .btn { flex: 1 1 100%; min-height: 44px; }
}
