/* KPI charts (js/kpi-charts.js): the dashboard widgets' look.
   Ported from Bencho "Stacked bars" (MIT, bencho.dev/licence).
   Ink = --text, slab = --bg2 (the card), edge = --border, so light and
   dark mode both follow the app theme. --c, --i, --kc-r, --kc-rr are set
   per element by the script. */
.kc {
  --kc-ink: var(--text);
  --kc-slab: var(--bg2);
  --kc-soft:  color-mix(in srgb, var(--kc-ink) 72%, var(--kc-slab));
  --kc-mute:  color-mix(in srgb, var(--kc-ink) 52%, var(--kc-slab));
  --kc-faint: color-mix(in srgb, var(--kc-ink) 32%, var(--kc-slab));
  --kc-w6:  color-mix(in srgb, var(--kc-ink) 6%, transparent);
  --kc-w12: color-mix(in srgb, var(--kc-ink) 12%, transparent);
  --kc-alert: #e5484d;
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 10px;
  color: var(--kc-ink); font-size: 13px;
  user-select: none; -webkit-user-select: none;
}
.kc-figure { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 32px; }
.kc-fig-l { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.kc-num { font-size: 30px; font-weight: 500; letter-spacing: -0.03em; line-height: 32px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kc-unit { font-size: 13px; color: var(--kc-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* pop in: each character rises a touch from below, out of a slight blur and
   from nothing, a hair past its mark, left to right, 70ms apart */
.kc-digit { display: inline-block; }
.kc-digit[data-pop] { animation: kc-pop 500ms cubic-bezier(0.34, 1.45, 0.64, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes kc-pop { from { transform: translateY(0.18em); opacity: 0; filter: blur(2px); } to { transform: none; opacity: 1; filter: blur(0); } }

/* segmented control (Month / Quarter, LTFR / TRFR / HRFR) */
.kc-seg { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px; border-radius: 10px; background: var(--kc-w6); flex-shrink: 0; }
.kc-thumb { position: absolute; top: 2px; bottom: 2px; left: 2px; border-radius: 8px; background: var(--kc-slab); box-shadow: 0 0 0 0.5px var(--kc-w12); transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1); }
.kc-tab { position: relative; appearance: none; border: 0; background: none; padding: 0 10px; height: 26px; font: inherit; font-size: 12px; font-weight: 500; color: var(--kc-mute); cursor: pointer; border-radius: 8px; white-space: nowrap; transition: color 160ms ease, scale 160ms cubic-bezier(0.22, 1, 0.36, 1); }
.kc-tab[data-on] { color: var(--kc-ink); }
.kc-tab:hover:not([data-on]) { color: var(--kc-soft); }
.kc-tab:active { scale: 0.96; }
.kc-tab:focus-visible { outline: 2px solid var(--navy, #2563eb); outline-offset: -2px; }

.kc-plot { position: relative; flex: 1; min-height: 48px; touch-action: none; cursor: crosshair; }
.kc-base { position: absolute; left: 0; right: 0; height: 1px; background: var(--kc-w12); }
.kc-col { position: absolute; top: 0; bottom: 0; }
.kc-bar, .kc-esc {
  position: absolute; border-radius: var(--kc-r);
  transition: height 600ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i) * 14ms),
              bottom 600ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i) * 14ms),
              background-color 160ms ease;
}
.kc-bar { background-color: var(--c); }
.kc-esc { background-color: var(--kc-alert); }
/* before the card scrolls into view, bars wait flat on the baseline */
.kc[data-pre] .kc-bar { height: 0 !important; bottom: var(--kc-b0) !important; }
.kc[data-pre] .kc-esc { height: 0 !important; }
/* scrubbing: the others step back by mixing toward the slab */
.kc[data-scrub] .kc-col:not([data-on]) .kc-bar { background-color: color-mix(in srgb, var(--c) 38%, var(--kc-slab)); }
.kc[data-scrub] .kc-col:not([data-on]) .kc-esc { background-color: color-mix(in srgb, var(--kc-alert) 38%, var(--kc-slab)); }

.kc-svg { position: absolute; inset: 0; overflow: visible; }
.kc-line { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: stroke-dashoffset 900ms cubic-bezier(0.22, 1, 0.36, 1); }
.kc-area { transition: opacity 600ms ease 200ms; }
.kc[data-pre] .kc-area { opacity: 0; }

.kc-ring { position: absolute; top: 0; left: 0; box-sizing: border-box; border: 1.5px solid var(--kc-mute); border-radius: var(--kc-rr, 7px); pointer-events: none; opacity: 0; transition: opacity 160ms ease; }
.kc[data-scrub] .kc-ring { opacity: 1; }

.kc-tip { position: absolute; top: 0; left: 0; z-index: 4; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 10px; background: var(--kc-slab); border: 1px solid color-mix(in srgb, var(--kc-ink) 10%, var(--kc-slab)); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06); font-size: 12px; line-height: 16px; pointer-events: none; opacity: 0; transition: opacity 160ms ease; }
.kc[data-scrub] .kc-tip { opacity: 1; }
.kc-tip-head, .kc-tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.kc-tip-head { justify-content: space-between; gap: 14px; color: var(--kc-mute); margin-bottom: 2px; }
.kc-tip b { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--kc-ink); }
.kc-tip-row span { flex: 1; color: var(--kc-soft); }
.kc-tip-row b { font-weight: 400; }
.kc-tip-row b[data-on] { font-weight: 500; }
.kc-tip-row i, .kc-key i { flex: none; width: 8px; height: 8px; border-radius: 2px; background-color: var(--c); }

.kc-axis { display: flex; justify-content: space-between; gap: 8px; margin-top: -4px; font-size: 11px; line-height: 14px; color: var(--kc-faint); font-variant-numeric: tabular-nums; }
.kc-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 11px; line-height: 16px; color: var(--kc-mute); }
.kc-key { display: inline-flex; align-items: center; gap: 5px; appearance: none; border: 0; background: none; padding: 0; font: inherit; color: inherit; }
button.kc-key { cursor: pointer; border-radius: 4px; }
button.kc-key:hover { color: var(--kc-soft); }
button.kc-key[aria-pressed="true"] { color: var(--kc-ink); }
button.kc-key:focus-visible { outline: 2px solid var(--navy, #2563eb); outline-offset: 2px; }

/* ranked bars (category charts) */
.kc-rank { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.kc-row { display: grid; grid-template-columns: minmax(60px, 34%) 1fr auto; align-items: center; gap: 10px; min-height: 20px; }
.kc-row-l { font-size: 12px; color: var(--kc-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kc-row-v { font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; min-width: 24px; text-align: right; }
.kc-track { position: relative; height: 10px; display: flex; gap: 2px; }
.kc-track .kc-bar { position: static; height: 10px; border-radius: 3px; transition: flex-basis 600ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i) * 30ms), background-color 160ms ease; flex: 0 0 var(--w); }
.kc[data-pre] .kc-track .kc-bar { flex-basis: 0; height: 10px !important; }
.kc[data-scrub] .kc-row:not([data-on]) .kc-bar { background-color: color-mix(in srgb, var(--c) 38%, var(--kc-slab)); }
.kc[data-scrub] .kc-row:not([data-on]) .kc-row-l, .kc[data-scrub] .kc-row:not([data-on]) .kc-row-v { color: var(--kc-faint); }
.kc-more { font-size: 11px; color: var(--kc-faint); }

/* ring (pie) */
.kc-donut { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; gap: 18px; }
.kc-donut-fig { position: relative; flex: none; }
.kc-donut-fig svg { display: block; transform: rotate(-90deg); }
.kc-arc { fill: none; transition: stroke 160ms ease, stroke-dashoffset 800ms cubic-bezier(0.22, 1, 0.36, 1); cursor: pointer; }
.kc[data-scrub] .kc-arc:not([data-on]) { stroke: color-mix(in srgb, var(--c) 38%, var(--kc-slab)); }
.kc-donut-mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; padding: 0 18%; }
.kc-donut-mid .kc-num { font-size: 26px; line-height: 28px; }
.kc-donut-mid .kc-unit { font-size: 11px; max-width: 100%; }
.kc-donut .kc-rank { justify-content: center; }
.kc-donut .kc-row { grid-template-columns: auto 1fr auto auto; cursor: default; }
.kc-pct { font-size: 11px; color: var(--kc-faint); font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }

/* single number */
.kc-big { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.kc-big .kc-num { font-size: 44px; line-height: 46px; }
.kc-big .kc-unit { white-space: normal; }

@media (prefers-reduced-motion: reduce) {
  .kc-digit[data-pop] { animation: none; }
  .kc-bar, .kc-esc, .kc-line, .kc-area, .kc-arc, .kc-thumb, .kc-track .kc-bar { transition: none; }
}
