:root {
  --navy: #1b365d;
  --navy-deep: #12243f;
  --red: #c8102e;
  --gold: #c9a227;
  --gold-soft: #f6e7b5;
  --blue-soft: #e8eef6;
  --blue-mid: #d5deee;
  --ink: #1a1a1a;
  --muted: #5a6570;
  --green: #1f7a4d;
  --green-soft: #e6f4ec;
  --line: #c5cdd8;
  --bg: #f4f6fa;
  --white: #ffffff;
  --rank1: #f5c518;
  --rank2: #c5ced8;
  --rank3: #e0b089;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; }
body {
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  background: var(--white);
  color: var(--ink);
  min-height: 100vh;
}
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

.stripe { height: 8px; background: var(--red); }
.topbar {
  background: var(--navy);
  color: white;
  padding: 16px 20px 12px;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; }
.topbar .sub { color: var(--gold-soft); font-style: italic; margin-top: 4px; font-size: 13px; }
.meta-line { color: #d5deee; font-size: 12px; margin-top: 8px; }

.nav {
  background: var(--navy-deep);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 8px 16px;
}
.nav a, .nav .drop > span {
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  display: inline-block;
}
.nav a:hover, .nav .drop:hover > span { background: #1b365d; text-decoration: none; }
.nav a.active { background: var(--gold); color: var(--navy-deep); }
.nav .drop { position: relative; }
.nav .drop .menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  z-index: 20;
}
.nav .drop:hover .menu { display: block; }
.nav .drop .menu a { color: var(--navy); display: block; font-weight: 600; }
.nav .drop .menu a:hover { background: var(--blue-soft); }

.search {
  margin-left: auto;
  display: flex;
  gap: 6px;
}
.search input {
  border: 0;
  border-radius: 4px;
  padding: 7px 10px;
  min-width: 220px;
}
.search button, .btn {
  background: var(--gold);
  color: var(--navy-deep);
  border: 0;
  border-radius: 4px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}
.btn.secondary { background: white; color: var(--navy); border: 1px solid var(--line); }
.btn.danger { background: var(--red); color: white; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 16px; }
.actions a { text-decoration: none; }

.wrap { width: 100%; max-width: none; margin: 0; padding: 12px 16px 28px; }
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 0 0 12px;
  border: 1px solid var(--line);
}
.kpi {
  background: var(--blue-soft);
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 14px 12px;
  text-align: center;
}
.kpi:last-child { border-right: 0; }
.kpi:first-child { background: var(--gold-soft); }
.kpi .lbl { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .4px; }
.kpi .val { font-size: 22px; font-weight: 800; color: var(--navy); margin-top: 4px; }

.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0;
  margin-bottom: 12px;
  overflow: auto;
}
.card h2 {
  margin: 0;
  font-size: 16px;
  color: white;
  background: var(--navy);
  padding: 10px 14px;
  border-radius: 0;
}
.card > p,
.card > ul {
  margin: 10px 14px;
}
.muted { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 12px; }
@media (max-width: 900px) {
  .kpis, .grid-2 { grid-template-columns: 1fr; }
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); }
  .kpi:last-child { border-bottom: 0; }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
th {
  background: var(--navy-deep);
  color: white;
  padding: 8px;
  text-align: left;
  position: sticky;
  top: 0;
}
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:nth-child(even) td { background: #f7f9fc; }
tr.r1 td { background: var(--rank1); font-weight: 700; }
tr.r2 td { background: var(--rank2); font-weight: 700; }
tr.r3 td { background: var(--rank3); font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ranking { table-layout: fixed; }
.ranking col.c-rank, .ranking col.c-no { width: 56px; }
.ranking col.c-votes { width: 110px; }
.ranking col.c-share { width: 90px; }
.ranking col.c-party { width: 22%; }
.ranking th.c-rank, .ranking td.c-rank,
.ranking th.c-no, .ranking td.c-no { text-align: center; font-variant-numeric: tabular-nums; }
.ranking th.c-name, .ranking td.c-name { text-align: left; }
.ranking th.c-party, .ranking td.c-party { text-align: left; }
.ranking th.c-votes, .ranking td.c-votes,
.ranking th.c-share, .ranking td.c-share { text-align: right; font-variant-numeric: tabular-nums; }
.swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  align-self: center;
}
.actions .pill { padding: 8px 12px; font-size: 12px; }
.ok { background: var(--green-soft); color: var(--green); }
.no { background: #f4c7c3; color: #8a1f11; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.province-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0;
}
.province-cards a {
  display: block;
  background: var(--blue-soft);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 14px;
  color: inherit;
  text-decoration: none;
}
.province-cards a:hover { background: var(--gold-soft); }
.province-cards h3 { margin: 0 0 6px; color: var(--navy); }
.chart-box { height: min(58vh, 560px); min-height: 320px; position: relative; padding: 10px 14px 16px; }
.bar-cell {
  height: 10px;
  background: var(--navy);
  border-radius: 2px;
}
.footer {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0 16px;
}
details.barangay { margin: 0; border: 0; border-bottom: 1px solid var(--line); background: white; border-radius: 0; }
details.barangay summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  color: var(--navy);
}
details.barangay table { margin: 0; }

