@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ===== FONTS & VARIABLES ===== */
:root {
  --bg-color: #0d1117;          /* Github Darkish bg */
  --surface-color: #161b22;     /* Cards bg */
  --surface-color-hover: #1f242e; /* Card hover */
  --border: #30363d;            /* Subtle borders */
  
  --text-primary: #e6edf3;
  --text-muted: #7d8590;
  
  --accent: #B30410;            /* Rojo Ludosport */
  --accent-light: rgba(179, 4, 16, 0.15);
  
  --win-bg: rgba(46, 160, 67, 0.15);
  --win-text: #3fb950;
  
  --lose-bg: rgba(248, 81, 73, 0.15);
  --lose-text: #f85149;
}

html, body {
  height: auto;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding-bottom: 60px;
}

/* ===== ENCABEZADO & NAVEGACIÓN ===== */
.header { margin-bottom: 0.5rem; text-align: center; margin-top: 20px; }
.logo-academia { max-width: 180px; margin: 0 auto 10px auto; display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }
h1 { font-size: 1.8rem; margin: 5px 0 15px 0; text-align: center; color: #fff; font-weight: 600; letter-spacing: -0.02em; }
h2, h3 { text-align: center; margin-bottom: 1rem; font-weight: 500; color: #fff; letter-spacing: -0.01em; }

/* Contenedores de Vistas Principales */
.main-view { width: 100%; display: flex; flex-direction: column; align-items: center; padding: 0 1rem; box-sizing: border-box; }
.hidden-view { display: none !important; }

/* Botones Navegación Principal */
.top-nav { display: flex; gap: 12px; justify-content: center; margin-bottom: 30px; }
.nav-btn {
  cursor: pointer;
  padding: 0.7rem 1.5rem;
  border-radius: 9999px; /* Pill shape */
  background: var(--surface-color);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.nav-btn:hover { background: var(--surface-color-hover); transform: translateY(-1px); }
.nav-btn.active-nav { background: var(--accent); color: white; border-color: transparent; box-shadow: 0 4px 12px rgba(179, 4, 16, 0.4); }

/* ===== ELEMENTOS COMUNES ===== */
select, button, input[type="file"] {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: #fff;
  background: var(--surface-color);
  transition: all 0.2s ease;
  outline: none;
}
input[type="file"] { padding: 5px 10px; }
select:focus, button:focus, input[type="file"]:focus { border-color: var(--accent); }
button { cursor: pointer; }
button:hover { background-color: var(--surface-color-hover); }

/* Grids & Tarjetas */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--surface-color);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  color: var(--text-primary);
  box-sizing: border-box;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.1); }

.title-sm { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

/* Dashboard Layout Base */
.dashboard-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* Tablas Globales */
.tabla-wrapper, .scroll-container {
  width: 100%;
  margin: 0 auto 2rem auto;
  border-radius: 12px;
  background: var(--surface-color);
  border: 1px solid var(--border);
  box-sizing: border-box;
  overflow: hidden; /* So border-radius clips the table */
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}
.scroll-container { overflow-x: auto; padding: 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: transparent;
  color: var(--text-primary);
}
thead th { 
  background: rgba(255, 255, 255, 0.02); 
  font-weight: 500; 
  padding: 12px 16px; 
  white-space: nowrap; 
  user-select: none; 
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  text-align: left;
}
th, td { 
  text-align: left; 
  padding: 12px 16px; 
  border-bottom: 1px solid var(--border);
}
/* Center numeric cols */
td:nth-child(n+5), th:nth-child(n+5) { text-align: center; } 

tbody tr { transition: background-color 0.15s ease; }
tbody tr:hover { background-color: rgba(255, 255, 255, 0.04); cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }

/* ========================================================
   APLICACIÓN A: DUELOS
   ======================================================== */
.csv-uploader { display: flex; flex-direction: column; align-items: center; margin-bottom: 2rem; }
.csv-uploader > div { margin-bottom: 1rem; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.5rem; }

.pill { display:inline-block; padding:.25rem .75rem; border-radius:999px; font-size:.75rem; font-weight: 500; }
.pill-win { background:var(--win-bg); color:var(--win-text); }
.pill-lose { background:var(--lose-bg); color:var(--lose-text); }
.diccionario-badge { margin-left:.5rem; font-size:.7rem; background: var(--surface-color); border: 1px solid var(--accent); color: var(--accent); }

#bloque-metricas { display: none; margin-top: 1em; width: 100%; }

/* Rediseño Dashboard de Métricas */
.metrics-dashboard {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 1.5rem;
  margin-bottom: 2rem;
  align-items: stretch;
}

@media (max-width: 900px) {
  .metrics-dashboard { grid-template-columns: 1fr; }
}

.kpi-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { 
  background: var(--surface-color); 
  border: 1px solid var(--border); 
  border-radius: 12px; 
  padding: 1.25rem; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
}
.kpi:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.15); }
.kpi .label { font-size:0.8rem; color:var(--text-muted); font-weight: 500; margin-bottom: 0.5rem; }
.kpi .value { font-size:1.75rem; font-weight:700; color: #fff; line-height: 1; }

.radar-container {
  background: var(--surface-color);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 380px;
  height: 320px;
  margin: 0 auto;
}
.canvas-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Comparador */
#comparador-wrapper { padding: 0; overflow: hidden; margin-top: 2rem; width: 100%; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-color); }
#comparador-wrapper > summary { 
  list-style: none; cursor: pointer; display:flex; align-items:center; gap:.5rem; 
  padding: 1.25rem; font-weight:600; 
  color: #fff;
  transition: background 0.2s;
}
#comparador-wrapper > summary:hover { background: rgba(255,255,255,0.03); }
#comparador-wrapper > summary::-webkit-details-marker { display:none; }
#comparador-wrapper > summary .chev { transition: transform .2s ease; font-size: 1rem; color: var(--text-muted); }
#comparador-wrapper[open] > summary .chev { transform: rotate(90deg); }
#comparador-wrapper > summary .estado::after { content: " (cerrado)"; color: var(--text-muted); font-weight: 400; font-size: 0.85em; }
#comparador-wrapper[open] > summary .estado::after { content: " (abierto)"; }
#comparador-wrapper[open] > summary { border-bottom: 1px solid var(--border); }

