/* =========================================================
   Show pages: the expense show page (header card, product lines, payment and attachment cards) and the change log
   timeline (partials/change_log_timeline.php, opt-in of ChangeLogCell::tabs). Only theme tokens (theme.css) and
   Bootstrap variables, so light and dark themes both work. Loaded by layouts/default.php before theme.css.
   ========================================================= */

/* ---------- page grid: phone order is title, header, actions, tabs, delete ---------- */
.fm-xshow { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "title" "header" "actions" "tabs" "delete"; gap: 1rem; padding-bottom: 1.5rem; }
.fm-xshow-title { grid-area: title; margin: 0; align-self: center; }
.fm-xshow-actions { grid-area: actions; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.fm-xshow-actions .btn, .fm-xshow-delete .btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.75rem; }
.fm-xshow-back { display: none !important; }
.fm-xshow-edit { order: -1; }
.fm-xshow-delete { grid-area: delete; display: grid; }
.fm-xshow-header { grid-area: header; min-width: 0; }
.fm-xshow-tabs { grid-area: tabs; min-width: 0; }
@media (min-width: 768px) {
  .fm-xshow { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title actions delete" "header header header" "tabs tabs tabs"; column-gap: .5rem; }
  .fm-xshow-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; }
  .fm-xshow-actions .btn, .fm-xshow-delete .btn { min-height: 2.5rem; }
  .fm-xshow-back { display: inline-flex !important; }
  .fm-xshow-edit { order: 0; }
  .fm-xshow-delete { display: flex; align-items: center; }
}

/* ---------- cards ---------- */
.fm-xhead, .fm-xcard { background: var(--fm-surface); border: 1px solid var(--fm-line); border-radius: var(--fm-radius-card); }
.fm-xcard { overflow: hidden; }
.fm-xcard-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; background: transparent; border-bottom: 1px solid var(--fm-line); padding: .9rem 1.25rem; }
.fm-xcard-title { margin: 0; font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: .6rem; }
.fm-xcard-ico { width: 2rem; height: 2rem; border-radius: .65rem; background: var(--fm-brand-soft); color: var(--fm-brand-text); display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: 1rem; }
.fm-xcard-link { font-size: .85rem; font-weight: 600; }
.fm-xcount { padding: 0 .5rem; border-radius: 999px; background: var(--fm-line); color: var(--fm-ink); font-size: .75rem; font-weight: 600; line-height: 1.35rem; }
.fm-income { color: var(--fm-income-text); }

/* ---------- header card ---------- */
.fm-xhead { padding: 1.5rem; display: flex; flex-direction: row; flex-wrap: wrap; gap: 1.5rem; justify-content: space-between; align-items: center; }
.fm-xhead-place { display: flex; gap: 1.1rem; align-items: center; flex: 1 1 26rem; min-width: 0; }
.fm-tile.fm-tile-xl { width: 4.5rem; height: 4.5rem; border-radius: 1.1rem; font-size: 1.9rem; }
.fm-xhead-names { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.fm-xhead-supplier { font-size: 1.5rem; font-weight: 700; color: var(--fm-ink); text-decoration: none; overflow-wrap: anywhere; }
a.fm-xhead-supplier:hover { color: var(--fm-brand-text); text-decoration: underline; }
.fm-xhead-branch { display: inline-flex; align-items: center; gap: .35rem; font-weight: 600; text-decoration: none; }
.fm-xhead-branch:hover { text-decoration: underline; }
.fm-xhead-address { color: var(--fm-muted); font-size: .85rem; }
.fm-xhead-total { display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }
.fm-xhead-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--fm-muted); }
.fm-xhead-amount { font-size: 2.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.fm-xhead-chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }
.fm-xchip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem; border-radius: 999px; background: var(--fm-line); color: var(--fm-ink); font-size: .75rem; font-weight: 500; white-space: nowrap; text-decoration: none; }
/* "From template": the same tint as a template-created row in the expense list (tr.fm-row-template in lists.css) */
.fm-xchip-template { background: var(--fm-brand-soft); color: var(--fm-ink); font-weight: 600; }
.fm-xchip-template .bi { color: var(--fm-brand-text); }
.fm-xchip-template:hover, .fm-xchip-template:focus-visible { background: color-mix(in srgb, var(--fm-brand-soft) 78%, var(--fm-brand-text)); color: var(--fm-ink); }
/* Tablet (iPad portrait / landscape with the sidebar): the supplier block and the total no longer fit side by side, so
   the total wraps to its own line. Let it fill that line: label and amount on the left, date and product count on the
   right, instead of leaving white space beside a left-aligned block. */
