:root {
  --bg: #eee9df;
  --panel: #fbfaf7;
  --panel-strong: rgba(255, 255, 255, 0.76);
  --text: #172033;
  --muted: #566274;
  --line: #ded8cf;
  --line-soft: #e9e3da;
  --accent: #274e13;
  --accent-soft: #e7efdf;
  --radius: 7px;
  font-family: montserrat, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(100deg, #07192f 0%, #0a2038 58%, #0c2a46 100%);
  color: #fffdf8;
}

.eyebrow,
.section-label {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fffdf8;
  font-size: clamp(1.85rem, 2.5vw, 2.55rem);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.035em;
}

.topbar-title {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-logo {
  display: block;
  width: auto;
  max-width: 118px;
  max-height: 58px;
  object-fit: contain;
}

.subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}


.control-group {
  display: grid;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

select,
input,
button {
  font: inherit;
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--text);
  outline: none;
}

select {
  min-height: 42px;
  padding: 10px 34px 10px 11px;
  cursor: pointer;
}

input {
  padding: 10px 11px;
}

select:focus,
input:focus {
  border-color: #6e8065;
  box-shadow: 0 0 0 2px rgba(39, 78, 19, 0.12);
}

button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #e8e3d9;
  color: var(--text);
  padding: 9px 13px;
  font-weight: 650;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: #ddd7cc;
}

.layout {
  position: relative;
  isolation: isolate;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(380px, 25vw) minmax(0, 1fr);
}

.panel {
  position: relative;
  z-index: 20;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.92);
}

.summary-card,
.search-card,
.detail-card,
.rank-card {
  background: var(--panel-strong);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: 0 1px 12px rgba(23, 32, 51, 0.06);
  padding: 14px;
  margin-bottom: 12px;
  backdrop-filter: blur(3px);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.kpi {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 11px;
  background: #f4f0e8;
}

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.kpi strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

#clearButton {
  background: #e8e3d9;
  color: var(--text);
}

.detail-card h2 {
  margin: 0 0 12px;
  font-size: 1.12rem;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.turnout-hero {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.turnout-hero span {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.turnout-hero small {
  color: var(--muted);
  font-weight: 600;
}

.detail-list {
  margin: 0;
}

.detail-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.detail-list div:last-child {
  border-bottom: 0;
}

.detail-list div[hidden] {
  display: none;
}

dt {
  color: var(--muted);
  font-size: 0.84rem;
}

dd {
  margin: 0;
  font-weight: 650;
  text-align: right;
}

.rank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.record-count {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
}

.data-table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  background: rgba(255,255,255,0.44);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0;
  border-bottom: 1px solid var(--line);
  background: #f8f5ee;
  text-align: left;
}

.data-table thead th:last-child {
  width: 34%;
  text-align: right;
}

.table-sort-button {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  box-shadow: none;
}

.data-table thead th:last-child .table-sort-button {
  text-align: right;
}

.table-sort-button.is-active {
  color: var(--text);
}

.data-table tbody tr {
  cursor: pointer;
}

.data-table tbody tr:hover {
  background: rgba(106, 168, 79, 0.10);
}

.data-table tbody tr.is-selected {
  background: rgba(23, 32, 51, 0.08);
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  line-height: 1.2;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table td:first-child {
  font-weight: 650;
}

.data-table td:last-child {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.source-note {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
  margin: 12px 3px 0;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #eef4f3;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #eef4f3;
}

.atlas-map-controls {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 760;
  display: grid;
  gap: 8px;
}

.map-tool-group {
  display: grid;
  width: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fffdf8;
  overflow: hidden;
}

.map-tool-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: #fffdf8;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
}

.map-tool-button:last-child {
  border-bottom: 0;
}

.map-tool-button:hover,
.map-tool-button:focus-visible {
  background: #f1ede5;
}

.map-tool-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.map-hover-label {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 720;
  max-width: min(320px, calc(100% - 20px));
  padding: 5px 7px;
  border: 1px solid #1e2a3a;
  border-radius: 3px;
  background: #fffdf8;
  color: var(--text);
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.2;
  pointer-events: none;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.map-hover-label[hidden] {
  display: none;
}

.map-loading {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 700;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--muted);
  font-weight: 650;
}

.legend {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 700;
  min-width: 218px;
  padding: 12px;
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: none;
  border: 1px solid var(--line);
}

.legend-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.legend-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: 0.81rem;
  color: var(--text);
}

.legend-swatch {
  width: 22px;
  height: 13px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.16);
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: none;
  border: 1px solid var(--line);
}

.leaflet-popup-tip {
  box-shadow: none;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 700;
}

.popup-stat {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 5px 0;
}

.popup-stat span:first-child {
  color: var(--muted);
}

.popup-stat strong {
  font-weight: 650;
}

.ta-tooltip {
  padding: 4px 7px;
  border: 1px solid #1e2a3a;
  border-radius: 3px;
  background: #fffdf8;
  color: var(--text);
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 650;
}

.ta-tooltip::before {
  display: none;
}

.no-data {
  fill: #d8d3cb;
}

.leaflet-ta-pane {
  z-index: 430 !important;
}

.leaflet-outline-pane {
  z-index: 650 !important;
}
/* Keep Leaflet clipped to the map column without resizing its internal SVG/canvas.
   Do not set max-width on Leaflet panes or SVGs: that breaks Leaflet's
   coordinate maths and makes hover/click hit-testing drift away from polygons. */
.leaflet-container {
  overflow: hidden !important;
}

.leaflet-pane,
.leaflet-map-pane,
.leaflet-pane > svg,
.leaflet-pane > canvas {
  max-width: none !important;
}

.leaflet-zoom-box {
  display: none !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius) !important;
  box-shadow: none !important;
}

.leaflet-control-zoom a {
  background: #fffdf8 !important;
  color: var(--text) !important;
}

.leaflet-control-attribution {
  border: 1px solid var(--line) !important;
  background: rgba(255, 253, 248, 0.92) !important;
  color: var(--muted) !important;
  box-shadow: none !important;
}

.leaflet-interactive {
  cursor: pointer;
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { min-height: 100vh; height: auto; }
  .topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(100deg, #07192f 0%, #0a2038 58%, #0c2a46 100%);
  color: #fffdf8;
}
    .layout { grid-template-columns: 1fr; }
  .panel {
  position: relative;
  z-index: 20;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.92);
}
  .map-wrap { min-height: 62vh; }
  .legend { left: 14px; right: auto; bottom: 14px; }
}

/* Popups are disabled in app.js; keep Leaflet popup pane from showing stale/broken click cards if a cached layer tries to open one. */
.leaflet-popup-pane { display: none; }


/* Floating map filters */
.map-floating-filters {
  position: absolute;
  right: 18px;
  bottom: 178px;
  z-index: 710;
  display: grid;
  gap: 8px;
  width: 218px;
  max-width: calc(100% - 36px);
}

.floating-control {
  position: relative;
}

.floating-toggle-button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--text);
  text-align: left;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.2;
}

.floating-toggle-button::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
}

.floating-toggle-button[aria-expanded="true"]::after {
  content: "▴";
}

.floating-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  bottom: auto;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: 0 2px 12px rgba(23, 32, 51, 0.12);
  z-index: 760;
}

.floating-panel[hidden] {
  display: none;
}

.floating-panel-title {
  margin: 2px 4px 8px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.floating-option-list {
  display: grid;
  gap: 4px;
}

.floating-option {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 0.83rem;
  font-weight: 600;
}

.floating-option:hover,
.floating-option:focus-visible {
  background: #f1ede5;
}

.floating-option.is-active {
  background: #ece8dd;
  border-color: var(--line);
}

@media (max-width: 800px) {
  .map-floating-filters,
  .legend {
    right: 12px;
  }

  .map-floating-filters {
    width: 206px;
    bottom: 168px;
  }

  .legend {
    min-width: 206px;
  }
}

.floating-option:disabled {
  color: #8d887e;
  cursor: not-allowed;
  opacity: 0.68;
}

.floating-option:disabled:hover,
.floating-option:disabled:focus-visible {
  background: transparent;
}


/* Right-side map controls and flexible legend */
.map-right-stack {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 710;
  width: 218px;
  max-width: calc(100% - 36px);
  max-height: calc(100% - 36px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.map-right-stack .map-floating-filters,
.map-right-stack .legend {
  pointer-events: auto;
}

.map-right-stack .map-floating-filters {
  position: static;
  right: auto;
  bottom: auto;
  z-index: auto;
  width: 100%;
  max-width: none;
  flex: 0 0 auto;
}

.map-right-stack .legend {
  position: static;
  right: auto;
  bottom: auto;
  z-index: auto;
  width: 100%;
  min-width: 0;
  max-height: min(48vh, 360px);
  overflow-y: auto;
  flex: 0 1 auto;
}

.map-right-stack .legend-title {
  line-height: 1.15;
}

.map-right-stack .legend-row {
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  line-height: 1.18;
}

.map-right-stack .legend-swatch {
  width: 20px;
  margin-top: 1px;
}

.map-right-stack .floating-panel {
  position: static;
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: 0 2px 12px rgba(23, 32, 51, 0.12);
}

@media (max-width: 800px) {
  .map-right-stack {
    right: 12px;
    bottom: 12px;
    width: 206px;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
  }

  .map-right-stack .legend {
    min-width: 0;
    max-height: min(45vh, 320px);
  }
}


@media (max-width: 1200px) {
  .layout {
    grid-template-columns: minmax(430px, 520px) minmax(0, 1fr);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(520px, 36vw) minmax(0, 1fr);
  }
}



/* Artist-impression layout tweaks */
.summary-card {
  display: none;
}

.map-right-stack {
  position: absolute;
  inset: 18px 20px 18px auto;
  z-index: 710;
  width: 230px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  pointer-events: none;
}

.map-floating-filters {
  position: static;
  right: auto;
  bottom: auto;
  width: 100%;
  max-width: none;
  pointer-events: auto;
}

.legend {
  position: static;
  right: auto;
  bottom: auto;
  width: 100%;
  min-width: 0;
  margin-top: auto;
  pointer-events: auto;
  max-height: min(42vh, 360px);
  overflow: auto;
}

.floating-toggle-button {
  min-height: 46px;
  padding: 11px 13px;
  background: rgba(255,255,255,0.88);
  box-shadow: 0 2px 10px rgba(23, 32, 51, 0.10);
}

.search-card {
  margin-top: 0;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: minmax(430px, 42vw) minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 370px minmax(0, 1fr);
  }

  .map-right-stack {
    width: 210px;
    right: 12px;
    top: 12px;
    bottom: 12px;
  }
}


/* Top-right dropdown behaviour */
.floating-control {
  position: relative;
  z-index: 1;
}

.floating-control:has(.floating-toggle-button[aria-expanded="true"]) {
  z-index: 20;
}

.map-floating-filters {
  overflow: visible;
}

.map-right-stack {
  overflow: visible;
}


/* Controlled authority dropdown: avoids stale native-select state after reload. */
.authority-picker {
  position: relative;
  min-width: 0;
}

.authority-picker-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--text);
  text-align: left;
  font-weight: 400;
}

.authority-picker-button::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
}

.authority-picker-button[aria-expanded="true"]::after {
  content: "▴";
}

.authority-picker-button.is-placeholder {
  color: var(--muted);
}

.authority-picker-panel {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  z-index: 900;
  max-height: min(340px, 52vh);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: 0 4px 18px rgba(23, 32, 51, 0.15);
}

