/*
  Widget de mapa electoral - Brasil (por estado y localidad)

  Mismo lenguaje visual que brazil-election-widget.css: fondo blanco, texto
  #333, secundario #999, radios chicos, sin sombras. El color de cada
  territorio es el del candidato ganador ahí, en un tono más claro o más
  oscuro según el porcentaje de votos que obtuvo (ver
  brazil-election-map-widget.js).
*/

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

  /* Todos los font-size de este archivo usan calc(N * --bewmap-unit) en vez
     de "Nrem" directo: un rem depende del font-size del <html> del sitio
     donde se inserte el widget (en el sitio de destino 1rem = 10px, no los
     16px "de fábrica" del navegador), así que con rem el texto salía mucho
     más chico de lo pensado. --bewmap-unit fija ese valor nosotros mismos
     (en px, no depende del host) y queda como único lugar para agrandar o
     achicar todo el texto del widget de una sola vez. */
  --bewmap-unit: 16px;

  font-family: var(--bewmap-font);
  color: var(--bewmap-text);
  background: var(--bewmap-bg);
  border: 1px solid var(--bewmap-border);
  border-radius: var(--bewmap-radius);
  padding: 14px;
  width: 100%;
  box-sizing: border-box;
  font-size: calc(0.86 * var(--bewmap-unit));
}

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

/* ---------- Header ---------- */

