<template>
  <!-- Loading state as a single card -->
  <div v-if="loading" class="card glass">
    <div class="card-header">
      <h2 class="card-title">Eventos y comparación</h2>
    </div>
    <div class="placeholder">Cargando datos…</div>
  </div>

  <!-- Count/percent view in a single card -->
  <div v-else-if="viewMode !== 'ratio'" class="card glass">
    <div class="card-header">
      <h2 class="card-title">Eventos y comparación</h2>
      <div v-if="filtersCollapsed && (activeFilters?.hasFilters || selectedPlayerUuid)" class="active-filters-summary">
        <span class="filter-tag" v-if="activeFilters?.dataSource !== 'aggregated'">
          {{ activeFilters?.dataSource === 'active-rooms' ? '🔴 Tiempo Real' : '📁 Agregado' }}
        </span>
        <span class="filter-tag" v-if="activeFilters?.round !== 'all'">
          Ronda {{ activeFilters?.round }}
        </span>
        <span class="filter-tag" v-if="activeFilters?.game !== 'all'">
          {{ activeFilters?.game }}
        </span>
        <span class="filter-tag player-tag" v-if="selectedPlayerUuid && activeFilters?.selectedPlayer">
          👤 {{ activeFilters.selectedPlayer }}
        </span>
        <span class="filter-tag room-tag" v-if="activeFilters?.selectedRoom">
          🏠 {{ activeFilters.selectedRoom }}
        </span>
      </div>
    </div>
    <div class="bars big">
      <div 
        v-for="eventType in eventTypes" 
        :key="eventType" 
        class="bar-row" 
        :class="{ highlight: highlighted === eventType }" 
        @mouseenter="highlighted = eventType" 
        @mouseleave="highlighted = ''"
      >
        <div class="bar">
          <div 
            class="bar-fill global shimmer" 
            :style="{ 
              width: globalBarWidth(eventType) + '%', 
              background: EVENT_STYLES[eventType]?.gradient || 'linear-gradient(90deg, #94a3b8, #64748b)' 
            }"
          ></div>
          <div 
            v-if="selectedPlayerUuid" 
            class="bar-fill player" 
            :style="{ 
              width: playerBarWidth(eventType) + '%', 
              background: playerBarGradient 
            }"
          ></div>
          <div 
            class="bar-chip" 
            :style="{ 
              background: getEventChipBg(eventType), 
              borderColor: getEventBorderColor(eventType) 
            }"
          >
            <span class="event-icon">{{ EVENT_STYLES[eventType]?.icon || '📊' }}</span>
            <span class="chip-label">{{ friendlyEventName(eventType) }}</span>
            <span class="chip-count global">{{ globalValueLabel(eventType) }}</span>
            <span v-if="selectedPlayerUuid" class="chip-count player">{{ playerValueLabel(eventType) }}</span>
          </div>
        </div>
      </div>
      <div class="hint small">Basado en mensajes disponibles por sala. Haz clic en un jugador para comparar.</div>
    </div>
  </div>

  <!-- Ratio view: one card per group -->
  <div v-else class="ratio-cards">
    <div 
      v-for="group in ratioData" 
      :key="group.name"
      v-show="group.total > 0"
      class="card glass ratio-card"
      :class="{ highlight: highlighted === group.name }"
      @mouseenter="highlighted = group.name" 
      @mouseleave="highlighted = ''"
    >
      <div class="card-header">
        <h3 class="card-title">{{ group.name }}</h3>
        <span class="group-total">{{ group.total }}</span>
      </div>
      <div class="ratio-bar">
        <div 
          v-for="(action, actionIndex) in group.actions" 
          :key="action"
          class="ratio-segment"
          :style="{
            width: group.percentages[actionIndex] + '%',
            background: EVENT_STYLES[action]?.gradient || 'linear-gradient(90deg, #94a3b8, #64748b)'
          }"
        >
          <div 
            class="ratio-event-chip"
            v-if="group.percentages[actionIndex] > 5"
            :style="{
              background: getEventChipBg(action),
              borderColor: getEventBorderColor(action)
            }"
          >
            <span class="ratio-icon">{{ EVENT_STYLES[action]?.icon || '📊' }}</span>
            <span class="ratio-label">{{ group.labels[actionIndex] }}</span>
            <span class="ratio-count">{{ group.values[actionIndex] }} ({{ Math.round(group.percentages[actionIndex]) }}%)</span>
          </div>
        </div>
      </div>
    </div>
    <div class="hint small">
      {{ selectedPlayerUuid ? 'Proporciones del jugador seleccionado' : 'Proporciones globales' }}. 
      Los segmentos muestran la proporción relativa dentro de cada categoría.
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';

