:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --text: #17201d;
  --muted: #5d6965;
  --border: #dde2de;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d9f0ec;
  --red: #b42318;
  --red-soft: #fde7e4;
  --orange: #b54708;
  --orange-soft: #fdecd8;
  --yellow: #8a6a00;
  --yellow-soft: #fbf3cf;
  --green: #18794e;
  --green-soft: #ddf3e6;
  --gray: #4b5563;
  --gray-soft: #eceff1;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .04);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1e2723;
    --text: #e7ece9;
    --muted: #9aa8a2;
    --border: #2b3632;
    --accent: #2dd4bf;
    --accent-ink: #062521;
    --accent-soft: #123a35;
    --red: #ff8a7a;
    --red-soft: #3d1d19;
    --orange: #ffb067;
    --orange-soft: #3b2614;
    --yellow: #f2d06b;
    --yellow-soft: #352d10;
    --green: #6fdba3;
    --green-soft: #15301f;
    --gray: #b8c2bd;
    --gray-soft: #26302c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412;
  --surface: #171e1b;
  --surface-2: #1e2723;
  --text: #e7ece9;
  --muted: #9aa8a2;
  --border: #2b3632;
  --accent: #2dd4bf;
  --accent-ink: #062521;
  --accent-soft: #123a35;
  --red: #ff8a7a;
  --red-soft: #3d1d19;
  --orange: #ffb067;
  --orange-soft: #3b2614;
  --yellow: #f2d06b;
  --yellow-soft: #352d10;
  --green: #6fdba3;
  --green-soft: #15301f;
  --gray: #b8c2bd;
  --gray-soft: #26302c;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: 400; }