@media (min-width: 768px) and (max-width: 1199.98px) {
  .fm-xhead-place { flex-basis: 100%; }
  .fm-xhead-total { flex: 1 1 100%; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "label chips" "amount chips"; align-items: center; column-gap: 1.5rem; row-gap: .35rem; padding-top: 1rem; border-top: 1px solid var(--fm-line); }
  .fm-xhead-total .fm-xhead-label { grid-area: label; justify-self: start; }
  .fm-xhead-total .fm-xhead-amount { grid-area: amount; justify-self: start; }
  .fm-xhead-total .fm-xhead-chips { grid-area: chips; align-self: center; margin-top: 0; }
}
@media (max-width: 767.98px) {
  .fm-xhead { flex-direction: column; text-align: center; padding: 1.25rem; gap: 1rem; }
  .fm-xhead-place { flex-direction: column; flex-basis: auto; gap: .6rem; }
  .fm-xhead-names { align-items: center; }
  .fm-xhead-supplier { font-size: 1.25rem; }
  .fm-xhead-total { align-items: center; }
  .fm-xhead-chips { justify-content: center; }
  .fm-xhead-amount { font-size: 2.25rem; }
}

/* ---------- product lines and totals ---------- */
.fm-plines { list-style: none; margin: 0; padding: 0; }
.fm-pline { display: flex; align-items: center; gap: .85rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--fm-line); }
.fm-pline-ico { width: 2.75rem; height: 2.75rem; border-radius: .75rem; background: var(--fm-brand-soft); color: var(--fm-brand-text); display: flex; align-items: center; justify-content: center; flex: none; font-size: 1.3rem; }
.fm-pline-ico-none { background: var(--fm-line); color: var(--fm-muted); }
.fm-pline-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.fm-pline-name { font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.fm-pline-name:hover { text-decoration: underline; }
.fm-pline-meta { font-size: .8rem; color: var(--fm-muted); font-variant-numeric: tabular-nums; }
.fm-pill-income { padding: .15rem .55rem; border-radius: 999px; background: var(--fm-income-soft); color: var(--fm-income-text); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.fm-pline-total { font-weight: 600; min-width: 4.75rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fm-xtotals { display: flex; flex-direction: column; gap: .6rem; }
.fm-xtotals-row { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.fm-xtotals-grand { align-items: baseline; padding-top: .75rem; border-top: 1px solid var(--fm-line); }
.fm-xtotals-grand strong:last-child { font-size: 1.25rem; }
.fm-xtotals-saved { font-size: .85rem; font-weight: 500; }
@media (max-width: 575.98px) {
  .fm-pline { padding: .75rem 1rem; gap: .7rem; flex-wrap: wrap; }
  .fm-pline-ico { width: 2.5rem; height: 2.5rem; }
  .fm-pline-main { flex-basis: calc(100% - 3.25rem - 5.5rem); }
}

/* ---------- payment and attachments ---------- */
.fm-pay { display: flex; align-items: center; gap: .75rem; }
.fm-pay-logo { width: 2.4rem; height: 2.4rem; border-radius: .75rem; border: 1px solid var(--fm-line); background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.fm-pay-logo img { width: 100%; height: 100%; object-fit: contain; }
.fm-pay-logo-icon { background: var(--fm-brand-soft); color: var(--fm-brand-text); border-color: transparent; font-size: 1.1rem; }
.fm-pay-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.fm-pay-name { font-weight: 600; overflow-wrap: anywhere; }
.fm-pay-role { font-size: .75rem; color: var(--fm-muted); }
.fm-pay-amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* One attachment per row: icon + name (+ comment below), actions on the right, the comment editor underneath */
.fm-files { display: flex; flex-direction: column; gap: .5rem; }
.fm-file { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "open actions" "comment actions" "edit edit"; align-items: center; column-gap: .75rem; row-gap: .1rem; padding: .55rem .75rem; border: 1px solid var(--fm-line); border-radius: .75rem; min-width: 0; }
.fm-file-open { grid-area: open; display: flex; align-items: center; gap: .65rem; color: var(--fm-ink); text-decoration: none; min-width: 0; }
.fm-file-open:hover .fm-file-name { text-decoration: underline; }
.fm-file-thumb { width: 2.25rem; height: 2.6rem; 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.2rem; }
.fm-file-name { font-size: .875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fm-file-comment { grid-area: comment; padding-left: 2.9rem; font-size: .75rem; color: var(--fm-muted); overflow-wrap: anywhere; }
.fm-file-actions { grid-area: actions; display: flex; gap: .35rem; }
.fm-file-edit { grid-area: edit; margin-top: .4rem; }

/* ---------- change log timeline ---------- */
.fm-timeline { list-style: none; margin: 0; padding: 0; }
.fm-timeline-item { display: flex; gap: .85rem; }
.fm-timeline-rail { display: flex; flex-direction: column; align-items: center; flex: none; }
.fm-timeline-rail::after { content: ""; flex: 1 1 auto; width: 2px; background: var(--fm-line); margin: .3rem 0; }
.fm-timeline-item:last-child .fm-timeline-rail::after { display: none; }
.fm-timeline-body { flex: 1 1 auto; min-width: 0; padding-bottom: 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.fm-timeline-head { display: flex; justify-content: space-between; gap: .25rem .75rem; flex-wrap: wrap; align-items: baseline; }
.fm-timeline-who { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .45rem; min-width: 0; }
.fm-timeline-when { font-size: .8rem; color: var(--fm-muted); white-space: nowrap; }
.fm-source-pill { display: inline-flex; align-items: center; gap: .3rem; padding: 0 .5rem 0 .4rem; border-radius: 999px; background: var(--fm-brand-soft); color: var(--fm-brand-text); font-size: .72rem; font-weight: 600; line-height: 1.3rem; }
.fm-change { background: var(--fm-canvas); border-radius: .75rem; padding: .6rem .75rem; display: flex; flex-direction: column; gap: .2rem; }
.fm-change-field { display: flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 600; }
.fm-change-values { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; font-size: .85rem; overflow-wrap: anywhere; min-width: 0; }
.fm-change-old { color: var(--fm-muted); }
.fm-change-arrow { color: var(--fm-muted); }
.fm-log-badge { padding: 0 .45rem; border-radius: 999px; font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; line-height: 1.2rem; }
.fm-badge-added { background: var(--fm-income-soft); color: var(--fm-income-text); }
.fm-badge-removed { background: var(--fm-alert-soft); color: var(--fm-alert-text); }
.fm-badge-created { background: var(--fm-brand); color: #fff; }
.fm-badge-restored { background: var(--bs-info-bg-subtle); color: var(--bs-info-text-emphasis); }

/* avatars: picture, initials or the system robot */
.fm-avatar-circle { width: 2.25rem; height: 2.25rem; border-radius: 50%; flex: none; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; }
.fm-avatar-circle.fm-avatar-sm { width: 2rem; height: 2rem; font-size: .72rem; }
.fm-avatar-initials { background: hsl(var(--h, 200) 42% 89%); color: hsl(var(--h, 200) 55% 27%); }
[data-bs-theme="dark"] .fm-avatar-initials { background: hsl(var(--h, 200) 42% 24%); color: hsl(var(--h, 200) 55% 82%); }
.fm-avatar-system { background: var(--fm-brand-soft); color: var(--fm-brand-text); font-size: 1rem; }
.fm-avatar-stack { display: inline-flex; flex: none; }
.fm-avatar-stack .fm-avatar-circle { box-shadow: 0 0 0 2px var(--fm-surface); }
.fm-avatar-stack .fm-avatar-circle + .fm-avatar-circle { margin-left: -.6rem; }

/* side facts: History and Template runs cards */
.fm-fact { display: flex; align-items: center; gap: .75rem; }
.fm-fact-ico { width: 2.25rem; height: 2.25rem; border-radius: .75rem; background: var(--fm-brand-soft); color: var(--fm-brand-text); display: flex; align-items: center; justify-content: center; flex: none; }
.fm-fact-ico-income { background: var(--fm-income-soft); color: var(--fm-income-text); }
.fm-fact-ico-warn { background: var(--fm-warn-soft); color: var(--fm-warn-text); }
.fm-fact-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.fm-fact-label { font-size: .75rem; color: var(--fm-muted); }
.fm-fact-value { font-weight: 600; overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  .fm-file-edit.collapsing { transition: none; }
}
