/*
  Widget de resultados electorales - Brasil

  Paleta y lenguaje visual tomados del CSS real de referencia (.elecciones-2024):
  fondo blanco, texto #333, secundario #999, radios chicos (3px, no píldoras),
  sin sombras ni tarjetas con fondo de color; el color de cada candidato se
  usa en su texto (partido, porcentaje) y en el relleno de la barra, no como
  fondo de bloque. Variables pensadas para ser sobreescritas desde el CSS del
  sitio anfitrión (redefiniendo --bew-* en un selector más específico).
*/

.bew-widget {
  --bew-bg: #ffffff;
  --bew-track: #ebebeb;
  --bew-border: #e0e0e0;
  --bew-text: #333333;
  --bew-text-muted: #999999;
  --bew-accent: #0f766e;
  --bew-radius: 8px;
  --bew-radius-sm: 3px;
  --bew-font: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --bew-font-headline: Bitter, Georgia, "Times New Roman", serif;

  --bew-live-color: #dc2626;
  --bew-warn-text: #92400e;
  --bew-danger-text: #991b1b;
  --bew-leader-bg: #eff6ff;
  --bew-leader-text: #1d4ed8;

  font-family: var(--bew-font);
  color: var(--bew-text);
  background: var(--bew-bg);
  border: 1px solid var(--bew-border);
  border-radius: var(--bew-radius);
  padding: 14px;
  width: 100%;
  box-sizing: border-box;
  font-size: 1.312rem;
}

.bew-widget * {
  box-sizing: border-box;
}

/* ---------- Header: título + vuelta (texto plano) ---------- */

.bew-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 2px;
}

.bew-title {
  font-family: var(--bew-font-headline);
  font-size: 1.84rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.bew-round {
  color: var(--bew-text-muted);
  font-size: 1.12rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------- Línea de actualización + estado en vivo ---------- */

.bew-hora {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 1.152rem;
  color: var(--bew-text-muted);
}

.bew-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.bew-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bew-live-color);
  display: inline-block;
  flex-shrink: 0;
}

.bew-widget[data-closed="true"] .bew-live-dot {
  background: #aaaaaa;
}

.bew-live[data-live="true"] .bew-live-dot {
  animation: bew-pulse 1.6s ease-in-out infinite;
}

@keyframes bew-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

/* ---------- Nota metodológica ---------- */

.bew-disclaimer {
  margin: 0 0 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bew-border);
  font-size: 1.056rem;
  font-style: italic;
  color: var(--bew-text-muted);
}

/* ---------- Candidatos destacados (1º y 2º) ---------- */

.bew-hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 14px;
}

.bew-hero {
  min-width: 0;
}

.bew-hero:nth-child(2) {
  padding-left: 20px;
  border-left: 1px solid var(--bew-border);
}

.bew-hero-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.bew-avatar {
  border-radius: 50%;
  background: var(--bew-c, var(--bew-accent));
  border: 2px solid var(--bew-c, var(--bew-accent));
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bew-avatar--lg {
  width: 68px;
  height: 68px;
}

.bew-avatar--sm {
  width: 26px;
  height: 26px;
  border-width: 1px;
}

.bew-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bew-avatar svg {
  width: 56%;
  height: 56%;
  fill: rgba(255, 255, 255, 0.92);
}

.bew-hero-id {
  min-width: 0;
  flex: 1 1 auto;
}

.bew-hero-name {
  display: block;
  font-family: var(--bew-font-headline);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.2;
  color: var(--bew-c, var(--bew-accent));
  white-space: normal;
  word-break: break-word;
}

.bew-hero-party-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
}

.bew-hero-party {
  font-size: 1.248rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #333;
}

.bew-badge {
  font-size: 0.864rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--bew-radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.bew-badge--leader {
  background: var(--bew-leader-bg);
  color: var(--bew-leader-text);
}

.bew-hero-pct-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.bew-hero-pct {
  font-size: 3.52rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--bew-c, var(--bew-accent));
}

/* Barra única: todos los candidatos, en orden y color, como un solo
   segmento continuo. Reemplaza las barras individuales por candidato. */
.bew-unified-bar {
  position: relative;
  display: flex;
  width: 100%;
  height: 10px;
  background: var(--bew-track);
  border-radius: 2px;
  overflow: hidden;
  margin: 2px 0 16px;
}

.bew-unified-seg {
  display: block;
  height: 100%;
  flex-shrink: 0;
}

/* Marca punteada en el 50%: umbral de mayoría absoluta para ganar en primera
   vuelta, tal como en la barra original de .elecciones-partido-barra. */
.bew-unified-bar::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(0, 0, 0, 0.3);
}

/* Vínculo de hover entre candidato (tarjeta destacada, mini-tarjeta) y su
   segmento en la barra única: al pasar el mouse sobre cualquiera de sus
   representaciones, el resto baja levemente de opacidad. */