interface Props {
  filteredData?: {
    events: any[];
    players: any[];
    metrics: Record<string, number>;
    aggregatedCounts: Record<string, number>;
    sourceData: string;
  };
  selectedPlayerUuid?: string;
  viewMode: 'count' | 'percent' | 'ratio';
  loading?: boolean;
  filtersCollapsed?: boolean;
  activeFilters?: {
    dataSource: string;
    round: string;
    game: string;
    hasFilters: boolean;
    selectedPlayer?: string;
    selectedRoom?: string;
  };
}

const props = withDefaults(defineProps<Props>(), {
  selectedPlayerUuid: '',
  loading: false
});

// Event types and styles
const EVENTS = [
  'p1_propose', 'p1_no_offer',
  'p2_snatch', 'p2_accept', 'p2_force', 'p2_no_force', 'p2_reject',
  'p1_shame', 'p1_no_shame', 'p1_report', 'p1_no_report'
];

const METRICS = [
  'players_seated', 'score_p1', 'score_p2', 'players_with_shame', 'players_without_shame'
];

const ALL_CHART_TYPES = [...EVENTS, ...METRICS];

const EVENT_STYLES: Record<string, { icon: string; color: string; gradient: string }> = {
  'p1_propose': { icon: '✨', color: '#667eea', gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' },
  'p1_no_offer': { icon: '❌', color: '#6b7280', gradient: 'linear-gradient(135deg, #94a3b8 0%, #64748b 100%)' },
  'p2_accept': { icon: '✓', color: '#10b981', gradient: 'linear-gradient(135deg, #10b981 0%, #059669 100%)' },
  'p2_reject': { icon: '✕', color: '#f59e0b', gradient: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)' },
  'p2_snatch': { icon: '👹', color: '#ef4444', gradient: 'linear-gradient(135deg, #ef4444 0%, #dc2626 100%)' },
  'p2_force': { icon: '⚡', color: '#667eea', gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' },
  'p2_no_force': { icon: '🚫', color: '#6b7280', gradient: 'linear-gradient(135deg, #94a3b8 0%, #64748b 100%)' },
  'p1_shame': { icon: '😶', color: '#fbbf24', gradient: 'linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%)' },
  'p1_no_shame': { icon: '🙂', color: '#6b7280', gradient: 'linear-gradient(135deg, #94a3b8 0%, #64748b 100%)' },
  'p1_report': { icon: '⚖️', color: '#8b5cf6', gradient: 'linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)' },
  'p1_no_report': { icon: '🤝', color: '#6b7280', gradient: 'linear-gradient(135deg, #94a3b8 0%, #64748b 100%)' },
  'players_seated': { icon: '👥', color: '#06b6d4', gradient: 'linear-gradient(135deg, #06b6d4 0%, #0891b2 100%)' },
  'score_p1': { icon: '🦃', color: '#16a34a', gradient: 'linear-gradient(135deg, #16a34a 0%, #15803d 100%)' },
  'score_p2': { icon: '🌽', color: '#d97706', gradient: 'linear-gradient(135deg, #d97706 0%, #b45309 100%)' },
  'players_with_shame': { icon: '😶', color: '#dc2626', gradient: 'linear-gradient(135deg, #dc2626 0%, #b91c1c 100%)' },
  'players_without_shame': { icon: '👥', color: '#06b6d4', gradient: 'linear-gradient(135deg, #06b6d4 0%, #0891b2 100%)' }
};

const highlighted = ref('');

// Main data computations
const eventTypes = computed(() => ALL_CHART_TYPES);

const globalEventCounts = computed(() => {
  if (!props.filteredData) return {};
  return {
    ...props.filteredData.aggregatedCounts,
    ...props.filteredData.metrics
  };
});

const playerEventCounts = computed(() => {
  if (!props.selectedPlayerUuid || !props.filteredData) return {};
  
  // Calculate player-specific counts from filtered events
  const playerCounts: Record<string, number> = {};
  EVENTS.forEach(eventType => {
    playerCounts[eventType] = props.filteredData!.events.filter(
      (e: any) => e.kind === eventType && e.playerUuid === props.selectedPlayerUuid
    ).length;
  });
  
  // Calculate player-specific metrics
  const selectedPlayer = props.filteredData.players.find((p: any) => p.uuid === props.selectedPlayerUuid);
  if (selectedPlayer) {
    let totalP1Scores = 0;
    let totalP2Scores = 0;
    let p1Count = 0;
    let p2Count = 0;
    let playersWithShame = selectedPlayer.shameTokens > 0 ? 1 : 0;
    
    if (selectedPlayer.roomScoreHistory) {
      selectedPlayer.roomScoreHistory.forEach((roomScore: any) => {
        roomScore.scores.forEach((score: any) => {
          if (score.role === 'P1') {
            totalP1Scores += score.score;
            p1Count++;
          } else if (score.role === 'P2') {
            totalP2Scores += score.score;
            p2Count++;
          }
        });
      });
    }
    
    playerCounts.players_seated = 1;
    playerCounts.score_p1 = p1Count > 0 ? Math.round((totalP1Scores / p1Count) * 10) / 10 : 0;
    playerCounts.score_p2 = p2Count > 0 ? Math.round((totalP2Scores / p2Count) * 10) / 10 : 0;
    playerCounts.players_with_shame = playersWithShame;
    playerCounts.players_without_shame = 1 - playersWithShame;
  }
  
  return playerCounts;
});

const playerBarGradient = computed(() => '#8b5cf6');

// Group totals computation
const groupTotals = computed(() => {
  const counts = globalEventCounts.value;
  return {
    offers: (counts.p1_propose || 0) + (counts.p1_no_offer || 0),
    responses: (counts.p2_accept || 0) + (counts.p2_reject || 0) + (counts.p2_snatch || 0),
    force: (counts.p2_force || 0) + (counts.p2_no_force || 0),
    shame: (counts.p1_shame || 0) + (counts.p1_no_shame || 0),
    report: (counts.p1_report || 0) + (counts.p1_no_report || 0),
    averageScore: calculateAverageScore(),
    totalPlayers: counts.players_seated || 0
  };
});

function calculateAverageScore(): number {
  if (!props.filteredData?.players.length) return 0;
  
  let totalScores = 0;
  let totalScoreCount = 0;
  
  props.filteredData.players.forEach((player: any) => {
    if (player.roomScoreHistory) {
      player.roomScoreHistory.forEach((roomScore: any) => {
        roomScore.scores.forEach((score: any) => {
          totalScores += score.score;
          totalScoreCount++;
        });
      });
    }
  });
  
  return totalScoreCount > 0 ? Math.round((totalScores / totalScoreCount) * 10) / 10 : 0;
}

// Define ratio groups for superposed view
const ratioGroups = computed(() => [
  {
    name: 'Ofertas',
    actions: ['p1_propose', 'p1_no_offer'],
    labels: ['Ofrecer', 'No Ofrecer'],
    total: groupTotals.value.offers
  },
  {
    name: 'Respuestas',
    actions: ['p2_accept', 'p2_reject', 'p2_snatch'],
    labels: ['Aceptar', 'Rechazar', 'Robar'],
    total: groupTotals.value.responses
  },
  {
    name: 'Forzar',
    actions: ['p2_force', 'p2_no_force'],
    labels: ['Forzar', 'No Forzar'],
    total: groupTotals.value.force
  },
  {
    name: 'Avergonzar',
    actions: ['p1_shame', 'p1_no_shame'],
    labels: ['Asignar', 'No Asignar'],
    total: groupTotals.value.shame
  },
  {
    name: 'Denunciar',
    actions: ['p1_report', 'p1_no_report'],
    labels: ['Denunciar', 'No Denunciar'],
    total: groupTotals.value.report
  },
  {
    name: 'Puntaje Promedio',
    actions: ['score_p1', 'score_p2'],
    labels: ['P1', 'P2'],
    total: groupTotals.value.averageScore.toFixed(1)
  },
  {
    name: 'Total Jugadores',
    actions: ['players_with_shame', 'players_without_shame'],
    labels: ['Con vergüenza', 'Sin vergüenza'],
    total: groupTotals.value.totalPlayers,
    isCustomRatio: true // Special handling needed
  }
]);

// Compute ratio data for each group
const ratioData = computed(() => {
  return ratioGroups.value.map(group => {
    const counts = props.selectedPlayerUuid 
      ? playerEventCounts.value 
      : globalEventCounts.value;
    
    let values = group.actions.map(action => counts[action] || 0);
    
    // Special handling for players ratio (shame vs no shame)
    if (group.isCustomRatio && group.name === 'Total Jugadores') {
      const playersWithShame = counts['players_with_shame'] || 0;
      const playersWithoutShame = counts['players_without_shame'] || 0;
      values = [playersWithShame, playersWithoutShame];
    }
    
    const total = values.reduce((sum, val) => sum + val, 0);
    
    return {
      ...group,
      values,
      total,
      percentages: total > 0 ? values.map(val => (val / total) * 100) : values.map(() => 0)
    };
  });
});

// Global calculations
const globalMax = computed(() => {
  const vals = eventTypes.value.map(k => globalEventCounts.value[k] || 0);
  const m = Math.max(0, ...vals);
  return m || 1;
});

const globalTotal = computed(() => 
  eventTypes.value.reduce((acc, k) => acc + (globalEventCounts.value[k] || 0), 0) || 1
);

function globalBarWidth(eventType: string) {
  const v = globalEventCounts.value[eventType] || 0;
  return Math.round((v / (props.viewMode === 'percent' ? globalTotal.value : globalMax.value)) * 100);
}

function globalValueLabel(eventType: string) {
  const v = globalEventCounts.value[eventType] || 0;
  return props.viewMode === 'percent' ? `${Math.round((v / globalTotal.value) * 100)}%` : String(v);
}

// Player calculations
const playerMax = computed(() => {
  const vals = eventTypes.value.map(k => playerEventCounts.value[k] || 0);
  const m = Math.max(0, ...vals);
  return m || 1;
});

const playerTotal = computed(() => 
  eventTypes.value.reduce((acc, k) => acc + (playerEventCounts.value[k] || 0), 0) || 1
);

function playerBarWidth(eventType: string) {
  const v = playerEventCounts.value[eventType] || 0;
  return Math.round((v / (props.viewMode === 'percent' ? playerTotal.value : playerMax.value)) * 100);
}

function playerValueLabel(eventType: string) {
  const v = playerEventCounts.value[eventType] || 0;
  return props.viewMode === 'percent' ? `${Math.round((v / playerTotal.value) * 100)}%` : String(v);
}

// Styling helpers
function getEventChipBg(eventType: string): string {
  const style = EVENT_STYLES[eventType];
  if (!style) return 'rgba(255,255,255,0.82)';
  return `linear-gradient(135deg, ${style.color}15 0%, rgba(255,255,255,0.9) 100%)`;
}

function getEventBorderColor(eventType: string): string {
  const style = EVENT_STYLES[eventType];
  if (!style) return 'rgba(229,231,235,0.9)';
  return `${style.color}40`;
}

function friendlyEventName(eventType: string): string {
  const friendlyNames: Record<string, string> = {
    p1_propose: 'Ofrecer',
    p1_no_offer: 'No Ofrecer',
    p2_snatch: 'Robar',
    p2_accept: 'Aceptar Oferta',
    p2_force: 'Forzar Oferta',
    p2_no_force: 'No Forzar Oferta',
    p2_reject: 'Rechazar Oferta',
    p1_shame: 'Asignar Vergüenza',
    p1_no_shame: 'No Asignar Vergüenza',
    p1_report: 'Denunciar',
    p1_no_report: 'No Denunciar',
  };
  return friendlyNames[eventType] || eventType;
}
</script>

<style scoped>
.card { 
  padding: 14px 16px; 
  display: flex; 
  flex-direction: column; 
  flex: 1 1 auto; 
  min-height: 0; 
}

.glass { 
  background: rgba(255, 255, 255, 0.92); 
  border: 1px solid rgba(229, 231, 235, 0.95); 
  box-shadow: 0 18px 50px rgba(0,0,0,0.12), inset 0 1px 0 rgba(255,255,255,0.75); 
  backdrop-filter: blur(18px) saturate(120%); 
  -webkit-backdrop-filter: blur(18px) saturate(120%); 
  border-radius: 16px; 
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-title { 
  margin: 0; 
  color: #334155; 
}

.ratio-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.active-filters-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-tag {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(102,126,234,0.25);
  white-space: nowrap;
}

.filter-tag.player-tag {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 2px 6px rgba(16,185,129,0.25);
}

.placeholder { 
  color: #64748b; 
  padding: 12px; 
  border: 1px dashed #e5e9f0; 
  border-radius: 10px; 
  background: #fff; 
}

.bars { 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  flex: 1 1 auto; 
  min-height: 0; 
}

.bars.big { 
  height: 100%; 
}

.bars.big .bar-row { 
  flex: 1 1 0; 
  min-height: 36px; 
}

.bar-row { 
  display: flex; 
  align-items: stretch; 
  padding: 0; 
  background: transparent; 
  transition: transform .18s ease; 
}

.bar-row.highlight { 
  transform: translateX(4px); 
}

.bar { 
  position: relative; 
  height: 100%; 
  background: linear-gradient(135deg, rgba(238,242,255,0.4) 0%, rgba(199,210,254,0.2) 100%); 
  border-radius: 12px; 
  overflow: hidden; 
  border: 1px solid rgba(199,210,254,0.3); 
  width: 100%; 
}

.bar-fill { 
  position: absolute; 
  left: 0; 
  top: 0; 
  height: 100%; 
  transform-origin: left center; 
  transition: width .65s cubic-bezier(.2,.7,.1,1); 
  border-radius: 12px; 
}

.bar-fill.global { 
  backdrop-filter: blur(4px); 
  opacity: 0.75; 
}

.bar-fill.player { 
  mix-blend-mode: normal; 
  opacity: 0.85; 
  backdrop-filter: blur(4px); 
}

.bar-chip { 
  position: absolute; 
  left: 50%; 
  top: 50%; 
  transform: translate(-50%, -50%); 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  padding: 5px 10px; 
  border-radius: 999px; 
  border: 1px solid; 
  box-shadow: 0 4px 12px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.4); 
  backdrop-filter: blur(8px) saturate(120%); 
  -webkit-backdrop-filter: blur(8px) saturate(120%); 
  transition: all 0.3s ease;
  min-width: 160px;
}

.bar-row:hover .bar-chip { 
  transform: translate(-50%, -50%) scale(1.05); 
  box-shadow: 0 6px 16px rgba(0,0,0,0.12), inset 0 1px 0 rgba(255,255,255,0.6); 
}

.event-icon { 
  font-size: 16px; 
}

.chip-label { 
  font-weight: 800; 
  color: #0f172a; 
  letter-spacing: .1px; 
  white-space: nowrap; 
  font-size: 14px; 
  flex: 1;
  text-align: center;
}

.chip-count { 
  padding: 3px 8px; 
  border-radius: 999px; 
  font-weight: 800; 
  font-size: 12px; 
  box-shadow: 0 1px 3px rgba(0,0,0,0.06); 
  margin-left: 4px; 
}

.chip-count.global { 
  background: rgba(255,255,255,0.7); 
  color: #1f2937; 
  border: 1px solid rgba(229,231,235,0.5); 
}

.chip-count.player { 
  background: rgba(99,102,241,0.15); 
  color: #312e81; 
  border: 1px solid rgba(99,102,241,0.3); 
}

/* Shimmer on global bars for subtle movement */
.shimmer::after { 
  content: ''; 
  position: absolute; 
  inset: 0; 
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.25) 50%, transparent 70%); 
  transform: translateX(-100%); 
  animation: shimmer 3.2s ease-in-out infinite; 
}

