/* Money screens (estimates, invoices, get paid, books, month-end, job costing, assemblies, price lists):
   the Apple-style flow from docs/ux/flow-guide.md on top of the app.css components. Tokens only.
   Building blocks: js/lib/money-ui.js (card, summary, details, note). */

/* A screen's action bar can wait until there is something to act on (Receive payment before a customer). */
.action-bar[hidden] { display: none !important; }

/* ---- summary tiles under the title ---- */
.mx-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: var(--s2); margin: 0 0 var(--s5); }
.mx-tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: var(--tap); padding: var(--s3) var(--s4); border: 0; border-radius: var(--r-group); background: var(--surface); color: var(--text); text-align: left; text-decoration: none; font: inherit; }
.mx-tile.is-link { cursor: pointer; }
.mx-tile.is-link:active { background: var(--fill-strong); }
@media (hover: hover) { .mx-tile.is-link:hover { background: var(--surface-2); } }
.mx-tile:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: 2px; }
.mx-tile-label { font-size: var(--fs-footnote); line-height: var(--lh-footnote); color: var(--text-muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-tile-value { font-size: var(--fs-title3); line-height: var(--lh-title3); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-tile-hint { font-size: var(--fs-footnote); line-height: var(--lh-footnote); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-tile.is-danger .mx-tile-value { color: var(--danger); }
.mx-tile.is-success .mx-tile-value { color: var(--success); }
.mx-tile.is-accent .mx-tile-value { color: var(--accent); }
.mx-tile.is-warning .mx-tile-value { color: var(--warning); }

/* ---- an inset grouped section that holds a form or editor ---- */
.mx-section .mx-card { background: var(--surface); border-radius: var(--r-group); padding: var(--s4); min-width: 0; }
.mx-section .mx-card > :first-child { margin-top: 0; }
.mx-section .mx-card > :last-child { margin-bottom: 0; }
.mx-section .mx-card > * + * { margin-top: var(--s3); }
.mx-section .ios-group-header .btn { min-height: 32px; }
.mx-card .form-grid { gap: var(--s3); }

/* ---- quiet disclosure ---- */
.mx-details { margin: 0 0 var(--s5); border-radius: var(--r-group); background: var(--surface); }
.mx-details > summary { cursor: pointer; padding: var(--s3) var(--s4); min-height: var(--row); display: flex; align-items: center; gap: var(--s2); font-weight: 600; font-size: var(--fs-body); list-style: none; }
.mx-details > summary::-webkit-details-marker { display: none; }
.mx-details > summary::after { content: ""; margin-left: auto; flex: none; width: 9px; height: 9px; border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); transition: transform var(--t-base); }
.mx-details[open] > summary::after { transform: rotate(-135deg); }
.mx-details > summary:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: -3px; border-radius: var(--r-group); }
.mx-details-body { padding: 0 var(--s4) var(--s4); min-width: 0; }
.mx-details-body > * + * { margin-top: var(--s3); }
.mx-details .ios-list { background: var(--bg); }

/* ---- notes ---- */
.mx-note { display: flex; gap: var(--s3); align-items: flex-start; margin: 0 0 var(--s5); padding: var(--s3) var(--s4); border-radius: var(--r-group); background: var(--info-soft); color: var(--text); font-size: var(--fs-subhead); line-height: var(--lh-subhead); }
.mx-note-icon { flex: none; display: grid; margin-top: 1px; color: var(--info); }
.mx-note-text { min-width: 0; overflow-wrap: anywhere; }
.mx-note.tone-warning { background: var(--warning-soft); } .mx-note.tone-warning .mx-note-icon { color: var(--warning); }
.mx-note.tone-danger { background: var(--danger-soft); } .mx-note.tone-danger .mx-note-icon { color: var(--danger); }
.mx-note.tone-success { background: var(--success-soft); } .mx-note.tone-success .mx-note-icon { color: var(--success); }
.mx-note.tone-neutral { background: var(--surface); } .mx-note.tone-neutral .mx-note-icon { color: var(--text-muted); }

/* ---- lists ---- */
.mx-seg { margin: 0 0 var(--s5); }
.mx-hint { margin-top: calc(-1 * var(--s3)); }
.mx-list .ios-row-value { font-weight: 600; color: var(--text); }
.mx-list .is-quiet .ios-row-value { font-weight: 400; color: var(--text-muted); }
.ios-row .mx-badges { display: inline-flex; gap: 4px; flex: none; align-items: center; }
.mx-neg, .mx-list .mx-neg .ios-row-value { color: var(--danger); }
.mx-danger .ios-row { justify-content: center; }
.mx-danger .ios-row-text { align-items: center; }
.mx-quick .quick-actions, .quick-actions.mx-quick { margin: 0 0 var(--s5); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ios-dot.mx-st-draft, .ios-dot.mx-st-void, .ios-dot.mx-st-superseded { background: var(--tile-gray); }
.ios-dot.mx-st-sent, .ios-dot.mx-st-applied { background: var(--tile-blue); }
.ios-dot.mx-st-accepted, .ios-dot.mx-st-paid { background: var(--tile-green); }
.ios-dot.mx-st-declined, .ios-dot.mx-st-overdue { background: var(--tile-red); }
.ios-dot.mx-st-partial { background: var(--tile-orange); }
@media (max-width: 480px) { .mx-list .mx-wide-only { display: none; } }

/* inline controls inside a row (a date, a select, a count) */
.mx-inline { min-height: 36px; max-width: 100%; padding: 4px 10px; border: 0; border-radius: 8px; background: var(--fill); color: var(--text); font: inherit; font-size: var(--fs-subhead); }
.mx-inline:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: 1px; }
select.mx-inline { max-width: 52vw; }
input.mx-inline[type=number] { width: 96px; text-align: right; }
.mx-field-row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; }
.mx-field-row .field { flex: 1 1 160px; min-width: 0; }

/* buttons and actions inside sections */
.mx-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.mx-actions .btn { min-height: var(--tap); }
.mx-fact-sheet .ios-group:last-child { margin-bottom: 0; }

/* ---- document builders (estimate, invoice): editor and totals ---- */
.mx-doc .doc-layout { gap: var(--s5); }
.mx-doc .doc-layout > * { min-width: 0; }
@media (max-width: 1000px) { .mx-doc .doc-layout { grid-template-columns: minmax(0, 1fr); } }
.mx-doc .doc-layout > .stack, .mx-doc .doc-side.stack { gap: 0; }
.mx-doc .doc-side { top: var(--s4); }
.mx-doc .totals-row.grand { font-size: var(--fs-title3); line-height: var(--lh-title3); }
.mx-doc .lines-add { flex-wrap: wrap; gap: var(--s2); }
.mx-doc .lines-add .btn, .mx-doc .line-actions .btn { min-height: 40px; }
.mx-doc .money-terms { margin: calc(-1 * var(--s3)) var(--s4) var(--s5); color: var(--text-muted); font-size: var(--fs-footnote); line-height: var(--lh-footnote); white-space: pre-wrap; }
@media (max-width: 640px) {
  /* One line: description on top; qty, unit, amount and the move/delete buttons in one row under it. */
  .mx-doc .line-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "desc desc desc desc" "qty unit amt act"; column-gap: var(--s2); row-gap: var(--s1); align-items: end; }
  .mx-doc .line-actions { grid-area: act; justify-content: flex-end; }
  .mx-doc .line-actions .btn { width: 36px; min-width: 36px; padding: 0; }
}

