html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #f6f6f4;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  color: #242424;
  font-family: Inter, "Segoe UI", Tahoma, sans-serif;
}

.topbar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
  flex-wrap: wrap;
  z-index: 1010;
  box-sizing: border-box;
}

.brand {
  font-family: "Outfit", Inter, "Segoe UI", sans-serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.top-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f4f4f4;
  border: 1px solid #d7d7d7;
  font-size: 13px;
  font-weight: 500;
  color: #444;
  line-height: 1;
}

.chip-green {
  background: #eaf5ed;
  color: #307655;
  border-color: #cde2d2;
  font-weight: 700;
}

.chip-3d {
  background: rgba(15, 109, 114, 0.12);
  color: #0f6d72;
  border-color: rgba(15, 109, 114, 0.25);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dark-theme .chip-3d {
  background: rgba(45, 183, 234, 0.15);
  color: #2db7ea;
  border-color: rgba(45, 183, 234, 0.3);
}

.source-methodology-btn {
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.68);
  color: #2f2f2f;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.source-methodology-btn:hover {
  background: #ffffff;
}
.dark-theme .source-methodology-btn {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: #e8e8e8;
}
.dark-theme .source-methodology-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.info-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, 0.46);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.info-modal {
  width: min(560px, 100%);
  max-height: min(82vh, 720px);
  overflow-y: auto;
  background: #ffffff;
  color: #242424;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
.info-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #e8e8e8;
}
.info-modal-header h2 {
  margin: 0;
  font-family: "Outfit", Inter, "Segoe UI", sans-serif;
  font-size: 20px;
  line-height: 1.2;
}
.info-modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #f7f7f7;
  color: #333;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.info-modal-close:hover {
  background: #eeeeee;
}
.info-modal-body {
  padding: 16px 18px 18px;
  font-size: 14px;
  line-height: 1.5;
}
.info-modal-body section {
  margin-bottom: 14px;
}
.info-modal-body h3 {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #0f6d72;
}
.info-modal-body p {
  margin: 0 0 8px;
}
.info-modal-body ul {
  margin: 0;
  padding-left: 18px;
}
.info-modal-body li {
  margin-bottom: 6px;
}
.info-modal-warning {
  margin-top: 14px !important;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff6df;
  border: 1px solid #ead79d;
  color: #6b5319;
  font-weight: 600;
}
.dark-theme .info-modal {
  background: #1c1c1c;
  color: #e8e8e8;
  border-color: rgba(255, 255, 255, 0.08);
}
.dark-theme .info-modal-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
.dark-theme .info-modal-close {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: #eeeeee;
}
.dark-theme .info-modal-close:hover {
  background: rgba(255, 255, 255, 0.12);
}
.dark-theme .info-modal-body h3 {
  color: #2db7ea;
}
.dark-theme .info-modal-warning {
  background: rgba(234, 215, 157, 0.12);
  border-color: rgba(234, 215, 157, 0.35);
  color: #ead79d;
}

.layout {
  position: relative;
  width: 100%;
  height: 100vh;
}

.sidebar {
  position: absolute;
  top: 96px;
  bottom: 20px;
  width: 320px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  overflow-y: auto;
  padding: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-left {
  left: 20px;
}

.sidebar-right {
  right: 20px;
}

.panel-block {
  border-bottom: none;
  padding: 0;
}

.panel-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #9b9b9b;
  font-weight: 700;
  margin-bottom: 8px;
}

.segmented {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 3px;
}

.segmented-2 {
  grid-template-columns: 1fr 1fr;
}

.segmented-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.segmented-4 {
  grid-template-columns: 1fr 1fr;
}

.seg {
  border: none;
  background: transparent;
  border-radius: 5px;
  padding: 7px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #6f6f6f;
  cursor: pointer;
}

.seg.active {
  background: #ffffff;
  color: #2b2b2b;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.seg.is-disabled {
  opacity: 0.85;
  pointer-events: none;
  cursor: default;
}

.ui-select {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px;
  color: #242424;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.legend-box.compact {
  background: #f1f1f1;
  border: 1px solid #d0d0d0;
  border-radius: 12px;
  padding: 10px;
}

