:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --card: #fff;
  --accent: #003087;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

header {
  padding: 1.6rem 1.2rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
}
h1 { margin: 0 0 .2rem; font-size: 1.7rem; }
.subtitle { margin: 0; color: var(--muted); font-size: .95rem; }

/* ---- term (kadencja) switcher ---- */
.term-switch { display: inline-flex; margin-top: .8rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); padding: 3px; gap: 2px; }
.term-btn { display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  border: none; background: none; cursor: pointer; padding: .35rem 1rem; border-radius: 8px;
  font-size: .92rem; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.term-btn small { font-size: .68rem; font-weight: 400; opacity: .8; }
.term-btn:hover { background: #f0f0f0; }
.term-btn.active { background: var(--accent); color: #fff; }
.term-btn.active:hover { background: var(--accent); }
.term-btn.active small { opacity: .85; }

main { max-width: 1100px; margin: 0 auto; padding: 0 1.2rem 2rem; }

.controls {
  display: flex; flex-wrap: wrap; gap: .8rem; align-items: center;
  margin: 1rem 0;
}
#search {
  flex: 1 1 240px; min-width: 180px;
  padding: .55rem .8rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
.toggle { font-size: .9rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.reset {
  padding: .5rem .9rem; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.reset:hover { background: #f0f0f0; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .6rem; border-radius: 999px; cursor: pointer;
  font-size: .82rem; border: 1px solid var(--line); background: var(--card);
  user-select: none; transition: opacity .15s;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.dim { opacity: .35; }

.chart-wrap { position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: .8rem; margin-bottom: 1.4rem; }
.chart-wrap h2 { margin: .2rem .4rem .6rem; font-size: 1rem; color: var(--muted); font-weight: 600; }
svg { width: 100%; display: block; }

.dot-mp { cursor: pointer; stroke: #fff; stroke-width: .5; }
.dot-mp.dimmed { opacity: .12; }
.dot-mp.hit { stroke: #000; stroke-width: 1.5; }
.ci-line { stroke-opacity: .35; stroke-width: 1; }

.axis text { fill: var(--muted); font-size: 11px; }
.axis line, .axis path { stroke: var(--line); }
.zero-line { stroke: #999; stroke-dasharray: 4 3; stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 12px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: #111; color: #fff; padding: .5rem .65rem; border-radius: 8px;
  font-size: .82rem; max-width: 240px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.tooltip b { font-size: .9rem; }
.tooltip .club { opacity: .8; }
.tooltip .pos { margin-top: .25rem; font-variant-numeric: tabular-nums; }

.howto { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.2rem; margin-bottom: 1.4rem; }
.howto h2 { margin-top: 0; font-size: 1.05rem; }
.howto p { font-size: .92rem; color: #333; }

footer { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem;
  color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); }
footer a { color: var(--accent); }
.disclaimer { font-style: italic; }

.dot-mp.selected { stroke: #000; stroke-width: 2; }

/* ---- profile panel ---- */
.profile {
  position: fixed; top: 0; right: 0; height: 100%; width: 360px; max-width: 90vw;
  background: var(--card); box-shadow: -4px 0 24px rgba(0,0,0,.15);
  padding: 1.2rem 1.3rem; overflow-y: auto; z-index: 50;
  transform: translateX(100%); transition: transform .22s ease;
}
.profile[hidden] { display: block; }       /* keep rendered; off-screen until .open */
.profile.open { transform: translateX(0); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 40; }

.profile .close { position: absolute; top: .5rem; right: .8rem; border: none;
  background: none; font-size: 1.7rem; line-height: 1; cursor: pointer; color: #999; }
.profile .close:hover { color: #000; }
.profile h2 { margin: .2rem 0 .5rem; font-size: 1.3rem; padding-right: 1.6rem; }
.profile h3 { margin: 1.2rem 0 .4rem; font-size: .9rem; color: var(--muted); }
.club-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem;
  padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 999px; }
.club-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.big-pos { font-size: 2.2rem; font-weight: 700; margin: .8rem 0 .2rem; font-variant-numeric: tabular-nums; }
.big-pos .ci { display: block; font-size: .72rem; font-weight: 400; color: var(--muted); }
#mini-axis { width: 100%; margin: .3rem 0 .5rem; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: .35rem .8rem; margin: .6rem 0; font-size: .9rem; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.stats .muted { color: var(--muted); font-weight: 400; font-size: .8rem; }
.stats .ok { color: #1a9850; } .stats .warn { color: #d73027; }
.neighbors { list-style: none; padding: 0; margin: .2rem 0 0; }
.neighbors li { display: flex; align-items: center; gap: .5rem; padding: .4rem .3rem;
  border-radius: 6px; cursor: pointer; font-size: .9rem; }
.neighbors li:hover { background: #f2f2f2; }
.neighbors .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.neighbors .nm { flex: 1; }
.neighbors .nx { color: var(--muted); font-variant-numeric: tabular-nums; }

.hist-btn { width: 100%; margin: .6rem 0 .2rem; padding: .6rem; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; border-radius: 8px; cursor: pointer; font-size: .92rem; }
.hist-btn:hover { opacity: .92; }

/* ---- voting history modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 2vh 1rem; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 12px; width: 100%; max-width: 880px;
  max-height: 92vh; display: flex; flex-direction: column; padding: 1.1rem 1.3rem; position: relative; }
.modal-card h2 { margin: 0 1.6rem .6rem 0; font-size: 1.15rem; }
.modal-card .close { position: absolute; top: .4rem; right: .7rem; border: none; background: none;
  font-size: 1.7rem; line-height: 1; cursor: pointer; color: #999; }
.modal-card .close:hover { color: #000; }
.loading { padding: 2rem; color: var(--muted); text-align: center; }
.hist-controls { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.hist-controls #hist-search { flex: 1 1 220px; padding: .45rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: .95rem; }
.hist-list { overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.hist-item { border-bottom: 1px solid #eee; }
.hist-row { display: grid; grid-template-columns: 84px 128px 1fr; gap: .6rem;
  padding: .55rem .2rem; align-items: start; }
.bd-toggle { border: none; background: none; color: var(--accent); cursor: pointer;
  font-size: .78rem; padding: 0; }
.bd-toggle:hover { text-decoration: underline; }
.bd-wrap svg { width: 100%; display: block; margin: .2rem 0; background: #fbfbfb; border-radius: 6px; }
.bd-cap { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; font-size: .76rem;
  color: var(--muted); padding: 0 .2rem .6rem; }
.bd-cap .k { display: inline-flex; align-items: center; gap: .3rem; }
.bd-cap .k i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.bd-cap .coh { margin-left: auto; font-weight: 600; color: #333; }
.hr-date { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.hr-votes { display: grid; grid-template-columns: auto 1fr; gap: .15rem .3rem; align-items: center; }
.hr-lab { font-size: .66rem; color: var(--muted); text-transform: uppercase; }
.hr-title { font-weight: 600; font-size: .88rem; }
.hr-topic { font-size: .82rem; color: #444; margin: .1rem 0; }
.hr-result { font-size: .78rem; color: var(--muted); }
.hr-result .za { color: #1a9850; } .hr-result .pr { color: #d73027; }
.hr-result a { color: var(--accent); }
.badge { display: inline-block; padding: .08rem .4rem; border-radius: 5px; font-size: .72rem; font-weight: 600; }
.badge.za { background: #e3f4e4; color: #1a7a34; }
.badge.pr { background: #fbe3e3; color: #c0392b; }
.badge.ab { background: #fff3d6; color: #9a6a00; }
.badge.none { background: #eee; color: #999; }
.tag { background: #eee; color: #777; padding: .05rem .35rem; border-radius: 4px; font-size: .7rem; }
.hist-more { text-align: center; padding-top: .6rem; }
.hist-more button { padding: .45rem 1rem; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; cursor: pointer; }

@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .hist-row { grid-template-columns: 1fr; gap: .25rem; }
  .hr-votes { grid-template-columns: auto auto auto auto; }
}
