/* Sales Hub UI clean-up m2 (2026-10-09, rev 2 after review): the Credit Memos tab (Invoices -> Credit Memos) and its
   create / edit / void dialogs in the Invoice Calculator look. Additions on top of billing-engine.css (the calculator's
   stylesheet) and the m1 clean-up styles. Scoped to .billing-engine.sh-clean.sh-cm (the tab) and
   .billing-engine.sh-clean.sh-cm-dialog (its dialogs), so no other page can change. */

/* Cards and their headers */
.billing-engine.sh-clean.sh-cm .sh-cm-card { overflow: hidden; container: sh-cm-card / inline-size; }
.billing-engine.sh-clean.sh-cm .sh-cm-cardhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.billing-engine.sh-clean.sh-cm .sh-cm-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.billing-engine.sh-clean.sh-cm .be-subtitle + .be-subtitle { margin-top: 4px; }
.billing-engine.sh-clean.sh-cm .sh-head > div:first-child { flex: 1 1 420px; min-width: 0; }
.billing-engine.sh-clean.sh-cm .sh-head > .be-button { flex-shrink: 0; }

/* Tables: fixed layout so every column keeps a sensible width; the description takes the remaining space and wraps. When
   that space would get too small, each row becomes a compact card instead of a squeezed table: below 960px of card width
   for the memo table with the Actions column, below 840px for the other memo tables, below 560px for the credit lines. */
