/**
 * Stats Cards & Match History Styles
 * CSS for the player statistics dashboard and match history components
 */

/* ============================================================================
   STATS GRID LAYOUT
   ============================================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
}

/* ============================================================================
   STAT CARDS
   ============================================================================ */

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-color: var(--accent);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 50%, transparent 100%);
  opacity: 0.6;
}

.stat-card.primary::before {
  background: linear-gradient(90deg, var(--accent) 0%, #22d3ee 100%);
}

.stat-card.success::before {
  background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
}

.stat-card.warning::before {
  background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%);
}

.stat-card.danger::before {
  background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  min-width: 0;
}

.stat-card-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 8px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-card.primary .stat-card-icon {
  background: rgba(34, 211, 238, 0.1);
}

.stat-card.success .stat-card-icon {
  background: rgba(16, 185, 129, 0.1);
}

.stat-card.warning .stat-card-icon {
  background: rgba(245, 158, 11, 0.1);
}

.stat-card.danger .stat-card-icon {
  background: rgba(239, 68, 68, 0.1);
}

.stat-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.15;
  min-width: 0;
  overflow-wrap: normal;
  word-break: normal;
}

.stat-card-value {
  font-size: clamp(1.55rem, 2.2vw, 1.9rem);
  font-weight: 700;
  color: var(--text);
  line-height: 1.05;
  margin-bottom: 0.25rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.stat-card--wide-value .stat-card-value {
  font-size: clamp(1.35rem, 2vw, 1.7rem);
}

.stat-card-change {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.stat-card-change.positive {
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.stat-card-change.negative {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.stat-card-change.neutral {
  color: var(--text-muted);
  background: var(--bg-elevated);
}

.stat-card-footer {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.25;
}

/* ============================================================================
   STAT SECTIONS
   ============================================================================ */

.stats-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.stats-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.stats-section-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stats-section-action {
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.stats-section-action:hover {
  text-decoration: underline;
}

/* ============================================================================
   STATS ROWS
   ============================================================================ */

.stats-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.stats-row-item {
  flex: 1;
  min-width: 120px;
  text-align: center;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: 12px;
}

.stats-row-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.stats-row-value.accent {
  color: var(--accent);
}

.stats-row-value.success {
  color: #10b981;
}

.stats-row-value.danger {
  color: #ef4444;
}

.stats-row-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ============================================================================
   PERFORMANCE BARS
   ============================================================================ */

.performance-bar {
  margin-bottom: 1rem;
}

.performance-bar-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.performance-bar-label {
  font-weight: 500;
}

.performance-bar-value {
  color: var(--text-muted);
}

.performance-bar-track {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.performance-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.performance-bar-fill.win {
  background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
}

.performance-bar-fill.loss {
  background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}

.performance-bar-fill.neutral {
  background: var(--accent);
}

/* ============================================================================
   FORM INDICATOR
   ============================================================================ */

.form-indicator {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-dot {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.form-dot.win {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

.form-dot.loss {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.form-dot.current {
  box-shadow: 0 0 0 2px var(--accent);
}

.form-string {
  font-family: monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.form-string .win {
  color: #10b981;
}

.form-string .loss {
  color: #ef4444;
}

/* ============================================================================
   STREAK BADGE
   ============================================================================ */

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 100px;
  font-weight: 600;
  font-size: 0.875rem;
}

.streak-badge.winning {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.streak-badge.losing {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.streak-badge.neutral {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.streak-badge-icon {
  font-size: 1rem;
}

/* ============================================================================
   PARTNER CARDS
   ============================================================================ */

.partner-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.partner-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  transition: all 0.2s ease;
}

.partner-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.partner-card-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  border: 2px solid var(--border);
}

.partner-card-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.partner-card-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.partner-card-stats {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.partner-card-winrate {
  margin-top: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.partner-card-winrate.good {
  color: #10b981;
}

.partner-card-winrate.bad {
  color: #ef4444;
}

/* ============================================================================
   OPPONENT LIST
   ============================================================================ */

.opponent-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.opponent-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border-radius: 12px;
  transition: all 0.2s ease;
}

.opponent-item:hover {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.opponent-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.opponent-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.opponent-info {
  flex: 1;
  min-width: 0;
}

.opponent-name {
  font-weight: 600;
  margin-bottom: 0.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opponent-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.opponent-record {
  text-align: right;
}

.opponent-wins {
  font-size: 1.25rem;
  font-weight: 700;
  color: #10b981;
}

.opponent-losses {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ef4444;
}

.opponent-divider {
  color: var(--text-muted);
  margin: 0 0.25rem;
}

/* ============================================================================
   TOURNAMENT PERFORMANCE LIST
   ============================================================================ */

.tournament-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tournament-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
}

.tournament-item.champion {
  border-left-color: #ffd700;
}

.tournament-item.runner-up {
  border-left-color: #c0c0c0;
}

.tournament-item.semifinalist {
  border-left-color: #cd7f32;
}

.tournament-placement {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--bg-card);
  flex-shrink: 0;
}

.tournament-info {
  flex: 1;
  min-width: 0;
}

.tournament-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tournament-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tournament-stats {
  text-align: right;
}

.tournament-record {
  font-weight: 700;
  font-size: 1rem;
}

.tournament-winrate {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================================
   MINI CHART
   ============================================================================ */

.mini-chart {
  height: 60px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding-top: 0.5rem;
}

.mini-chart-bar {
  flex: 1;
  min-height: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.mini-chart-bar:hover {
  opacity: 1;
}

.mini-chart-bar.win {
  background: #10b981;
}

.mini-chart-bar.loss {
  background: #ef4444;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-grid.compact {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .stats-row {
    gap: 0.75rem;
  }
  
  .stats-row-item {
    min-width: calc(50% - 0.375rem);
  }
  
  .partner-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .stat-card-value {
    font-size: clamp(1.45rem, 6vw, 1.8rem);
  }
}

@media (max-width: 480px) {
  .stats-grid.compact {
    grid-template-columns: 1fr;
  }
  
  .stats-row-item {
    min-width: 100%;
  }
  
  .partner-cards {
    grid-template-columns: 1fr;
  }
  
  .form-dot {
    width: 28px;
    height: 28px;
    font-size: 0.625rem;
  }
  
  .opponent-item {
    flex-wrap: wrap;
  }
  
  .opponent-record {
    width: 100%;
    text-align: left;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
  }
}

/* Player/team redesign stat containment */
.stats-dashboard-component,
.stats-grid,
.stats-section,
.stat-card,
.performance-bars,
.tournament-placement-badges {
  min-width: 0;
  max-width: 100%;
}
.stats-grid,
.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
}
.stat-card {
  border-radius: 16px;
  padding: clamp(0.85rem, 2vw, 1rem);
}
.stat-card-header { align-items: flex-start; }
.stat-card-icon { flex: 0 0 34px; width: 34px; height: 34px; }
.stat-card-value {
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
}
.stat-card--wide-value .stat-card-value {
  font-size: clamp(1.25rem, 3.6vw, 1.65rem);
}
.stat-card-footer,
.provisional-indicator,
.tier-badge,
.performance-bar-label,
.performance-bar-value,
.placement-badge__label,
.placement-badge__value {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.stats-section-header {
  gap: 0.75rem;
  flex-wrap: wrap;
}
.stats-section-title { min-width: 0; overflow-wrap: anywhere; }
.stats-section-action,
.stats-section-share {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.45rem 0.75rem;
  text-decoration: none;
  white-space: nowrap;
}
.tournament-placement-badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 0.65rem;
}
.placement-badge {
  min-width: 0;
  overflow: hidden;
}
.performance-bar-header { gap: 0.75rem; }
.partner-card-name,
.opponent-name,
.tournament-name {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}
@media (max-width: 480px) {
  .stats-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { padding: 0.8rem; }
  .stat-card-value { font-size: clamp(1.2rem, 8vw, 1.65rem); }
  .stat-card-icon { width: 30px; height: 30px; flex-basis: 30px; }
  .tournament-placement-badges { grid-template-columns: 1fr; }
}
@media (max-width: 360px) {
  .stats-grid.compact { grid-template-columns: 1fr; }
}

/* Ralph player/team redesign: SVG icon normalization and stricter value containment */
.stat-card-icon {
  color: var(--accent);
  line-height: 0;
}
.stat-card-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}
.stat-card.primary .stat-card-icon { color: var(--accent); }
.stat-card.success .stat-card-icon { color: #34d399; }
.stat-card.warning .stat-card-icon { color: #fbbf24; }
.stat-card.danger .stat-card-icon { color: #f87171; }
.stat-card-label,
.stat-card-value,
.stat-card-footer {
  min-width: 0;
  max-width: 100%;
}
.stat-card-value {
  word-break: normal;
  overflow-wrap: anywhere;
}
@media (max-width: 480px) {
  .stats-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card-value { font-size: clamp(1.15rem, 7vw, 1.55rem); }
}
@media (max-width: 340px) {
  .stats-grid.compact { grid-template-columns: 1fr; }
}
