/**
 * Stat card (DS nv-o-stat). Markup comes from one function,
 * design-system/shared/stat-card.js (product copy: js/ds/stat-card.js).
 *
 * Every product stat row renders from that module and carries [data-nv-stats]
 * (a hook for live data, not a style scope). The legacy KPI blocks (.nv-o-stat
 * in contracts, nv-fin-stat, dash-kpi on the dashboard) are gone, so this
 * layer is the only source of the look. No importance flags: a page that needs
 * a different stat is a new DS case, not a local override.
 *
 * Values match the Taxes reference: 104 px island, 24 px frame, 36 px neutral
 * icon circle with an 18 px glyph, label callout 13 / value numeric-title 16–22 / meta caption 11
 * (roles from components/nv-typography.css, DS shared/typography.css).
 * Colours read the DS table tokens and fall back to the dash-* tokens, so a page
 * without the DS primitives gets the same neutral fill.
 */
@layer components {
  .nv-o-stat {
    position: relative;
    box-sizing: border-box;
    min-width: 0;
    min-height: 104px;
    padding: var(--nv-island-padding, 24px);
    overflow: hidden;
    border: 0;
    border-radius: var(--nv-island-radius, 32px);
    background: var(--nv-table-well, var(--dash-surface-hover, var(--dash-card)));
    box-shadow: none;
    color: var(--nv-table-text, var(--dash-text));
    font-family: var(--lib-font-primary, inherit);
    container: nv-stat-card / inline-size;
  }

  .nv-o-stat--chart {
    display: grid;
    grid-template-columns: minmax(0, 2.4fr) minmax(56px, 1fr);
    align-items: center;
    column-gap: 18px;
  }

  .nv-o-stat__top {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    gap: 12px;
  }

  .nv-o-stat__icon {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--dash-text, #eee) 8%, transparent);
    color: var(--dash-text, #eee);
  }

  .nv-o-stat__icon svg {
    display: block;
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
  }

  .nv-o-stat__copy {
    min-width: 0;
    flex: 1;
  }

  .nv-o-stat__copy p {
    margin: 0;
  }

  .nv-o-stat__label,
  .nv-o-stat__meta {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .nv-o-stat__label {
    color: var(--nv-table-cell, var(--dash-text-muted));
    font-size: var(--nv-type-callout-size);
    line-height: var(--nv-type-callout-line);
    letter-spacing: var(--nv-type-callout-tracking);
  }

  .nv-o-stat__value {
    overflow: hidden;
    color: var(--nv-table-text, var(--dash-text));
    font-size: clamp(17px, 6cqi, var(--nv-type-numeric-title-size));
    font-weight: var(--nv-type-numeric-title-weight);
    font-variant-numeric: var(--nv-type-numeric-figures);
    letter-spacing: var(--nv-type-numeric-title-tracking);
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Meta is the quiet line: the delta reads as secondary text so the value stays the only primary. */
  .nv-o-stat__meta {
    font-size: var(--nv-type-caption-size);
    font-weight: var(--nv-type-caption-weight);
    line-height: var(--nv-type-caption-line);
    letter-spacing: var(--nv-type-caption-tracking);
  }

  .nv-o-stat__meta--up,
  .nv-o-stat__meta--down {
    color: var(--nv-table-cell, var(--dash-text-muted));
  }

  .nv-o-stat__meta--muted {
    color: var(--nv-table-head, var(--dash-text-subtle));
  }

  .nv-o-stat__spark {
    width: 100%;
    height: 28px;
    align-self: center;
    pointer-events: none;
  }

  .nv-o-stat__spark svg {
    display: block;
    width: 100%;
    height: 100%;
  }

  .nv-o-stat__meter {
    width: 100%;
    height: 6px;
    align-self: center;
    border-radius: 999px;
  }

  .nv-o-stat__meter-fill--red { --nv-meter-tone: var(--nv-feedback-error); }
  .nv-o-stat__meter-fill--green { --nv-meter-tone: var(--nv-feedback-success); }
  .nv-o-stat__meter-fill--orange { --nv-meter-tone: var(--nv-table-pending); }

  /* Foot: the chart row under the copy, one height with a spark, a meter, nothing, or a loading bone. */
  .nv-o-stat__foot {
    display: flex;
    height: 20px;
    flex-direction: column;
    justify-content: flex-end;
  }

  .nv-o-stat__foot > .nv-o-stat__spark {
    height: 100%;
  }

  /* Loading look: the stat card's own loading state, and every stat row while its page loads
     (body[data-nv-page-data="loading"]), so no page shows "—" and "Loading …" in place of bars (owner, 2026-10-27). */
  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) .nv-o-stat__foot::after {
    content: "";
    height: 6px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--nv-table-text, var(--dash-text, #888)) 11%, transparent);
  }

  /* Loading bars: a thin pill centred in each text line (10px, the value 16px), never the whole line box, so the
     three bars keep the gaps of the real text instead of touching (owner, 2026-10-27). */
  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) :is(.nv-o-stat__label, .nv-o-stat__value, .nv-o-stat__meta) {
    position: relative;
    width: fit-content;
    min-width: 3rem;
    color: transparent;
  }

  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) :is(.nv-o-stat__label, .nv-o-stat__value, .nv-o-stat__meta)::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    top: 50%;
    height: 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--nv-table-text, var(--dash-text, #888)) 11%, transparent);
    translate: 0 -50%;
  }

  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) .nv-o-stat__value::after {
    height: 16px;
  }

  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) .nv-o-stat__icon {
    background: color-mix(in srgb, var(--nv-table-text, var(--dash-text, #888)) 11%, transparent);
  }

  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) .nv-o-stat__icon svg {
    visibility: hidden;
  }

  /* While loading, the foot shows the loading bar only: a meter or spark under it would read as data. */
  :is(.nv-o-stat--loading, :is(body[data-nv-page-data="loading"], html.nv-cloudflare-preview-auth:not(.dash-landing-preview) body[data-nv-first-paint]:not([data-nv-page-data], [data-preview-dataset="demo"])) [data-nv-stats] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-budgets-state]) [data-nv-stats="budget"] .nv-o-stat, body[data-nucleus-budgets-state="loading"] [data-nv-stats="budget"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-invoices-state]) [data-nv-stats="invoicing"] .nv-o-stat, body[data-nucleus-invoices-state="loading"] [data-nv-stats="invoicing"] .nv-o-stat, html.nv-cloudflare-preview-auth body:not([data-nucleus-transactions-state]) [data-nv-stats="transactions"] .nv-o-stat, body[data-nucleus-transactions-state="loading"] [data-nv-stats="transactions"] .nv-o-stat) .nv-o-stat__foot > * {
    display: none;
  }

  /* Narrow card: the value steps down instead of truncating early. */
  @container nv-stat-card (max-width: 260px) {
    .nv-o-stat__value {
      font-size: var(--nv-type-title-3-size);
      letter-spacing: var(--nv-type-title-3-tracking);
    }
  }
}