.bew-hero,
.bew-mini,
.bew-unified-seg {
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.bew-dim {
  opacity: 0.35;
}

.bew-hero-votes {
  font-size: 1.12rem;
  color: var(--bew-text-muted);
  text-align: right;
}

/* ---------- Carrusel: resto de candidatos ---------- */

.bew-carousel {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 12px;
}

.bew-car-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--bew-track);
  color: var(--bew-text-muted);
  font-size: 1.36rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bew-car-btn:hover {
  background: #dddddd;
  color: var(--bew-text);
}

.bew-car-viewport {
  flex: 1 1 auto;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  min-width: 0;
  -webkit-mask-image: linear-gradient(90deg, transparent, black 14px, black calc(100% - 14px), transparent);
  mask-image: linear-gradient(90deg, transparent, black 14px, black calc(100% - 14px), transparent);
}

.bew-car-viewport::-webkit-scrollbar {
  display: none;
}

.bew-car-track {
  display: flex;
  gap: 14px;
  padding: 0 2px;
}

.bew-mini {
  scroll-snap-align: start;
  flex: 0 0 auto;
  width: 130px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  column-gap: 7px;
  row-gap: 3px;
  border-left: 3px solid var(--bew-c, var(--bew-accent));
  padding-left: 7px;
  padding-top: 2px;
  padding-bottom: 2px;
}

.bew-mini[data-annulled="true"] {
  opacity: 0.5;
}

.bew-mini .bew-avatar {
  order: 1;
}

.bew-mini-pct-wrap {
  order: 2;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.bew-mini-info {
  order: 3;
  min-width: 0;
  flex: 1 1 100%;
  line-height: 1.3;
}

.bew-mini-name {
  font-family: var(--bew-font-headline);
  font-size: 1.056rem;
  font-weight: 700;
  color: var(--bew-c, var(--bew-accent));
  word-break: break-word;
}

.bew-mini-divider {
  display: inline-block;
  width: 1px;
  height: 0.7em;
  margin: 0 5px;
  background: var(--bew-border);
  vertical-align: middle;
}

.bew-mini-party {
  font-size: 0.928rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #333;
}

.bew-mini-pct {
  font-size: 1.184rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--bew-c, var(--bew-accent));
}

.bew-mini-votes {
  font-size: 0.896rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--bew-text-muted);
}

/* ---------- Pie: blancos / nulos / abstención / válidos ---------- */

.bew-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  padding-top: 10px;
  border-top: 1px solid var(--bew-border);
}

.bew-footer-stat {
  font-size: 1.088rem;
  font-weight: 700;
  color: var(--bew-text);
  white-space: nowrap;
  padding: 2px 12px;
}

.bew-footer-stat:first-child {
  padding-left: 0;
}

.bew-footer-stat:not(:first-child) {
  border-left: 1px solid var(--bew-border);
}

.bew-footer-scrutiny {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bew-scrutiny-bar {
  display: inline-block;
  width: 40px;
  height: 6px;
  background: var(--bew-track);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Relleno a rayas (en vez de sólido), como guiño al indicador de "circuitos
   escrutados" del sitio original, que usa un patrón repetido en diagonal. */
.bew-scrutiny-fill {
  display: block;
  height: 100%;
  background-color: var(--bew-accent);
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.35) 0,
    rgba(255, 255, 255, 0.35) 2px,
    transparent 2px,
    transparent 5px
  );
}

.bew-source-tag {
  margin-top: 6px;
  font-size: 0.928rem;
  font-weight: 600;
  color: var(--bew-text-muted);
  text-align: right;
}

.bew-source-tag[data-source="fallback"] {
  color: var(--bew-warn-text);
}

/* ---------- Estados: loading / error ---------- */

.bew-loading,
.bew-error {
  text-align: center;
  padding: 24px 12px;
  color: var(--bew-text-muted);
  font-size: 1.248rem;
}

.bew-loading::before {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: 3px solid var(--bew-track);
  border-top-color: var(--bew-accent);
  animation: bew-spin 0.8s linear infinite;
}

@keyframes bew-spin {
  to { transform: rotate(360deg); }
}

.bew-error {
  color: var(--bew-danger-text);
}

.bew-retry-btn {
  margin-top: 8px;
  background: var(--bew-accent);
  color: #fff;
  border: none;
  border-radius: var(--bew-radius-sm);
  padding: 6px 14px;
  font-size: 1.152rem;
  font-weight: 600;
  cursor: pointer;
}

.bew-retry-btn:hover {
  opacity: 0.9;
}

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .bew-hero-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .bew-hero:nth-child(2) {
    padding-left: 0;
    border-left: none;
    padding-top: 14px;
    border-top: 1px solid var(--bew-border);
  }

  /* El porcentaje siempre cae a su propia línea en mobile, sin depender
     de si el nombre del candidato es corto o largo. */
  .bew-hero-pct-wrap {
    flex-basis: 100%;
    align-items: flex-start;
  }
}

@media (max-width: 360px) {
  .bew-avatar--lg {
    width: 52px;
    height: 52px;
  }

  .bew-hero-top {
    gap: 10px;
  }

  .bew-hero-pct {
    font-size: 2.88rem;
  }

  .bew-mini {
    width: 112px;
  }
}
