:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-card: #1a2029;
  --border: #263040;
  --text: #e6edf3;
  --text-dim: #8b98a8;
  --accent: #3fb950;
  --accent-2: #58a6ff;
  --hi: #3fb950;
  --mid: #d29922;
  --lo: #f85149;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16202e 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.wrap { width: min(1080px, 92vw); margin: 0 auto; }

/* Topbar */
.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar .wrap {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 34px; }
.brand h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.sub { color: var(--text-dim); font-size: 13px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.pill-ghost { background: transparent; }

/* Tabs */
.tabs { display: flex; gap: 8px; margin: 26px 0 20px; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--text-dim); background: var(--bg-soft);
  border: 1px solid var(--border); padding: 9px 18px; border-radius: 999px;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); border-color: #3a4757; }
.tab.active { color: #06210d; background: var(--accent); border-color: var(--accent); }

/* Grid de cards */
.grid { display: grid; gap: 14px; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); display: grid;
  grid-template-columns: 40px 136px 1fr auto; gap: 18px; align-items: center;
}

.thumb {
  width: 136px; height: 100px; border-radius: 10px; overflow: hidden;
  background: var(--bg-soft); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-empty { font-size: 26px; opacity: 0.5; }
.rank-n {
  font-size: 26px; font-weight: 800; color: var(--text-dim);
  text-align: center; font-variant-numeric: tabular-nums;
}
.card:first-child .rank-n { color: var(--accent); }
/* Recomendada por calidad (⭐) */
.card.reco { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.star { font-size: 15px; }

.card-main { min-width: 0; }
.card-name { font-size: 17px; font-weight: 600; margin-bottom: 10px; }

.specs { display: flex; flex-wrap: wrap; gap: 7px; }
.spec {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 4px 9px; border-radius: 8px;
}
.spec b { color: var(--text); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.score { text-align: right; }
.score-n { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.bar { height: 6px; width: 90px; background: var(--bg-soft); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.price { font-size: 14px; font-weight: 700; color: var(--text); margin-top: 8px; }
.valor { font-size: 11px; color: var(--accent-2); margin-top: 2px; white-space: nowrap; }

/* Barra de orden (Puntaje / Calidad-precio) */
.orden-bar { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; flex-wrap: wrap; }
.orden-lbl { font-size: 13px; color: var(--text-dim); }
.orden-btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--text-dim); background: var(--bg-soft); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 999px; transition: all 0.15s ease;
}
.orden-btn:hover { color: var(--text); border-color: #3a4757; }
.orden-btn.active { color: #06210d; background: var(--accent); border-color: var(--accent); }

/* Paneles */
.panel {
  margin-top: 26px; padding: 20px; border-radius: var(--radius);
  background: var(--bg-soft); border: 1px solid var(--border);
}
.panel h2 { font-size: 16px; margin-bottom: 4px; }
.panel-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.panel.warn { border-color: #5c4415; background: #241d0e; }
.panel.warn h2 { color: var(--mid); }
.panel ul { list-style: none; display: grid; gap: 6px; }
.panel li { font-size: 13px; color: var(--text-dim); }
.excl li b { color: var(--text); }

.foot { color: var(--text-dim); font-size: 12px; padding: 30px 0; text-align: center; }
.hidden { display: none; }

/* Selector de disciplina (MTB / Ruta) */
.disc-selector {
  display: inline-flex; gap: 4px; margin: 24px 0 6px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px;
}
.disc-btn {
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  color: var(--text-dim); background: transparent; border: none;
  border-radius: 999px; padding: 8px 22px; transition: all 0.15s ease;
}
.disc-btn:hover { color: var(--text); }
.disc-btn.active { color: #06210d; background: var(--accent); }

/* Navegación de vistas (Ranking / Componentes) */
.views { display: flex; gap: 8px; margin: 12px 0 8px; }
.view-btn {
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  color: var(--text-dim); background: transparent; border: none;
  border-bottom: 2px solid transparent; padding: 8px 6px; transition: all 0.15s ease;
}
.view-btn:hover { color: var(--text); }
.view-btn.active { color: var(--text); border-bottom-color: var(--accent); }

/* Vista Comparar (tabla) */
.guia-intro { color: var(--text-dim); font-size: 14px; margin: 14px 0 20px; max-width: 680px; }
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-card);
}
.comp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.comp-table th, .comp-table td {
  padding: 11px 14px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.comp-table thead th {
  color: var(--text-dim); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.03em;
  position: sticky; top: 0; background: var(--bg-soft); z-index: 2;
}
.th-peso { color: var(--accent-2); font-weight: 600; margin-left: 6px; font-size: 11px; }
.comp-table .tname {
  font-weight: 600; text-transform: none;
  position: sticky; left: 0; background: var(--bg-card); z-index: 1;
}
.comp-table .cell { display: inline-flex; align-items: center; gap: 6px; text-transform: capitalize; }
.comp-table .cell b { color: var(--text-dim); font-weight: 700; font-variant-numeric: tabular-nums; }
.comp-table .ttotal { font-weight: 800; font-size: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.comp-table tbody tr:hover td { background: var(--bg-soft); }
.comp-table tbody tr:hover .tname { background: var(--bg-soft); }

/* Guía de Equipamiento (una tabla por tipo) */
.equip-sec { margin-bottom: 24px; }
.equip-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.equip-head h2 { font-size: 18px; font-weight: 700; }
.equip-table td, .equip-table th { text-transform: none; }
.equip-table .tname { text-transform: none; font-weight: 600; }
.equip-table .col-notas { white-space: normal; min-width: 240px; color: var(--text-dim); }
.equip-table .tnivel { text-align: center; }
.equip-table .tnivel .dot { display: inline-block; margin-right: 6px; vertical-align: middle; }
.equip-table .tnivel b { font-variant-numeric: tabular-nums; }

/* Link comprar */
.buy {
  display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 600;
  color: var(--accent-2); text-decoration: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 10px; white-space: nowrap;
}
.buy:hover { border-color: var(--accent-2); background: var(--bg-soft); }

/* Filtro presupuesto */
.presu { display: inline-flex; align-items: center; gap: 4px; }
.presu-input {
  font: inherit; font-size: 13px; width: 130px; background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  color: var(--text); outline: none;
}
.presu-input:focus { border-color: var(--accent-2); }

/* Gráfico calidad-precio (scatter) */
.scatter-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
.scatter { width: 100%; height: auto; min-width: 660px; display: block; }
.scatter .grid { stroke: var(--border); stroke-width: 1; }
.scatter .avg { stroke: var(--text-dim); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .55; }
.scatter .ax { fill: var(--text-dim); font-size: 12px; }
.scatter .ax-r { text-anchor: end; }
.scatter .ax-c { text-anchor: middle; }
.scatter .ax-lbl { fill: var(--text); font-weight: 600; }
.scatter .pt-lbl { fill: var(--text); font-size: 11px; }
.scatter circle { cursor: pointer; }

/* Comparar lado a lado */
.cmp-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.cmp-chip {
  font: inherit; font-size: 13px; cursor: pointer; color: var(--text-dim);
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 13px; transition: all 0.15s ease;
}
.cmp-chip:hover { color: var(--text); border-color: #3a4757; }
.cmp-chip.on { color: #06210d; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.cmp-table td { white-space: normal; }
.cmp-table .buy { margin-top: 0; }

/* Gráfico ECharts */
.chart-box { width: 100%; height: 560px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }

/* Estado de carga */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 0; color: var(--text-dim); font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Transición al cambiar de vista */
#vista-ranking, #vista-grafico, #vista-comparar, #vista-componentes, #vista-accesorios { animation: fadeup 0.28s ease; }
@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Hover en las cards del ranking */
.card { transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; }
.card:hover { transform: translateY(-2px); border-color: #33404f; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); }

/* Responsive / móvil */
@media (max-width: 640px) {
  .chart-box { height: 440px; }
  .views { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .view-btn { white-space: nowrap; flex: none; }
  .orden-bar { gap: 6px; }
  .presu-input { width: 110px; }
  .wrap { width: 94vw; }
  /* El pill de pesos ya no fuerza scroll horizontal: dejalo envolver */
  .meta { max-width: 100%; }
  .pill-ghost { white-space: normal; }
  .topbar .wrap { row-gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 560px) {
  .card { grid-template-columns: 30px 108px 1fr; gap: 12px; }
  .thumb { width: 108px; height: 82px; }
  /* El puntaje/precio/comprar pasan a una fila completa abajo, en línea */
  .score {
    grid-column: 1 / -1; text-align: left; margin-top: 10px; padding-top: 10px;
    border-top: 1px solid var(--border); display: flex; align-items: center;
    gap: 12px; flex-wrap: wrap;
  }
  .score .bar { display: none; }
  .score .score-label { display: none; }
  .buy { margin-top: 0; margin-left: auto; }
}

/* Lightbox (ampliar foto de la bici) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(1, 4, 9, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: lbfade 0.15s ease;
}
.lightbox.open { display: flex; }
@keyframes lbfade { from { opacity: 0; } to { opacity: 1; } }

.lb-fig {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 92vw;
  max-height: 92vh;
}
.lb-fig img {
  max-width: 92vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.lb-fig figcaption {
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}
.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lb-close:hover { background: var(--bg-card); }

@media (prefers-reduced-motion: reduce) {
  .lightbox { animation: none; }
}