.authority-picker-panel[hidden] {
  display: none;
}

.authority-picker-option {
  width: 100%;
  display: block;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 500;
}

.authority-picker-option:hover,
.authority-picker-option:focus-visible {
  background: #f1ede5;
}

.authority-picker-option.is-active {
  background: #ece8dd;
  border-color: var(--line);
}


/* Authority picker should float above the selected-area card */
.search-card {
  position: relative;
  z-index: 80;
}

.search-card:has(.authority-picker-button[aria-expanded="true"]) {
  z-index: 220;
}

.detail-card,
.rank-card {
  position: relative;
  z-index: 1;
}

.authority-picker-panel {
  z-index: 5000;
  max-height: min(420px, 62vh);
}

/* More compact selected-area detail table */
.detail-card {
  padding-top: 12px;
  padding-bottom: 12px;
}

.detail-card h2 {
  margin-bottom: 8px;
}

.turnout-hero {
  margin-bottom: 8px;
  padding-bottom: 9px;
}

.turnout-hero span {
  font-size: 1.75rem;
}

.turnout-hero small {
  font-size: 0.78rem;
}

.detail-list div {
  padding: 5px 0;
  gap: 12px;
}

dt {
  font-size: 0.78rem;
}

dd {
  font-size: 0.82rem;
}



body.about-modal-open {
  overflow: hidden;
}

/* About modal */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-left: auto;
}

.about-button {
  border: 1px solid rgba(255,255,255,0.32);
  background: rgba(255,255,255,0.09);
  color: #fffdf8;
  box-shadow: none;
}

.about-button:hover {
  background: rgba(255,255,255,0.16);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(7, 20, 38, 0.44);
}

.modal-backdrop[hidden] {
  display: none;
}

.about-modal {
  width: min(780px, calc(100vw - 42px));
  max-height: min(820px, calc(100vh - 56px));
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 8px;
  background: #fbfaf7;
  box-shadow: 0 18px 48px rgba(7, 20, 38, 0.28);
  color: var(--text);
}

.about-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8f5ee;
}

.about-modal-header h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

.modal-close-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 5px;
  font-size: 1.35rem;
  line-height: 1;
  box-shadow: none;
}

.about-modal-body {
  max-height: calc(min(820px, 100vh - 56px) - 82px);
  overflow: auto;
  padding: 18px 22px 22px;
}

.about-modal-body p {
  margin: 0 0 13px;
  color: var(--muted);
  line-height: 1.48;
}

.about-modal-body h3 {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 0.86rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.about-modal-body ul {
  margin: 0 0 12px 18px;
  padding: 0;
  color: var(--muted);
  line-height: 1.45;
}

.about-modal-body li + li {
  margin-top: 5px;
}

.about-glossary {
  margin: 0;
  border-top: 1px solid var(--line-soft);
}

.about-glossary div {
  display: grid;
  grid-template-columns: minmax(150px, 0.44fr) minmax(0, 1fr);
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.about-glossary dt {
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 750;
}

.about-glossary dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.38;
  text-align: left;
}

@media (max-width: 720px) {
  .topbar-actions {
    gap: 10px;
  }

  .about-button {
    padding: 8px 10px;
  }

  .about-glossary div {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}



/* Election Services website-style branding refresh.
   Layout and functionality are intentionally unchanged. */
:root {
  --bg: #eef4f3;
  --panel: #ffffff;
  --panel-strong: rgba(255, 255, 255, 0.88);
  --text: #173f47;
  --muted: #6d9188;
  --line: #cfded9;
  --line-soft: #e5eeeb;
  --accent: #156570;
  --accent-soft: #edf7f6;
  --brand-moss: #7CA295;
  --brand-lime: #D6E342;
  --brand-mint: #9CDCD9;
  --brand-aqua: #156570;
}

html,
body {
  background: var(--bg);
}

.topbar {
  min-height: 82px;
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.96), rgba(255,255,255,0.90)),
    url("images/brand_background.png") center 42% / cover no-repeat,
    #ffffff;
  color: var(--text);
  box-shadow: 0 1px 10px rgba(21, 101, 112, 0.08);
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 7px;
  background: url("images/brand_pattern.png") center center / cover no-repeat;
  pointer-events: none;
}

h1 {
  color: var(--brand-aqua);
  font-family: Roboto, "Segoe UI", Arial, sans-serif;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.topbar-logo {
  max-width: 126px;
  max-height: 58px;
  filter: none;
}

.about-button {
  border-color: rgba(124, 162, 149, 0.58);
  background: rgba(255,255,255,0.72);
  color: var(--brand-aqua);
}

.about-button:hover,
.about-button:focus-visible {
  background: var(--accent-soft);
  border-color: var(--brand-aqua);
}

.panel {
  background:
    linear-gradient(rgba(246,250,249,0.92), rgba(246,250,249,0.92)),
    url("images/brand_background.png") left bottom / 760px auto no-repeat;
  border-right-color: var(--line);
}

.summary-card,
.search-card,
.detail-card,
.rank-card,
.legend,
.floating-toggle-button,
.floating-panel,
.authority-picker-panel,
.about-modal {
  border-color: var(--line);
  background-color: rgba(255, 255, 255, 0.90);
  box-shadow: 0 2px 13px rgba(21, 101, 112, 0.08);
}

.summary-card,
.search-card,
.detail-card,
.rank-card {
  background:
    linear-gradient(rgba(255,255,255,0.91), rgba(255,255,255,0.91)),
    url("images/brand_background.png") right bottom / 520px auto no-repeat;
}

.eyebrow,
.section-label,
label,
.legend-title,
.floating-panel-title,
.record-count,
.table-sort-button {
  color: var(--brand-moss);
}

.detail-card h2,
.kpi strong,
.data-table td:first-child,
.floating-toggle-button,
.authority-picker-button,
.about-modal-header h2 {
  color: var(--text);
}

button {
  border-color: var(--line);
}

button:hover,
button:focus-visible {
  border-color: rgba(21, 101, 112, 0.45);
  box-shadow: 0 0 0 2px rgba(156, 220, 217, 0.28);
}

#clearButton {
  border-color: var(--brand-moss);
  background: var(--brand-moss);
  color: #ffffff;
}

#clearButton:hover,
#clearButton:focus-visible {
  background: var(--brand-aqua);
  border-color: var(--brand-aqua);
}

select,
input,
.authority-picker-button {
  border-color: var(--line);
  background: rgba(255,255,255,0.94);
}

select:focus,
input:focus,
.authority-picker-button:focus-visible {
  border-color: var(--brand-aqua);
  box-shadow: 0 0 0 2px rgba(156, 220, 217, 0.35);
}

.turnout-hero {
  border-bottom-color: var(--line);
}

.turnout-hero span {
  color: var(--brand-aqua);
}

.turnout-hero small::before {
  background: var(--brand-aqua);
}

.detail-list div,
.data-table td,
.data-table thead th {
  border-color: var(--line-soft);
}

.data-table thead th,
.about-modal-header {
  background: #f4f8f7;
}

.table-sort-button.is-active,
.data-table td:last-child {
  color: var(--brand-aqua);
}

.data-table tbody tr:hover {
  background: rgba(156, 220, 217, 0.13);
}

.data-table tbody tr.is-selected,
.floating-option.is-active,
.authority-picker-option.is-active,
.authority-picker-option[aria-selected="true"] {
  background: rgba(214, 227, 66, 0.18);
  border-color: rgba(124, 162, 149, 0.34);
}

.floating-option:hover,
.floating-option:focus-visible,
.authority-picker-option:hover,
.authority-picker-option:focus-visible {
  background: rgba(156, 220, 217, 0.16);
}

#map {
  background:
    linear-gradient(rgba(246,250,249,0.86), rgba(246,250,249,0.86)),
    url("images/brand_background.png") center center / cover no-repeat,
    #eef4f3;
}

.leaflet-control-zoom a,
.leaflet-bar a,
.leaflet-control-home {
  color: var(--brand-aqua) !important;
  background: rgba(255,255,255,0.94) !important;
  border-color: var(--line) !important;
}

.leaflet-control-zoom a:hover,
.leaflet-bar a:hover,
.leaflet-control-home:hover {
  background: var(--accent-soft) !important;
}

.ta-tooltip {
  border-color: var(--brand-aqua);
  color: var(--text);
}

.modal-backdrop {
  background: rgba(21, 101, 112, 0.34);
}

.modal-close-button {
  color: var(--brand-aqua);
  background: #ffffff;
}

.about-modal-body h3 {
  color: var(--brand-aqua);
}

.about-glossary dt {
  color: var(--brand-aqua);
}

.source-note {
  color: rgba(23, 63, 71, 0.66);
}



/* Minor brand-refresh fixes */
.topbar {
  padding-top: 25px;
}

.topbar::before {
  height: 14px;
}

/* Keep the About overlay neutral so the app does not turn teal when opened */
.modal-backdrop {
  background: rgba(10, 24, 28, 0.14);
}

/* Make picker panels fully opaque so underlying data does not show through */
.authority-picker-panel {
  background: #ffffff !important;
  backdrop-filter: none !important;
}

.authority-picker-option {
  background: #ffffff;
}

.authority-picker-option.is-active,
.authority-picker-option[aria-selected="true"] {
  background: rgba(214, 227, 66, 0.22);
}

.authority-picker-option:hover,
.authority-picker-option:focus-visible {
  background: rgba(156, 220, 217, 0.22);
}



/* Make About dialog fully opaque */
.about-modal,
.about-modal-body,
.about-modal-header {
  background-image: none !important;
  background-color: #ffffff !important;
  backdrop-filter: none !important;
}

.about-modal-body {
  background: #ffffff !important;
}

.about-glossary,
.about-glossary div {
  background: #ffffff;
}



/* Option A: compact distribution strip under the legend */
.legend-distribution {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line-soft);
}

.legend-distribution-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.legend-distribution-chart-wrap {
  overflow: hidden;
}

.legend-distribution-chart {
  position: relative;
  height: 58px;
  padding-top: 2px;
}

.legend-distribution-bars {
  position: absolute;
  inset: 0 0 10px;
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  gap: 2px;
  align-items: end;
}

.legend-distribution-bars::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  border-bottom: 1px solid rgba(86, 98, 116, 0.22);
}

.legend-distribution-bar {
  display: block;
  min-height: 8px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, rgba(124, 162, 149, 0.68) 0%, rgba(103, 144, 131, 0.92) 100%);
}

.legend-distribution-marker {
  position: absolute;
  top: 0;
  bottom: 10px;
  width: 0;
  pointer-events: none;
}

.legend-distribution-marker-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-left: 2px solid var(--brand-aqua, #2c7b84);
}

.legend-distribution-marker-dot {
  position: absolute;
  left: -4px;
  bottom: -4px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--brand-aqua, #2c7b84);
  border: 2px solid #fffdf8;
  box-shadow: 0 0 0 1px rgba(44, 123, 132, 0.15);
}

