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

:root {
  --bg: #05070d;
  --surface: #0d1117;
  --border: #182030;
  --text: #e8eaf0;
  --muted: #4e5c73;
  --green: #22c55e;
  --red-flag: #d91023;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding: 20px 16px 32px;
  max-width: 720px;
  margin: 0 auto;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.flag { display: flex; gap: 3px; flex-shrink: 0; }
.flag span { width: 5px; height: 40px; border-radius: 2px; }
.flag .r { background: var(--red-flag); }
.flag .w { background: #e8eaf0; }
header h1 { font-size: 1.15rem; font-weight: 700; line-height: 1.25; }
header p  { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
  transition: background .3s;
}
.dot.live  { background: var(--green); animation: pulse 2s infinite; }
.dot.error { background: var(--red-flag); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── Stats ── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat .lbl {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.stat .val { font-size: 1.25rem; font-weight: 700; line-height: 1; color: #94a3b8; }
.stat .sub { font-size: 0.68rem; color: var(--muted); margin-top: 3px; }
.stat.hl .val { color: #f59e0b; }

/* ── Section label ── */
.section-lbl {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #38bdf8;
  margin-bottom: 8px;
  margin-top: 20px;
}
.section-lbl:first-of-type { margin-top: 0; }

/* ── Party row (senators) ── */
.party-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  position: relative;
  overflow: hidden;
}
.party-row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--party-color, var(--muted));
  border-radius: 8px 0 0 8px;
}
.party-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.party-logo {
  width: 28px; height: 28px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.party-logo img { width: 100%; height: 100%; object-fit: contain; }
.party-logo .fb { font-size: 0.5rem; font-weight: 700; color: var(--muted); }
.party-label { flex: 1; min-width: 0; }
.party-label .name {
  font-size: 0.78rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.party-label .votes { font-size: 0.62rem; color: var(--muted); margin-top: 1px; }
.party-pct {
  font-size: 1.05rem; font-weight: 700;
  color: var(--party-color, var(--text));
  flex-shrink: 0;
}
.section-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px 16px;
  margin-top: 28px;
  margin-bottom: 10px;
}
.section-header .title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #38bdf8;
  line-height: 1.2;
}
.section-header .meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: #cbd5e1;
  font-weight: 500;
  margin-top: 10px;
}
.section-header .meta .time {
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
}
.section-header .meta .sep {
  color: var(--muted);
}

/* ── Candidate cards ── */
.candidates { display: flex; flex-direction: column; gap: 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 8px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--party-color, var(--muted));
  border-radius: 8px 0 0 8px;
}

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pos {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}
.card .pos,
.party-row .pos { color: var(--party-color, var(--muted)); }

/* ── Avatar (photo + logo badge) ── */
.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.avatar .photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  border: 2px solid var(--party-color, var(--border));
  display: block;
}
.avatar .badge {
  position: absolute;
  bottom: -2px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--bg);
  background: var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar .badge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.avatar .badge .fb {
  font-size: 0.45rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  line-height: 1.1;
}

/* ── Info ── */
.info { flex: 1; min-width: 0; }
.cand-name {
  font-size: 0.95rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.party-name {
  font-size: 0.73rem;
  color: var(--party-color, var(--muted));
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  opacity: .9;
}

.pct-block { text-align: right; flex-shrink: 0; }
.pct-main {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--party-color, var(--text));
  line-height: 1;
}
.pct-sub { font-size: 0.62rem; color: var(--muted); margin-top: 2px; }

/* ── Progress bar ── */
.bar-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--party-color, var(--muted));
  border-radius: 2px;
  transition: width .6s ease;
  opacity: .8;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  body { padding: 14px 12px 28px; }

  header h1 { font-size: 0.98rem; }
  header p  { font-size: 0.65rem; }
  .status   { font-size: 0.75rem; }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .stat .val { font-size: 1rem; }
  .stat .lbl { font-size: 0.58rem; }

  .cand-name  { font-size: 0.8rem; }
  .party-name { font-size: 0.65rem; }
  .pct-main   { font-size: 1rem; }
  .pct-sub    { font-size: 0.58rem; }

  .avatar { width: 38px; height: 38px; }
  .avatar .photo { width: 38px; height: 38px; }
  .avatar .badge { width: 17px; height: 17px; }

  .section-header .title { font-size: 0.88rem; }
  .section-header .meta  { font-size: 0.68rem; }

  .party-label .name  { font-size: 0.72rem; }
  .party-label .votes { font-size: 0.58rem; }
  .party-pct { font-size: 0.9rem; }
}

/* ── Skeleton ── */
.skeleton {
  height: 70px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

.error-msg {
  background: rgba(217,16,35,.1);
  border: 1px solid rgba(217,16,35,.3);
  border-radius: 8px;
  padding: 14px;
  font-size: 0.82rem;
  color: #ff6b6b;
  text-align: center;
}

footer {
  margin-top: 24px;
  text-align: center;
  font-size: 0.65rem;
  color: var(--muted);
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--text); }