.billing-engine.sh-clean.sh-cm .sh-cm-scroll { overflow-x: auto; }
.billing-engine.sh-clean.sh-cm table.sh-cm-table { min-width: 0; table-layout: fixed; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-customer { width: 20%; }
.billing-engine.sh-clean.sh-cm .sh-cm-table.sh-cm-lines col.sh-cm-c-customer { width: 30%; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-date { width: 100px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-amount { width: 108px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table.sh-cm-lines col.sh-cm-c-amount { width: 132px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-state { width: 180px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-actions { width: 104px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table col.sh-cm-c-invoice { width: 24%; }
.billing-engine.sh-clean.sh-cm .sh-cm-table th { padding: 0 10px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table td { padding: 12px 10px; vertical-align: top; }
.billing-engine.sh-clean.sh-cm .sh-cm-table th:first-child, .billing-engine.sh-clean.sh-cm .sh-cm-table td:first-child { padding-left: 16px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table th:last-child, .billing-engine.sh-clean.sh-cm .sh-cm-table td:last-child { padding-right: 16px; }
.billing-engine.sh-clean.sh-cm .sh-cm-table thead { background: color-mix(in oklab, var(--muted) 40%, var(--background)); }

/* Cells */
.billing-engine.sh-clean.sh-cm .sh-cm-customer { font-weight: 500; overflow-wrap: anywhere; }
.billing-engine.sh-clean.sh-cm .sh-cm-customer .be-customer { align-items: flex-start; gap: 6px; }
.billing-engine.sh-clean.sh-cm .sh-cm-customer a { color: inherit; text-decoration: none; }
.billing-engine.sh-clean.sh-cm .sh-cm-customer a:hover { text-decoration: underline; }
.billing-engine.sh-clean.sh-cm .sh-cm-toggle { margin-top: 2px; border-radius: 4px; }
.billing-engine.sh-clean.sh-cm .sh-cm-toggle > .be-icon { transition: transform 0.15s; }
.billing-engine.sh-clean.sh-cm .sh-cm-toggle[aria-expanded="true"] > .be-icon { transform: rotate(90deg); }
.billing-engine.sh-clean.sh-cm .sh-cm-desc { overflow-wrap: anywhere; white-space: normal; }
.billing-engine.sh-clean.sh-cm .sh-cm-note { display: flex; align-items: flex-start; gap: 6px; margin-top: 6px; font-size: 12px; line-height: 16px; font-weight: 500; color: oklch(47.3% 0.137 46.201); }
.billing-engine.sh-clean.sh-cm .sh-cm-note > .be-icon { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; }
.billing-engine.sh-clean.sh-cm .sh-cm-sub { display: block; margin-top: 2px; }
.billing-engine.sh-clean.sh-cm .sh-cm-date { white-space: nowrap; color: var(--muted-foreground); font-size: 13px; }
.billing-engine.sh-clean.sh-cm .sh-cm-stack-label { display: none; }
.billing-engine.sh-clean.sh-cm .sh-cm-amount { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.billing-engine.sh-clean.sh-cm .sh-cm-status { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.billing-engine.sh-clean.sh-cm .sh-cm-status .be-pill { cursor: default; max-width: 100%; white-space: normal; }
.billing-engine.sh-clean.sh-cm .sh-cm-actions .be-row-actions { gap: 4px; }
.billing-engine.sh-clean.sh-cm .be-button.be-small.sh-cm-btn { height: 26px; padding: 0 8px; }
.billing-engine.sh-clean.sh-cm .sh-cm-btn-void { color: oklch(50.5% 0.213 27.518); }
.billing-engine.sh-clean.sh-cm .sh-cm-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 400; color: var(--muted-foreground); }
.billing-engine.sh-clean.sh-cm .sh-cm-invoice { overflow-wrap: anywhere; }
.billing-engine.sh-clean.sh-cm .sh-cm-link { color: var(--primary); font-weight: 500; text-decoration: none; }
.billing-engine.sh-clean.sh-cm .sh-cm-link:hover { text-decoration: underline; }
.billing-engine.sh-clean.sh-cm .sh-cm-warn, .billing-engine.sh-clean.sh-cm-dialog .sh-cm-warn { color: oklch(47.3% 0.137 46.201); }
.billing-engine.sh-clean.sh-cm .sh-cm-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }

/* Details on demand (the calculator's expandable row) */
.billing-engine.sh-clean.sh-cm .sh-cm-details > td { padding: 4px 16px 16px 44px; }
.billing-engine.sh-clean.sh-cm .sh-cm-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.billing-engine.sh-clean.sh-cm tr.sh-cm-open { border-bottom: 0; }
.billing-engine.sh-clean.sh-cm tr.sh-cm-open, .billing-engine.sh-clean.sh-cm tr.sh-cm-open:hover { background: color-mix(in oklab, var(--muted) 30%, transparent); }

/* Dialogs (rendered in a portal; the dialog content itself carries .billing-engine.sh-clean.sh-cm-dialog) */
.billing-engine.sh-clean.sh-cm-dialog { gap: 16px; }
@media (min-width: 640px) { .billing-engine.sh-clean.sh-cm-dialog.sh-cm-dialog-wide { max-width: 576px; } }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-form { display: flex; flex-direction: column; gap: 14px; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-label { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--foreground); }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-label-note { font-weight: 400; color: var(--muted-foreground); }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-label-note::before { content: "· "; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-required { color: oklch(50.5% 0.213 27.518); }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-hint { font-size: 11px; line-height: 16px; color: var(--muted-foreground); }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-counter { display: flex; justify-content: space-between; gap: 8px; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.billing-engine.sh-clean.sh-cm-dialog .be-native-select, .billing-engine.sh-clean.sh-cm-dialog .sh-input { width: 100%; min-width: 0; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-amount-input { width: 160px; text-align: right; font-variant-numeric: tabular-nums; }
.billing-engine.sh-clean.sh-cm-dialog textarea.sh-input { height: auto; min-height: 64px; padding: 8px 12px; line-height: 20px; resize: vertical; }
.billing-engine.sh-clean.sh-cm-dialog .be-info > strong { display: block; font-weight: 500; }
.billing-engine.sh-clean.sh-cm-dialog .be-info > strong.sh-cm-wrap { overflow-wrap: anywhere; font-weight: 400; }
.billing-engine.sh-clean.sh-cm-dialog .be-error { margin: 0; }
.billing-engine.sh-clean.sh-cm-dialog .sh-cm-footer { gap: 8px; }
.billing-engine.sh-clean.sh-cm-dialog .be-button.be-destructive { background: oklch(57.7% 0.245 27.325); color: #fff; box-shadow: var(--be-control-shadow); }
.billing-engine.sh-clean.sh-cm-dialog .be-button.be-destructive:hover:not(:disabled) { background: oklch(50.5% 0.213 27.518); }
.billing-engine.sh-clean.sh-cm-dialog fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* Narrow cards: each memo becomes a compact card: customer and amount; the description (and its run notes); the status
   badge, "Created <date>" and the Edit / Void buttons. The memo table with the Actions column switches below 960px of card
   width (Created, Amount, Status and Actions take 492px and Customer 20%, so the description keeps at least ~275px); the
   other memo and void-history tables switch below 840px, the three-column credit-lines table only below 560px; on phones the
   date gets its own line. */
@container sh-cm-card (max-width: 959px) {
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions colgroup, .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions thead { display: none; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions tbody { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions tbody > tr.sh-cm-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "customer customer amount" "desc desc desc" "state date actions"; align-items: center; gap: 6px 12px; padding: 12px 16px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions tbody > tr.sh-cm-row > td { display: block; padding: 0; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-customer { grid-area: customer; align-self: start; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-amount { grid-area: amount; align-self: start; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-desc { grid-area: desc; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-state { grid-area: state; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-state .sh-cm-status { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-actions { grid-area: actions; justify-self: end; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-actions .be-row-actions > .be-muted { display: none; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-date { grid-area: date; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions td.sh-cm-date .sh-cm-stack-label { display: inline; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions tbody > tr.sh-cm-details { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-has-actions tbody > tr.sh-cm-details > td { display: block; padding: 0 16px 14px; }
}
@container sh-cm-card (max-width: 839px) {
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) colgroup, .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) thead { display: none; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) tbody { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) tbody > tr.sh-cm-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "customer customer amount" "desc desc desc" "state date actions"; align-items: center; gap: 6px 12px; padding: 12px 16px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) tbody > tr.sh-cm-row > td { display: block; padding: 0; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-customer { grid-area: customer; align-self: start; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-amount { grid-area: amount; align-self: start; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-desc { grid-area: desc; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-state { grid-area: state; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-state .sh-cm-status { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-actions { grid-area: actions; justify-self: end; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-actions .be-row-actions > .be-muted { display: none; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-date { grid-area: date; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-date .sh-cm-stack-label { display: inline; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) tbody > tr.sh-cm-details { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) tbody > tr.sh-cm-details > td { display: block; padding: 0 16px 14px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines).sh-cm-no-actions tbody > tr.sh-cm-row { grid-template-areas: "customer customer amount" "desc desc desc" "state date date"; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines).sh-cm-simple tbody > tr.sh-cm-row { grid-template-areas: "customer customer amount" "desc desc desc" "invoice invoice date"; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines).sh-cm-simple td.sh-cm-date { justify-self: end; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines) td.sh-cm-invoice { grid-area: invoice; }
}
@container sh-cm-card (max-width: 559px) {
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines colgroup, .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines thead { display: none; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines tbody { display: block; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines tbody > tr.sh-cm-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "customer amount" "desc desc"; gap: 6px 12px; padding: 12px 16px; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines tbody > tr.sh-cm-row > td { display: block; padding: 0; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines td.sh-cm-customer { grid-area: customer; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines td.sh-cm-amount { grid-area: amount; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table.sh-cm-lines td.sh-cm-desc { grid-area: desc; }
}
@container sh-cm-card (max-width: 479px) {
  .billing-engine.sh-clean.sh-cm .sh-cm-detail { grid-template-columns: 1fr; }
  .billing-engine.sh-clean.sh-cm table.sh-cm-table:not(.sh-cm-lines):not(.sh-cm-simple) tbody > tr.sh-cm-row { grid-template-areas: "customer customer amount" "desc desc desc" "state state actions" "date date date"; }
}

/* Phones: full-width create button, one field per row in the dialogs. */
@media (max-width: 639px) {
  .billing-engine.sh-clean.sh-cm .sh-head > .be-button { width: 100%; }
  .billing-engine.sh-clean.sh-cm-dialog .sh-cm-pair { grid-template-columns: 1fr; }
  .billing-engine.sh-clean.sh-cm-dialog .sh-cm-amount-input { width: 100%; }
}

/* m2r3 (owner 2026-10-09): Invoices -> Summary, first card "Invoice total": the line under the total with what was sent and
   what is not ("Sent $A · Not sent $B", the Invoice Calculator's own month numbers), drawn exactly like the calculator's
   month page draws it (calc.css .billing-engine .be-count > .calc-sent-split: the card's own small label style). Only shown
   when the backend passes the calculator's summary; scoped to that card. */
.sh-summary-total > .sh-sent-split {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}