.legend-distribution-marker--hover .legend-distribution-marker-line {
  border-left-style: dashed;
  border-left-width: 1px;
  border-left-color: var(--brand-moss, #7ca295);
}

.legend-distribution-marker--hover .legend-distribution-marker-dot {
  background: var(--brand-moss, #7ca295);
  box-shadow: 0 0 0 1px rgba(124, 162, 149, 0.18);
}

.legend-distribution-axis {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
}

.legend-distribution-marker-text {
  margin: 6px 0 0;
  color: var(--text);
  font-size: 0.76rem;
  line-height: 1.25;
}

.legend-distribution-marker-text--hover {
  color: var(--muted);
}



/* Distribution strip: standalone, subtle bottom-left map scale. */
.map-distribution-strip {
  position: absolute;
  left: 22px;
  bottom: 40px;
  z-index: 708;
  width: 168px;
  max-width: calc(100% - 280px);
  pointer-events: none;
  opacity: 0.66;
  transition: opacity 120ms ease;
}

.map-distribution-strip:hover {
  opacity: 0.84;
}

.map-distribution-strip[hidden] {
  display: none;
}

.map-distribution-strip .legend-distribution {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.map-distribution-strip .legend-distribution-title {
  display: none;
}

.map-distribution-strip .legend-distribution-chart-wrap {
  overflow: visible;
}

.map-distribution-strip .legend-distribution-chart {
  height: 30px;
  padding: 0;
}

.map-distribution-strip .legend-distribution-bars {
  inset: 3px 0 1px;
  gap: 1px;
  align-items: end;
}

.map-distribution-strip .legend-distribution-bars::after {
  display: none;
}

.map-distribution-strip .legend-distribution-bar {
  min-height: 0;
  border-radius: 1px 1px 0 0;
  opacity: 0.48;
}

.map-distribution-strip .legend-distribution-bar--empty {
  height: 0 !important;
  opacity: 0 !important;
}

.map-distribution-strip .legend-distribution-axis {
  margin-top: 5px;
  min-height: 11px;
  color: rgba(21, 101, 112, 0.62);
  font-size: 0.52rem;
  font-weight: 650;
  line-height: 1;
}

.map-distribution-strip .legend-distribution-marker {
  top: 3px;
  bottom: 1px;
  transform: translateX(-0.5px);
}

.map-distribution-strip .legend-distribution-marker-line {
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-left: 1px solid rgba(21, 101, 112, 0.72);
  background: none;
}

.map-distribution-strip .legend-distribution-marker-dot {
  left: -3px;
  bottom: -3px;
  width: 6px;
  height: 6px;
  border: 1px solid rgba(255,255,255,0.86);
  background: rgba(21, 101, 112, 0.78);
  box-shadow: 0 0 0 1px rgba(21, 101, 112, 0.20);
}

.map-distribution-strip .legend-distribution-marker--hover .legend-distribution-marker-line {
  border-left: 1px dashed rgba(124, 162, 149, 0.72);
  background: none;
}

.map-distribution-strip .legend-distribution-marker--hover .legend-distribution-marker-dot {
  left: -2px;
  bottom: -2px;
  width: 5px;
  height: 5px;
  border: 1px solid rgba(255,255,255,0.82);
  background: rgba(124, 162, 149, 0.72);
  box-shadow: none;
}

.map-distribution-strip .legend-distribution-marker-text {
  display: none;
}

@media (max-width: 800px) {
  .map-distribution-strip {
    left: 12px;
    bottom: 40px;
    width: 146px;
    max-width: calc(100% - 24px);
  }
}

/* Mobile data-first layout -------------------------------------------------
   Phones get the filters and records first; the map is hidden on mobile. */
.table-title-mobile,
.table-meta,
.table-metric-label {
  display: none;
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow: auto;
    background: #f6faf9;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 2000;
    min-height: 60px;
    gap: 10px;
    padding: 15px 12px 8px;
  }

  .topbar::before {
    height: 7px;
  }

  h1 {
    font-size: 0;
    letter-spacing: 0;
  }

  h1::after {
    content: "NZ Local Election Data Explorer ";
    color: var(--brand-aqua);
    font-size: 1.55rem;
    line-height: 1;
    font-weight: 600;
    letter-spacing: -0.035em;
  }

  .topbar-actions {
    gap: 8px;
  }

  .about-button {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 0.82rem;
  }

  .topbar-logo {
    max-width: 58px;
    max-height: 38px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .map-wrap {
    order: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
    padding: 10px 10px 11px;
    border-bottom: 1px solid var(--line);
    background:
      linear-gradient(rgba(246,250,249,0.96), rgba(246,250,249,0.96)),
      url("images/brand_background.png") right bottom / 520px auto no-repeat,
      #f6faf9;
  }

  .panel {
    order: 2;
    overflow: visible;
    padding: 10px;
    border-right: 0;
    background:
      linear-gradient(rgba(246,250,249,0.94), rgba(246,250,249,0.94)),
      url("images/brand_background.png") left bottom / 560px auto no-repeat,
      #f6faf9;
  }


  .map-right-stack {
    order: 1;
    position: static;
    inset: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    display: block;
    pointer-events: auto;
  }

  .map-floating-filters {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .floating-toggle-button {
    min-height: 42px;
    padding: 10px 11px;
    background: #ffffff;
    box-shadow: 0 1px 7px rgba(21, 101, 112, 0.08);
    font-size: 0.83rem;
  }

  .floating-panel {
    position: static;
    width: 100%;
    margin-top: 6px;
    max-height: 58dvh;
    overflow: auto;
    background: #ffffff !important;
  }

  .floating-option {
    min-height: 36px;
    padding: 9px 10px;
    font-size: 0.88rem;
  }

  #map,
  .map-loading {
    display: none !important;
  }


  .atlas-map-controls,
  .map-distribution-strip,
  .map-hover-label {
    display: none !important;
  }

  .legend {
    display: none;
  }


  .search-card,
  .detail-card,
  .rank-card {
    margin-bottom: 10px;
    padding: 11px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 8px rgba(21, 101, 112, 0.06);
  }

  .search-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
  }

  .authority-picker-button {
    min-height: 42px;
    padding: 10px 11px;
  }

  #clearButton {
    min-height: 42px;
    padding: 8px 10px;
  }

  .authority-picker-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    top: 72px;
    max-height: calc(100dvh - 92px);
    z-index: 6000;
  }

  .detail-card h2 {
    font-size: 1.04rem;
  }

  .turnout-hero {
    align-items: center;
  }

  .turnout-hero span {
    font-size: 1.55rem;
  }

  .detail-list div {
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
  }

  dt {
    font-size: 0.78rem;
  }

  dd {
    font-size: 0.82rem;
  }

  .rank-header {
    position: sticky;
    top: 60px;
    z-index: 100;
    margin: -11px -11px 8px;
    padding: 10px 11px 8px;
    border-bottom: 1px solid var(--line-soft);
    background: #ffffff;
  }

  .data-table-wrap {
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    padding: 10px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: rgba(255,255,255,0.94);
    box-shadow: 0 1px 8px rgba(21, 101, 112, 0.05);
  }

  .data-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .data-table tbody tr.is-selected {
    border-color: rgba(124, 162, 149, 0.56);
    background: rgba(214, 227, 66, 0.18);
  }

  .data-table td {
    padding: 0;
    border: 0;
    line-height: 1.25;
  }

  .data-table td:first-child {
    min-width: 0;
    font-weight: 650;
  }

  .data-table td:last-child {
    text-align: right;
    white-space: normal;
  }

  .table-title-desktop {
    display: none;
  }

  .table-title-mobile,
  .table-meta,
  .table-metric-label,
  .table-metric-value {
    display: block;
  }

  .table-title-mobile {
    color: var(--text);
    font-size: 0.91rem;
  }

  .table-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 500;
  }

  .table-metric-label {
    color: var(--muted);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .table-metric-value {
    margin-top: 3px;
    color: var(--brand-aqua);
    font-size: 0.94rem;
    font-weight: 750;
  }

  .source-note {
    margin: 12px 2px 18px;
    font-size: 0.72rem;
  }

  .about-modal {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }

  .about-modal-header,
  .about-modal-body {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-width: 420px) {
  .map-floating-filters {
    gap: 6px;
  }

  .floating-toggle-button {
    min-height: 40px;
    font-size: 0.8rem;
  }


  .data-table tbody tr {
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
    gap: 8px;
  }

  .table-title-mobile {
    font-size: 0.87rem;
  }

  .table-metric-value {
    font-size: 0.88rem;
  }
}


/* Mobile refinements: data-only phone view. */
@media (max-width: 760px) {
  .map-wrap {
    border-bottom: 0;
    padding-bottom: 6px;
  }

  .detail-card.is-empty {
    display: none;
  }

  .table-meta:empty {
    display: none;
  }

  .table-title-mobile {
    line-height: 1.22;
  }

  .modal-backdrop {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100dvh;
    padding: 12px;
    box-sizing: border-box;
    overflow: hidden;
  }

  .about-modal {
    width: min(420px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    margin: 0 auto;
  }

  .about-modal-body {
    max-height: calc(100dvh - 112px);
  }
}


/* Mobile tidy-ups: cleaner picker row and simpler About header */
@media (max-width: 760px) {
  .search-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .authority-picker-button {
    min-height: 44px;
    align-items: flex-start;
    padding: 11px 12px;
    line-height: 1.25;
    white-space: normal;
  }

  .authority-picker-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    max-height: min(52dvh, 420px);
  }

  #clearButton {
    width: 100%;
    min-height: 40px;
  }

  .about-modal-header {
    align-items: flex-start;
  }

  .about-modal-header h2 {
    margin: 0;
  }
}

/* -------------------------------------------------------------------------
   Flat editorial refresh
   Reduces the card-based dashboard treatment in favour of continuous panels,
   simple dividers and a compact map control rail.
   ------------------------------------------------------------------------- */
:root {
  --radius: 2px;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --bg: #f1f5f3;
  --line: #cfdcd7;
  --line-soft: #e2ebe7;
}

.topbar {
  box-shadow: none;
}

.panel {
  padding: 0;
  background: #ffffff;
}

.summary-card,
.search-card,
.detail-card,
.rank-card {
  margin: 0;
  padding: 18px 16px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: #ffffff;
  background-image: none;
  box-shadow: none;
  backdrop-filter: none;
}

.rank-card {
  border-bottom: 0;
}

.section-label,
label,
.record-count,
.table-sort-button,
.floating-panel-title,
.legend-title {
  letter-spacing: 0.045em;
}

.search-row {
  gap: 6px;
}

.authority-picker-button,
#clearButton,
.about-button,
.modal-close-button {
  border-radius: 2px;
  box-shadow: none;
}

.authority-picker-button {
  background: #ffffff;
}

#clearButton {
  padding-inline: 12px;
}

.authority-picker-panel {
  padding: 4px 0;
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: 0 6px 18px rgba(23, 63, 71, 0.12);
}

.authority-picker-option {
  padding: 9px 12px;
  border: 0;
  border-radius: 0;
}

.authority-picker-option.is-active,
.authority-picker-option[aria-selected="true"] {
  border: 0;
}

.detail-card h2 {
  margin-bottom: 9px;
}

.turnout-hero {
  margin-bottom: 8px;
  padding-bottom: 10px;
}

.detail-list div {
  padding: 6px 0;
}

.rank-header {
  margin-bottom: 6px;
}

.data-table-wrap {
  max-height: 400px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: #ffffff;
}

.data-table thead th {
  background: #ffffff;
}

.table-sort-button {
  padding: 9px 8px;
}

.data-table td {
  padding: 9px 8px;
}

.data-table tbody tr:hover {
  background: #f2f7f5;
}

.data-table tbody tr.is-selected {
  background: #f0f3d8;
  box-shadow: inset 3px 0 0 var(--brand-moss);
}

.source-note {
  margin: 0;
  padding: 12px 16px 18px;
  border-top: 1px solid var(--line-soft);
}

