/* ==========================================================================
   KPI Overview — dashboard "Performance" board.
   Big-number tiles + period deltas + inline-SVG trend + CSS lane/equipment
   bars + latest-lane map card. Theme-aware via tokens only (no raw colors);
   spacing snapped to the 8px ramp {0,4,8,12,16,24,32,48,60,80,120}. On dark,
   --accent resolves to periwinkle (#8DA2F9); on light to brand cobalt.
   ========================================================================== */

.qf-kpi-section {
  margin: 0 0 32px;
}

/* ── Header + period toggle ─────────────────────────────────────────── */
.qf-kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.qf-kpi-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
}
.qf-kpi-period-btn {
  min-height: 44px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all .2s ease;
}
.qf-kpi-period-btn:hover {
  color: var(--ink);
}
.qf-kpi-period-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ── Tile row (4 → 2 at small widths) ───────────────────────────────── */
.qf-kpi-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin: 0 0 24px;
}
.qf-kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 0;
}
.qf-kpi-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.qf-kpi-value {
  margin-top: 8px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qf-kpi-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.qf-kpi-delta {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  border-radius: var(--radius-btn);
}
.qf-kpi-delta.is-up { color: var(--success); background: var(--success-bg); }
.qf-kpi-delta.is-down { color: var(--error); background: var(--error-bg); }
.qf-kpi-delta.is-flat { color: var(--muted); background: var(--surface-2); }
.qf-kpi-sub {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Charts grid (trend / lanes / equipment / map) ──────────────────── */
.qf-kpi-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}
.qf-kpi-card {
  min-width: 0;
  padding: 24px;
}
.qf-kpi-card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0 0 16px;
}

/* Trend — responsive area+line SVG. */
.qf-kpi-trend { width: 100%; }
.qf-kpi-trend-svg {
  display: block;
  width: 100%;
  height: 96px;
}
.qf-kpi-trend-area {
  fill: var(--accent-soft);
  stroke: none;
}
.qf-kpi-trend-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* Bars — lane / equipment horizontal fills. */
.qf-kpi-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qf-kpi-bar-row {
  display: grid;
  grid-template-columns: minmax(0, 40%) 1fr auto;
  align-items: center;
  gap: 12px;
}
.qf-kpi-bar-label {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.qf-kpi-bar-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.qf-kpi-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent);
}
.qf-kpi-bar-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Engagement mini-grid — 5 interaction counts inside their KPI card. The big
   numbers sit directly on the card's ≥0.5 glass tint (no separate wash), which
   keeps them legible per the readability rule. */
.qf-kpi-engage {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.qf-kpi-engage-cell {
  min-width: 0;
  text-align: center;
}
.qf-kpi-engage-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.qf-kpi-engage-label {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* Latest-lane map card. */
.qf-kpi-map-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.qf-kpi-map-img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.qf-kpi-map-caption {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.qf-kpi-map-link:hover .qf-kpi-map-caption { color: var(--accent); }

/* ── Responsive — tiles 4→2, charts stack, denser padding ───────────── */
@media (max-width: 720px) {
  .qf-kpi-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
  .qf-kpi-charts {
    grid-template-columns: 1fr;
  }
  .qf-kpi-tile,
  .qf-kpi-card {
    padding: 16px;
  }
  .qf-kpi-value { font-size: 28px; }
  /* 5 engagement cells → 3-up on phones so the numbers never crush. */
  .qf-kpi-engage {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px 8px;
  }
}
