:root {
  /* --brand e --brand-rgb vêm do <style> inline gerado pelo pg-index.php,
     a partir da cor única definida em $corMarca. Tudo abaixo deriva dela. */
  --brand-04: rgba(var(--brand-rgb), 0.04);
  --brand-08: rgba(var(--brand-rgb), 0.08);
  --brand-14: rgba(var(--brand-rgb), 0.14);
  --brand-22: rgba(var(--brand-rgb), 0.22);
  --brand-40: rgba(var(--brand-rgb), 0.40);
  --brand-70: rgba(var(--brand-rgb), 0.70);
  --brand-solid: rgba(var(--brand-rgb), 1);

  /* --text-on-brand também vem do <style> inline do pg-index.php —
     calculado a partir da luminância de $corMarca, para o texto ficar
     legível tanto em cores claras quanto escuras. Só é usado sobre
     fundo 100% sólido da marca (botões, aba ativa); em fundos
     translúcidos (tints), usar --text normalmente. */
  --bg: #F8F7F5;
  --surface: #FFFFFF;
  --line: #E9E7E3;
  --text: #1C1A17;
  --muted: #6F6B64;
  --muted-2: #9B968D;

  --status-eleito-bg: #E4F5EA;
  --status-eleito-text: #1B7A44;
  --status-segundo-bg: #E7EEFB;
  --status-segundo-text: #2E52A6;

  --content-max: 1240px;
  --font: "Archivo", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(var(--brand-rgb), 0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px clamp(16px, 4vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.topbar__logo {
  height: 44px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  flex-shrink: 0;
}

.topbar__cta {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-on-brand);
  background: var(--brand-solid);
  padding: 9px 18px;
  border-radius: 999px;
  white-space: nowrap;
  transition: filter 0.15s ease;
}

.topbar__cta:hover {
  filter: brightness(1.05);
}

/* Hero */
.hero {
  background:
    radial-gradient(720px 360px at 15% -20%, var(--brand-14), transparent 60%),
    var(--bg);
  border-bottom: 1px solid var(--line);
}

.hero__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: clamp(20px, 3vw, 32px) clamp(16px, 4vw, 32px) clamp(16px, 2.5vw, 22px);
}

.hero__title {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.hero__subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.1rem);
  font-weight: 500;
}

.hero__live {
  margin-top: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
}

.hero__live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
}

.hero__live.is-live .hero__live-dot {
  background: var(--status-eleito-text);
  position: relative;
}

.hero__live.is-live .hero__live-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--status-eleito-text);
  animation: pulso-ao-vivo 1.8s ease-out infinite;
}

@keyframes pulso-ao-vivo {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
    opacity: 0.6;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(3.2);
  }
}

/* Tabs row */
.tabs-row {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tabs-row__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 14px clamp(16px, 4vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.tab:hover {
  border-color: var(--brand-40);
  color: var(--text);
}

.tab:focus-visible {
  outline: 2px solid var(--brand-solid);
  outline-offset: 1px;
}

.tab.is-active {
  color: var(--text-on-brand);
  background: var(--brand-solid);
  border-color: transparent;
  font-weight: 700;
}

/* Estado select */
.estado-select {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.estado-select__label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.estado-select__control {
  appearance: none;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 32px 8px 14px;
  cursor: pointer;
  max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236F6B64' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}

.estado-select__control:hover {
  border-color: var(--brand-40);
}

.estado-select__control:focus-visible {
  outline: 2px solid var(--brand-solid);
  outline-offset: 1px;
}

/* Content */
.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: clamp(24px, 4vw, 36px) clamp(16px, 4vw, 32px) 64px;
}

.loading {
  color: var(--muted);
  font-size: 0.9rem;
}

.error {
  color: #B3401F;
  font-size: 0.92rem;
}

/* Stats strip */
.stats-strip {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px clamp(16px, 3vw, 26px) 20px;
  margin-bottom: 32px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 18px;
  box-shadow: 0 1px 2px rgba(20, 16, 8, 0.03);
}

.stats-strip__item {
  min-width: 0;
}

.stats-strip__value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stats-strip__label {
  margin-top: 3px;
  font-size: 0.74rem;
  color: var(--muted);
}

.stats-strip__bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 3px;
  background: var(--brand-08);
  overflow: hidden;
  margin-top: 4px;
}

.stats-strip__bar-fill {
  height: 100%;
  width: 0%;
  background: var(--brand-solid);
  border-radius: 3px;
  transition: width 1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.stats-strip__updated {
  grid-column: 1 / -1;
  font-size: 0.74rem;
  color: var(--muted-2);
}

/* Cargo title */
.cargo-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

/* Grid de candidatos */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(20, 16, 8, 0.03);
  display: flex;
  flex-direction: column;
  min-width: 0;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(20, 16, 8, 0.08);
  border-color: var(--brand-40);
}

.card:focus-visible {
  outline: 2px solid var(--brand-solid);
  outline-offset: 2px;
}

.card.situacao-eleito,
.card.situacao-eleito_qp,
.card.situacao-eleito_media {
  border-color: #B9E3C6;
}

.card.situacao-segundo_turno {
  border-color: #C3D3F2;
}

.card.situacao-suplente {
  border-color: var(--brand-40);
}

.card.situacao-nao_eleito {
  opacity: 0.65;
}

.card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card__avatar-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  padding: 3px;
  flex-shrink: 0;
  background: conic-gradient(var(--brand-solid) calc(var(--pct, 0) * 1%), var(--line) 0);
}

.card__avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--surface);
  background: var(--brand-14);
  box-sizing: border-box;
}

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

.card__result {
  text-align: right;
  min-width: 0;
}

.card__percentual {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.card__votos {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

.card__partido-line {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.card__nome {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
  overflow-wrap: break-word;
}

.card__badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 7px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.card__badge svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.card__badge--apurando {
  background: #F1EFEC;
  color: var(--muted);
}

.card__badge--eleito,
.card__badge--eleito_qp,
.card__badge--eleito_media {
  background: var(--status-eleito-bg);
  color: var(--status-eleito-text);
}

.card__badge--segundo_turno {
  background: var(--status-segundo-bg);
  color: var(--status-segundo-text);
}

.card__badge--suplente {
  background: var(--brand-14);
  color: var(--text);
}

.card__badge--nao_eleito {
  background: #F1EFEC;
  color: var(--muted);
}

.card__vice {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.card__vice strong {
  color: var(--text);
  font-weight: 600;
}

.card__bar-row {
  margin-top: auto;
}

.card__bar {
  height: 6px;
  border-radius: 3px;
  background: var(--brand-08);
  overflow: hidden;
}

.card__bar-fill {
  height: 100%;
  width: 0%;
  background: var(--brand-solid);
  border-radius: 3px;
  transition: width 1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* Footer */
.footer {
  border-top: 1px solid var(--line);
  padding: 20px clamp(16px, 4vw, 32px) 40px;
  background: var(--surface);
}

.footer p {
  max-width: var(--content-max);
  margin: 0 auto;
  color: var(--muted-2);
  font-size: 0.76rem;
}

.footer code {
  color: var(--muted);
}

/* Responsividade */
@media (max-width: 900px) {
  .stats-strip {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 720px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
  }
}

@media (max-width: 640px) {
  .tabs-row__inner {
    flex-direction: column;
    align-items: stretch;
  }
  .estado-select {
    justify-content: space-between;
    margin-top: 4px;
  }
  .estado-select__control {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .topbar__logo {
    height: 34px;
    max-width: 140px;
  }
}
