*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e; color: #e0e0e0;
  height: 100vh; display: flex; flex-direction: column;
}

/* ── Top bar ── */
#topbar {
  display: flex; align-items: center; gap: .6rem 1rem;
  padding: .6rem 1rem;
  background: #16213e; border-bottom: 1px solid #0f3460;
  flex-shrink: 0; flex-wrap: wrap;
}
#topbar h1 { font-size: 1rem; font-weight: 600; color: #e0e0e0; white-space: nowrap; flex-shrink: 0; }
.topbar-controls { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.btn-group { display: flex; gap: .4rem; }
.btn {
  padding: .35rem .9rem; border: 1px solid #0f3460; border-radius: 20px;
  background: #1a1a2e; color: #aaa; cursor: pointer; font-size: .8rem;
  transition: all .15s;
}
.btn:hover  { background: #0f3460; color: #fff; }
.btn.active { background: #e94560; border-color: #e94560; color: #fff; }
#view-toggle .btn { border-radius: 4px; }

/* ── Layout ── */
#main { display: flex; flex: 1; overflow: hidden; }

#left-panel {
  width: 260px; background: #16213e; border-right: 1px solid #0f3460;
  display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0;
}

#map-wrap { flex: 1; position: relative; overflow: hidden; }
#map      { width: 100%; height: 100%; }

/* ── Panel ── */
#panel {
  width: 340px; background: #16213e; border-left: 1px solid #0f3460;
  display: flex; flex-direction: column; overflow: hidden; transition: width .2s;
}
#panel.collapsed { width: 0; }
#panel-inner { padding: 1rem; overflow-y: auto; flex: 1; }
#panel h2 {
  font-size: .95rem; color: #e94560;
  margin-bottom: .8rem; padding-bottom: .4rem; border-bottom: 1px solid #0f3460;
}
#panel h3 { font-size: .85rem; color: #aaa; margin: .8rem 0 .3rem; }