.bewmap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.bewmap-header-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bewmap-title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.bewmap-title {
  font-family: var(--bewmap-font-headline);
  font-size: calc(1.1 * var(--bewmap-unit));
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.bewmap-round {
  color: var(--bewmap-text-muted);
  font-size: calc(0.7 * var(--bewmap-unit));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bewmap-subtitle {
  margin: 0;
  font-size: calc(0.78 * var(--bewmap-unit));
  color: var(--bewmap-text-muted);
}

.bewmap-back {
  flex-shrink: 0;
  background: var(--bewmap-track);
  color: var(--bewmap-text);
  border: none;
  border-radius: var(--bewmap-radius-sm);
  padding: 6px 12px;
  font-size: calc(0.78 * var(--bewmap-unit));
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.bewmap-back:hover {
  background: #dddddd;
}

/* ---------- Cuerpo: mapa + panel ---------- */

.bewmap-body {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.bewmap-stage {
  position: relative;
  flex: 1 1 62%;
  min-width: 0;
  aspect-ratio: 1000 / 912;
  background: #fafafa;
  border: 1px solid var(--bewmap-border);
  border-radius: var(--bewmap-radius-sm);
  overflow: hidden;
}

.bewmap-svg,
.bewmap-municipios-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.bewmap-svg {
  display: block;
}

/* Un solo atributo en .bewmap-stage decide qué capa se ve (ver
   showPais/showEstado en el JS): evita que la silueta plana de estados
   quede visible encima del detalle de municipios (el bug de Mato
   Grosso/Amazonas). El SVG de municipios arranca en visibility:hidden
   (no display:none) porque necesita layout real para poder medir su
   bounding box al hacer drill-down. */
.bewmap-municipios-wrap {
  visibility: hidden;
}

.bewmap-stage[data-view="estado"] .bewmap-svg--estados {
  display: none;
}

.bewmap-stage[data-view="estado"] .bewmap-municipios-wrap {
  visibility: visible;
}

.bewmap-shape {
  cursor: pointer;
  transition: fill 0.2s ease;
}

.bewmap-shape:hover {
  filter: brightness(0.92);
}

/* ---------- Tooltip: sigue al mouse sobre el mapa ---------- */

.bewmap-tooltip {
  position: absolute;
  display: none;
  z-index: 2;
  pointer-events: none;
  background: rgba(33, 33, 33, 0.92);
  color: #ffffff;
  font-size: calc(0.72 * var(--bewmap-unit));
  font-weight: 700;
  line-height: 1.3;
  padding: 4px 8px;
  border-radius: var(--bewmap-radius-sm);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bewmap-panel {
  flex: 1 1 34%;
  min-width: 220px;
  border: 1px solid var(--bewmap-border);
  border-radius: var(--bewmap-radius-sm);
  padding: 12px;
  container-type: inline-size;
}

.bewmap-panel-title {
  font-family: var(--bewmap-font-headline);
  font-size: calc(1 * var(--bewmap-unit));
  font-weight: 700;
  margin: 0 0 4px;
}

.bewmap-panel-meta {
  margin: 0 0 10px;
  font-size: calc(0.76 * var(--bewmap-unit));
  color: var(--bewmap-text-muted);
}

.bewmap-panel-empty {
  color: var(--bewmap-text-muted);
  font-size: calc(0.8 * var(--bewmap-unit));
}

/* ---------- Lista de candidatos (panel) ---------- */

.bewmap-cand-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bewmap-cand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.bewmap-cand-row--leader .bewmap-cand-name {
  font-weight: 800;
}

/* Los 2 candidatos a la cabeza: todo un poco más grande que el resto de
   la lista (avatar, tipografía, barra), con una separación sutil antes
   del resto (ver .bewmap-cand-divider). */
.bewmap-cand-row--top2 {
  gap: 10px;
}

.bewmap-cand-row--top2 .bewmap-cand-avatar {
  width: 46px;
  height: 46px;
}

.bewmap-cand-row--top2 .bewmap-cand-name {
  font-size: 14px;
  font-family: var(--font-2);
}

.bewmap-cand-row--top2 .bewmap-cand-party {
  font-size: calc(0.76 * var(--bewmap-unit));
}

.bewmap-cand-row--top2 .bewmap-cand-pct {
  font-size: 24px;
}

.bewmap-cand-row--top2 .bewmap-cand-votes {
  font-size: calc(0.72 * var(--bewmap-unit));
}

.bewmap-cand-row--top2 .bewmap-cand-bar {
  height: 7px;
}

.bewmap-cand-divider {
  border-top: 1px solid var(--bewmap-border);
  margin: 2px 0;
}

.bewmap-cand-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bewmap-c, #999);
  border: 2px solid var(--bewmap-c, #999);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.bewmap-cand-info {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.bewmap-cand-name {
  font-size: calc(0.8 * var(--bewmap-unit));
  font-weight: 700;
  line-height: 1.3;
}

.bewmap-cand-party {
  font-size: calc(0.68 * var(--bewmap-unit));
  color: var(--bewmap-text-muted);
  text-transform: uppercase;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.bewmap-cand-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-shrink: 0;
}

.bewmap-cand-pct {
  font-size: calc(0.86 * var(--bewmap-unit));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bewmap-cand-votes {
  font-size: 14px;
  color: var(--bewmap-text-muted);
  white-space: nowrap;
  line-height: 1.2;
}

.bewmap-cand-bar {
  flex: 1 1 100%;
  height: 5px;
  background: var(--bewmap-track);
  border-radius: 2px;
  overflow: hidden;
}

.bewmap-cand-bar-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
}

.bewmap-panel-totales {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--bewmap-border);
  font-size: 12px;
  color: var(--bewmap-text-muted);
  line-height: 1.4;
}

/* ---------- Leyenda ---------- */

.bewmap-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--bewmap-border);
  font-size: 11px;
  color: var(--bewmap-text-muted);
}

.bewmap-legend-candidatos {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* La fila de cada candidato y la de etiquetas de rango comparten esta
   misma grilla para que los chips y sus porcentajes queden alineados. */
.bewmap-legend-candidato,
.bewmap-legend-scale-labels {
  display: grid;
  grid-template-columns: minmax(150px, max-content) repeat(4, 34px);
  align-items: flex-start;
  column-gap: 4px;
}

.bewmap-legend-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--bewmap-text);
  font-weight: 700;
  line-height: 1.2;
}

.bewmap-legend-note {
  line-height: 1.2;
  font-size: 1.2rem;
}

.bewmap-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.bewmap-legend-chip {
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

.bewmap-legend-scale-labels {
  font-size: calc(0.62 * var(--bewmap-unit));
  line-height: 1;
  margin-bottom: 1.5rem;
}

.bewmap-legend-scale-label {
  text-align: center;
}

.bewmap-source-tag {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bewmap-text-muted);
  text-align: right;
  line-height: 1.2;
}

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

.bewmap-loading,
.bewmap-error {
  text-align: center;
  padding: 30px 10px;
  color: var(--bewmap-text-muted);
  font-size: calc(0.85 * var(--bewmap-unit));
}

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

@media (max-width: 640px) {
  .bewmap-body {
    flex-direction: column;
  }

  .bewmap-stage {
    flex: 1 1 auto;
    width: 100%;
  }

  .bewmap-panel {
    flex: 1 1 auto;
    width: 100%;
  }
}

@media only screen and (max-width: 767px) {
  .bewmap-source-tag {
    text-align: left;
  }
}

@media only screen and (min-width: 400px) {
  .bewmap-legend-scale-labels {
    column-gap: 8px;
  }

  .bewmap-legend-scale-label,
  .bewmap-legend-chip {
    text-wrap: nowrap;
  }

  .bewmap-legend-name,
  .bewmap-legend-scale-spacer {
    min-width: 181px;
  }
}

@media screen and (min-width: 388px) and (max-width: 438px) {
  .bewmap-cand-info {
    width: 138px;
  }
}

@container (width < 341px) {
  .bewmap-cand-info {
    width: calc(100% - 56px);
  }

  .bewmap-cand-party {
    margin-bottom: 0;
  }
}