/* The four map controls now read as one compact rail rather than four cards. */
.map-right-stack {
  gap: 10px;
}

.map-floating-filters {
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.floating-control + .floating-control {
  border-top: 1px solid var(--line-soft);
}

.floating-toggle-button {
  min-height: 43px;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
  font-weight: 650;
}

.floating-toggle-button:hover,
.floating-toggle-button:focus-visible,
.floating-toggle-button[aria-expanded="true"] {
  border: 0;
  background: #f1f6f4;
  box-shadow: none;
}

.map-right-stack .floating-panel {
  margin: 0;
  padding: 5px 0 7px;
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.floating-panel-title {
  margin: 5px 12px 6px;
}

.floating-option-list {
  gap: 0;
}

.floating-option {
  min-height: 34px;
  padding: 8px 12px;
  border: 0;
  border-radius: 0;
}

.floating-option.is-active {
  border: 0;
  background: #f0f3d8;
  box-shadow: inset 3px 0 0 var(--brand-moss);
}

.legend {
  border: 1px solid var(--line);
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.legend-swatch {
  border-radius: 0;
}

.leaflet-bar,
.leaflet-bar a,
.leaflet-control-home {
  border-radius: 0 !important;
  box-shadow: none !important;
}

.about-modal {
  border-radius: 0;
  box-shadow: 0 14px 36px rgba(10, 24, 28, 0.18);
}

.about-modal-header,
.about-modal-body {
  background: #ffffff;
}

.about-glossary div {
  border-radius: 0;
}

/* Data-first mobile view: one continuous surface, not a stack of cards. */
@media (max-width: 760px) {
  body,
  .panel,
  .map-wrap {
    background: #ffffff;
    background-image: none;
  }

  .map-wrap {
    padding: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .map-right-stack {
    width: 100%;
    gap: 0;
  }

  .map-floating-filters {
    border: 0;
    border-radius: 0;
  }

  .floating-control + .floating-control {
    border-top: 1px solid var(--line-soft);
  }

  .floating-toggle-button {
    min-height: 44px;
    padding: 11px 16px;
    font-size: 0.82rem;
  }

  .floating-panel {
    margin: 0;
  }

  .search-card,
  .detail-card,
  .rank-card {
    margin: 0;
    padding: 16px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    border-radius: 0;
    background: #ffffff;
    box-shadow: none;
  }

  .rank-card {
    border-bottom: 0;
  }

  .search-row {
    gap: 7px;
  }

  .authority-picker-button,
  #clearButton {
    border-radius: 0;
  }

  .authority-picker-panel {
    border-radius: 0;
  }

  .rank-header {
    margin: -16px -16px 8px;
    padding: 12px 16px 9px;
    background: #ffffff;
  }

  .data-table tbody tr {
    margin: 0;
    padding: 12px 0;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .data-table tbody tr:last-child {
    border-bottom: 0;
  }

  .data-table tbody tr:hover {
    background: #f2f7f5;
  }

  .data-table tbody tr.is-selected {
    margin-inline: -16px;
    padding-inline: 16px;
    background: #f0f3d8;
    box-shadow: inset 3px 0 0 var(--brand-moss);
  }

  .source-note {
    padding-inline: 16px;
  }

  .about-modal,
  .about-button,
  .modal-close-button {
    border-radius: 0;
  }
}


/* -------------------------------------------------------------------------
   Compact left panel
   Keeps the selected-area information available while prioritising the list.
   ------------------------------------------------------------------------- */
.detail-card.is-empty {
  display: none;
}

.detail-heading-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}

.detail-heading-row h2 {
  min-width: 0;
  margin: 0;
}

.detail-heading-row .turnout-hero {
  display: block;
  min-width: 88px;
  margin: 0;
  padding: 0;
  border: 0;
  text-align: right;
}

.detail-heading-row .turnout-hero span,
.detail-heading-row .turnout-hero small {
  display: block;
}

.detail-heading-row .turnout-hero span {
  font-size: 1.45rem;
  line-height: 1;
}

.detail-heading-row .turnout-hero small {
  margin-top: 4px;
  font-size: 0.68rem;
  line-height: 1.15;
}

.detail-summary-list {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.35fr) minmax(72px, 0.7fr);
  gap: 0;
  margin: 13px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.detail-summary-list > div {
  min-width: 0;
  padding: 0 10px;
  border-left: 1px solid var(--line-soft);
}

.detail-summary-list > div:first-child {
  padding-left: 0;
  border-left: 0;
}

.detail-summary-list > div:last-child {
  padding-right: 0;
}

.detail-summary-list dt,
.detail-summary-list dd {
  display: block;
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-summary-list dt {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.15;
}

.detail-summary-list dd {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.25;
}

.detail-more {
  margin-top: 11px;
  border-top: 1px solid var(--line-soft);
}

.detail-more summary {
  position: relative;
  padding: 9px 18px 1px 0;
  color: var(--brand-aqua);
  font-size: 0.74rem;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.detail-more summary::-webkit-details-marker {
  display: none;
}

.detail-more summary::after {
  content: "+";
  position: absolute;
  right: 0;
  top: 7px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 400;
}

.detail-more[open] summary::after {
  content: "−";
}

.detail-more .detail-list {
  margin-top: 7px;
}

.detail-more .detail-list div {
  padding: 5px 0;
}

/* On desktop, the records list takes every remaining pixel in the sidebar. */
@media (min-width: 761px) {
  .panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .search-card,
  .detail-card,
  .source-note {
    flex: 0 0 auto;
  }

  .search-card {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .detail-card {
    padding-top: 14px;
    padding-bottom: 12px;
  }

  .rank-card {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: 13px;
    padding-bottom: 0;
  }

  .rank-header {
    flex: 0 0 auto;
  }

  .data-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }

  .data-table td {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .table-sort-button {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .source-note {
    min-height: 28px;
    padding: 7px 16px 8px;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.62rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 760px) {
  .detail-heading-row {
    gap: 10px;
  }

  .detail-summary-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 10px;
  }

  .detail-summary-list > div:nth-child(3) {
    padding-left: 0;
    border-left: 0;
  }
}


/* -------------------------------------------------------------------------
   Plain-language guidance
   Adds orientation without introducing cards, borders or onboarding overlays.
   ------------------------------------------------------------------------- */
.control-guidance {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 0 1px;
}

.control-guidance p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.reset-view-button {
  flex: 0 0 auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand-aqua);
  font-size: 0.7rem;
  font-weight: 650;
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reset-view-button:hover,
.reset-view-button:focus-visible {
  border: 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.metric-help {
  margin: 0 1px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.floating-panel-note {
  margin: 7px 12px 5px;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.3;
}

.floating-option-with-description {
  display: block;
  padding-top: 8px;
  padding-bottom: 8px;
  text-align: left;
}

.floating-option-with-description span,
.floating-option-with-description small {
  display: block;
}

.floating-option-with-description small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 400;
  line-height: 1.25;
}

.floating-option-with-description.is-active small {
  color: rgba(23, 63, 71, 0.72);
}

.empty-selection-hint {
  margin: 0;
  padding: 9px 16px 12px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.empty-selection-hint[hidden],
.sort-hint[hidden] {
  display: none;
}

.sort-hint {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 16px 5px;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.25;
}

@media (min-width: 761px) {
  .empty-selection-hint {
    flex: 0 0 auto;
  }
}

@media (max-width: 760px) {
  .control-guidance {
    align-items: center;
    padding: 1px 0 3px;
  }

  .control-guidance p {
    font-size: 0.7rem;
  }

  .metric-help {
    margin: 2px 0 4px;
  }

  .desktop-map-hint {
    display: none;
  }

  .empty-selection-hint {
    padding: 5px 11px 12px;
  }

  .sort-hint {
    padding-inline: 0;
  }
}


/* Keep the plain-text guidance interactive inside the non-interactive map overlay. */
.map-right-stack .control-guidance {
  pointer-events: auto;
}


/* -------------------------------------------------------------------------
   Zoom / small-window resilience
   Browser zoom reduces the CSS viewport. Below 1100px, the full map layout
   becomes cramped, so the app switches to the same data-first structure used
   on phones while keeping desktop typography/table styling.
   ------------------------------------------------------------------------- */
@media (min-width: 761px) and (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .topbar {
    min-height: 68px;
    padding: 10px 18px;
    gap: 14px;
  }

  h1 {
    font-size: clamp(1.6rem, 3.2vw, 2.1rem);
  }

  .topbar-logo {
    max-width: 82px;
    max-height: 44px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .map-wrap {
    order: 1;
    position: relative;
    min-height: 0;
    overflow: visible;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--line-soft);
    background: #ffffff;
  }

  #map,
  .map-loading,
  .atlas-map-controls,
  .map-distribution-strip,
  .map-hover-label,
  .legend {
    display: none !important;
  }

  .map-right-stack {
    position: static;
    inset: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    gap: 8px;
    pointer-events: auto;
  }

  .map-floating-filters {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--line);
  }

  .floating-control + .floating-control {
    border-top: 0;
    border-left: 1px solid var(--line-soft);
  }

  .floating-toggle-button {
    min-height: 46px;
    padding: 9px 10px;
    white-space: normal;
    text-align: left;
  }

  .map-right-stack .floating-panel {
    position: absolute;
    z-index: 7000;
    top: calc(100% + 4px);
    left: 0;
    right: auto;
    width: min(360px, calc(100vw - 32px));
    max-height: min(58dvh, 430px);
    overflow: auto;
    border: 1px solid var(--line);
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(23, 63, 71, 0.14);
  }

  .floating-control {
    min-width: 0;
  }

  .metric-help {
    margin-top: 2px;
  }

  .panel {
    order: 2;
    display: block;
    overflow: visible;
    min-height: 0;
  }

  .search-card,
  .detail-card,
  .rank-card,
  .source-note {
    flex: none;
  }

  .rank-card {
    display: block;
    min-height: 0;
  }

  .data-table-wrap {
    max-height: none;
    overflow: visible;
  }
}

@media (min-width: 761px) and (max-width: 900px) {
  .map-floating-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .floating-control:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .floating-control:nth-child(4) {
    border-top: 1px solid var(--line-soft);
  }
}


/* Optional reference place names. Kept deliberately quiet so they orient
   users without competing with the election data. */
/* Place-name reference layer lives with the map tools, not the data filters. */
.map-places-button {
  width: 32px;
  height: 32px;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fffdf8;
  color: var(--text);
  box-shadow: none;
}

.map-places-button:hover,
.map-places-button:focus-visible {
  background: #f1ede5;
}

.map-places-button[aria-pressed="true"] {
  color: var(--brand-aqua, #156570);
  background: #eef4f1;
}

.map-places-icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none !important;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.leaflet-place-pane {
  pointer-events: none;
}

.place-marker {
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  background: transparent !important;
}

.place-dot {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
  background: #31585c;
}

.place-name {
  position: absolute;
  left: 7px;
  top: -7px;
  white-space: nowrap;
  color: #294d51;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0.005em;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,0.96),
     1px -1px 0 rgba(255,255,255,0.96),
    -1px  1px 0 rgba(255,255,255,0.96),
     1px  1px 0 rgba(255,255,255,0.96);
}

.place-marker-left .place-name {
  left: auto;
  right: 7px;
  text-align: right;
}

.place-marker-top .place-name {
  left: 0;
  top: -18px;
  transform: translateX(-50%);
}

.place-marker-bottom .place-name {
  left: 0;
  top: 8px;
  transform: translateX(-50%);
}



/* Keep reference labels and map shading from showing through the right-side UI. */
@media (min-width: 1101px) {
  .map-right-stack .control-guidance,
  .map-right-stack .metric-help {
    padding: 7px 8px;
    background: rgba(246, 250, 249, 0.97);
  }

  .map-right-stack .control-guidance {
    margin-bottom: -2px;
  }

  .map-right-stack .metric-help {
    margin: -2px 0 0;
  }

  .map-right-stack .map-floating-filters,
  .map-right-stack .legend {
    background: rgba(255, 255, 255, 0.98);
  }
}

/* -------------------------------------------------------------------------
   Mobile / zoomed-screen final pass
   Keeps compact mode plain and usable after the place-name/map-control changes.
   ------------------------------------------------------------------------- */
html,
body {
  overflow-x: hidden;
}

@media (min-width: 761px) and (max-width: 1100px) {
  .map-wrap {
    padding: 12px 16px 11px;
  }

  .map-floating-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .floating-control:nth-child(odd) {
    border-left: 0;
  }

  .floating-control:nth-child(n + 3) {
    border-top: 1px solid var(--line-soft);
  }

  .floating-toggle-button {
    min-height: 44px;
    line-height: 1.25;
  }

  .control-guidance {
    align-items: center;
  }

  .panel {
    padding-top: 0;
  }

  .source-note {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}

@media (max-width: 760px) {
  .topbar {
    min-height: 58px;
    padding: 13px 10px 8px;
  }

  h1::after {
    content: "NZLEDE";
    font-size: 1.55rem;
    letter-spacing: -0.035em;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .topbar-logo {
    max-width: 54px;
    max-height: 34px;
  }

  .about-button {
    min-height: 32px;
    padding: 6px 8px;
  }

  .map-wrap {
    padding: 10px 12px 8px;
    background: #ffffff !important;
  }

  .map-right-stack {
    gap: 7px;
  }

  .map-floating-filters {
    grid-template-columns: 1fr;
    gap: 0;
    border: 1px solid var(--line-soft);
  }

  .floating-control,
  .floating-control:nth-child(n) {
    border-left: 0;
    border-top: 0;
  }

  .floating-control + .floating-control {
    border-top: 1px solid var(--line-soft);
  }

  .floating-toggle-button {
    min-height: 42px;
    padding: 10px 12px;
    line-height: 1.25;
    box-shadow: none;
  }

  .floating-panel {
    position: static !important;
    width: 100% !important;
    max-height: min(52dvh, 420px);
    margin: 0;
    border: 0;
    border-top: 1px solid var(--line-soft);
    box-shadow: none;
  }

  .control-guidance {
    gap: 10px;
    align-items: flex-start;
  }

  .control-guidance p {
    font-size: 0.68rem;
    line-height: 1.3;
  }

  .reset-view-button {
    font-size: 0.68rem;
  }

  .metric-help {
    margin: 0;
    font-size: 0.68rem;
  }

  .panel {
    padding: 0;
    background: #ffffff !important;
  }

  .search-card,
  .detail-card,
  .rank-card {
    margin: 0;
    padding: 14px 12px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    border-radius: 0;
    box-shadow: none;
  }

  .search-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .authority-picker-button,
  #clearButton {
    width: 100%;
    min-height: 42px;
    border-radius: 0;
  }

  .authority-picker-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: min(54dvh, 430px);
    border-radius: 0;
  }

  .empty-selection-hint {
    padding: 0 12px 12px;
  }

  .detail-heading-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .detail-heading-row .turnout-hero {
    min-width: 0;
    text-align: left;
  }

  .detail-heading-row .turnout-hero span,
  .detail-heading-row .turnout-hero small {
    display: inline;
  }

  .detail-heading-row .turnout-hero small {
    margin-left: 6px;
  }

  .detail-summary-list {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .detail-summary-list > div,
  .detail-summary-list > div:nth-child(3) {
    padding: 7px 0;
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .detail-summary-list > div:first-child {
    border-top: 0;
  }

  .rank-header {
    position: static;
    top: auto;
    margin: 0 0 8px;
    padding: 0 0 9px;
  }

  .sort-hint {
    padding: 0 0 6px;
  }

  .data-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin: 0;
    padding: 11px 0;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .data-table tbody tr.is-selected {
    margin-inline: -12px;
    padding-inline: 12px;
  }

  .table-title-mobile {
    display: block;
    padding: 0;
    overflow: visible;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.22;
    text-overflow: clip;
    white-space: normal;
  }

  .table-meta {
    margin-top: 3px;
    font-size: 0.71rem;
  }

  .table-metric-label {
    font-size: 0.62rem;
  }

  .table-metric-value {
    font-size: 0.9rem;
  }

  .source-note {
    margin: 0;
    padding: 9px 12px 18px;
    overflow: visible;
    font-size: 0.66rem;
    line-height: 1.3;
    text-overflow: clip;
    white-space: normal;
  }

  .about-modal {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }

  .about-modal-body {
    max-height: calc(100dvh - 92px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 430px) {
  .control-guidance {
    display: block;
  }

  .reset-view-button {
    margin-top: 4px;
  }

  .data-table tbody tr {
    grid-template-columns: minmax(0, 1fr) minmax(68px, auto);
  }
}


/* -------------------------------------------------------------------------
   Purpose-built phone layout
   Compact filters, dense records and a concise selected-area summary.
   Desktop and zoomed-tablet layouts are unchanged.
   ------------------------------------------------------------------------- */
.mobile-filter-bar,
.mobile-selected-summary,
.clear-label-mobile {
  display: none;
}

@media (max-width: 760px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 8000;
  }

  .mobile-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 50px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line-soft);
    background: #ffffff;
  }

  .mobile-filter-bar p {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 0.76rem;
    font-weight: 650;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #mobileFilterToggle {
    flex: 0 0 auto;
    min-height: 0;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--brand-aqua);
    font-size: 0.72rem;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
  }

  #mobileFilterToggle:hover,
  #mobileFilterToggle:focus-visible {
    border: 0;
    background: transparent;
    color: var(--text);
    box-shadow: none;
  }

  .map-wrap {
    padding: 0 !important;
    border-bottom: 0;
  }

  .map-right-stack {
    display: none;
    position: static;
    width: 100%;
    padding: 0 12px 12px;
    background: #ffffff;
  }

  .map-right-stack.is-mobile-open {
    display: flex;
    flex-direction: column;
  }

  .map-right-stack .map-floating-filters {
    order: 1;
    border-top: 1px solid var(--line-soft);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
  }

  .map-right-stack .metric-help {
    order: 2;
    margin: 8px 0 0;
    padding: 0;
    font-size: 0.68rem;
  }

  .map-right-stack .control-guidance {
    order: 3;
    display: block;
    margin-top: 8px;
    padding: 0;
  }

  .map-right-stack .control-guidance p {
    display: none;
  }

  .map-right-stack .reset-view-button {
    margin: 0;
    font-size: 0.68rem;
  }

  .floating-toggle-button {
    min-height: 40px;
    padding: 9px 4px;
    font-size: 0.78rem;
  }

  .floating-panel {
    max-height: 48dvh;
  }

  .panel {
    display: block;
    overflow: visible;
  }

  .search-card {
    padding: 13px 12px 11px;
  }

  .search-card label {
    margin-bottom: 6px;
  }

  .search-row {
    grid-template-columns: minmax(0, 1fr) 42px;
    gap: 6px;
  }

  .authority-picker-button {
    min-height: 42px;
    padding: 9px 10px;
  }

  #clearButton {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    font-size: 1.45rem;
    font-weight: 400;
    line-height: 1;
  }

  .clear-label-desktop {
    display: none;
  }

  .clear-label-mobile {
    display: inline;
  }

  .empty-selection-hint {
    padding: 7px 12px 11px;
    font-size: 0.68rem;
  }

  .detail-card {
    padding: 13px 12px 10px;
  }

  .detail-heading-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
  }

  .detail-card h2 {
    font-size: 0.98rem;
    line-height: 1.2;
  }

  .detail-heading-row .turnout-hero {
    min-width: 70px;
    text-align: right;
  }

  .detail-heading-row .turnout-hero span {
    display: block;
    font-size: 1.3rem;
    line-height: 1;
  }

  .detail-heading-row .turnout-hero small {
    display: block;
    margin: 3px 0 0;
    font-size: 0.65rem;
  }

  .mobile-selected-summary {
    display: block;
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.35;
  }

  .mobile-selected-summary[hidden] {
    display: none;
  }

  .detail-summary-list {
    display: none;
  }

  .detail-more {
    margin-top: 9px;
  }

  .detail-more summary {
    padding: 8px 0 5px;
    font-size: 0.72rem;
  }

  .detail-more .detail-list div {
    padding: 5px 0;
  }

  .rank-card {
    display: block !important;
    height: auto !important;
    min-height: 0;
    padding: 12px 12px 0;
    overflow: visible !important;
  }

  .rank-header {
    display: flex;
    position: static;
    align-items: baseline;
    justify-content: space-between;
    margin: 0;
    padding: 0 0 7px;
    border-bottom: 0;
  }

  .rank-header .section-label,
  .record-count {
    font-size: 0.67rem;
  }

  .sort-hint {
    display: none !important;
  }

  .data-table-wrap,
  .data-table,
  .data-table thead,
  .data-table tbody {
    display: block;
    width: 100%;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .data-table thead {
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line-soft);
  }

  .data-table thead tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
  }

  .data-table thead th {
    display: block;
    position: static;
    width: auto !important;
    padding: 0;
    border: 0;
    background: #ffffff;
  }

  .data-table thead th:last-child {
    min-width: 84px;
  }

  .table-sort-button {
    padding: 7px 0 6px;
    font-size: 0.64rem;
  }

  .data-table thead th:last-child .table-sort-button {
    text-align: right;
  }

  .data-table tbody tr {
    min-height: 50px;
    grid-template-columns: minmax(0, 1fr) minmax(66px, auto);
    gap: 9px;
    padding: 9px 0;
  }

  .data-table tbody tr.is-selected {
    margin-inline: -12px;
    padding-inline: 12px;
  }

  .table-title-mobile {
    font-size: 0.83rem;
    line-height: 1.18;
  }

  .table-meta {
    display: none;
  }

  .table-metric-label {
    display: none !important;
  }

  .table-metric-value {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.15;
  }

  .source-note {
    display: block;
    position: static !important;
    width: auto;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 12px 12px 22px;
    clear: both;
    overflow: visible !important;
    border-top: 1px solid var(--line-soft);
    background: #ffffff;
    font-size: 0.61rem;
    line-height: 1.35;
    white-space: normal !important;
  }

  .authority-picker-panel {
    position: fixed;
    top: 66px;
    right: 8px;
    left: 8px;
    max-height: calc(100dvh - 82px);
  }
}

@media (max-width: 380px) {
  .mobile-filter-bar p {
    font-size: 0.71rem;
  }

  .topbar-logo {
    max-width: 48px;
  }

  .about-button {
    padding-inline: 7px;
  }
}

/* -------------------------------------------------------------------------
   Native mobile record browser
   The phone experience is intentionally a search/filter/list interface rather
   than a stacked version of the desktop map dashboard.
   ------------------------------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.mobile-record-tools,
.mobile-list-toolbar,
.mobile-record-details-row {
  display: none;
}

@media (max-width: 760px) {
  body,
  .app-shell,
  .layout,
  .panel {
    background: #ffffff !important;
  }

  .panel {
    padding: 0 14px 0 !important;
  }

  /* Desktop-only selection/detail furniture is replaced by direct list search
     and inline row expansion on phones. */
  .search-card,
  .empty-selection-hint,
  .detail-card,
  .rank-header,
  .sort-hint {
    display: none !important;
  }

  .mobile-record-tools {
    display: block;
    padding: 13px 0 9px;
  }

  .mobile-search-field {
    position: relative;
  }

  #mobileRecordSearch {
    width: 100%;
    min-height: 44px;
    padding: 10px 42px 10px 12px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: #ffffff;
    color: var(--text);
    font-size: 0.92rem;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
  }

  #mobileRecordSearch::-webkit-search-cancel-button {
    display: none;
  }

  #mobileRecordSearch:focus {
    border-color: var(--brand-aqua);
    box-shadow: none;
  }

  #mobileSearchClear {
    position: absolute;
    top: 50%;
    right: 2px;
    width: 40px;
    height: 40px;
    min-height: 0;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1.35rem;
    font-weight: 400;
    line-height: 1;
  }

  #mobileSearchClear[hidden] {
    display: none !important;
  }

  #mobileSearchClear:hover,
  #mobileSearchClear:focus-visible {
    border: 0;
    background: transparent;
    color: var(--text);
    box-shadow: none;
  }

  .rank-card {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    background: #ffffff !important;
  }

  .mobile-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 34px;
    padding: 0 0 7px;
    border-bottom: 1px solid var(--line);
  }

  #mobileListCount {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 650;
  }

  .mobile-sort-buttons {
    display: inline-flex;
    align-items: center;
    gap: 2px;
  }

  .mobile-sort-button {
    min-height: 30px;
    padding: 4px 7px;
    border: 0;
    border-bottom: 1px solid transparent;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 650;
    box-shadow: none !important;
  }

  .mobile-sort-button.is-active {
    border-bottom-color: var(--brand-aqua);
    color: var(--brand-aqua);
  }

  .mobile-sort-button:focus-visible {
    outline: 1px solid var(--brand-aqua);
    outline-offset: 1px;
  }

  .data-table-wrap,
  .data-table,
  .data-table tbody {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .data-table tbody tr:not(.mobile-record-details-row) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(68px, auto) !important;
    align-items: center;
    gap: 12px;
    min-height: 57px;
    margin: 0 !important;
    padding: 10px 4px !important;
    border: 0 !important;
    border-bottom: 1px solid var(--line-soft) !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    cursor: pointer;
  }

  .data-table tbody tr:not(.mobile-record-details-row):focus-visible {
    outline: 2px solid rgba(21, 101, 112, 0.28);
    outline-offset: -2px;
  }

  .data-table tbody tr.is-selected:not(.mobile-record-details-row) {
    margin-inline: -14px !important;
    padding-inline: 18px !important;
    background: #f1f6f3 !important;
  }

  .data-table td {
    display: block !important;
    width: auto !important;
    min-width: 0;
    padding: 0 !important;
    border: 0 !important;
  }

  .table-title-desktop,
  .table-metric-label {
    display: none !important;
  }

  .table-title-mobile {
    display: block !important;
    overflow: visible;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 680;
    line-height: 1.22;
    text-overflow: clip;
    white-space: normal;
  }

  .table-meta {
    display: block !important;
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.25;
  }

  .table-metric-value {
    display: block !important;
    margin: 0 !important;
    color: var(--brand-aqua);
    font-size: 0.95rem;
    font-weight: 750;
    line-height: 1.15;
    text-align: right;
    white-space: nowrap;
  }

  .mobile-record-details-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    margin: 0 -14px !important;
    padding: 0 18px 13px !important;
    border: 0 !important;
    border-bottom: 1px solid var(--line) !important;
    background: #f1f6f3 !important;
  }

  .mobile-record-details-row td {
    grid-column: 1 / -1;
  }

  .mobile-inline-summary {
    margin: 0;
    padding: 1px 0 9px;
    color: var(--muted);
    font-size: 0.71rem;
    line-height: 1.35;
  }

  .mobile-inline-grid {
    margin: 0;
    padding: 7px 0 0;
    border-top: 1px solid rgba(126, 159, 149, 0.24);
  }

  .mobile-inline-grid > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 5px 0;
  }

  .mobile-inline-grid dt,
  .mobile-inline-grid dd {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.25;
  }

  .mobile-inline-grid dt {
    color: var(--muted);
    font-weight: 500;
  }

  .mobile-inline-grid dd {
    color: var(--text);
    font-weight: 650;
    text-align: right;
  }

  .mobile-empty-row {
    display: block !important;
    min-height: 0 !important;
    padding: 24px 0 !important;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
  }

  /* Keep the temporary filter editor separate from the record list. */
  .map-wrap {
    background: #ffffff !important;
  }

  .mobile-filter-bar {
    min-height: 45px;
    padding: 8px 14px;
  }

  .mobile-filter-bar p {
    font-size: 0.73rem;
  }

  .map-right-stack {
    padding: 0 14px 12px !important;
    background: #f7faf8 !important;
  }

  .map-right-stack .map-floating-filters {
    border-color: var(--line-soft);
    background: #ffffff;
  }

  .source-note {
    position: static !important;
    margin: 0 -14px !important;
    padding: 15px 14px 24px !important;
    border-top: 1px solid var(--line-soft);
    background: #ffffff !important;
    color: var(--muted);
    font-size: 0.61rem;
    line-height: 1.35;
    white-space: normal !important;
  }
}


