/*
 * 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);
  background: var(--color-success-bg);
}

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

.kpi-trend--neutral {
  color: var(--color-neutral-400);
  background: color-mix(in srgb, var(--text-secondary) 12%, transparent);
}

/* ─── 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);
}

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

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

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

/* ─── Click-to-filter active state (FR13) ─── */
.kpi-tile--active {
  outline: 2px solid var(--accent);
  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);
  background: var(--color-success-bg);
}
[data-theme="dark"] .kpi-status-badge--yellow {
  color: var(--color-warning-text);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
}
[data-theme="dark"] .kpi-status-badge--red {
  color: var(--color-error-text);
  background: var(--color-error-bg);
}

[data-theme="light"] .kpi-status-badge--green {
  color: var(--color-success-text);
  background: color-mix(in srgb, var(--color-success) 8%, transparent);
}
[data-theme="light"] .kpi-status-badge--yellow {
  color: var(--color-warning-text);
  background: color-mix(in srgb, var(--color-warning) 8%, transparent);
}
[data-theme="light"] .kpi-status-badge--red {
  color: var(--color-error-text);
  background: color-mix(in srgb, var(--color-error) 8%, transparent);
}

[data-theme="dark"] .kpi-tile--active {
  background: var(--accent-muted);
}

[data-theme="light"] .kpi-tile--active {
  background: var(--accent-muted);
}

/* ─── 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;
  }
}