.legend-bar {
  display: flex;
  width: 100%;
  height: 16px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.legend-segment {
  height: 100%;
}

.legend-row {
  display: grid;
  grid-template-columns: 10px 90px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 12px;
}

.legend-row:last-child {
  margin-bottom: 0;
}

.legend-track-bg {
  height: 4px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 2px;
  width: 100%;
}

.dark-theme .legend-track-bg {
  background: rgba(255, 255, 255, 0.1);
}

.legend-stats {
  color: #666;
  font-size: 11px;
  font-family: "Outfit", Inter, sans-serif;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.dark-theme .legend-stats {
  color: #aaa;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  display: inline-block;
}

.pdc { background: #0f6d72; }
.libre { background: #e1524e; }
.unidad { background: #f3b347; }
.ap { background: #7f64a8; }
.apbs { background: #3e1f72; }
.mas { background: #2f7486; }
.fp { background: #2db7ea; }
.lyp { background: #b61f31; }
.otros { background: #c48294; }

.legend-party {
  white-space: nowrap;
  color: #2c2c2c;
}

.legend-pct,
.legend-votes {
  color: #666;
  font-size: 11px;
}

.wins-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.win-card {
  border: 1px solid #cfcfcf;
  border-radius: 7px;
  background: #ededed;
  padding: 9px 6px 7px;
  text-align: center;
}

.win-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  font-family: "Outfit", Inter, "Segoe UI", sans-serif;
  letter-spacing: -0.01em;
}

.pdc-text {
  color: #0f6d72;
}

.libre-text {
  color: #e1524e;
}

.win-label {
  font-size: 11px;
  color: #7a7a7a;
  margin-top: 4px;
}

.hidden {
  display: none;
}

.map-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#map {
  width: 100%;
  height: 100%;
}

.basemap-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #e8e8e8;
  border: 1px solid #d5d5d5;
  border-radius: 999px;
  padding: 3px;
}

.dark-theme .basemap-bar {
  background: #252525;
  border-color: #383838;
}

.base-btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #666;
  transition: all 0.2s ease;
}

.dark-theme .base-btn {
  color: #aaa;
}

.base-btn.active {
  background: #ffffff;
  color: #111;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.dark-theme .base-btn.active {
  background: #3a3a3a;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.btn-reset {
  color: #0f6d72 !important;
  font-weight: 700 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  height: 28px;
  padding: 0 10px !important;
  border-radius: 999px !important;
  white-space: nowrap;
}

.dark-theme .btn-reset {
  color: #2db7ea !important;
}

.leaflet-control-zoom {
  margin-top: 12px !important;
  margin-left: 10px !important;
  border: 1px solid #c7c7c7 !important;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.16) !important;
}

.leaflet-control-zoom a {
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  color: #3a3a3a !important;
}

.elex-popup .leaflet-popup-content-wrapper {
  border-radius: 14px;
  padding: 0;
}

.elex-popup .leaflet-popup-content {
  margin: 0;
  width: 290px !important;
}

.popup-card {
  padding: 14px 14px 12px;
  color: #2a2a2a;
}

.popup-title {
  font-family: "Outfit", Inter, "Segoe UI", sans-serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.popup-subtitle {
  color: #666;
  font-size: 13px;
  margin-top: 3px;
}

.popup-winner {
  margin-top: 12px;
  background: #f5f5f4;
  border: 1px solid #dedede;
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
}

.popup-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.popup-winner-name {
  font-weight: 700;
}

.popup-winner-pct {
  font-weight: 700;
  font-size: 16px;
}

.popup-party-box {
  margin-top: 10px;
  background: #f5f5f4;
  border: 1px solid #dedede;
  border-radius: 8px;
  padding: 9px 10px;
}

.popup-mini-bar {
  display: flex;
  height: 18px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 7px;
}

.popup-segment {
  height: 100%;
}

.popup-party-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 7px;
  align-items: center;
  font-size: 12px;
  margin-top: 2px;
}

.popup-party {
  color: #4a4a4a;
}

.popup-pct {
  color: #2f2f2f;
}

.popup-votes {
  color: #7a7a7a;
}

.popup-metrics {
  margin-top: 10px;
  border-top: 1px solid #e5e5e5;
  padding-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.popup-metrics div {
  text-align: left;
}

.popup-metrics strong {
  display: block;
  font-family: "Outfit", Inter, "Segoe UI", sans-serif;
  font-size: 20px;
  line-height: 1.1;
  color: #222;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.popup-metrics span {
  font-size: 11px;
  color: #8a8a8a;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 280px;
    border-right: none;
    border-bottom: 1px solid #d7d7d7;
  }

  .topbar {
    padding: 8px 10px;
  }

  .brand {
    font-size: 18px;
  }

  .chip {
    font-size: 11px;
  }
}

/* Search UI in sidebar */
.search-box-container {
  position: relative;
  width: 100%;
}
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-wrap i {
  position: absolute;
  left: 10px;
  color: #888;
  font-size: 13px;
  pointer-events: none;
}
.search-input-wrap input {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 9px 12px 9px 32px;
  font-size: 12px;
  color: #242424;
  box-sizing: border-box;
  transition: all 0.2s ease;
}
.search-input-wrap input:focus {
  outline: none;
  border-color: #0f6d72;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(15, 109, 114, 0.1);
}
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #d7d7d7;
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 1200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: 4px;
}
.search-result-item {
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f1f1;
  transition: background 0.15s ease;
  display: flex;
  flex-direction: column;
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background: #f5f5f5;
}
.search-result-item .item-title {
  font-weight: 600;
  color: #222;
}
.search-result-item .item-subtitle {
  font-size: 10px;
  color: #777;
  margin-top: 2px;
}

/* Color mode legends */
.legend-colorbar {
  width: 100%;
  height: 12px;
  border-radius: 4px;
  margin-top: 6px;
  margin-bottom: 6px;
  border: 1px solid rgba(0,0,0,0.1);
}
.legend-colorbar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #666;
  font-weight: 500;
  gap: 8px;
}
.legend-colorbar-labels span {
  flex: 1;
  line-height: 1.25;
}
.legend-colorbar-labels span:nth-child(2) {
  text-align: center;
}
.legend-colorbar-labels span:last-child {
  text-align: right;
}
.legend-colorbar-labels small {
  color: #888;
  font-size: 9px;
}
.legend-note {
  margin: 2px 0 8px;
  color: #555;
  font-size: 11px;
  line-height: 1.35;
}

/* Popup Candidates Section */
.popup-candidates-title {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: #888;
  font-weight: 700;
  margin-top: 12px;
  margin-bottom: 6px;
  text-transform: uppercase;
  border-top: 1px solid #e5e5e5;
  padding-top: 8px;
}
.popup-candidates-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}
.popup-candidate-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fdfdfd;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  padding: 6px 8px;
}
.popup-cand-party-stripe {
  width: 4px;
  height: 24px;
  border-radius: 2px;
  flex-shrink: 0;
}
.popup-cand-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
}
.popup-cand-name {
  font-weight: 600;
  font-size: 11px;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.popup-cand-details {
  font-size: 9px;
  color: #777;
  margin-top: 1px;
}
.popup-cand-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  background: #eaf5ed;
  color: #307655;
  flex-shrink: 0;
}

/* Tema Oscuro (Dark Theme) */
body.dark-theme {
  background: #121212;
  color: #e0e0e0;
}
.dark-theme .topbar {
  background: rgba(26, 26, 26, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.dark-theme .brand {
  color: #ffffff;
}
.dark-theme .chip {
  background: #242424;
  border-color: #3d3d3d;
  color: #ccc;
}
.dark-theme .chip-green {
  background: #14321d;
  color: #69c48b;
  border-color: #1b4728;
}
.dark-theme .sidebar {
  background: rgba(24, 24, 24, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.dark-theme .panel-block {
  border-bottom: none;
}
.dark-theme .panel-label {
  color: #7c7c7c;
}
.dark-theme .segmented {
  border: 1px solid #333333;
  background: #252525;
}
.dark-theme .seg {
  color: #aaa;
}
.dark-theme .seg.active {
  background: #3a3a3a;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.dark-theme .ui-select {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.3);
  color: #eee;
}
.ui-select option {
  background: #ffffff !important;
  color: #242424 !important;
}
.dark-theme .ui-select option {
  background: #1c1c1e !important;
  color: #eeeeee !important;
}
.dark-theme .search-input-wrap input {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.3);
  color: #eee;
}
.dark-theme .search-input-wrap input:focus {
  border-color: #2db7ea;
  background: rgba(0, 0, 0, 0.5);
}
.dark-theme .search-results-dropdown {
  background: #222222;
  border: 1px solid #3d3d3d;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}
.dark-theme .search-result-item {
  border-bottom: 1px solid #2d2d2d;
}
.dark-theme .search-result-item:hover {
  background: #2e2e2e;
}
.dark-theme .search-result-item .item-title {
  color: #eee;
}
.dark-theme .search-result-item .item-subtitle {
  color: #999;
}
.dark-theme .legend-box.compact {
  background: #1e1e1e;
  border: 1px solid #333;
}
.dark-theme .legend-party {
  color: #eee;
}
.dark-theme .legend-pct,
.dark-theme .legend-votes {
  color: #aaa;
}
.dark-theme .win-card {
  border: 1px solid #333;
  background: #222;
}
.dark-theme .win-label {
  color: #999;
}
.dark-theme .basemap-bar {
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #3d3d3d;
}
.dark-theme .base-btn {
  color: #aaa;
}
.dark-theme .base-btn.active {
  background: #eee;
  color: #111;
}
.dark-theme .legend-colorbar-labels {
  color: #aaa;
}
.dark-theme .legend-colorbar-labels small,
.dark-theme .legend-note {
  color: #9a9a9a;
}

/* Dark mode Leaflet Popups */
.dark-theme .elex-popup .leaflet-popup-content-wrapper {
  background: #1c1c1c !important;
  color: #e0e0e0 !important;
  border: 1px solid #333;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.dark-theme .elex-popup .leaflet-popup-tip {
  background: #1c1c1c !important;
}
.dark-theme .popup-title {
  color: #ffffff;
}
.dark-theme .popup-subtitle {
  color: #aaa;
}
.dark-theme .popup-winner {
  background: #252525;
  border-color: #383838;
  color: #fff;
}
.dark-theme .popup-party-box {
  background: #252525;
  border-color: #383838;
}
.dark-theme .popup-party {
  color: #ddd;
}
.dark-theme .popup-pct {
  color: #eee;
}
.dark-theme .popup-votes {
  color: #aaa;
}
.dark-theme .popup-metrics {
  border-top-color: #333;
}
.dark-theme .popup-metrics strong {
  color: #fff;
}
.dark-theme .popup-metrics span {
  color: #999;
}
.dark-theme .popup-candidates-title {
  border-top-color: #333;
  color: #aaa;
}
.dark-theme .popup-candidate-item {
  background: #252525;
  border-color: #333;
}
.dark-theme .popup-cand-name {
  color: #fff;
}
.dark-theme .popup-cand-details {
  color: #aaa;
}
.dark-theme .popup-cand-badge {
  background: #14321d;
  color: #69c48b;
}
.dark-theme .leaflet-bar a {
  background-color: #242424 !important;
  color: #eee !important;
  border-bottom: 1px solid #3d3d3d !important;
}
.dark-theme .leaflet-bar a:hover {
  background-color: #333 !important;
}
.dark-theme .leaflet-control-zoom {
  border-color: #3d3d3d !important;
}

/* Mode Switch Button (2D/3D switcher) */
.mode-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0f6d72, #0d5c60);
  color: #ffffff !important;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  line-height: 1;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(15, 109, 114, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
}
.mode-switch-btn i {
  font-size: 12px;
}
.mode-switch-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 109, 114, 0.5);
  background: linear-gradient(135deg, #138288, #0f6d72);
}
.dark-theme .mode-switch-btn {
  background: linear-gradient(135deg, #148085, #0f6d72);
  box-shadow: 0 2px 10px rgba(15, 109, 114, 0.4);
}
.dark-theme .mode-switch-btn:hover {
  background: linear-gradient(135deg, #1ea3aa, #148085);
  box-shadow: 0 4px 15px rgba(20, 128, 133, 0.6);
}

/* Sidebar Collapse Handle */
.sidebar-toggle-handle {
  display: flex;
  width: 100%;
  padding: 10px 0;
  text-align: center;
  cursor: pointer;
  background: rgba(0,0,0,0.02);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: 12px;
  flex-shrink: 0;
  user-select: none;
}
.sidebar-toggle-handle:focus-visible {
  outline: 2px solid #0f6d72;
  outline-offset: 2px;
}
.handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #ccc;
}
.handle-text {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #777;
}
.dark-theme .sidebar-toggle-handle {
  background: rgba(255,255,255,0.02);
  border-bottom-color: rgba(255,255,255,0.05);
}
.dark-theme .handle-bar {
  background: #555;
}
.dark-theme .handle-text {
  color: #aaa;
}

.sidebar.sidebar-collapsed {
  width: 48px;
  padding: 8px;
  overflow: visible;
}
.sidebar.sidebar-collapsed > :not(.sidebar-toggle-handle) {
  display: none !important;
}
.sidebar.sidebar-collapsed .sidebar-toggle-handle {
  height: 100%;
  min-height: 180px;
  justify-content: center;
  border-bottom: none;
}
.sidebar.sidebar-collapsed .handle-bar {
  width: 4px;
  height: 36px;
}
.sidebar.sidebar-collapsed .handle-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

/* Precinct Details Panel (Desktop: Elegant Right Side Panel, Mobile: Slide-Up Bottom Sheet) */
.precinct-details-panel {
  position: fixed;
  top: 75px; /* Aligned nicely below topbar */
  right: 20px;
  width: 310px;
  max-height: calc(100vh - 95px); /* Maximized vertical space for better readability */
  background: #ffffff;
  color: #2a2a2a;
  border-radius: 16px;
  box-shadow: 0 10px 35px rgba(0,0,0,0.12);
  padding: 16px;
  z-index: 1500;
  border: 1px solid #dedede;
  overflow-y: auto;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.precinct-details-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(40px);
}
.dark-theme .precinct-details-panel {
  background: #1c1c1c;
  color: #e0e0e0;
  border-color: #333;
  box-shadow: 0 10px 35px rgba(0,0,0,0.35);
}
.precinct-details-panel .close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s ease;
}
.precinct-details-panel .close-btn:hover {
  color: #333;
}
.dark-theme .precinct-details-panel .close-btn:hover {
  color: #fff;
}

/* Sidebar Right Header and Back Button */
.sidebar-right-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.btn-back {
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.8);
  color: #242424;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  line-height: 1;
}

.btn-back:hover {
  background: #ffffff;
  border-color: #0f6d72;
  color: #0f6d72;
}

.dark-theme .btn-back {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.3);
  color: #eee;
}

.dark-theme .btn-back:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: #2db7ea;
  color: #2db7ea;
}

/* Mobile responsive sheet tabs */
.mobile-tabs {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(0,0,0,0.03);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  margin-bottom: 8px;
}
.dark-theme .mobile-tabs {
  background: rgba(255,255,255,0.03);
  border-bottom-color: rgba(255,255,255,0.05);
}
.mobile-tab-btn {
  border: none;
  background: transparent;
  padding: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #666;
  cursor: pointer;
  border-radius: 8px;
  text-align: center;
  transition: all 0.2s ease;
}
.mobile-tab-btn.active {
  background: #fff;
  color: #111;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.dark-theme .mobile-tab-btn {
  color: #aaa;
}
.dark-theme .mobile-tab-btn.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.sidebar-mobile-hidden {
  display: flex;
}

/* Zoom controls adjustments below the topbar */
.leaflet-control-zoom {
  margin-top: 90px !important;
  margin-left: 20px !important;
}

.maplibregl-ctrl-top-left {
  top: 85px !important;
  left: 10px !important;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  .sidebar-toggle-handle {
    display: flex;
  }
  
  .layout {
    flex-direction: column;
    position: relative;
  }
  
  .sidebar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    max-height: 52vh;
    height: 52vh;
    z-index: 1000;
    box-shadow: 0 -4px 25px rgba(0,0,0,0.15);
    border-right: none;
    border-top: 1px solid rgba(0,0,0,0.08);
    border-radius: 20px 20px 0 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    top: auto !important;
  }
  
  .dark-theme .sidebar {
    border-top-color: rgba(255,255,255,0.08);
    background: #1c1c1c;
  }

  .sidebar.sidebar-collapsed {
    transform: translateY(calc(100% - 40px)) !important;
  }
  .sidebar.sidebar-collapsed .sidebar-toggle-handle {
    height: auto;
    min-height: 40px;
    justify-content: flex-start;
  }
  .sidebar.sidebar-collapsed .handle-bar {
    width: 36px;
    height: 4px;
  }
  .sidebar.sidebar-collapsed .handle-text {
    writing-mode: horizontal-tb;
    transform: none;
  }
  
  .sidebar-mobile-hidden {
    display: none !important;
  }
  
  .mobile-tabs {
    display: grid;
  }
  
  .map-wrap {
    height: 100vh;
    width: 100%;
  }

  /* Compact elements in mobile sidebar */
  .panel-block {
    padding: 0;
  }
  
  .brand {
    font-size: 16px;
  }
  
  .topbar {
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 8px 16px;
  }
  
  .leaflet-control-zoom {
    margin-top: 110px !important;
    margin-left: 10px !important;
  }
}
