/* Shared KPI number fit — paired with js/kpi_fit.js (all PEARL HTMLs).
   Scope: ONLY elements the fitter marks [data-kfit] (short single-figure values in
   the recognised KPI value classes) plus explicit opt-in utilities below.
   Never targets generic .card / .grid / table. Themes, fonts, colours and
   phone-width tracker layouts are untouched (no layout, padding or size rules). */

/* 1. Fitted value: one line, marker glued, never clipped or ellipsized.
      In an exceptionally narrow host, scroll the value locally rather than
      widening the grid or letting it overlap the next card. */
[data-kfit] {
  display: flex !important;
  align-items: flex-end;
  min-height: var(--kfit-line);
  white-space: nowrap !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  text-overflow: clip !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  min-width: 0;
}

/* Leave original text intact for copying, accessibility and DOM-based exports.
   The generated visual text is the only content sized/abbreviated. */
[data-kfit-display] {
  font-size: 0 !important;
  line-height: var(--kfit-line) !important;
}
[data-kfit-display]::after {
  content: attr(data-kfit-display);
  content: attr(data-kfit-display) / "";
  font-size: var(--kfit-size) !important;
  line-height: 1.2;
  letter-spacing: normal;
}

/* Only recognized KPI components, not arbitrary cards/tables. Natural row
   heights are retained; the value sits at the same bottom edge in each row. */
:is(.qdor-stat, .acl-kpi, .ser-kpi):has(> [data-kfit]) {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
:is(.qdor-stat, .acl-kpi, .ser-kpi) > [data-kfit] {
  margin-top: auto;
}
.kpi-card:has([data-kfit]) > div:has(> [data-kfit]) {
  min-width: 0;
  flex: 1 1 auto;
}

/* 2. Opt-in: value wrapper whose label may wrap while the figure stays whole.
      Use: <div class="kfit-pair"><span class="kfit-label">..</span><span class="kfit-num">..</span></div> */
.kfit-num {
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.kfit-label {
  white-space: normal;
  overflow-wrap: break-word;
  min-width: 0;
}
.kfit-mark { white-space: nowrap; margin-left: .15em; }

/* 3. Opt-in grid: lets cards shrink without forcing overflow. Column count
      inherits from the page; only adds min-width safety to children. */
.kfit-grid > * { min-width: 0; }
.kfit-card { min-width: 0; overflow: visible; }
