/* =========================================================================
   Settings → Costs (src/features/settings/settingsCosts.js, admin only).
   The page head is Storage's (.stor-head / .stor-tools, settings.css); under it the shared .segmented picks the tab.
   Overview: the four figures are the Analytics .stat-cell parts in ONE bordered panel with hairline dividers (the
   card's own fill shows through a 1px grid gap), the months are the shared ReportingChartCard, and Coming up is a
   card in the chart card's shape. Services and Payments are the shared .stat-table--rows in a card, dressed as the
   Leads table (a sunk 38px head in sm medium, 56px rows, faint dividers); Automatic is .set-rows.
   Tokens only; JS writes only the skeleton's --sk-w and a vendor tile's --logo (the mark's file).
   ========================================================================= */
.cost-page { max-width: 880px; }
.cost-top { gap: var(--space-5); scroll-margin-top: var(--space-6); }   /* (a figure's link scrolls back up to here) */
.cost-tabs { align-self: flex-start; }
.cost-pane { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
/* a tab's own line (what it lists) and its action, over its card */
.cost-pane-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3) var(--space-4); min-width: 0; }
.cost-pane-lead { margin: 0; font-size: var(--text-sm); color: var(--text-soft); max-width: 62ch; }
.cost-pane-head > .btn { flex-shrink: 0; }
.cost-soft, .cost-nil { color: var(--text-soft); }

/* ---- Overview: the four figures in one panel, the rates on a line under it ---- */
.cost-figures { display: flex; flex-direction: column; gap: var(--space-2-5); }
.cost-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; overflow: hidden; background: var(--border-faint); }
.cost-kpi { gap: var(--space-1-5); padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5); background: var(--surface); }
.cost-kpi-sub { font-size: var(--text-xs); line-height: var(--leading-snug); color: var(--text-soft); text-wrap: pretty; }
.cost-kpi-sub .set-link { text-align: left; }
.cost-rates { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); margin: 0; font-size: var(--text-xs); color: var(--text-soft); font-variant-numeric: tabular-nums; }
.cost-rate.is-unset { color: var(--warning-700); }

/* the months: the shared chart card, and what its bars leave out under them */
.cost-chart .rchart-card { margin: 0; }
.cost-chart .rchart-footer:empty { display: none; }
.cost-chart-note { margin: 0; font-size: var(--text-sm); color: var(--text-soft); }

/* Coming up: a card in the chart card's shape (its padding and title), the next renewals as rows that open the service */
.cost-card { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--chart-pad); }
.cost-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.cost-card-title { margin: 0; font-size: var(--text-base); font-weight: var(--fw-semibold); color: var(--text-strong); }
.cost-card-head .btn-ghost { margin-right: calc(-1 * var(--space-2-5)); }   /* (the btn-sm's own padding: its words end on the figures' edge) */
.cost-card-empty { margin: 0; padding: var(--space-4) 0 var(--space-1); font-size: var(--text-sm); color: var(--text-soft); }
.cost-soon-t tbody tr:first-child td { border-top: 1px solid var(--border-faint); }
.cost-soon-t tbody tr:last-child td { padding-bottom: var(--space-2); }
.cost-soon-t td:first-child { width: 100%; max-width: 0; }
.cost-soon-when { color: var(--text-soft); white-space: nowrap; }
.cost-soon-when.is-due { color: var(--warning-700); }
.cost-soon-amt { min-width: 6.5em; white-space: nowrap; font-weight: var(--fw-medium); color: var(--text-strong); }