/* Mobile: use a conventional sortable table header. */
@media (max-width: 760px) {
  .mobile-list-toolbar {
    min-height: 28px;
    padding: 0 0 5px;
    border-bottom: 0;
  }

  .mobile-sort-buttons {
    display: none !important;
  }

  .data-table thead {
    display: block !important;
    width: 100% !important;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #ffffff;
  }

  .data-table thead tr {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(78px, auto);
    align-items: center;
    width: 100%;
  }

  .data-table thead th {
    display: block !important;
    position: static !important;
    width: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: #ffffff !important;
  }

  .data-table thead th:last-child {
    min-width: 78px;
  }

  .table-sort-button {
    min-height: 34px;
    padding: 7px 4px 6px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--muted);
    font-size: 0.67rem !important;
    font-weight: 700;
    letter-spacing: 0.035em;
    text-transform: uppercase;
    box-shadow: none !important;
  }

  .table-sort-button.is-active {
    color: var(--brand-aqua);
  }

  .data-table thead th:last-child .table-sort-button {
    text-align: right;
  }

  .table-sort-button:focus-visible {
    outline: 1px solid var(--brand-aqua);
    outline-offset: -1px;
  }
}


/* Colour-system and attribution refinements -------------------------------- */
:root {
  --muted: #527169;
  --brand-moss-text: #557a70;
}

