/* =========================================================
   The new / edit expense form (Views/Expense/form.php, edit.php, new.php; behaviour in js/expense-form.js).
   Cards, tiles and the section icons are the ones of the show page (show-page.css, list-cards.css). Only theme
   tokens (theme.css) and Bootstrap variables, so the light and the dark theme both work. Loaded by
   layouts/default.php before theme.css.
   ========================================================= */

/* ---------- title bar: breadcrumb is the layout's; Cancel / Save on the bar only on phones ---------- */
.fm-xtop { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.fm-xtop-title { margin: 0; font-size: 1.5rem; font-weight: 700; }
.fm-xtop .btn { min-height: 2.5rem; white-space: nowrap; }
@media (max-width: 767.98px) {
  .fm-xtop { position: sticky; top: 0; z-index: 10; margin: 0 -.75rem 1rem; padding: .6rem .75rem; background: var(--fm-surface); border-bottom: 1px solid var(--fm-line); }
  .fm-xtop-title { font-size: 1.05rem; flex: 1 1 auto; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.fm-xnote { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem 1rem; margin-bottom: 1rem; border-radius: var(--fm-radius-control); background: var(--fm-brand-soft); color: var(--fm-ink); font-size: .9rem; }
.fm-xnote .bi { color: var(--fm-brand-text); font-size: 1.1rem; line-height: 1.3; }

.fm-xedit { padding-bottom: 1rem; }
/* The form uses the full width next to the menu (the shell caps pages at 1320px and centres them): the breadcrumb,
   the page and the footer of this page share the same container, so they stay aligned */
.fm-main:has(.fm-xedit) > .container { max-width: none; }
.fm-xedit .fm-xcard { background: var(--fm-surface); border: 1px solid var(--fm-line); border-radius: var(--fm-radius-card); }
.fm-xedit .fm-xcard .card-body { padding: 1.25rem; }

/* ---------- supplier branch picker: logo or monogram, "Supplier — Branch", address ---------- */
.fm-bsel { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.fm-bsel .fm-tile { width: 2rem; height: 2rem; border-radius: .55rem; font-size: .9rem; }
.fm-bsel-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.fm-bsel-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-bsel-addr { font-size: .78rem; color: var(--fm-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-xedit #supplier_branch_id + .select2-container .select2-selection--single { height: auto; min-height: 3.1rem; padding-top: .3rem; padding-bottom: .3rem; }
.fm-xedit #supplier_branch_id + .select2-container .select2-selection__rendered { line-height: 1.25; }
.fm-xedit #supplier_branch_id + .select2-container .select2-selection__arrow { height: 100%; top: 0; transform: none; display: flex; align-items: center; }
.select2-container .fm-xdd .select2-results__option, .fm-xdd .select2-results__option { padding: .5rem .75rem; }

.fm-recent { display: flex; align-items: center; gap: .6rem; margin-top: .65rem; min-width: 0; }
.fm-recent[hidden] { display: none; }
.fm-recent-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--fm-muted); flex: none; }
.fm-recent-chips { display: flex; gap: .5rem; min-width: 0; flex: 1 1 auto; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.fm-chip-branch { display: inline-flex; align-items: center; gap: .45rem; flex: none; max-width: 16rem; padding: .2rem .75rem .2rem .25rem; border: 1px solid var(--fm-line); border-radius: 999px; background: var(--fm-surface); color: var(--fm-ink); font-size: .8rem; font-weight: 500; cursor: pointer; }
.fm-chip-branch:hover { border-color: var(--fm-brand); }
.fm-chip-branch:focus-visible { outline: 2px solid var(--fm-brand); outline-offset: 2px; }
.fm-chip-branch.is-selected { background: var(--fm-brand-soft); border-color: var(--fm-brand); font-weight: 600; }
.fm-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 768px) { .fm-recent-chips { flex-wrap: wrap; overflow: visible; } }

/* ---------- product lines: ONE row each ---------- */
.fm-xedit { --fm-cols: 24px minmax(0, 1fr) 116px 100px 100px 112px 24px 36px; } /* numeric cells fit 3-digit numbers (999 / 999.99) */
.fm-xlines-head { display: none; }
.fm-xline-error:empty { display: none !important; } /* beats Bootstrap's .d-block on the empty placeholders */
.fm-xline { position: relative; background: var(--fm-surface); border: 1px solid var(--fm-line); border-radius: .75rem; margin-bottom: .5rem; }
.fm-xline .fm-xlabel, .fm-xline .fm-xline-error { font-size: .72rem; }
.fm-xline .fm-xline-error { margin: 0; padding: 0 .5rem .35rem; color: var(--fm-alert-text); width: 100%; }
.fm-xline-nums { min-width: 0; }
.fm-xline input[type="text"] { border: 0; background: transparent; color: var(--fm-ink); width: 100%; min-width: 0; padding: .25rem; box-shadow: none; outline: 0; font-variant-numeric: tabular-nums; }
.fm-xline input[type="text"]:focus-visible { outline: 2px solid var(--fm-brand); outline-offset: -2px; border-radius: .4rem; }
.fm-xline input.is-invalid { background-image: none; color: var(--fm-alert-text); padding-right: .25rem; }
.fm-xline.has-error, .fm-xline:has(.is-invalid) { border-color: var(--fm-alert); background: var(--fm-alert-soft); }
.fm-xline.is-lifted { border-color: var(--fm-brand); background: var(--fm-surface); box-shadow: 0 .8rem 1.6rem rgba(0, 0, 0, .22); cursor: grabbing; }
.fm-xdroppos { position: relative; height: 0; pointer-events: none; }
.fm-xdroppos::before { content: ""; position: absolute; left: 0; right: 0; top: -.34rem; height: 3px; border-radius: 3px; background: var(--fm-brand); }
body.fm-dragging { user-select: none; cursor: grabbing; }

/* the product Select2 sits in the row without a box of its own */
.fm-xline .select2-container { width: 100% !important; }
.fm-xline .select2-container .select2-selection--single,
.fm-xline .select2-container--default .select2-selection--single { border: 0; background: transparent; box-shadow: none; height: 100%; min-height: 3rem; padding: .25rem .5rem; background-image: none; }
.fm-xline .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--fm-ink); line-height: 1.3; padding: 0; }
.fm-xcell-product { flex-direction: column; flex-wrap: nowrap; align-items: stretch; justify-content: center; }
.fm-xcell-product .select2-container { flex: 1 1 auto; align-self: stretch; display: flex; }
.fm-xcell-product .select2-container .selection { flex: 1 1 auto; display: flex; min-width: 0; }
.fm-xcell-product .select2-container .select2-selection--single { flex: 1 1 auto; height: auto; display: flex; align-items: center; }
.fm-xcell-product .select2-container .select2-selection__rendered { flex: 1 1 auto; line-height: 1.3; }
.fm-xline .select2-container--default .select2-selection--single .select2-selection__placeholder { color: var(--fm-muted); }
.fm-xline .select2-container--default .select2-selection--single .select2-selection__arrow { display: none; }
.fm-xline .select2-container--default.select2-container--focus .select2-selection--single { box-shadow: none; outline: 2px solid var(--fm-brand); outline-offset: -2px; border-radius: .6rem; }

.fm-grip, .fm-move, .fm-remove, .fm-qty-btn { appearance: none; border: 0; background: transparent; color: var(--fm-muted); padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.fm-grip { width: 100%; height: 100%; min-height: 2rem; cursor: grab; touch-action: none; border-radius: .6rem 0 0 .6rem; }
.fm-grip:hover, .fm-move:hover:not(:disabled), .fm-qty-btn:hover { color: var(--fm-brand-text); }
.fm-remove:hover:not(:disabled) { color: var(--fm-alert-text); }
.fm-grip:focus-visible, .fm-move:focus-visible, .fm-remove:focus-visible, .fm-qty-btn:focus-visible { outline: 2px solid var(--fm-brand); outline-offset: -2px; }
.fm-move:disabled, .fm-remove:disabled { opacity: .3; cursor: not-allowed; }

.fm-qty { display: flex; align-items: center; gap: 1px; width: 100%; min-width: 0; }
.fm-qty input { flex: 1 1 auto; text-align: center; min-width: 0; }
.fm-xline .quantity-input { min-width: 0; }
.fm-qty-btn { display: none; width: 22px; height: 22px; flex: none; border: 1px solid var(--fm-line); border-radius: .4rem; font-size: .95rem; line-height: 1; }
.fm-qty.is-stepper .fm-qty-btn { display: inline-flex; }
.fm-qty.is-stepper input { padding-left: 0; padding-right: 0; }
.fm-qty .quantity-unit-text { flex: none; font-size: .75rem; color: var(--fm-muted); }
.fm-qty .quantity-unit-text:empty, .fm-qty.is-stepper .quantity-unit-text,
#products-list.fm-xlines .fm-qty.is-stepper .quantity-unit-text, #products-list.fm-xlines .fm-qty .quantity-unit-text:empty { display: none; }
#products-list.fm-xlines .fm-qty .quantity-unit-text { min-width: 0; min-height: 0; padding: 0; height: auto; }
.fm-xeur { color: var(--fm-muted); font-size: .8rem; flex: none; }
.fm-xcell-total input { font-weight: 700; font-size: 15px; text-align: right; }
.fm-xcell-price input, .fm-xcell-rebate input { text-align: right; }

/* The products card picks its layout by its own width (not the window's): next to the menu at about 1100px it is
   only ~530px wide, too narrow for a one-row table. >= 720px: one row per line; below: the two-line row. */
.fm-xproducts { container: fmprod / inline-size; }
@container fmprod (min-width: 720px) {
  .fm-xlines-head { display: grid; grid-template-columns: var(--fm-cols); padding: 0 1px .35rem; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; color: var(--fm-muted); }
  .fm-xlines-head span { padding: 0 .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fm-xlines-head span:nth-child(n+3):nth-child(-n+6) { text-align: center; }
  .fm-xline { display: grid; grid-template-columns: var(--fm-cols); align-items: stretch; min-height: 3rem; }
  .fm-xline-nums { display: contents; }
  .fm-xcell { display: flex; align-items: center; gap: .25rem; padding: 0 .4rem; border-left: 1px solid var(--fm-line); min-width: 0; flex-wrap: wrap; }
  .fm-xcell-product { padding: 0; }
  .fm-xcell-qty { padding: 0 .25rem; }
  .fm-xcell-qty, .fm-xcell-price, .fm-xcell-rebate, .fm-xcell-total { flex-wrap: nowrap; }
  .fm-xcell-product .fm-xline-error { padding-left: .5rem; }
  .fm-xcell .fm-xlabel { display: none; }
  .fm-xcell-total { background: var(--fm-canvas); border-radius: 0; }
  .fm-xline-grip { display: flex; }
  .fm-xline-move { display: flex; flex-direction: column; border-left: 1px solid var(--fm-line); }
  .fm-move { flex: 1 1 50%; width: 100%; font-size: .7rem; }
  .fm-xline-remove { display: flex; align-items: center; justify-content: center; border-left: 1px solid var(--fm-line); }
  .fm-remove { width: 100%; height: 100%; }
  .fm-xline-error-row { grid-column: 1 / -1; padding: 0 .75rem .35rem !important; }
}

/* narrow card (phones): grip rail, then the product with the move / remove buttons, then ONE joined bar of four cells */
@container fmprod (max-width: 719.98px) {
  .fm-xline { display: grid; grid-template-columns: 1.75rem minmax(0, 1fr) auto auto; grid-template-areas: "grip product move remove" "grip nums nums nums"; gap: .4rem .25rem; align-items: center; padding: .5rem .5rem .5rem 0; margin-bottom: .65rem; border-radius: .9rem; }
  .fm-xline-grip { grid-area: grip; align-self: stretch; display: flex; border-right: 1px solid var(--fm-line); }
  .fm-xcell-product { grid-area: product; min-width: 0; }
  .fm-xline-move { grid-area: move; display: flex; flex-direction: column; }
  .fm-move { width: 1.75rem; height: 1.3rem; font-size: .7rem; }
  .fm-xline-remove { grid-area: remove; }
  .fm-remove { width: 2rem; height: 2rem; }
  .fm-xline-nums { grid-area: nums; display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.25fr; border: 1px solid var(--fm-line); border-radius: .65rem; overflow: hidden; background: var(--fm-surface); }
  .fm-xline-nums .fm-xcell { display: flex; flex-direction: column; padding: .3rem .5rem; border-left: 1px solid var(--fm-line); min-width: 0; }
  .fm-xline-nums .fm-xcell:first-child { border-left: 0; padding-left: .35rem; padding-right: .35rem; }
  .fm-qty.is-stepper input { min-width: 4ch; }
  .fm-xline .fm-xlabel { display: block; text-transform: uppercase; letter-spacing: .03em; color: var(--fm-muted); font-size: .62rem; font-weight: 700; white-space: nowrap; }
  .fm-xeur { display: none; }
  .fm-xcell-total { background: var(--fm-canvas); }
  .fm-xline input[type="text"] { padding: .1rem 0; font-size: 1rem; }
  .fm-xline-error-row { grid-column: 2 / -1; padding: 0 .25rem !important; }
  .fm-xlines.is-collapsed .product-row:nth-child(n+5) { display: none; }
  .fm-xcell-product .fm-xline-error { padding-left: .25rem; }
}
.fm-xmore { padding-left: 0; }
@container fmprod (min-width: 720px) { .fm-xmore { display: none; } }

/* ---------- totals under the lines ---------- */
.fm-xlines-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-top: 1rem; }
.fm-xsums { display: flex; flex-direction: column; gap: .5rem; margin-left: auto; min-width: min(100%, 18rem); }
.fm-xsum { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.fm-xsum label { margin: 0; }
.fm-xsum-input { display: inline-flex; align-items: center; gap: .3rem; color: var(--fm-muted); }
.fm-xsum-input input { width: 5.5rem; text-align: right; border: 1px solid var(--bs-border-color); border-radius: .5rem; padding: .25rem .5rem; background: var(--bs-body-bg); color: var(--bs-body-color); }
.fm-xsum-input input.is-invalid { border-color: var(--fm-alert); }
.fm-xsum-grand { padding-top: .6rem; border-top: 1px solid var(--fm-line); font-weight: 700; }
.fm-xgrand { display: inline-flex; align-items: baseline; gap: .2rem; font-size: 1.6rem; font-weight: 700; color: var(--fm-ink); }
.fm-xgrand input { border: 0; background: transparent; color: inherit; font: inherit; width: 6ch; text-align: right; padding: 0; }
.fm-xgrand input:focus { outline: 0; }

/* ---------- payment ---------- */
.fm-xpm { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.fm-xpm-logo { width: 1.875rem; height: 1.875rem; border-radius: .55rem; border: 1px solid var(--fm-line); background: #fff; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.fm-xpm-logo img { width: 100%; height: 100%; object-fit: contain; }
.fm-xpm-logo-icon { background: var(--fm-brand-soft); color: var(--fm-brand-text); border-color: transparent; font-size: 1rem; }
.fm-xpm-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; flex: 1 1 auto; }
.fm-xpm-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-xpm-type { font-size: .75rem; color: var(--fm-muted); }
.fm-xpm-check { color: var(--fm-brand-text); font-size: 1.1rem; flex: none; }
.select2-results__option--highlighted .fm-xpm-type, .select2-results__option--highlighted .fm-xpm-check { color: inherit; opacity: .85; }
.fm-xedit .fm-paysel + .select2-container .select2-selection--single { height: auto; min-height: 2.9rem; padding-top: .25rem; padding-bottom: .25rem; }
.fm-xedit .fm-paysel + .select2-container .select2-selection__rendered { line-height: 1.25; }
.fm-xedit .fm-paysel + .select2-container .select2-selection__arrow { height: 100%; top: 0; transform: none; display: flex; align-items: center; }
.fm-xrest { margin: .25rem 0 0; font-size: .85rem; font-weight: 600; color: var(--fm-income-text); }
.fm-xrest:empty { display: none; }
@media (max-width: 767.98px) {
  /* the payment lists open as full-width lists */
  .fm-xdd-pay.select2-dropdown { border-radius: .75rem; }
}

/* ---------- attachments ---------- */
.fm-xfiles { display: flex; flex-direction: column; gap: .5rem; }
.fm-xfile { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border: 1px solid var(--fm-line); border-radius: .75rem; min-width: 0; }
.fm-xfile-ico { width: 2.1rem; height: 2.4rem; flex: none; border-radius: .5rem; background: var(--fm-canvas); border: 1px solid var(--bs-border-color); display: flex; align-items: center; justify-content: center; color: var(--fm-alert-text); font-size: 1.15rem; }
.fm-xfile-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.fm-xfile-name { font-size: .875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fm-ink); text-decoration: none; }
a.fm-xfile-name:hover { text-decoration: underline; }
.fm-xfile-actions { display: flex; gap: .3rem; flex: none; }
.fm-xdrop { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 1rem; border: 2px dashed var(--bs-border-color); border-radius: .9rem; color: var(--fm-muted); cursor: pointer; text-align: center; font-size: .9rem; }
.fm-xdrop .bi { font-size: 1.4rem; color: var(--fm-brand-text); }
.fm-xdrop-link { color: var(--fm-brand-text); font-weight: 600; text-decoration: underline; }
.fm-xdrop:hover, .fm-xdrop.is-over { border-color: var(--fm-brand); background: var(--fm-brand-soft); }
.fm-xnew-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .6rem; }
@media (max-width: 767.98px) { .fm-xdrop { display: none; } }

/* ---------- sticky action bar ---------- */
.fm-xbar { position: sticky; bottom: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1rem 0 0; padding: .75rem 1.25rem; background: var(--fm-surface); border: 1px solid var(--fm-line); border-radius: var(--fm-radius-card); box-shadow: 0 -.5rem 1rem rgba(0, 0, 0, .06); }
.fm-xbar-total { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; min-width: 0; }
.fm-xbar-label { color: var(--fm-muted); font-size: .85rem; }
.fm-xbar-total strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.fm-xbar-lines { color: var(--fm-muted); font-size: .85rem; }
.fm-xbar-actions { display: flex; gap: .5rem; flex: none; }
@media (max-width: 1399.98px) { .fm-xbar { padding-right: 4.5rem; } } /* clear of the assistant button */
@media (max-width: 991.98px) { .fm-xbar { bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); } }
@media (max-width: 767.98px) {
  .fm-xbar { padding: .6rem .75rem; border-radius: .9rem; }
  .fm-xbar-label, .fm-xbar-lines { display: none; }
  .fm-xbar-actions .btn-secondary { display: none; }
  .fm-xbar-actions .btn-primary { min-width: 7rem; }
}