/* Summary cards use tighter spacing inside an island. */
body.dash-page :is(.nv-o-table--with-summary, .nv-inv-cal, .dash-month-summary) > [data-nv-stats] > .nv-o-stat {
  min-block-size: 0;
  padding: 16px;
  border-radius: calc(var(--nv-island-radius, 32px) - 4px);
}


[data-nv-stats] .nv-o-stat__value {
  margin-block-start: var(--spacing-xxs, 4px);
}

/* Compact KPI cards follow the summary width, including when a rail is open. */
body.dash-page [data-nv-stats] {
  container: nv-stat-summary / inline-size;
}

@container nv-stat-summary (width <= 792px) {
  body.dash-page [data-nv-stats][data-nv-stats] > .nv-o-stat {
    min-height: 0;
    padding: var(--spacing-sm, 8px) var(--spacing-md, 12px);
    border-radius: var(--control-radius-lg, 16px);
  }
  body.dash-page [data-nv-stats] .nv-o-stat__label {
    display: block;
    font-size: var(--nv-type-footnote-size, 12px);
    overflow-wrap: anywhere;
  }
  body.dash-page [data-nv-stats] .nv-o-stat__value {
    font-size: var(--nv-type-subhead-size, 14px);
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@container nv-stat-card (width <= 180px) {
  body.dash-page [data-nv-stats] .nv-o-stat__icon { display: none; }
}

/* Keep the caption spacing above the product's unlayered paragraph resets. */
.nv-o-stat__value + .nv-o-stat__meta {
  margin-block-start: var(--spacing-xxs, 4px);
}

/* Stat island (nv-o-stats, owner audit 2026-11-17): a stat row is never nested in a content island. It is its own
   island: the first island of the right rail, or a sibling above the content island on a page without a rail.
   The stats sit on that island's surface: no tile, no plate behind the copy, only the icon circle (a functional
   well). Markup:
   <div class="nv-o-card nv-o-stats"><section class="… nv-kpi-summary" data-nv-stats="…">…</section></div> */
body.dash-page .nv-o-stats {
  container: nv-o-stats / inline-size;
}

/* A stat row the page hides (Invoicing off the invoices view) takes its island with it: no empty island. */
body.dash-page .nv-o-stats:not(:has(> [data-nv-stats]:not([hidden]))) {
  display: none;
}

/* The island's grid (one column, four in a row) is in dash-kpi-contract.css, beside the summary grid it replaces. */
body.dash-page .nv-o-stats > [data-nv-stats][data-nv-stats] > .nv-o-stat {
  min-height: 0;
  padding: 0;
  overflow: visible;
  border-radius: 0;
  background: transparent;
}

/* The stat keeps its reading size in the island: the compact summary type above is for tiles squeezed four in a row. */
body.dash-page .nv-o-stats [data-nv-stats] .nv-o-stat__label {
  display: -webkit-box;
  font-size: var(--nv-type-callout-size);
}

body.dash-page .nv-o-stats [data-nv-stats] .nv-o-stat__value {
  font-size: clamp(17px, 9cqi, var(--nv-type-numeric-title-size));
  white-space: nowrap;
  overflow-wrap: normal;
}