.eyebrow,
.section-label,
label,
.legend-title,
.floating-panel-title,
.record-count,
.table-sort-button {
  color: var(--brand-moss-text);
}

#clearButton,
#clearButton:hover,
#clearButton:focus-visible {
  border-color: var(--brand-aqua);
  background: var(--brand-aqua);
  color: #ffffff;
}

.legend-swatch--state {
  border-width: 1px;
}

.map-source-note {
  position: absolute;
  left: 22px;
  right: auto;
  bottom: 8px;
  z-index: 709;
  display: flex;
  align-items: center;
  gap: 7px;
  width: min(520px, calc(100% - 310px));
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  pointer-events: auto;
}

.map-source-text {
  min-width: 0;
  overflow: hidden;
  padding: 3px 5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.76);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.map-source-separator {
  flex: 0 0 auto;
  color: var(--muted);
}

.map-source-button,
.map-source-link {
  flex: 0 0 auto;
  padding: 2px 1px;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.76);
  color: var(--brand-aqua);
  font: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
  box-shadow: none;
}

.map-source-button:hover,
.map-source-button:focus-visible,
.map-source-link:hover,
.map-source-link:focus-visible {
  border: 0;
  background: rgba(255, 255, 255, 0.94);
  color: #0f4f58;
  box-shadow: 0 0 0 2px rgba(156, 220, 217, 0.34);
}

@media (max-width: 1100px) and (min-width: 761px) {
  .map-source-note {
    left: 12px;
    right: auto;
    bottom: 8px;
    width: min(500px, calc(100% - 248px));
  }

  .map-distribution-strip {
    left: 12px;
    bottom: 40px;
  }
}

@media (max-width: 760px) {
  .map-source-note {
    position: static;
    order: 2;
    display: flex;
    width: 100%;
    margin-top: 9px;
    padding: 9px 4px 1px;
    font-size: 0.68rem;
  }

  .map-source-text {
    padding: 0;
    background: transparent;
    white-space: normal;
  }

  .map-source-button,
  .map-source-link {
    background: transparent;
  }
}

/* -------------------------------------------------------------------------
   Reference-style mobile layout
   Brings the phone view closer to a conventional public-data table while
   retaining the desktop map experience unchanged.
   ------------------------------------------------------------------------- */
.mobile-menu-wrap,
.mobile-rank-header,
.mobile-rank-cell,
.mobile-search-icon,
.mobile-filter-icon {
  display: none;
}

/* System is a normal sortable desktop column. It is suppressed only for the
   Māori ward poll, where no electoral-system value applies. */
.mobile-system-header {
  width: 18%;
}

.mobile-system-header,
.mobile-system-cell {
  white-space: nowrap;
}

.data-table.hide-system-column .mobile-system-header,
.data-table.hide-system-column .mobile-system-cell {
  display: none !important;
}

