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

:root {
  --rojo: #b8102a;
  --rojo-oscuro: #8c0c1f;
  --blanco: #ffffff;
  --fondo: #f7f4ef;
  --gris-claro: #f0ece5;
  --gris-borde: #ddd8d0;
  --gris-texto: #6b6258;
  --negro: #1c1713;
  --bajo: #1a7a3f;
  --medio: #b07d10;
  --alto: #c95228;
  --muy-alto: #b81429;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--fondo);
  color: var(--negro);
  font-size: 15px;
  line-height: 1.5;
}

/* HEADER */
header {
  background: #1c1410;
  color: var(--blanco);
  padding: 36px 24px 32px;
  border-bottom: 3px solid var(--rojo);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.header-flag {
  flex-shrink: 0;
  width: 4px;
  height: 72px;
  background: var(--rojo);
  border-radius: 2px;
  margin-top: 6px;
}

h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.subtitulo {
  font-size: 0.84rem;
  opacity: 0.75;
  max-width: 600px;
  line-height: 1.6;
  font-weight: 400;
}

.subtitulo a {
  color: var(--blanco);
  text-decoration: underline;
  opacity: 1;
}

/* MAIN */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* LEYENDA */
.leyenda {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  color: white;
}

.badge-bajo    { background: var(--bajo); }
.badge-medio   { background: var(--medio); }
.badge-alto    { background: var(--alto); }
.badge-muy-alto { background: var(--muy-alto); }

/* PALABRAS */
.palabras-count {
  font-size: 0.72rem;
  color: var(--gris-texto);
  margin-top: 1px;
}

.col-palabras {
  text-align: center;
  font-size: 0.82rem;
  color: var(--gris-texto);
}

.dropdown-palabras {
  font-size: 0.72rem;
  color: var(--gris-texto);
}

/* TABLA HEADER */
.tabla-header {
  display: grid;
  grid-template-columns: 20px 72px 1fr 100px 220px;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gris-texto);
  border-bottom: 2px solid var(--gris-borde);
  margin-bottom: 4px;
}

.col-sort {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gris-texto);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: color 0.15s;
}

.col-sort:hover {
  color: var(--rojo);
}

.col-sort.active {
  color: var(--rojo);
}

.sort-icon {
  font-size: 0.8rem;
  min-width: 10px;
}

