:root {
  --bg: #f7f3eb;
  --bg2: #efe8dc;
  --panel: #fffcf6;
  --line: #d8c7ad;
  --ink: #24190f;
  --muted: #6f5b46;
  --accent: #b7461f;
  --accent-soft: #ffe8da;
  --good: #1f8f52;
  --warn: #b77a1f;
  --bad: #a51f1f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 16px;
  font-family: "Sora", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg), var(--bg2));
}

main {
  max-width: 1500px;
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.hero, .panel {
  max-width: 1500px;
  margin: 0 auto;
}

.hero {
  padding: 8px 2px 2px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(1.4rem, 2.1vw, 2.2rem);
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.source-note {
  margin-top: 8px;
  color: #5f4834;
  font-size: 12px;
  line-height: 1.4;
}

.source-note p {
  margin: 2px 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 2px 12px rgba(91, 56, 23, 0.07);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px;
}

.kpi {
  background: #fff6ee;
  border: 1px solid #eacfb2;
  border-radius: 10px;
  padding: 8px 10px;
}

.kpi .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.kpi .value {
  margin-top: 4px;
  font-size: 1.35rem;
  font-weight: 700;
  color: #5d2d10;
}

.view-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  background: #fff7ee;
  color: #5a3b22;
  border-radius: 999px;
  padding: 6px 10px;
  font: 600 12px "Sora", sans-serif;
  cursor: pointer;
}

.tab.active {
  background: #b7461f;
  border-color: #9d3918;
  color: #fff;
}

[data-section-pane][hidden] {
  display: none !important;
}

.filters {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, 1fr);
  gap: 8px;
}

input, select {
  width: 100%;
  border: 1px solid #dcbfa2;
  background: #fff;
  color: #3a2515;
  border-radius: 8px;
  padding: 9px 10px;
  font: 500 14px "Sora", sans-serif;
}

input::placeholder {
  color: #90755d;
}

.split-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 12px;
}

.detail-panel {
  min-width: 0;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.table-head h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.table-head span {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
}

.table-wrap-main {
  max-height: 78vh;
}

.table-wrap-detail {
  max-height: 78vh;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th, td {
  border-top: 1px solid #ecdac5;
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #fff5e9;
  color: #775b43;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:nth-child(even) {
  background: #fffcf7;
}

tbody tr:hover {
  background: #fff1e1;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row.selected {
  background: #ffe4c7 !important;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

.party-with-logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

.party-logo {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #e1c7a9;
  background: #fff;
}

.party-inline-paren {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  vertical-align: middle;
  white-space: nowrap;
}

.loc-link {
  color: #8f2d07;
  text-decoration: underline;
  font-weight: 600;
}

.loc-link:hover {
  color: #b7461f;
}

.form-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 4px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 600;
}

.form-chip.constituency {
  background: #e5f4e8;
  color: #165a34;
  border-color: #badfca;
}

.form-chip.party_list {
  background: #fff1df;
  color: #7a4b1c;
  border-color: #e8cda8;
}

.compare-meta {
  font-size: 12px;
  color: #694d33;
  margin-bottom: 6px;
}

.skew-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid #ead5bd;
  border-radius: 8px;
  background: #fff6ea;
  font-size: 12px;
  color: #513723;
}

.diff-pos {
  color: #a51f1f;
  font-weight: 700;
}

.diff-neg {
  color: #185fb0;
  font-weight: 700;
}

.skew-map {
  width: 100%;
  height: 560px;
  border: 1px solid #d8c7ad;
  border-radius: 12px;
  overflow: hidden;
  background: #f8efe2;
}

.skew-map .leaflet-container {
  background: #f8efe2;
}

.map-legend {
  background: rgba(255, 249, 239, 0.95);
  border: 1px solid #d8c7ad;
  color: #402a18;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.3;
}

.map-legend .row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.map-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

@media (max-width: 1100px) {
  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body {
    padding: 10px;
  }
  .filters {
    grid-template-columns: 1fr;
  }
  .table-wrap-main,
  .table-wrap-detail {
    max-height: 58vh;
  }
  .skew-map {
    height: 420px;
  }
}