@keyframes shimmer { 
  0% { transform: translateX(-100%); } 
  45% { transform: translateX(110%); } 
  100% { transform: translateX(110%); } 
}

.hint.small { 
  font-size: 12px; 
  color: #64748b; 
}

/* Ratio bars styles */
.ratio-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.ratio-group {
  flex: 0 0 auto;
  min-height: 120px;
  margin-bottom: 8px;
  transition: transform .18s ease;
}

.ratio-group.highlight {
  transform: translateX(4px);
}

/* Group header styles */
.ratio-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(229, 231, 235, 0.4);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.group-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: -0.025em;
}

.group-total {
  font-size: 16px;
  font-weight: 900;
  color: #667eea;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(102, 126, 234, 0.08) 100%);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(102, 126, 234, 0.25);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
  min-width: 48px;
  text-align: center;
}

/* Place the group total just next to the title */
.ratio-card .card-header {
  justify-content: flex-start;
  gap: 8px;
}
.ratio-card .group-total {
  margin-left: 6px;
}

.ratio-bar {
  position: relative;
  height: 60px;
  background: linear-gradient(135deg, rgba(238,242,255,0.4) 0%, rgba(199,210,254,0.2) 100%);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(199,210,254,0.3);
  width: 100%;
  display: flex;
}