/* Estimate: the next step on top, scope, then advanced pricing (tests read .estimate-next and .estimate-pricing). */
.estimate-experience .estimate-next .money-signed { margin-top: var(--s2); }
.estimate-experience .estimate-next .status-card a { color: inherit; }
.estimate-experience .estimate-tax-reason:has(.qbo-notax:not([hidden])) { margin-top: var(--s4); padding-top: var(--s3); border-top: .5px solid var(--separator); }
.estimate-experience .estimate-hint { margin: 0; color: var(--text-muted); font-size: var(--fs-subhead); line-height: var(--lh-subhead); }
.estimate-experience .estimate-pricing .form-grid { margin-top: var(--s3); }
.resi-checklist .mx-hint-top { margin: 0 var(--s4) var(--s4); }
.mx-status-chips { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mx-status-chips:empty { display: none; }

/* Invoice */
.inv-pay-tools { margin: 0 0 var(--s5); }
.inv-pay-tools:empty { display: none; }
.inv-pay-tools > * + * { margin-top: var(--s2); }
.inv-statement .doc-preview { margin: 0 0 var(--s5); }

/* Job costing and month-end sit in a flex column (css/reports.css): never let a page outgrow it. */
.reports:has(> .mx-page) { display: block; }
.reports > .mx-page { min-width: 0; }
.rep-body { min-width: 0; }
.rep-tools { margin: 0 0 var(--s4); }

/* Sibling sections (Books, Job costing): the scrollable tab row under the title */
.mx-tabs-row { margin: calc(-1 * var(--s2)) 0 var(--s5); overflow-x: auto; scrollbar-width: none; }
.mx-tabs-row::-webkit-scrollbar { display: none; }
.mx-tabs-row .tabs { display: inline-flex; min-width: 100%; }
.mx-tabs-row .tabs [role=tab] { white-space: nowrap; }

@media print { .ops-tabs-row, .mx-tabs-row, .page-search, .mx-seg { display: none !important; } }
