:root {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #0f172a;
  background: #e9edf7;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% -10%, #f8fbff 0%, #dfe7fb 45%, #c8d4f4 100%);
  color: #0f172a;
}

.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.98);
  color: #f8fafc;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.4);
  transform: translate(-50%, -120%);
  transition: opacity 0.15s ease;
  opacity: 0;
  z-index: 20;
}

.chart-tooltip[data-show="true"] {
  opacity: 1;
}

.chart-tooltip.hidden {
  opacity: 0;
}

.chart-tooltip strong {
  display: block;
  font-size: 0.78rem;
  color: #cbd5f5;
  margin-bottom: 0.15rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chart-tooltip .dataset {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 0.1rem;
}

.chart-tooltip span {
  font-size: 1rem;
  font-weight: 600;
}

.chart-tooltip .mini {
  font-size: 0.8rem;
  opacity: 0.8;
  display: block;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem clamp(1.25rem, 4vw, 3rem) 3rem;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.5rem;
  align-items: flex-end;
}

.eyebrow {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  color: #64748b;
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.75rem);
}

.lede {
  margin: 0.35rem 0 0;
  max-width: 52ch;
  color: #475569;
  font-size: 1rem;
}

.hero-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.badge.success {
  background: rgba(16, 185, 129, 0.16);
  color: #047857;
}

.badge.muted {
  background: rgba(15, 23, 42, 0.08);
  color: #475569;
}

.controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: flex-end;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(15, 30, 70, 0.08);
  backdrop-filter: blur(6px);
}

.control-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  color: #475569;
  gap: 0.25rem;
}

select,
button {
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #cbd5f5;
  min-width: 160px;
  font-family: inherit;
}

select {
  appearance: none;
  background: white
    url('data:image/svg+xml,%3Csvg width="12" height="8" viewBox="0 0 12 8" xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d="M1 1.5L6 6.5L11 1.5" stroke="%231d4ed8" stroke-width="1.5" stroke-linecap="round"/%3E%3C/svg%3E')
    no-repeat right 0.85rem center;
  background-size: 12px;
  font-weight: 500;
}

button {
  background: #2563eb;
  border: none;
  color: white;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding-inline: 1.75rem;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 12px 25px rgba(37, 99, 235, 0.35);
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(37, 99, 235, 0.4);
  color: #2563eb;
  box-shadow: none;
  padding-inline: 1.25rem;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 30px rgba(37, 99, 235, 0.45);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 10px 18px rgba(37, 99, 235, 0.4);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: stretch;
}

.summary-row .province-coverage {
  flex: 0 1 260px;
  margin: 0;
}

.summary-row .insights {
  flex: 1 1 420px;
  margin: 0;
}

@media (max-width: 900px) {
  .summary-row {
    flex-direction: column;
  }
  .summary-row .province-coverage {
    flex: 1 1 auto;
  }
}

.insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.province-coverage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  margin: 0;
}

.province-coverage.is-hidden {
  display: none;
}

.province-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 14px;
  padding: 0.75rem 1rem 0.85rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.province-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.5rem;
}

.province-card__head span {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
}

.province-card__head strong {
  font-size: 1.35rem;
  line-height: 1;
}

.province-card__stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem 0.6rem;
}

.province-card__stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: #475569;
}

.province-card__stat span:first-child {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.province-card.is-active {
  border-color: rgba(37, 99, 235, 0.4);
  box-shadow: 0 18px 30px rgba(37, 99, 235, 0.2);
}

.insight-card {
  background: white;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.insight-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.insight-card strong {
  font-size: 1.35rem;
  display: block;
}

.insight-card span {
  font-size: 0.85rem;
  color: #0f172a;
}

.delta-positive {
  color: #16a34a;
}

.delta-negative {
  color: #dc2626;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 1rem 1.2rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  border: 1px solid rgba(15, 23, 42, 0.04);
}

.cards .card p {
  margin: 0;
  font-size: 0.9rem;
  color: #64748b;
}

.cards .card strong {
  display: block;
  margin-top: 0.4rem;
  font-size: 1.35rem;
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.panels-national {
  margin-top: 0.5rem;
}

.panels-regional {
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1rem;
}

.panels-local {
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  padding-top: 1rem;
}

.panel {
  background: white;
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.09);
  border: 1px solid rgba(148, 163, 184, 0.2);
  min-height: 320px;
  position: relative;
}

.panel-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.panel-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel-actions input[type="search"] {
  border: 1px solid #cbd5f5;
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  min-width: 240px;
}

.panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
}

.muted-text {
  font-size: 0.85rem;
  color: #64748b;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

canvas {
  max-height: 280px;
  width: 100%;
}

.panel.hidden {
  display: none;
}

.panel.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: linear-gradient(110deg, rgba(241, 245, 255, 0.85), rgba(99, 102, 241, 0.15), rgba(241, 245, 255, 0.85));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.table-wrapper {
  max-height: 260px;
  overflow-y: auto;
  overflow-x: auto;
}

#wardTable,
#centreTable,
#voterTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#wardTable thead,
#centreTable thead,
#voterTable thead {
  position: sticky;
  top: 0;
  background: #f8fafc;
}

#wardTable th,
#wardTable td,
#centreTable th,
#centreTable td,
#voterTable th,
#voterTable td {
  padding: 0.35rem;
  border-bottom: 1px solid #e2e8f0;
  text-align: right;
}

#wardTable th:first-child,
#wardTable td:first-child,
#wardTable th:nth-child(2),
#wardTable td:nth-child(2),
#centreTable th:first-child,
#centreTable td:first-child,
#voterTable th:first-child,
#voterTable td:first-child {
  text-align: left;
}

#wardTable tbody tr:nth-child(even),
#centreTable tbody tr:nth-child(even),
#voterTable tbody tr:nth-child(even) {
  background: rgba(148, 163, 184, 0.08);
}

#voterTable td:nth-child(2),
#voterTable td:nth-child(3) {
  text-align: center;
}

#voterTable td:nth-child(4) {
  text-align: center;
}

#voterTable td:nth-child(5),
#voterTable td:nth-child(6) {
  text-align: left;
}

@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-status {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .controls {
    padding: 0.75rem;
  }
}

@media (max-width: 1024px) {
  .controls {
    gap: 0.75rem;
  }

  .controls label {
    flex: 1 1 calc(50% - 0.75rem);
    min-width: 200px;
  }

  .control-buttons {
    width: 100%;
    justify-content: flex-start;
  }

  .control-buttons button {
    flex: 1;
  }

  .panels {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

@media (max-width: 640px) {
  .filter-toggle {
    display: inline-block;
  }

  .layout {
    padding: 1.5rem 1rem 2rem;
  }

  .controls {
    flex-direction: column;
  }

  .controls.is-collapsed {
    display: none;
  }

  .controls label,
  .control-buttons button {
    width: 100%;
  }

  button,
  button.ghost {
    width: 100%;
    text-align: center;
  }

  .insights,
  .cards {
    grid-template-columns: 1fr;
  }

  .panels {
    grid-template-columns: 1fr;
  }

  table {
    font-size: 0.85rem;
  }
}
.filter-toggle {
  display: none;
  margin-bottom: 0.5rem;
}