.muni-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}
.muni-switch select {
  padding: 7px 10px;
  min-width: 240px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 600;
}
.jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
  position: sticky;
  top: 0;
  z-index: 12;
  background: white;
  padding: 8px 0;
}
.jump a {
  background: var(--navy);
  color: white;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.jump a:hover { background: var(--gold); color: var(--navy-deep); text-decoration: none; }
.matrix-block { margin-bottom: 28px; }
.matrix-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--navy);
  color: white;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 14px;
}
.matrix-title .right { color: var(--gold-soft); font-weight: 700; letter-spacing: .3px; }
.matrix-scroll {
  overflow: auto;
  max-height: calc(100vh - 120px);
  border: 1px solid var(--line);
  border-top: 0;
  background: white;
}
.matrix {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  white-space: nowrap;
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}
.matrix col.col-no { width: 52px; }
.matrix col.col-name { width: 280px; }
.matrix col.col-total { width: 108px; }
.matrix col.col-precinct { width: 84px; }
.matrix th, .matrix td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  background: white;
  overflow: hidden;
  text-overflow: ellipsis;
}
.matrix thead th {
  position: sticky;
  z-index: 5;
  background: var(--navy);
  color: white;
  font-weight: 700;
}
.matrix thead tr:nth-child(1) th { top: 0; height: 28px; }
.matrix thead tr:nth-child(2) th { top: 28px; height: 28px; }
.matrix thead tr:nth-child(3) th { top: 56px; height: 26px; }
.matrix thead th.brgy { background: var(--navy-deep); text-align: center; }
.matrix thead th.pid { font-size: 11px; text-align: center; background: #243f68; }
.matrix thead th.pid a { color: var(--gold-soft); }
.matrix thead th.votes-lbl { font-size: 10px; letter-spacing: .3px; text-align: center; background: #1b365d; color: var(--gold-soft); }
.matrix .sticky-1, .matrix .sticky-2, .matrix .sticky-3, .matrix .sticky-span {
  position: sticky;
  z-index: 4;
  background: white;
}
.matrix .sticky-1 { left: 0; text-align: center; }
.matrix .sticky-2 { left: 52px; }
.matrix .sticky-3 { left: 332px; box-shadow: 4px 0 8px rgba(0,0,0,.08); }
.matrix .sticky-span { left: 0; z-index: 8; background: var(--navy); text-align: left; box-shadow: 4px 0 8px rgba(0,0,0,.08); }
.matrix thead th.sticky-1,
.matrix thead th.sticky-2,
.matrix thead th.sticky-3 {
  z-index: 8;
  background: var(--navy);
}
.matrix td.name { text-align: left; font-weight: 600; }
.matrix td.total { font-weight: 800; background: var(--gold-soft); text-align: right; }
.matrix thead th.sticky-3 { background: var(--navy); text-align: right; }
.matrix tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.matrix td.g1 { background: #eef3f9; }
.matrix .miss { background: #f8e0dd !important; color: #8a1f11; }
.matrix tbody tr:hover td { filter: brightness(0.97); }
.matrix tbody tr:hover td.sticky-1,
.matrix tbody tr:hover td.sticky-2,
.matrix tbody tr:hover td.sticky-3 { filter: none; background: #fff8dc; }