#comparador { padding: 1.5rem; }
.compare-controls { display:flex; gap:1rem; align-items:center; flex-wrap: wrap; margin-bottom: 1.5rem; }
#compare-results { margin-top: 1rem; }

/* Tooltip */
.tooltip { position: relative; cursor: help; border-bottom: 1px dotted var(--text-muted); display: inline-block; }
.tooltip-pop {
  position: absolute;
  z-index: 10000;
  background: var(--surface-color-hover);
  color: #fff;
  padding: 1em;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
  display: none;
  font-size: 13px;
  max-width: 250px;
  pointer-events: none;
}

/* ========================================================
   APLICACIÓN B: HISTÓRICO
   ======================================================== */
.upload-tools {
  background: var(--surface-color);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

#pdfSelector { display: block; width: 100%; max-width: 420px; font-size: 1em; padding: .6em 1em; }

/* Sub-Pestañas */
.tabs { display: flex; gap: .8rem; justify-content: center; margin: 2rem 0; position: relative; z-index: 10; flex-wrap: wrap; }
.tab-button { cursor: pointer; padding: .6rem 1.25rem; border-radius: 8px; background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-weight: 500; }
.tab-button:hover { background: rgba(255,255,255,.05); color: #fff; }
.tab-button[aria-selected="true"] { background: var(--accent); color: white; border-color: transparent; box-shadow: 0 4px 12px rgba(179, 4, 16, 0.4); }
.tab-content { display: none; width: 100%; margin: 0 auto; }

/* Top Highlight (Gold, Silver, Bronze on dark theme) */
.fila-alumno.top1, tbody tr.top1 td { background-color: rgba(255, 215, 0, 0.1) !important; color: #ffd700; font-weight: 600; }
.fila-alumno.top2, tbody tr.top2 td { background-color: rgba(192, 192, 192, 0.1) !important; color: #c0c0c0; font-weight: 600; }
.fila-alumno.top3, tbody tr.top3 td { background-color: rgba(205, 127, 50, 0.1) !important; color: #cd7f32; font-weight: 600; }

.th-name { text-align: left; width: 35%; }
.cell-name { text-align: left; white-space: normal; word-break: break-word; overflow-wrap: anywhere; font-weight: 500; }

/* Leyenda */
.leyenda {
  background: var(--surface-color);
  border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 1.5rem;
  margin-top: 1.5rem;
  font-size: 0.9em;
  line-height: 1.6;
  color: var(--text-muted);
}
.leyenda h3 { margin-top: 0; color: #fff; margin-bottom: .8rem; text-align: left;}
.leyenda ul { list-style: disc; margin-left: 1.5em; text-align: left; }
.leyenda code { background: rgba(255,255,255,0.05); padding: 0.2em 0.4em; border-radius: 4px; border: 1px solid var(--border); color: #fff; }
.leyenda p { margin-bottom: 0.8em; text-align: justify; }
.leyenda em { color: #fff; font-style: normal; font-weight: 600; }

/* Gráfico Histórico */
.mt-2 { width: 100%; margin: 2rem auto; overflow: hidden; background: var(--surface-color); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; box-sizing: border-box;}
#graficoEstilo {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: 400px !important;
  margin: 0 auto;
}
#exportarGrafico { margin: 15px auto 0 auto; display: block; background: var(--surface-color); color: #fff; border: 1px solid var(--border); }
#exportarGrafico:hover { background: var(--surface-color-hover); border-color: var(--text-muted); }

.order-select { margin: 0 auto 1.5rem auto; width: 220px; max-width: 100%; display: block; }
.full-width { width: 100%; }

@media (max-width: 768px) {
  th, td { font-size: 0.85em; padding: 10px; }
  .th-name { width: 45%; }
  .grid-2 { grid-template-columns: 1fr; }
  .dashboard-container { padding: 0 0.5rem; }
  .card, .kpi, .radar-container, .upload-tools { padding: 1rem; }
  .metrics-dashboard { grid-template-columns: 1fr; }
}