/* ---- the tables (Services, Payments, Coming up): the shared rows, dressed as the Leads table ---- */
.cost-tcard { padding: 0 var(--space-5); overflow: hidden; }
.cost-t thead th { height: var(--control-md); padding-top: 0; padding-bottom: 0; background: var(--surface-sunk); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-muted); vertical-align: middle; }
.cost-t tbody td { height: 56px; padding-top: var(--space-2); padding-bottom: var(--space-2); }
.cost-t tbody tr:not([role="button"]) { cursor: default; }
@media (hover: hover) and (pointer: fine) { .cost-t tbody tr:not([role="button"]):hover { background: none; } }
/* a service or a payment: its initials, its name and one quiet line */
.cost-who { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.cost-who-text { display: flex; flex-direction: column; gap: var(--space-0-5); min-width: 0; }
.cost-who-name { display: block; font-weight: var(--fw-medium); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-who-sub, .cost-who-meta { display: block; font-size: var(--text-xs); color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-who-meta { display: none; }   /* (a phone's line: what the columns it hides say) */
.cost-meta-part { white-space: nowrap; }   /* ("Next 17 Dec" stays on one line; the line breaks between its parts) */
.cost-meta-part.is-due { color: var(--warning-700); }
/* a vendor's tile (settingsCosts tileHTML, marks from costLogos.js): its initials, a one-colour mark or the models row's
   plain icon on one neutral disc (colour means status here: a brand's own colours are the only others); a mark in its
   own colours on the white logo well (.avatar--logo, as a client's logo), or the brand's own disc filling the circle */
.cost-mono { flex: none; background: var(--surface-2); color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border-faint); font-weight: var(--fw-semibold); }
.cost-tile svg { width: 14px; height: 14px; }
.cost-logo-mono { position: relative; color: var(--text-strong); }
.cost-logo-mono::after { content: ""; position: absolute; inset: 25%; background: currentColor; -webkit-mask: var(--logo) center / contain no-repeat; mask: var(--logo) center / contain no-repeat; }
.cost-tile.avatar--logo:not([data-tone])::after { inset: 21%; }   /* (a vendor's square mark: a little inside a client logo's 14%) */
/* a sheet's Service field: the tile sits in the field, following what's typed */
.cost-vendor { position: relative; }
.cost-vendor > .cost-tile { position: absolute; top: 50%; left: var(--space-2); width: 22px; height: 22px; transform: translateY(-50%); pointer-events: none; }
.cost-vendor > .input { padding-left: calc(var(--space-2) + 22px + var(--space-2)); }
/* a figure, and under it (smaller, quiet) what it is in its own currency and where it comes from */
.cost-amt { display: block; font-weight: var(--fw-medium); color: var(--text-strong); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cost-src { display: block; margin-top: var(--space-0-5); font-size: var(--text-xs); font-weight: var(--fw-regular); color: var(--text-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cost-src.is-warn { color: var(--warning-700); }
.cost-when { display: block; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Services: the name takes what the other columns leave; groups are quiet captions over their rows; the total is the
   sunk foot row */
.cost-svc-t td:first-child { width: 100%; max-width: 0; }
.cost-svc-t td.is-wide, .cost-svc-t .cost-col-next { white-space: nowrap; }
.cost-svc-t tbody tr:last-child td { border-bottom: 1px solid var(--border-faint); }
.cost-svc-t tbody:last-child tr:last-child > :is(th, td) { border-bottom: 0; }   /* (the total's label too, when nothing is folded under it) */
.cost-t .cost-grp th { padding-top: var(--space-4); padding-bottom: var(--space-1-5); border-bottom: 0; font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-soft); }
.cost-svc-t tr.is-past .cost-who-name, .cost-svc-t tr.is-past .cost-amt { color: var(--text-muted); }
.cost-svc-t .cost-total th, .cost-svc-t .cost-total td { height: 56px; background: var(--surface-sunk); }
.cost-svc-t .cost-total th { font-size: var(--text-sm); font-weight: var(--fw-regular); color: var(--text-soft); white-space: normal; vertical-align: middle; }
.cost-total-label { display: block; font-weight: var(--fw-semibold); color: var(--text-strong); }
.cost-total .cost-src { white-space: normal; }
.cost-total .set-link { text-align: left; }
.cost-total .cost-amt { font-weight: var(--fw-semibold); }
/* the services no longer paid, folded under the total */
.cost-t .cost-past-row th { padding-top: var(--space-1); padding-bottom: var(--space-1); }
.cost-past { display: inline-flex; align-items: center; gap: var(--space-1-5); min-height: var(--control-sm); padding: 0; border: 0; background: none; font: inherit; font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-strong); text-align: left; cursor: pointer; border-radius: var(--radius-sm); }
.cost-past svg { width: 14px; height: 14px; color: var(--text-muted); transform: rotate(-90deg); transition: transform var(--dur) var(--ease); }
.cost-past[aria-expanded="true"] svg { transform: none; }
.cost-past-n { font-weight: var(--fw-regular); color: var(--text-soft); font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) { .cost-past:hover span:first-of-type { text-decoration: underline; } }
.cost-past-rows tr:first-child td { border-top: 1px solid var(--border-faint); }
@media (prefers-reduced-motion: reduce) { .cost-past svg { transition: none; } }

/* Payments: what the amounts are, then search, the service filter and Add over the table; 25 at a time under it */
.cost-pay-top { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.cost-pay-tools { justify-content: flex-start; gap: var(--space-2); }
.cost-search.search { flex: 0 1 280px; min-width: 0; height: var(--control-sm); }
.cost-search input::-webkit-search-cancel-button { cursor: pointer; }
.cost-search:has(> input:disabled) { opacity: 0.55; pointer-events: none; }   /* (no payments yet: nothing to search) */
.cost-pay-tools .filter-dd { min-width: 0; }
.cost-filter { max-width: 100%; }
.cost-filter > span { min-width: 0; max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-pay-add { margin-left: auto; }
.cost-pay-t td.cost-pay-who { width: 100%; max-width: 0; }
.cost-pay-t .cost-who-sub { white-space: normal; }
.cost-t td.cost-nowrap { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cost-t tr.is-uncounted .cost-amt { font-weight: var(--fw-regular); color: var(--text-soft); text-decoration: line-through; }
.cost-tfoot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 52px; margin: 0 calc(-1 * var(--space-5)); padding: 0 var(--space-5); border-top: 1px solid var(--border-faint); }
.cost-count { font-size: var(--text-xs); color: var(--text-soft); font-variant-numeric: tabular-nums; }
.cost-tcard.is-empty { padding: 0; }
.cost-nomatch { margin: 0; }

/* Automatic: one row per source, the key it needs under what it reads */
.cost-srcs > .set-row:first-child { border-top: 0; }
.cost-needs { color: var(--text-soft); }

/* an empty book or list: the shared quiet empty state in a card */
.cost-empty { padding: 0; }

/* ---- the sheets ---- */
.cost-every, .cost-paid { align-self: flex-start; }
.cost-adds { margin: 0; color: var(--warning-700); }
.cost-from, .cost-sug { margin: 0; }

/* ---- the frame while it loads ---- */
.cost-sk { display: block; width: var(--sk-w, 50%); height: 10px; }
.cost-sk--av { flex: none; width: 26px; height: 26px; border-radius: var(--radius-full); }
.cost-sk--num { flex: none; width: 5em; margin-left: auto; }
.cost-sk--label { width: 7em; }
.cost-sk--total { width: 6em; height: 24px; }
.cost-sk--sub { width: 9em; }
.cost-sk-card { padding: var(--space-1) var(--space-5); }
.cost-sk-row { display: flex; align-items: center; gap: var(--space-3); height: 56px; }
.cost-sk-row + .cost-sk-row { border-top: 1px solid var(--border-faint); }

/* four across while each figure and its line fit on one line (the settings column at a 1280 laptop), two by two below
   that (a smaller laptop, a tablet), one under another on a phone */
@container main-col (max-width: 959px) {
  .cost-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .cost-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  /* the four tabs share the width */
  .cost-tabs { display: flex; align-self: stretch; }
  .cost-tabs button { flex: 1 1 0; min-width: 0; padding: 0 var(--space-1-5); }
  .cost-kpis { grid-template-columns: minmax(0, 1fr); }
  .cost-kpi { padding: var(--space-3-5) var(--space-4); }
  .cost-tcard { padding: 0 var(--space-4); }
  .cost-tfoot { margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
  .cost-rates { flex-direction: column; gap: var(--space-1); }
  .cost-sep { display: none; }
  .cost-card { padding: var(--space-4); }
  .cost-t.stat-table--rows { width: calc(100% + 2 * var(--space-4)); margin: 0 calc(-1 * var(--space-4)); }
  .cost-t.stat-table--rows th:first-child, .cost-t.stat-table--rows td:first-child { padding-left: var(--space-4); }
  .cost-t.stat-table--rows th:last-child, .cost-t.stat-table--rows td:last-child { padding-right: var(--space-4); }
  /* Services: the name, and a line with the plan, the billing and the next renewal; the figure on the right */
  .cost-svc-t .cost-col-next { display: none; }
  .cost-svc-t .cost-who-sub { display: none; }
  .cost-svc-t .cost-who-meta { display: block; white-space: normal; }
  .cost-svc-t td.num .cost-src-part { display: block; }
  .cost-svc-t td.num .cost-src-sep { display: none; }
  /* Payments: the date and the source go under the service, the amount keeps the card's gutter */
  .cost-pay-t .cost-col-date { display: none; }
  .cost-pay-t .cost-who-meta { display: block; }
  .cost-pay-t th.num, .cost-pay-t td.num { padding-right: var(--space-4); }
  /* the months: the average and its words one under the other, so the range keeps the room for all three */
  .cost-chart .rev-amount { flex-direction: column; align-items: flex-start; gap: 0; }
  /* Coming up: the day goes under the name */
  .cost-soon-t .cost-soon-when { display: none; }
  .cost-soon-t .cost-who-sub { display: none; }
  .cost-soon-t .cost-who-meta { display: block; }
  .cost-pane-head { flex-wrap: wrap; }
  .cost-pane-lead { flex: 1 1 100%; }
  /* Payments: the search across the top, the filter and Add under it */
  .cost-search.search { flex: 1 1 100%; height: var(--control-md); }
}
