:root {
  --bg: #17130f;
  --bg-soft: #1c1712;
  --surface: #221b16;
  --surface-2: #2b2119;
  --border: #3a2c22;
  --text: #f3e9df;
  --text-muted: #b3a394;
  --text-faint: #8a7c70;
  --terracotta: #b5563a;
  --terracotta-light: #dd8f6c;
  --terracotta-soft: rgba(181, 86, 58, 0.16);
  --green: #5fbf77;
  --red: #e5726a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

.serif { font-family: 'Source Serif 4', Georgia, serif; }

a { color: var(--terracotta-light); text-decoration: none; }
a:hover { color: var(--terracotta); }

button { font-family: inherit; }

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(140% 90% at 50% -10%, #241b14 0%, #17130f 55%);
}

/* ---- sidenav (desktop) ---- */
.sidenav {
  display: none;
  width: 232px;
  flex-shrink: 0;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
}

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

.logo-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--terracotta); /* replaced by JS with the party-color donut gradient */
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.side-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 28px;
}

.navlink {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
}

.navlink svg { width: 19px; height: 19px; flex-shrink: 0; }

.navlink.active {
  background: var(--terracotta-soft);
  color: var(--terracotta-light);
}

.side-live {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px rgba(138, 124, 112, 0.16);
  flex-shrink: 0;
}

.live-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(95, 191, 119, 0.16);
}

/* ---- shell / topbar (mobile) ---- */
.shell {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 14px;
  flex-shrink: 0;
}

.live {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px calc(88px + env(safe-area-inset-bottom));
}

.view { display: none; flex-direction: column; gap: 16px; }
.view.active { display: flex; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.view-head h1 { min-width: 0; }

h1, h2 { margin: 0; }

.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.card-head h2 { min-width: 0; }

.card h2 { font-size: 16px; font-weight: 600; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

.muted { color: var(--text-muted); }
.small { font-size: 12px; line-height: 1.6; }

.tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-card h2 { font-size: 21px; margin-top: 8px; }
.status-card p { margin: 6px 0 0; font-size: 13px; line-height: 1.5; }

.countdown-card { text-align: center; }
.countdown-value {
  font-size: 34px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 4px;
}
.countdown-card p { margin: 0; }

.progress {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-top: 14px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--terracotta);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ---- donut ---- */
.donut-wrap {
  position: relative;
  width: 176px;
  height: 176px;
  margin: 20px auto 6px;
}

.donut {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--surface-2);
}

.donut-center {
  position: absolute;
  inset: 26px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-number { font-size: 30px; font-weight: 600; line-height: 1; }
.donut-label { font-size: 9px; color: var(--text-faint); letter-spacing: 0.06em; margin-top: 4px; }

.legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

/* ---- bloc chart ---- */
.bloc-card { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }

.bloc-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.bloc-name-right { text-align: right; }

.bloc-track {
  position: relative;
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--surface-2);
  margin-top: 8px;
}
.bloc-seg { height: 100%; }
.bloc-midmarker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 50%;
  width: 2px;
  background: var(--text);
  opacity: 0.55;
}

.bloc-seats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-top: 8px;
}

.bloc-card > p { margin-top: 8px; }

.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.legend-dot { width: 9px; height: 9px; border-radius: 2.5px; flex-shrink: 0; }
.legend-code { font-weight: 600; }
.legend-value { color: var(--text-faint); font-size: 11px; }

/* ---- news (compact, hem) ---- */
.news-compact { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.news-compact-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 14px;
}

.news-source-row { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-faint); }

.news-badge {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  color: #17130f;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.news-compact-title { font-size: 14px; font-weight: 600; line-height: 1.35; }

.dot-sep { width: 2px; height: 2px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }

.linklike {
  border: none;
  background: none;
  padding: 0;
  color: var(--terracotta-light);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.linklike:hover { color: var(--terracotta); }

.teaser { display: flex; gap: 12px; margin-top: 4px; }
.teaser-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--terracotta); margin-top: 5px; flex-shrink: 0; }
.teaser-title { font-size: 14px; font-weight: 600; margin: 3px 0 8px; }

/* ---- resultat ---- */
.results-grid { display: flex; flex-direction: column; gap: 16px; }

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 3px;
}

.seg-btn {
  flex: 1;
  border: none;
  border-radius: 9px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
}

.seg-btn.active { background: var(--terracotta); color: #17130f; }

.party-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.party-row:last-child { border-bottom: none; }

.party-row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.party-id { display: flex; align-items: center; gap: 9px; min-width: 0; }
.party-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.party-code { font-size: 13px; font-weight: 700; flex-shrink: 0; }
.party-name { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.party-value-wrap { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.party-value { font-size: 13px; font-weight: 600; }
.party-diff { display: flex; align-items: center; gap: 2px; font-size: 10px; font-weight: 700; }
.party-diff svg { width: 9px; height: 9px; }

.party-bar-track { width: 100%; height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.party-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }

/* ---- nyheter ---- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }

.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  white-space: nowrap;
}

.chip.active { background: var(--terracotta); color: #17130f; border-color: var(--terracotta); }

.news-list { display: flex; flex-direction: column; gap: 12px; }

.news-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border-radius: 14px;
}

.news-card-title { font-size: 16px; font-weight: 600; line-height: 1.32; color: var(--text); }

.news-card-ingress {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-card-link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--terracotta-light);
}
.news-card-link svg { width: 12px; height: 12px; }

.empty-state { color: var(--text-faint); font-size: 13px; padding: 12px 0; }

/* ---- regeringsbildning ---- */
.infocard {
  background: var(--terracotta-soft);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.infocard svg { width: 18px; height: 18px; color: var(--terracotta-light); flex-shrink: 0; margin-top: 1px; }
.infocard p { margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.55; }

.timeline-row { display: flex; gap: 14px; }
.timeline-marker { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; width: 16px; }
.timeline-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--terracotta); flex-shrink: 0; }
.timeline-dot-pending { background: transparent; border: 2px solid var(--border); }
.timeline-line { width: 2px; flex: 1; background: var(--border); margin-top: 2px; }
.timeline-body { flex: 1; padding-bottom: 22px; min-width: 0; }
.timeline-date { font-size: 11px; color: var(--text-faint); letter-spacing: 0.03em; }
.timeline-title { font-size: 14.5px; font-weight: 600; margin-top: 4px; }
.timeline-source { font-size: 12px; color: var(--text-faint); margin-top: 3px; }
.timeline-note { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin-top: 6px; }

/* ---- bottom nav (mobile) ---- */
.bottomnav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}

.navbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 14px;
  min-height: 44px;
  color: var(--text-faint);
}

.navbtn svg { width: 21px; height: 21px; }
.navbtn span { font-size: 10px; font-weight: 600; }
.navbtn.active { color: var(--terracotta-light); }

/* ---- responsive ---- */
@media (min-width: 1024px) {
  .sidenav { display: flex; }
  .topbar, .bottomnav { display: none; }
  main { padding: 36px 44px; max-width: 1180px; }

  .view-head h1 { font-size: 26px; }
  .card h2 { font-size: 16px; }
  h1.serif { font-size: 26px; font-weight: 600; }

  .results-grid { flex-direction: row; align-items: flex-start; }
  .results-chart { flex: 0 0 320px; display: flex; flex-direction: column; align-items: center; }
  .results-list { flex: 1; padding: 8px 28px; }
  .segmented { width: 100%; }

  .news-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .news-card-ingress { -webkit-line-clamp: 3; }

  #view-bildning .timeline, #view-bildning .infocard { max-width: 640px; }
}
