/* kpi-trend-chart - a single KPI's own FY trend, shown in the right-hand
   column of the detail grid (kpi.js renderKpiTrendChart()). Box style now
   matches GFF_KPI_closeout_preview.html's own .panel exactly (white,
   bordered, 8px radius) - the same card style .kpi-criteria-panel already
   uses on the left - not the leftover gray-tinted box from an earlier
   round. */

/* Registers --pct as an animatable <number> (used by .kpi-donut__ring's
   conic-gradient, below) - without this, the browser treats it as an
   opaque string and transitioning it is a no-op. */
@property --pct {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

.kpi-trend-chart {
  padding: var(--sp6);
  padding-top: var(--sp3);
  background: var(--clr-white);
  border: 1px solid var(--clr-gray-300);
  border-radius: var(--radius-8, 8px);
}

.kpi-trend-chart__caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp3);
  margin-bottom: var(--sp6);
}

@media (max-width: 767px) {
  .kpi-trend-chart__caption {
    margin-bottom: 20px;
  }

  /* justify-content:space-between only pushes the chip to the right
     while both items share one line - once flex-wrap drops it to its
     own line (the title alone is already wide enough on a narrow
     screen), a lone wrapped item falls back to flex-start/left instead.
     margin-left:auto keeps it pinned to the right end regardless. */
  .kpi-trend-chip {
    margin-left: auto;
  }
}

/* .kpi-trend-chart__caption-title's font-size/weight/color are shared
   with .kpi-criteria-panel__title (kpi.css) - same style for both panel
   headers, not defined twice. */

.kpi-trend-chip {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-12);
  font-weight: var(--fw-bold);
  color: var(--clr-gray-dark);
  background: var(--clr-white);
  padding: var(--sp2) var(--sp4);
  border-radius: 999px;
}

.kpi-trend-chip--delta {
  gap: var(--sp1);
}

.kpi-trend-chip--up {
  color: #2e7d32;
  background: #e2f0e0;
}

.kpi-trend-chip--down {
  color: #c87d1e;
  background: #f8ecdb;
}

/* Stacked charts only (kpi.js kpiSvgStacked()) - ported directly from
   GFF_KPI_closeout_preview.html's own stacked(), a real inline <svg>.
   Centered, capped so it doesn't stretch full-width on a wide panel (the
   SVG's own viewBox already defines its internal layout/proportions). The
   non-stacked case (kpiTrendDonuts(), below) is plain HTML/CSS instead -
   not wrapped in .kpi-trend-svg. */
.kpi-trend-svg {
  display: flex;
  justify-content: center;
}

.kpi-trend-svg svg {
  width: 100%;
  max-width: 420px;
  height: auto;
}

.kpi-svg-mark {
  cursor: pointer;
}

/* Non-stacked trend chart - one donut per FY (kpi.js kpiTrendDonuts()).
   Plain divs, not SVG, specifically so the ring size/gap/wrap can be
   retuned per breakpoint with ordinary CSS instead of SVG viewBox math -
   see the max-480 override below. The ring itself is a conic-gradient
   fill (--pct, --donut-clr set inline per donut) masked into a ring with
   a radial-gradient mask (no background-color assumption about what's
   behind it, unlike a plain "white circle on top" hole punch). */
.kpi-donut-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 30px;
}

.kpi-donut {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp2);
}

.kpi-donut:not(:first-child) {
  padding-left: var(--sp6);
  border-left: 1px solid var(--clr-gray-300);
}

@media (max-width: 767px) {
  .kpi-donut-row {
    flex-direction: column;
  }

  .kpi-donut:not(:first-child) {
    padding-left: 0;
    padding-top: var(--sp6);
    border-left: none;
    border-top: 1px solid var(--clr-gray-300);
  }
}

.kpi-donut__circle {
  --donut-size: 110px;
  --donut-thickness: 14px;
  position: relative;
  width: var(--donut-size);
  height: var(--donut-size);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-donut__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    var(--donut-clr) calc(var(--pct) * 1%),
    #e7e2da 0
  );
  -webkit-mask: radial-gradient(
    farthest-side,
    transparent calc(100% - var(--donut-thickness)),
    #000 calc(100% - var(--donut-thickness) + 1px)
  );
  mask: radial-gradient(
    farthest-side,
    transparent calc(100% - var(--donut-thickness)),
    #000 calc(100% - var(--donut-thickness) + 1px)
  );
  transition: --pct 1s linear;
}

.kpi-donut__value {
  position: relative;
  font-size: var(--fs-18, 18px);
  font-weight: var(--fw-bold);
  color: #09544f;
  transition: opacity 0.2s linear 1s;
}

/* Grow-in on load, same reveal convention this component already uses
   for the criteria bars (.progress-bar__row/.animate-bars, see
   logic-model-responses.css: render the real value inline, hold it at
   zero via a higher-specificity !important rule, then let kpi.js flip
   one class shortly after insertion so the already-set value actually
   transitions instead of just appearing). --pct needs @property (above)
   for the browser to treat it as an animatable <number> at all - a plain
   `transition: background` can't interpolate a conic-gradient's angle. */
.kpi-donut-row:not(.kpi-donut-row--animate) .kpi-donut__ring {
  --pct: 0 !important;
}

.kpi-donut-row:not(.kpi-donut-row--animate) .kpi-donut__value {
  opacity: 0;
}

.kpi-donut__label {
  font-size: var(--fs-13);
  font-weight: var(--fw-bold);
  color: #09544f;
}

@media (max-width: 480px) {
  .kpi-donut__circle {
    --donut-size: 84px;
    --donut-thickness: 10px;
  }

  .kpi-donut__value {
    font-size: var(--fs-15, 15px);
  }
}

/* Hover tooltip for the SVG bars (kpi.js initSvgTip()) - ported from
   GFF_KPI_closeout_preview.html's own .gffk-tip. One shared floating
   element (appended to <body>, not nested in the SVG - a <path> can't
   contain arbitrary HTML), positioned via JS on pointermove. Styled to
   match the monitoring map's own .map-tooltip (white card, same radius/
   shadow/padding) instead of the original dark-green bubble. */
.kpi-svg-tip {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  background: var(--clr-white);
  color: var(--clr-gray-dark);
  font-size: var(--fs-12);
  line-height: 1.4;
  font-family: var(--primary-ff);
  padding: var(--sp3) var(--sp4);
  border-radius: var(--radius-8, 8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.1s;
  max-width: 260px;
}

.kpi-svg-tip.on {
  opacity: 1;
}

.kpi-trend-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp5);
  margin-top: var(--sp5);
  font-size: var(--fs-12);
  color: var(--clr-gray-medium);
}

.kpi-trend-legend__item {
  display: inline-flex;
  align-items: center;
  gap: var(--sp2);
  color: var(--clr-gray-dark);
}

.kpi-trend-legend__swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
}