/* FILAS */
.fila {
  display: grid;
  grid-template-columns: 20px 72px 1fr 100px 220px;
  gap: 8px;
  align-items: center;
  padding: 14px 20px 14px 12px;
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  margin-bottom: 6px;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.fila:hover {
  box-shadow: 0 3px 12px rgba(28,20,16,0.09);
  border-color: #c9c2b8;
}


.col-partido {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
}

.logo-placeholder {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 4px;
  background: var(--gris-borde);
  color: var(--gris-texto);
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.partido-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.partido-nombre {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.candidato-nombre {
  font-size: 0.78rem;
  color: var(--gris-texto);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.version {
  font-size: 0.7rem;
  color: var(--rojo);
  font-weight: 600;
  margin-top: 1px;
}

.col-pct {
  display: flex;
  align-items: center;
  justify-content: center;
}

.pct-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  color: white;
  white-space: nowrap;
}


/* LINK */
.col-link {
  text-align: right;
  padding-right: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.ver-reporte {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--rojo);
  text-decoration: none;
  border: 1px solid var(--rojo);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  display: inline-block;
}

.ver-reporte:hover {
  background: var(--rojo);
  color: var(--blanco);
}

.ext-arrow {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 1;
}

/* CHEVRON */
.col-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
}

.chevron {
  font-size: 1.1rem;
  color: var(--gris-texto);
  line-height: 1;
  transition: transform 0.2s ease;
  display: inline-block;
  user-select: none;
}

.fila-multi {
  cursor: pointer;
}

.fila-multi:hover .chevron {
  color: var(--rojo);
}

/* DROPDOWN */
.fila-wrapper {
  margin-bottom: 6px;
}

.dropdown {
  background: var(--gris-claro);
  border: 1px solid var(--gris-borde);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dropdown[hidden] {
  display: none;
}

.dropdown-row {
  display: flex;
  flex-direction: column;
}

.dropdown-version {
  font-size: 0.82rem;
  color: var(--negro);
  font-weight: 500;
  flex: 1;
  min-width: 120px;
}

.ver-reporte-sm {
  font-size: 0.75rem;
  padding: 3px 8px;
}

.sin-link {
  font-size: 0.75rem;
  color: var(--gris-texto);
  font-style: italic;
}

.fila[aria-expanded="true"] {
  border-radius: 8px 8px 0 0;
  border-bottom-color: transparent;
  margin-bottom: 0;
}

/* SPARKLINE / GRAFICO */
.grafico {
  background: var(--gris-claro);
  border: 1px solid var(--gris-borde);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 10px 16px 8px;
}

.grafico[hidden] { display: none; }

.grafico-inner {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}

.grafico-inner .sparkline-wrap {
  flex: 1;
  min-width: 0;
}

.grafico-inner-wrap {
  margin-top: 8px;
}

/* BREAKDOWN TABLE */
.breakdown-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  width: 240px;
  margin-left: 24px;
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.breakdown-bar {
  width: 3px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}

.breakdown-pct {
  font-weight: 700;
  font-size: 0.85rem;
  min-width: 38px;
  color: var(--negro);
}

.breakdown-label {
  color: var(--gris-texto);
  font-size: 0.75rem;
}

.grafico-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.sparkline-wrap {
  width: 100%;
  position: relative;
}

.sparkline-info {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gris-borde);
  color: var(--gris-texto);
  font-size: 9px;
  font-weight: 700;
  font-style: normal;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  z-index: 10;
  user-select: none;
  line-height: 1;
}

.sparkline-tooltip {
  display: none;
  position: absolute;
  top: -4px;
  left: 22px;
  background: var(--negro);
  color: #f0ece5;
  font-size: 0.72rem;
  font-weight: 400;
  font-style: normal;
  padding: 8px 12px;
  border-radius: 6px;
  width: 230px;
  line-height: 1.55;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.sparkline-info:hover .sparkline-tooltip {
  display: block;
}

.sparkline-svg {
  display: block;
  overflow: visible;
}

.sparkline-label {
  font-size: 9px;
  fill: #999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.dropdown-row-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.dropdown-row .sparkline-wrap {
  margin-top: 6px;
  border-top: 1px solid var(--gris-borde);
  padding-top: 6px;
}

/* Make expandable single rows behave like multi */
.fila-expandable {
  cursor: pointer;
}

.fila-expandable:hover .chevron {
  color: var(--rojo);
}

/* DISCLAIMER ICON */
.disclaimer-icon {
  position: absolute;
  top: 20px;
  right: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fef3c7;
  color: #b45309;
  font-size: 7px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  z-index: 10;
  user-select: none;
  line-height: 1;
  border: 1px solid #fcd34d;
}

.disclaimer-icon-tooltip {
  display: none;
  position: absolute;
  top: -4px;
  left: 22px;
  background: var(--negro);
  color: #f0ece5;
  font-size: 0.72rem;
  font-weight: 400;
  padding: 8px 12px;
  border-radius: 6px;
  width: 260px;
  line-height: 1.55;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.disclaimer-icon:hover .disclaimer-icon-tooltip {
  display: block;
}

/* NOTA */
.nota {
  font-size: 0.75rem;
  color: var(--gris-texto);
  margin-top: 28px;
  line-height: 1.7;
  border-left: 3px solid var(--rojo);
  padding-left: 14px;
  font-style: italic;
}

/* FOOTER */
footer {
  text-align: center;
  padding: 24px;
  font-size: 0.76rem;
  color: var(--gris-texto);
  border-top: 1px solid var(--gris-borde);
  background: var(--gris-claro);
  letter-spacing: 0.01em;
}

footer a {
  color: var(--rojo);
  text-decoration: none;
}

/* MOBILE */
@media (max-width: 600px) {
  h1 {
    font-size: 1.3rem;
  }

  main {
    padding: 20px 14px 48px;
  }

  .tabla-header {
    display: none;
  }

  .fila {
    grid-template-columns: 20px 64px 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
    padding: 12px 10px;
  }

  .col-chevron  { grid-column: 1; grid-row: 1; }
  .col-pct      { grid-column: 2; grid-row: 1; }
  .col-partido  { grid-column: 3; grid-row: 1; }
  .col-palabras { display: none; }
  .col-link {
    grid-column: 2 / 4;
    grid-row: 2;
    justify-content: flex-end;
    padding-right: 0;
    gap: 4px;
    padding-top: 2px;
  }
  .col-link:empty { display: none; }

  .logo {
    width: 28px;
    height: 28px;
  }

  .partido-nombre {
    font-size: 0.85rem;
  }

  /* Stack breakdown + sparkline vertically */
  .grafico-inner {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .breakdown-table {
    width: 100%;
    margin-left: 0;
    margin-top: 8px;
  }

  /* Tooltip: show left of the icon on mobile so it doesn't clip */
  .sparkline-tooltip {
    left: auto;
    right: 22px;
  }
}