.bv-meta { font-size: .8rem; color: #888; margin-bottom: .6rem; }
.bv-stats-row {
  display: flex; gap: .8rem; font-size: .76rem; color: #6af;
  margin-bottom: .5rem; flex-wrap: wrap;
}

/* ── Candidate rows ── */
.candidate {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .5rem; border-radius: 5px; margin-bottom: .25rem;
  background: #1a1a2e; font-size: .82rem;
  cursor: pointer; transition: background .12s, border-color .12s;
  border: 1.5px solid transparent;
}
.candidate:hover        { background: #1f2a45; }
.candidate.winner       { background: #0f3460; }
.candidate.winner:hover { background: #163880; }
.candidate.sel          { border-color: #fff; }
.candidate.abstention   { border-top: 1px solid #2a3a5e; margin-top: .4rem; }

.candidate .dot   { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.candidate .info  { flex: 1; min-width: 0; }
.candidate .name  { font-weight: 600; color: #e0e0e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.candidate .list  { color: #888; font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.candidate .votes { text-align: right; font-weight: 600; color: #e94560; white-space: nowrap; flex-shrink: 0; }
.candidate .pct   { font-size: .75rem; color: #888; font-weight: 400; }

.bar-wrap { margin: .2rem 0 0; }
.bar-bg   { background: #1f2a45; border-radius: 3px; height: 6px; }
.bar-fill { height: 6px; border-radius: 3px; transition: width .3s; }

.sel-check { color: #fff; font-size: .9rem; flex-shrink: 0; margin-left: .2rem; }

.btn-clear-sel {
  display: block; width: 100%; margin-bottom: .6rem;
  padding: .3rem; font-size: .78rem; cursor: pointer;
  background: #2a1a2e; border: 1px solid #e94560; border-radius: 4px;
  color: #e94560; text-align: center; transition: background .12s;
}
.btn-clear-sel:hover { background: #3a1a2e; }

/* ── Legend ── */
#legend {
  padding: .8rem .9rem; flex: 1;
}
#legend h4 { color: #e0e0e0; margin-bottom: .5rem; font-size: .8rem; }
.legend-item {
  display: flex; align-items: center; gap: .5rem;
  margin: .2rem 0; padding: .25rem .3rem; border-radius: 4px;
  cursor: pointer; transition: background .12s;
  border: 1px solid transparent;
}
.legend-item:hover { background: #1f2a45; }
.legend-item.sel   { border-color: rgba(255,255,255,.4); background: #1a2a3e; }
.legend-dot        { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; transition: box-shadow .15s; }
.legend-info       { flex: 1; min-width: 0; }
.legend-label      { display: block; font-size: .78rem; color: #e0e0e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-score      { display: block; font-size: .72rem; color: #6af; margin-top: .1rem; }
.legend-item .sel-check { font-size: .8rem; color: #fff; flex-shrink: 0; }

/* ── Loading / Error ── */
#loading {
  position: absolute; inset: 0; background: rgba(26,26,46,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; font-size: 1.1rem; color: #aaa;
}
#loading.hidden { display: none; }
.no-data { color: #555; font-size: .82rem; font-style: italic; }

/* ── Half-donut political split ── */
.half-donut-wrap { margin: .4rem 0 .6rem; }
.half-donut-wrap svg { display: block; width: 100%; overflow: visible; }
.donut-legend {
  display: flex; justify-content: space-around;
  font-size: .76rem; font-weight: 600; margin-top: .1rem;
}

/* ── Candidate readonly (non-current tour) ── */
.candidate.readonly { cursor: default; opacity: 0.65; }
.candidate.readonly:hover { background: #1a1a2e; }
.candidate.winner.readonly:hover { background: #0f3460; }

/* ── Transferts analysis block ── */
.transferts-block {
  background: #12192e; border: 1px solid #e94560;
  border-radius: 5px; padding: .6rem .8rem; margin-bottom: .8rem; font-size: .8rem;
}
.transferts-title {
  font-size: .78rem; font-weight: 700; color: #e94560;
  margin-bottom: .5rem; text-transform: uppercase; letter-spacing: .04em;
}
.transferts-winner {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem .4rem; border-radius: 4px; border: 1px solid;
  margin-bottom: .4rem; font-size: .8rem; font-weight: 600;
}
.transferts-winner .t-votes { margin-left: auto; color: #e94560; }
.transferts-row {
  display: flex; justify-content: space-between; gap: .5rem;
  padding: .2rem 0; border-bottom: 1px solid #1f2a45; color: #aaa;
}
.transferts-row .t-label { flex: 1; }
.transferts-row .t-val   { font-weight: 600; color: #e0e0e0; white-space: nowrap; }
.transferts-row.highlight { color: #ff6b35; font-weight: 700; border-color: #ff6b35; }
.transferts-row.highlight .t-val { color: #ff6b35; }
.transferts-row.ok-row .t-label  { color: #4f4; }
.transferts-row.ok-row .t-val    { color: #4f4; }
.transferts-note {
  margin-top: .4rem; font-size: .72rem; color: #ff6b35; font-style: italic;
}

/* ── Responsive: mobile / portrait ── */
@media (max-width: 767px) {
  body { height: auto; min-height: 100vh; }

  #topbar { gap: .4rem .7rem; padding: .5rem .75rem; }
  #topbar h1 { font-size: .9rem; width: 100%; }
  .topbar-controls { gap: .4rem; }
  #panel-toggle { display: none; }

  #main {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
  }

  #left-panel { display: none; }

  #map-wrap {
    width: 100%;
    height: 50vh;
    min-height: 240px;
    flex: none;
  }

  #panel {
    width: 100% !important;
    border-left: none;
    border-top: 1px solid #0f3460;
    overflow: visible;
    flex: none;
  }
  #panel-inner { overflow-y: visible; }
}

/* ── MapLibre overrides ── */
.maplibregl-popup-content {
  background: #16213e; color: #e0e0e0;
  border: 1px solid #0f3460; border-radius: 6px;
  padding: .7rem; font-size: .82rem; max-width: 220px;
}
.maplibregl-popup-tip { border-top-color: #16213e !important; }