@media (max-width: 760px) {
  html,
  body {
    min-height: 100%;
    background: #ffffff;
  }

  body {
    padding-bottom: 0;
  }

  .topbar {
    min-height: 76px;
    padding: 16px 12px 11px;
    gap: 8px;
    background:
      linear-gradient(90deg, rgba(255,255,255,0.97), rgba(255,255,255,0.92)),
      url("images/brand_background.png") center 48% / cover no-repeat,
      #ffffff;
  }

  .topbar::before {
    height: 8px;
  }

  .topbar-title {
    flex: 1 1 auto;
  }

  h1::after {
    content: "NZLEDE";
    font-size: 1.72rem;
    font-weight: 650;
    letter-spacing: -0.045em;
  }

  .topbar-actions {
    position: relative;
    flex: 0 0 auto;
    gap: 9px;
  }

  .about-button {
    min-height: 42px;
    padding: 8px 11px;
    border-radius: 3px;
    font-size: 0.9rem;
  }

  .topbar-logo {
    max-width: 54px;
    max-height: 42px;
  }

  .mobile-menu-wrap {
    display: none !important;
  }

  .mobile-menu-button {
    width: 42px;
    height: 42px;
    min-height: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    box-shadow: none;
  }

  .mobile-menu-button span {
    display: block;
    width: 23px;
    height: 3px;
    border-radius: 2px;
    background: currentColor;
  }

  .mobile-menu-button:hover,
  .mobile-menu-button:focus-visible {
    border: 0;
    background: #edf5f2;
    box-shadow: none;
  }

  .mobile-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 8500;
    width: min(235px, calc(100vw - 24px));
    padding: 5px 0;
    border: 1px solid var(--line);
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(16, 45, 49, 0.18);
  }

  .mobile-menu-panel[hidden] {
    display: none !important;
  }

  .mobile-menu-panel button,
  .mobile-menu-panel a {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 9px 13px;
    border: 0;
    border-radius: 0;
    background: #ffffff;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.25;
    text-align: left;
    text-decoration: none;
    box-shadow: none;
  }

  .mobile-menu-panel button:hover,
  .mobile-menu-panel button:focus-visible,
  .mobile-menu-panel a:hover,
  .mobile-menu-panel a:focus-visible {
    background: #edf5f2;
    color: var(--brand-aqua);
    outline: 0;
  }

  .mobile-filter-bar {
    min-height: 82px;
    align-items: center;
    padding: 14px 15px;
    gap: 12px;
    border-bottom: 1px solid var(--line-soft);
  }

  .mobile-filter-bar p {
    overflow: visible;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: clip;
    white-space: normal;
  }

  #mobileFilterToggle {
    min-width: 112px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--brand-aqua);
    border-radius: 7px;
    background: #ffffff;
    color: var(--brand-aqua);
    font-size: 0.92rem;
    font-weight: 650;
    text-decoration: none;
    box-shadow: none;
  }

  #mobileFilterToggle:hover,
  #mobileFilterToggle:focus-visible {
    border: 1px solid var(--brand-aqua);
    background: #eef7f5;
    color: var(--brand-aqua);
    box-shadow: none;
  }

  .mobile-filter-icon {
    width: 19px;
    height: 19px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .map-right-stack.is-mobile-open {
    padding: 0 15px 14px !important;
    border-bottom: 1px solid var(--line-soft);
    background: #f7faf8 !important;
  }

  .panel {
    padding: 0 15px !important;
  }

  .mobile-record-tools {
    padding: 18px 0 13px;
  }

  .mobile-search-field {
    position: relative;
  }

  .mobile-search-icon {
    position: absolute;
    left: 17px;
    top: 50%;
    z-index: 1;
    width: 23px;
    height: 23px;
    display: block;
    transform: translateY(-50%);
    fill: none;
    stroke: #65727b;
    stroke-width: 1.8;
    stroke-linecap: round;
    pointer-events: none;
  }

  #mobileRecordSearch {
    min-height: 56px;
    padding: 12px 46px 12px 54px;
    border-color: #cfd9d6;
    border-radius: 10px;
    font-size: 1rem;
    box-shadow: 0 1px 2px rgba(25, 58, 62, 0.04);
  }

  #mobileRecordSearch:focus {
    border-color: var(--brand-aqua);
    box-shadow: 0 0 0 2px rgba(21, 101, 112, 0.1);
  }

  #mobileSearchClear {
    right: 6px;
  }

  .mobile-list-toolbar {
    min-height: 50px;
    align-items: center;
    padding: 2px 0 10px;
    border-bottom: 0;
  }

  #mobileListCount {
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
  }

  .data-table thead {
    border-top: 1px solid #c7d9d4;
    border-bottom: 1px solid var(--brand-aqua);
    background: #edf7f6;
  }

  .data-table thead tr {
    grid-template-columns: minmax(0, 1fr) 64px minmax(108px, auto) !important;
    min-height: 42px;
  }

  .data-table.hide-system-column thead tr {
    grid-template-columns: minmax(0, 1fr) minmax(118px, auto) !important;
  }

  .data-table thead th {
    display: flex !important;
    align-items: center;
    min-width: 0 !important;
    background: #edf7f6 !important;
  }

  .data-table thead th.mobile-rank-header {
    display: none !important;
  }

  .mobile-system-header {
    display: flex !important;
    justify-content: flex-start;
    padding: 0 4px !important;
    color: var(--brand-aqua);
    font-size: 0.67rem;
    font-weight: 750;
    letter-spacing: 0.035em;
    text-transform: uppercase;
  }

  .data-table.hide-system-column .mobile-system-header {
    display: none !important;
  }

  .table-sort-button {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 8px 4px !important;
    color: var(--brand-aqua);
    font-size: 0.67rem !important;
    font-weight: 750;
    letter-spacing: 0.035em;
    text-transform: uppercase;
  }

  #sortNameButton {
    font-size: 0 !important;
  }

  #sortNameButton::before {
    content: attr(data-mobile-label);
    font-size: 0.67rem;
  }

  #sortSystemButton {
    justify-content: flex-start;
    text-align: left;
    white-space: nowrap;
  }

  #sortMetricButton {
    justify-content: flex-end;
    text-align: right;
  }

  .data-table tbody tr:not(.mobile-record-details-row) {
    grid-template-columns: minmax(0, 1fr) 64px minmax(108px, auto) !important;
    gap: 0 !important;
    min-height: 48px;
    padding: 0 !important;
  }

  .data-table.hide-system-column tbody tr:not(.mobile-record-details-row) {
    grid-template-columns: minmax(0, 1fr) minmax(118px, auto) !important;
  }

  .data-table tbody tr.is-selected:not(.mobile-record-details-row) {
    margin-inline: -15px !important;
    padding-inline: 15px !important;
  }

  .data-table tbody tr:not(.mobile-record-details-row) > td {
    min-height: 48px;
    display: flex !important;
    align-items: center;
    padding: 4px !important;
  }

  .data-table tbody tr:not(.mobile-record-details-row) > td.mobile-rank-cell {
    display: none !important;
  }

  .mobile-system-cell {
    justify-content: flex-start;
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
  }

  .data-table.hide-system-column .mobile-system-cell {
    display: none !important;
  }

  .record-name-cell {
    min-width: 0;
  }

  .record-metric-cell {
    justify-content: flex-end;
    text-align: right;
  }

  .table-title-mobile {
    font-size: 0.91rem;
    font-weight: 700;
    line-height: 1.18;
  }

  .table-meta {
    display: none !important;
  }

  .table-metric-value {
    font-size: 0.98rem;
    font-weight: 750;
  }

  .mobile-record-details-row {
    margin: 0 -15px !important;
    padding: 0 19px 14px !important;
  }

  .mobile-empty-row td {
    min-height: 0 !important;
  }

  .map-source-note {
    display: none !important;
  }

  .map-source-text {
    flex: 1 1 225px;
    overflow: visible;
    padding: 0;
    background: transparent;
    white-space: normal;
    text-overflow: clip;
  }

  .map-source-button {
    flex: 0 0 auto;
    padding: 2px 0;
    background: transparent;
    font-size: 0.72rem;
  }
}

@media (max-width: 390px) {
  .topbar {
    padding-inline: 10px;
  }

  h1::after {
    font-size: 1.55rem;
  }

  .topbar-actions {
    gap: 6px;
  }

  .about-button {
    padding-inline: 8px;
    font-size: 0.82rem;
  }

  .topbar-logo {
    max-width: 48px;
  }

  .mobile-menu-button {
    width: 38px;
  }

  .mobile-filter-bar {
    padding-inline: 12px;
  }

  .mobile-filter-bar p {
    font-size: 0.96rem;
  }

  #mobileFilterToggle {
    min-width: 100px;
    padding-inline: 10px;
  }

  .panel {
    padding-inline: 12px !important;
  }

  .data-table thead tr,
  .data-table tbody tr:not(.mobile-record-details-row) {
    grid-template-columns: minmax(0, 1fr) 60px minmax(104px, auto) !important;
  }

  .data-table.hide-system-column thead tr,
  .data-table.hide-system-column tbody tr:not(.mobile-record-details-row) {
    grid-template-columns: minmax(0, 1fr) minmax(112px, auto) !important;
  }

  .mobile-system-header,
  .table-sort-button,
  #sortNameButton::before {
    font-size: 0.61rem !important;
  }

  .mobile-system-cell {
    font-size: 0.74rem;
  }

  .table-title-mobile {
    font-size: 0.84rem;
  }

  .table-metric-value {
    font-size: 0.9rem;
  }

  .map-source-note {
    padding-inline: 12px !important;
  }
}

/* -------------------------------------------------------------------------
   Desktop zoom / short-window filter resilience
   Keep long option lists within the visible map area rather than allowing
   them to extend below the viewport when browser zoom reduces its height.
   ------------------------------------------------------------------------- */