.ratio-segment {
  height: 100%;
  transition: all 0.6s cubic-bezier(.2,.7,.1,1);
  backdrop-filter: blur(4px);
  opacity: 0.8;
}

.ratio-segment:first-child {
  border-top-left-radius: 12px;
  border-bottom-left-radius: 12px;
}

.ratio-segment:last-child {
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
}

.ratio-event-chip {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.4);
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  transition: all 0.3s ease;
  white-space: nowrap;
  max-width: 95%;
}

.ratio-segment:hover .ratio-event-chip {
  transform: translate(-50%, -50%) scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12), inset 0 1px 0 rgba(255,255,255,0.6);
}

.ratio-icon {
  font-size: 14px;
}

.ratio-label {
  color: #0f172a;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .1px;
}

.ratio-count {
  color: #1f2937;
  font-weight: 800;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(229,231,235,0.5);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 11px;
  margin-left: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Responsive chip sizing */
@media (min-width: 1200px) {
  .bar-chip {
    min-width: 200px;
    padding: 6px 12px;
    gap: 8px;
  }
  
  .event-icon {
    font-size: 16px;
  }
  
  .chip-label {
    font-size: 14px;
  }
  
  .chip-count {
    padding: 3px 8px;
    font-size: 12px;
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .bar-chip {
    min-width: 140px;
    padding: 5px 10px;
    gap: 6px;
  }
  
  .event-icon {
    font-size: 14px;
  }
  
  .chip-label {
    font-size: 12px;
  }
  
  .chip-count {
    padding: 2px 6px;
    font-size: 10px;
  }
}

@media (max-width: 767px) {
  .card { padding: 10px 12px; }
  .card-header { margin-bottom: 8px; }
  .card-title { font-size: 16px; }
  .bars.big .bar-row { min-height: 28px; }
  .ratio-group { min-height: 90px; }
  .ratio-bar { height: 42px; }
  .bar-chip {
    min-width: 120px;
    padding: 4px 8px;
    gap: 4px;
  }
  
  .event-icon {
    font-size: 12px;
  }
  
  .chip-label {
    font-size: 11px;
  }
  
  .chip-count {
    padding: 2px 4px;
    font-size: 9px;
    margin-left: 2px;
  }
}

@media (max-width: 480px) {
  .ratio-cards {
    gap: 8px;
  }
  .card {
    padding: 8px 10px;
  }

  .card-header {
    margin-bottom: 6px;
  }
  
  .card-title {
    font-size: 14px;
  }
  .bars.big .bar-row { min-height: 24px; }

  .group-total {
    font-size: 12px;
    padding: 3px 8px;
    min-width: 40px;
  }

  .ratio-bar {
    height: 34px;
  }

  .ratio-group {
    min-height: 74px;
  }

  .ratio-group-header {
    margin-top: 6px;
    margin-bottom: 6px;
    padding: 6px 8px;
  }

  .bar-chip {
    min-width: 100px;
    padding: 3px 6px;
    gap: 3px;
  }
  
  .event-icon {
    font-size: 11px;
  }
  
  .chip-label {
    font-size: 10px;
  }
  
  .chip-count {
    padding: 1px 3px;
    font-size: 8px;
    margin-left: 1px;
  }

  /* Ratio responsive styles */
  .ratio-event-chip {
    padding: 3px 6px;
    gap: 3px;
  }
  
  .ratio-icon {
    font-size: 11px;
  }
  
  .ratio-label {
    font-size: 10px;
  }
  
  .ratio-count {
    font-size: 8px;
    padding: 1px 3px;
  }

  .filter-tag {
    font-size: 10px;
    padding: 3px 6px;
  }

  .hint.small {
    display: none;
  }
}

@media (max-width: 767px) {
  .ratio-event-chip {
    padding: 3px 7px;
    gap: 4px;
  }
  
  .ratio-icon {
    font-size: 12px;
  }
  
  .ratio-label {
    font-size: 11px;
  }
  
  .ratio-count {
    font-size: 9px;
    padding: 1px 4px;
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .ratio-event-chip {
    padding: 4px 8px;
    gap: 5px;
  }
  
  .ratio-icon {
    font-size: 13px;
  }
  
  .ratio-label {
    font-size: 12px;
  }
  
  .ratio-count {
    font-size: 10px;
  }
}

@media (min-width: 1200px) {
  .ratio-event-chip {
    padding: 6px 12px;
    gap: 8px;
  }
  
  .ratio-icon {
    font-size: 16px;
  }
  
  .ratio-label {
    font-size: 14px;
  }
  
  .ratio-count {
    font-size: 12px;
    padding: 3px 8px;
  }
}
</style>
