/* Mission Analytics — view styles (P6 follow-up).
 *
 * Sibling of /css/pages/xp-dashboard.css. Shares brand tokens, font
 * stack, and surface-card aesthetic so the two analytics surfaces feel
 * like one product.
 *
 * Brand tokens: --surface-deep --amber --green --green-soft
 * Fonts:        Fraunces (titles) · General Sans (body)
 *
 * Mobile-first: 1-col stack <768px; multi-col >=768px.
 * 44px min tap targets on interactive controls.
 * prefers-reduced-motion respected.
 */

#mission-analytics-host,
.mission-analytics {
  display: block;
  margin: 16px auto 32px;
  max-width: 880px;
  padding: 0 16px;
  color: var(--text-primary);
  font-family: 'General Sans', system-ui, sans-serif;
}

/* ── Heading + window picker row ───────────────────────────────── */
.ma-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.ma-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 0;
  color: var(--text-primary);
}
.ma-window {
  display: inline-flex;
  align-self: flex-start;
  gap: 4px;
  background: var(--surface-card);
  border: 1px solid color-mix(in srgb, var(--amber) 18%, transparent);
  border-radius: 999px;
  padding: 3px;
}
.ma-window-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font: 500 0.85rem/1 'General Sans', system-ui, sans-serif;
  padding: 8px 14px;
  min-height: 44px;
  min-width: 56px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.ma-window-btn:hover {
  color: var(--text-primary);
}
.ma-window-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
.ma-window-btn-active {
  background: color-mix(in srgb, var(--amber) 14%, transparent);
  color: var(--amber);
  font-weight: 600;
}

/* ── Stat-card grid ────────────────────────────────────────────── */
.ma-stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
@media (min-width: 480px) {
  .ma-stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .ma-stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.ma-stat-card {
  background: var(--surface-card);
  border: 1px solid color-mix(in srgb, var(--amber) 18%, transparent);
  border-radius: 14px;
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 160ms ease;
}
.ma-stat-card:hover {
  border-color: color-mix(in srgb, var(--amber) 38%, transparent);
}
.ma-stat-icon {
  font-size: 1.25rem;
  line-height: 1;
  color: var(--amber);
}
.ma-stat-label {
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ma-stat-value {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.85rem;
  line-height: 1.05;
  font-weight: 600;
  color: var(--text-primary);
  /* Stop very long numbers from busting the card */
  overflow-wrap: anywhere;
}
@media (min-width: 768px) {
  .ma-stat-value { font-size: 2rem; }
}
.ma-stat-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1em; /* keep card heights aligned when sub is blank */
}
.ma-stat-card-loading .ma-stat-value {
  color: var(--text-muted);
}

/* ── Sections (chart / leaderboard / funnel) ───────────────────── */
.ma-section {
  background: var(--surface-card);
  border: 1px solid color-mix(in srgb, var(--amber) 14%, transparent);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.ma-section-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text-primary);
}
.ma-empty {
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 8px 0;
}

/* ── Activity chart ────────────────────────────────────────────── */
.ma-chart {
  display: block;
  width: 100%;
  height: 120px;
}
.ma-bar {
  fill: var(--amber);
  transition: fill 120ms ease, opacity 120ms ease;
}
.ma-bar-empty {
  fill: var(--text-muted);
  opacity: 0.35;
}
.ma-bar:hover {
  fill: var(--green-soft);
}
.ma-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Leaderboard ───────────────────────────────────────────────── */
.ma-lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  counter-reset: ma-rank;
}
.ma-lb-row {
  display: grid;
  grid-template-columns: 50px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--surface-deep) 60%, transparent);
  border-radius: 10px;
  font-size: 0.92rem;
}
.ma-lb-row:nth-child(even) {
  background: color-mix(in srgb, var(--surface-deep) 35%, transparent);
}
.ma-lb-row-self {
  border: 1px solid color-mix(in srgb, var(--amber) 55%, transparent);
  background: color-mix(in srgb, var(--amber) 8%, transparent);
}
.ma-lb-rank {
  color: var(--amber);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ma-lb-name {
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ma-lb-missions {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ma-lb-xp {
  color: var(--green-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ma-lb-self-wrap {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ma-lb-self-sep {
  text-align: center;
  letter-spacing: 0.4em;
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* ── Signal funnel ─────────────────────────────────────────────── */
.ma-fn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.ma-fn-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ma-fn-sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--text-muted);
}
.ma-fn-sw-completed { background: var(--green); }
.ma-fn-sw-accepted  { background: var(--green-soft); }
.ma-fn-sw-offered   { background: var(--amber); }
.ma-fn-sw-abandoned { background: color-mix(in srgb, var(--text-muted) 70%, transparent); }

.ma-fn-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ma-fn-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ma-fn-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.ma-fn-sig {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.88rem;
}
.ma-fn-count {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.ma-fn-bar {
  display: flex;
  width: 100%;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-deep) 60%, transparent);
}
.ma-fn-seg {
  display: block;
  height: 100%;
  transition: filter 120ms ease;
}
.ma-fn-seg:hover { filter: brightness(1.15); }
.ma-fn-seg-completed { background: var(--green); }
.ma-fn-seg-accepted  { background: var(--green-soft); }
.ma-fn-seg-offered   { background: var(--amber); }
.ma-fn-seg-abandoned { background: color-mix(in srgb, var(--text-muted) 70%, transparent); }
.ma-fn-foot {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Refresh action ────────────────────────────────────────────── */
.ma-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.ma-refresh-btn {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--amber) 32%, transparent);
  border-radius: 999px;
  color: var(--amber);
  font: 500 0.85rem/1 'General Sans', system-ui, sans-serif;
  padding: 0 14px;
  min-height: 44px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.ma-refresh-btn:hover {
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  border-color: color-mix(in srgb, var(--amber) 55%, transparent);
}
.ma-refresh-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ── Motion preferences ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ma-stat-card,
  .ma-bar,
  .ma-fn-seg,
  .ma-window-btn,
  .ma-refresh-btn {
    transition: none !important;
  }
}