@media (min-width: 761px) {
  .map-right-stack .floating-panel {
    max-height: min(50dvh, 560px, calc(100dvh - 410px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
}

/* -------------------------------------------------------------------------
   Desktop header, controls and sidebar — consolidated final implementation
   ------------------------------------------------------------------------- */

/* Branded banner with title over the artwork and a clean white logo zone. */
.app-shell > .topbar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 16px 20px;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid #d8dfdc;
  background:
    linear-gradient(90deg,
      rgba(3, 45, 53, 0.88) 0%,
      rgba(3, 45, 53, 0.62) 36%,
      rgba(255, 255, 255, 0.12) 67%,
      #ffffff 86%,
      #ffffff 100%),
    url("images/IES_Header_Pattern.png") left center / auto 100% no-repeat,
    #ffffff;
  color: #ffffff;
}

.app-shell > .topbar::before {
  display: none;
}

.app-shell > .topbar .topbar-title,
.app-shell > .topbar .topbar-actions {
  position: relative;
  z-index: 1;
}

.app-shell > .topbar .topbar-title {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.app-shell > .topbar h1 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(1.62rem, 2vw, 2.3rem);
  font-weight: 700;
  line-height: 1.03;
  letter-spacing: -0.035em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.topbar-subtitle {
  margin: 0;
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.25;
  opacity: 0.96;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.16);
}

.app-shell > .topbar .topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 190px;
}

.app-shell > .topbar .topbar-logo {
  display: block;
  width: auto;
  max-width: 184px;
  max-height: 48px;
  object-fit: contain;
}

/* One compact control row. Remove all inherited "vertical rail" borders. */
.top-controls {
  position: relative;
  z-index: 35;
  display: block;
  padding: 8px 12px 9px;
  border: 0;
  border-bottom: 1px solid #d8dfdc;
  background: #ffffff;
}

.top-controls .top-floating-filters {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.top-controls .floating-control,
.top-controls .floating-control + .floating-control,
.top-controls-actions,
.top-controls-about {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  padding: 0;
  border: 0 !important;
  background: transparent;
  box-shadow: none;
}

.top-controls .floating-control:nth-child(1) {
  width: 300px;
}

.top-controls .floating-control:nth-child(2) {
  width: 190px;
}

.top-controls .floating-control:nth-child(3) {
  width: 235px;
}

.top-controls .floating-control:nth-child(4) {
  width: 150px;
}

.top-controls .floating-toggle-button,
.top-controls .about-button,
.top-controls .reset-view-button {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  min-height: 40px;
  height: 40px;
  margin: 0;
  border: 1px solid #c6d1cc;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
  color: #123f49;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  outline-offset: 2px;
}

.top-controls .floating-toggle-button {
  display: block;
  width: 100%;
  overflow: hidden;
  padding: 0 32px 0 12px;
  text-align: left;
  text-overflow: ellipsis;
}

.top-controls .floating-toggle-button::after {
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
}

.top-controls .floating-toggle-button:hover,
.top-controls .floating-toggle-button:focus-visible,
.top-controls .floating-toggle-button[aria-expanded="true"],
.top-controls .about-button:hover,
.top-controls .about-button:focus-visible {
  border-color: #91a59d;
  background: #f7f9f8;
}

.top-controls .floating-toggle-button[aria-expanded="true"] {
  background: #ffffff;
}

.top-controls-actions {
  display: flex;
  align-items: stretch;
}

.top-controls .reset-view-button {
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
}

.top-controls .reset-view-button::before {
  content: "↻";
  display: inline-block;
  margin-right: 7px;
  font-weight: 700;
}

.top-controls .reset-view-button:hover,
.top-controls .reset-view-button:focus-visible {
  border-color: #c6d1cc;
  background: #f7f9f8;
}

.top-controls-about {
  display: flex;
  align-items: stretch;
  margin-left: auto;
}

.top-controls .about-button {
  min-width: 84px;
  padding: 0 16px;
}

/* Dropdowns are solid, correctly sized and independent of their button width. */
.top-controls .floating-control:has(.floating-toggle-button[aria-expanded="true"]) {
  z-index: 900;
}

.top-controls .floating-panel,
.top-controls .floating-control .floating-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: auto;
  left: 0;
  bottom: auto;
  max-height: min(62dvh, 590px);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #c6d1cc;
  border-radius: 0;
  background: #ffffff !important;
  opacity: 1 !important;
  box-shadow: 0 12px 28px rgba(23, 32, 51, 0.16);
  backdrop-filter: none !important;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  z-index: 920;
}

#selectionPanel { width: 374px; }
#metricPanel { width: 232px; }
#systemPanel { width: 226px; }
#yearPanel { width: 150px; }

.top-controls .floating-panel[hidden] {
  display: none;
}

.top-controls .floating-option {
  width: 100%;
}

.top-controls .floating-option:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

/* More room for names, values and the selected-area summary. */
.layout {
  grid-template-columns: minmax(420px, 460px) minmax(0, 1fr);
}

.panel {
  padding: 10px 14px 12px;
  background: #ffffff;
}

/* Only the legend remains on the right side of the map. */
.map-right-stack {
  position: absolute;
  right: 12px;
  bottom: 48px;
  top: auto;
  left: auto;
  width: auto;
  max-width: 280px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.map-right-stack .control-guidance,
.map-right-stack .map-floating-filters,
.map-right-stack .metric-help {
  display: none !important;
}

.map-right-stack .legend {
  position: static;
  max-width: 255px;
  padding: 10px 11px;
  border: 1px solid #d8dfdc;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 2px 10px rgba(23, 32, 51, 0.05);
  pointer-events: auto;
}

/* Clear expand/collapse affordance. */
.detail-more {
  margin-top: 11px;
  border-top: 1px solid var(--line-soft);
}

.detail-more summary {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 30px 3px 0;
  color: #175d6c;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.detail-more summary::-webkit-details-marker {
  display: none;
}

.detail-more summary::after {
  content: "+";
  position: absolute;
  right: 0;
  top: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 1px solid #c6d1cc;
  border-radius: 50%;
  background: #f7f9f8;
  color: #175d6c;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.detail-more[open] summary::after {
  content: "−";
}

.detail-more summary:hover::after,
.detail-more summary:focus-visible::after {
  border-color: #91a59d;
  background: #eef3f2;
}

.detail-more[open] > .detail-list {
  display: block;
  margin-top: 7px;
}

.detail-more:not([open]) > .detail-list {
  display: none;
}

/* Desktop sidebar state: exactly one lower view is visible at a time. */
@media (min-width: 761px) {
  .panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .panel .rank-card {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
  }

  .panel.details-expanded .rank-card {
    display: none !important;
  }

  .panel.details-expanded .detail-card {
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 0;
    overflow: auto;
  }
}

@media (max-width: 1180px) and (min-width: 761px) {
  .top-controls .top-floating-filters {
    flex-wrap: wrap;
  }

  .top-controls .floating-control:nth-child(n) {
    width: auto;
    min-width: 170px;
    flex: 1 1 calc(25% - 8px);
  }

  .top-controls .floating-control:first-child {
    min-width: 250px;
  }

  .top-controls-about {
    margin-left: auto;
  }
}

/* -------------------------------------------------------------------------
   Final phone filter sheet
   The desktop control row is replaced on phones by one contained sheet,
   opened from the Filters button. This prevents horizontal overflow and
   keeps every option within the viewport.
   ------------------------------------------------------------------------- */
.mobile-filter-sheet-header,
.mobile-filter-backdrop {
  display: none;
}

@media (max-width: 760px) {
  html,
  body,
  .app-shell {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.mobile-filters-open {
    overflow: hidden;
    overscroll-behavior: none;
  }


  .app-shell > .topbar {
    min-height: 132px;
    padding: 14px 16px;
    gap: 12px;
    align-items: center;
  }

  .app-shell > .topbar .topbar-title {
    flex: 1 1 48%;
    max-width: 48%;
  }

  .app-shell > .topbar h1 {
    font-size: clamp(1.35rem, 6.4vw, 1.68rem);
    line-height: 1.02;
    overflow-wrap: normal;
  }

  .app-shell > .topbar h1::after {
    content: none !important;
    display: none !important;
  }

  .app-shell > .topbar .topbar-subtitle {
    max-width: 18ch;
    margin-top: 2px;
    font-size: 0.68rem;
    line-height: 1.22;
  }

  .app-shell > .topbar .topbar-actions {
    flex: 1 1 48%;
    min-width: 0;
  }

  .app-shell > .topbar .topbar-logo {
    width: min(100%, 168px);
    max-width: 100%;
    max-height: 58px;
  }

  /* The desktop row must never consume horizontal space on a phone. */
  .top-controls {
    display: none;
  }

  .mobile-filter-backdrop {
    appearance: none;
    -webkit-appearance: none;
    position: fixed;
    inset: 0;
    z-index: 8800;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(8, 28, 31, 0.44);
    box-shadow: none;
    cursor: default;
    touch-action: none;
  }

  .mobile-filter-backdrop[hidden] {
    display: none !important;
  }

  .top-controls.is-mobile-open {
    position: fixed;
    z-index: 9000;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: block;
    width: auto;
    max-height: calc(100dvh - 20px - env(safe-area-inset-bottom));
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    border: 1px solid #bfcac6;
    border-radius: 9px;
    background: #ffffff;
    box-shadow: 0 18px 54px rgba(10, 32, 36, 0.3);
  }

  .mobile-filter-sheet-header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 56px;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid #d8dfdc;
    background: #ffffff;
  }

  .mobile-filter-sheet-header h2 {
    margin: 0;
    color: #123f49;
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -0.015em;
  }

  .mobile-filter-sheet-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
  }

  .mobile-filter-sheet-reset,
  .mobile-filter-sheet-close {
    min-width: 70px;
    min-height: 38px;
    padding: 7px 12px;
    border: 1px solid #176c7b;
    border-radius: 6px;
    background: #ffffff;
    color: #176c7b;
    font-size: 0.84rem;
    font-weight: 700;
  }

  .mobile-filter-sheet-reset {
    min-width: 62px;
    color: #315b62;
    border-color: #aebdb8;
  }

  .mobile-filter-sheet-reset:hover,
  .mobile-filter-sheet-reset:focus-visible,
  .mobile-filter-sheet-close:hover,
  .mobile-filter-sheet-close:focus-visible {
    border-color: #176c7b;
    background: #eef7f5;
    color: #176c7b;
  }

  .top-controls.is-mobile-open .top-floating-filters {
    display: flex;
    width: 100%;
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
  }

  .top-controls.is-mobile-open .floating-control,
  .top-controls.is-mobile-open .floating-control:nth-child(n),
  .top-controls.is-mobile-open .top-controls-about {
    display: block;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    margin: 0;
  }

  .top-controls.is-mobile-open .top-controls-actions {
    display: none;
  }

  .top-controls.is-mobile-open .floating-toggle-button,
  .top-controls.is-mobile-open .about-button {
    width: 100%;
    height: auto;
    min-height: 48px;
    border: 1px solid #c6d1cc;
    border-radius: 6px;
    background: #ffffff;
    font-size: 0.86rem;
    line-height: 1.25;
  }

  .top-controls.is-mobile-open .floating-toggle-button {
    padding: 11px 36px 11px 12px;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .top-controls.is-mobile-open .floating-toggle-button[aria-expanded="true"] {
    border-color: #176c7b;
    border-radius: 6px 6px 0 0;
    background: #f7faf8;
  }

  .top-controls.is-mobile-open .floating-panel,
  .top-controls.is-mobile-open .floating-control .floating-panel,
  .top-controls.is-mobile-open #selectionPanel,
  .top-controls.is-mobile-open #metricPanel,
  .top-controls.is-mobile-open #systemPanel,
  .top-controls.is-mobile-open #yearPanel {
    position: static;
    inset: auto;
    width: 100%;
    max-width: none;
    max-height: min(44dvh, 390px);
    margin: -9px 0 0;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    border: 1px solid #176c7b;
    border-top: 0;
    border-radius: 0 0 6px 6px;
    background: #ffffff !important;
    box-shadow: none;
  }

  .top-controls.is-mobile-open .floating-panel-title {
    margin: 2px 3px 7px;
  }

  .top-controls.is-mobile-open .floating-option {
    min-height: 42px;
    padding: 9px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
  }

  .top-controls.is-mobile-open .about-button {
    margin-top: 3px;
    color: #176c7b;
  }


  /* The old map-side container now holds only a desktop legend. It must not
     create a second mobile panel or any blank space. */
  #mobileFilterPanel,
  .map-right-stack,
  .map-right-stack.is-mobile-open {
    display: none !important;
  }
}

@media (max-width: 370px) {
  .mobile-filter-sheet-header {
    gap: 8px;
    padding-left: 12px;
  }

  .mobile-filter-sheet-actions {
    gap: 6px;
  }

  .mobile-filter-sheet-reset,
  .mobile-filter-sheet-close {
    min-width: 56px;
    padding-inline: 9px;
  }

  .app-shell > .topbar {
    min-height: 122px;
    padding-inline: 12px;
  }

  .app-shell > .topbar h1 {
    font-size: 1.28rem;
  }

  .app-shell > .topbar .topbar-subtitle {
    font-size: 0.63rem;
  }

  .app-shell > .topbar .topbar-logo {
    max-height: 50px;
  }
}


/* -------------------------------------------------------------------------
   Mobile About placement
   Keep About outside the filter sheet so it cannot be mistaken for Done.
   ------------------------------------------------------------------------- */
.mobile-filter-copy,
.mobile-about-button {
  display: none;
}

@media (max-width: 760px) {
  .mobile-filter-copy {
    min-width: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .mobile-filter-copy #mobileFilterSummary {
    width: 100%;
  }

  .mobile-about-button {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    min-height: 0;
    align-items: center;
    padding: 1px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--brand-aqua);
    font: inherit;
    font-size: 0.73rem;
    font-weight: 650;
    line-height: 1.2;
    text-decoration: underline;
    text-underline-offset: 2px;
    box-shadow: none;
    cursor: pointer;
  }

  .mobile-about-button:hover,
  .mobile-about-button:focus-visible {
    border: 0;
    background: transparent;
    color: var(--text);
    box-shadow: none;
  }

  /* Keep the desktop About button on desktop, but remove it from the phone
     filter sheet so Done is the only completion action. */
  .top-controls.is-mobile-open .top-controls-about {
    display: none !important;
  }
}


/* -------------------------------------------------------------------------
   Narrow-screen header background
   Keep the branded artwork edge-to-edge when the viewport becomes too narrow
   for the desktop white logo zone. The logo itself retains its white field.
   ------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .app-shell > .topbar {
    background:
      linear-gradient(90deg,
        rgba(3, 45, 53, 0.92) 0%,
        rgba(3, 45, 53, 0.76) 52%,
        rgba(3, 45, 53, 0.52) 100%),
      url("images/IES_Header_Pattern.png") left center / auto 100% no-repeat,
      #064b50;
  }
}