h1, h2, h3 { line-height: 1.2; margin: 0; }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
}
.site-header .wrap { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
  background: var(--accent); color: var(--accent-ink);
}
.brand h1 { font-size: 20px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.site-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.site-nav a {
  font-size: 13.5px; font-weight: 600; text-decoration: none; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; border: 1px solid transparent;
}
.site-nav a:hover { color: var(--text); border-color: var(--border); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.header-side { display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap; }
.countdown {
  font-size: 13px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
}
.countdown b { color: var(--text); }

main { padding-top: 20px; padding-bottom: 40px; }

.notice {
  background: var(--yellow-soft); border: 1px solid color-mix(in srgb, var(--yellow) 30%, transparent);
  border-radius: var(--radius); padding: 12px 14px; font-size: 14px; margin-bottom: 24px;
}

.section-title { font-size: 17px; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 13.5px; margin: 10px 0 24px; }

/* Role cards */
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.role-card {
  text-align: left; cursor: pointer; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.role-card:hover { border-color: var(--accent); }
.role-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.role-card .r-name { font-weight: 700; font-size: 15px; }
.role-card .r-seats { font-size: 13px; color: var(--muted); }
.role-card .r-stats { margin-top: 8px; font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.role-card .r-stats b { font-variant-numeric: tabular-nums; }
.role-card .r-desc { margin-top: 6px; font-size: 12.5px; color: var(--muted); }

/* Filters */
.filters {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  padding: 10px 0; margin-bottom: 8px; border-bottom: 1px solid var(--border);
}
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-row + .filter-row { margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1 1 150px; min-width: 0; max-width: 240px; }
.field.grow { flex: 2 1 220px; max-width: none; }
.field input, .field select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.toggles { font-size: 14px; gap: 16px; }
.toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

.result-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.count { margin: 0; font-size: 14px; color: var(--muted); }
.count b { color: var(--text); }
.party-summary { display: flex; gap: 6px; flex-wrap: wrap; }
.party-summary button {
  font: inherit; font-size: 12px; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}
.party-summary button:hover { border-color: var(--accent); }

/* Candidate cards */
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; align-items: start; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card.has-news { border-left: 4px solid var(--red); }
.card-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.num {
  min-width: 52px; padding: 6px 8px; border-radius: 8px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: .5px;
}
.who { min-width: 0; }
.ballot { font-size: 16px; overflow-wrap: anywhere; }
.full { margin: 2px 0 6px; font-size: 12.5px; overflow-wrap: anywhere; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; line-height: 1.6;
  padding: 0 7px; border-radius: 999px; background: var(--gray-soft); color: var(--gray); white-space: normal; max-width: 100%;
}
.badge.party { background: var(--accent-soft); color: var(--accent); cursor: pointer; border: 0; font-family: inherit; }
.badge.role { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.st-indeferido, .badge.st-sub-judice { background: var(--red-soft); color: var(--red); }
.badge.st-renuncia, .badge.st-pendente, .badge.st-apto-recurso { background: var(--orange-soft); color: var(--orange); }
.news-count {
  text-align: center; font-size: 11px; color: var(--muted); line-height: 1.2; min-width: 48px;
}
.news-count b { display: block; font-size: 20px; color: var(--red); font-variant-numeric: tabular-nums; }
.news-count.zero b { color: var(--green); }
.news-count.na b { color: var(--muted); font-size: 14px; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 4px 12px;
  margin: 12px 0 0; font-size: 12.5px;
}
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font-size: 11px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.mates { font-size: 12.5px; margin-top: 8px; color: var(--muted); }
.mates span { color: var(--text); }
.mates .mate-news { color: var(--red); font-weight: 600; }

.summary { font-size: 13.5px; margin-top: 10px; }
.summary:empty { display: none; }
.summary p.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.more-text { background: none; border: 0; padding: 0; font: inherit; font-size: 12.5px; color: var(--accent); cursor: pointer; text-decoration: underline; }
.summary .worst { font-size: 12.5px; color: var(--muted); }
.summary .reasons { color: var(--red); font-size: 12.5px; margin-top: 4px; }

.news { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.news summary { cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--accent); }
.news-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.news-item { font-size: 13px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.news-item .meta { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; font-size: 11.5px; color: var(--muted); }
.news-item a { font-weight: 600; overflow-wrap: anywhere; }
.news-item p { margin: 4px 0 0; }
.family-head { font-size: 12px; font-weight: 600; color: var(--orange); margin-top: 4px; }
.fam-count { margin-top: 4px; font-size: 10.5px; color: var(--orange); font-weight: 600; }
.family-line { font-size: 12.5px; margin-top: 6px; color: var(--muted); }
.family-line b { color: var(--text); font-weight: 600; }
.closed-head { font-size: 12px; font-weight: 600; color: var(--green); margin-top: 4px; }
.news-item .for-mate { font-size: 11.5px; color: var(--muted); font-style: italic; }

.chip { font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 999px; line-height: 1.7; white-space: nowrap; }
.chip.cat { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.chip.s-high { background: var(--red-soft); color: var(--red); }
.chip.s-mid { background: var(--orange-soft); color: var(--orange); }
.chip.s-low { background: var(--yellow-soft); color: var(--yellow); }
.chip.s-ok { background: var(--green-soft); color: var(--green); }
.chip.s-neutral { background: var(--gray-soft); color: var(--gray); }

.more { text-align: center; margin-top: 18px; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; padding: 9px 18px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); border: 0;
}
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 24px 0 36px; font-size: 13.5px; }
.site-footer h2 { font-size: 15px; margin-bottom: 8px; }
.site-footer p { margin: 0 0 8px; max-width: 900px; }

@media (max-width: 720px) {
  .list { grid-template-columns: 1fr; }
  .field { min-width: calc(50% - 5px); flex: 1 1 calc(50% - 5px); max-width: none; }
  .field.grow { flex-basis: 100%; }
  .filters { position: static; }
  .brand h1 .muted { display: block; font-size: 14px; }
  .roles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .role-card { padding: 10px 12px; }
  .role-card .r-desc { display: none; }
  .num { min-width: 44px; font-size: 16px; }
}
