/*
 * Kwalee BI — KPI Tile Component Styles
 *
 * Threshold status colours, trend indicators, hover tooltips,
 * and click-to-filter active state.
 *
 * Story 2.4: KPI Tile Component
 */

/* ─── KPI tile layout ─── */
.kpi-tile {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs, 4px);
  cursor: pointer;
  position: relative;
  user-select: none;
  padding: var(--spacing-md);
}

/* ─── KPI label row (label + status badge) ─── */
.kpi-label-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);
}

/* ─── Metric label ─── */
.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

[data-theme="dark"] .kpi-label {
  color: var(--color-neutral-400);
}

[data-theme="light"] .kpi-label {
  color: var(--color-neutral-500);
}

/* ─── Value + sparkline row ─── */
.kpi-value-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

/* ─── Metric value ─── */
.kpi-value {
  font-family: var(--font-heading, system-ui);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* ─── Sparkline ─── */
.kpi-sparkline {
  flex-shrink: 0;
  line-height: 0;
}

.kpi-sparkline iframe {
  display: block;
  background: transparent;
}

[data-theme="dark"] .kpi-value {
  color: var(--color-neutral-50);
}

[data-theme="light"] .kpi-value {
  color: var(--color-neutral-900);
}

/* ─── Trend row (arrow + delta + comparison) ─── */
.kpi-trend-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);
  min-height: 1.25rem;
  flex-wrap: wrap;
}

.kpi-trend-row--empty {
  /* Reserve space even when no delta is shown */
  visibility: hidden;
}

/* ─── Trend indicator ─── */
.kpi-trend {
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: var(--radius-sm, 4px);
  padding: 1px 6px;
}

.kpi-trend--positive {
  color: var(--color-success-text, #22c55e);
  background: var(--color-success-bg);
}

.kpi-trend--negative {
  color: var(--color-error-text, #ef4444);
  background: var(--color-error-bg);
}

.kpi-trend--neutral {
  color: var(--color-neutral-400);
  background: rgba(163, 163, 163, 0.12);
}

/* ─── Comparison period label ─── */
.kpi-comparison {
  font-size: 0.75rem;
}

[data-theme="dark"] .kpi-comparison {
  color: var(--color-neutral-500);
}

[data-theme="light"] .kpi-comparison {
  color: var(--color-neutral-400);
}

/* ─── Period label ─── */
.kpi-period {
  font-size: 0.6875rem;
  margin-top: auto;
}

[data-theme="dark"] .kpi-period {
  color: var(--color-neutral-500);
}

[data-theme="light"] .kpi-period {
  color: var(--color-neutral-400);
}

/* ─── Threshold status accent (top border strip) ─── */
.kpi-tile--green {
  border-top: 3px solid var(--color-success, #22c55e);
}

.kpi-tile--yellow {
  border-top: 3px solid var(--color-warning, #f59e0b);
}

.kpi-tile--red {
  border-top: 3px solid var(--color-error, #ef4444);
}

.kpi-tile--neutral {
  border-top: 3px solid var(--color-neutral-500, #737373);
}

/* ─── Click-to-filter active state (FR13) ─── */
.kpi-tile--active {
  outline: 2px solid var(--accent, #facc15);
  outline-offset: -2px;
}

.kpi-tile {
  transition:
    transform 0.15s ease,
    background 0.2s ease;
}

.kpi-tile:active {
  transform: scale(0.98);
}

/* ─── KPI status badge (dual encoding — icon + text, Story 7.3) ─── */
.kpi-status-badge {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: var(--radius-sm, 4px);
  white-space: nowrap;
  line-height: 1.3;
}

[data-theme="dark"] .kpi-status-badge--green {
  color: var(--color-success-text, #4ade80);
  background: var(--color-success-bg);
}
[data-theme="dark"] .kpi-status-badge--yellow {
  color: var(--color-warning-text, #fbbf24);
  background: rgba(251, 191, 36, 0.12);
}
[data-theme="dark"] .kpi-status-badge--red {
  color: var(--color-error-text, #f87171);
  background: var(--color-error-bg);
}

[data-theme="light"] .kpi-status-badge--green {
  color: var(--color-success-text, #15803d);
  background: rgba(21, 128, 61, 0.08);
}
[data-theme="light"] .kpi-status-badge--yellow {
  color: var(--color-warning-text, #b45309);
  background: rgba(180, 83, 9, 0.08);
}
[data-theme="light"] .kpi-status-badge--red {
  color: var(--color-error-text, #b91c1c);
  background: rgba(185, 28, 28, 0.08);
}

[data-theme="dark"] .kpi-tile--active {
  background: var(--accent-muted, rgba(250, 204, 21, 0.15));
}

[data-theme="light"] .kpi-tile--active {
  background: var(--accent-muted, rgba(234, 179, 8, 0.12));
}

/* ─── Hover tooltip via native title attribute ─── */
.kpi-tile:hover {
  cursor: pointer;
}

/* ─── Responsive adjustments ─── */
@media (max-width: 640px) {
  .kpi-tile {
    align-items: center;
    text-align: center;
  }

  .kpi-value {
    font-size: 1.5rem;
  }

  .kpi-label {
    font-size: 0.6875rem;
  }

  .kpi-label-row {
    justify-content: center;
  }

  .kpi-trend-row {
    justify-content: center;
  }
}
