* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  background: #f0f0f0;
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Search */
#search-container {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 280px;
}

#search-input {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  outline: none;
}

#search-input:focus {
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

#search-results {
  background: #fff;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 300px;
  overflow-y: auto;
  display: none;
}

#search-results.active {
  display: block;
}

.search-item {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}

.search-item:hover {
  background: #f5f5f5;
}

.search-item .search-code {
  color: #888;
  font-size: 11px;
  margin-left: 6px;
}

/* View toggle */
#view-toggle-container {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

#view-toggle {
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  overflow: hidden;
}

.map-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  background: #fff;
  padding: 4px 12px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.map-toggle input {
  display: none;
}

.map-toggle-text {
  font-size: 12px;
  font-weight: 500;
  color: #555;
}

.toggle-btn {
  padding: 8px 16px;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn:not(:last-child) {
  border-right: 1px solid #eee;
}

.toggle-btn:hover {
  background: #f5f5f5;
}

.toggle-btn.active {
  background: #2563eb;
  color: #fff;
}

/* Legend */
#legend {
  position: absolute;
  bottom: 32px;
  left: 12px;
  z-index: 10;
  background: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  min-width: 200px;
}

#legend-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #333;
}

#legend-bar {
  height: 12px;
  border-radius: 3px;
  margin-bottom: 4px;
}

#legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
}

/* Side panel */
#panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 400px;
  height: 100%;
  background: #fff;
  box-shadow: -4px 0 16px rgba(0,0,0,0.1);
  z-index: 20;
  overflow-y: auto;
  padding: 24px;
  transition: transform 0.25s ease;
}

#panel.hidden {
  transform: translateX(100%);
}

#panel-close,
#panel-minimize {
  position: absolute;
  top: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: #aaa;
  line-height: 1;
}

#panel-close {
  font-size: 28px;
}

#panel-minimize {
  font-size: 18px;
}

#panel-close {
  right: 16px;
}

#panel-minimize {
  right: 48px;
  display: none;
}

#panel-close:hover,
#panel-minimize:hover {
  color: #333;
}

#panel-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  padding-right: 36px;
  color: #111;
}

#panel-code {
  color: #888;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Summary stats */
#panel-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  flex: 1;
  background: #f7f7f8;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: #888;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: #111;
}

.stat-value.positive {
  color: #2563eb;
}

.stat-value.negative {
  color: #dc2626;
}

/* Action button */
.action-btn {
  width: 100%;
  padding: 10px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 20px;
  transition: background 0.15s;
}

.action-btn:hover {
  background: #1d4ed8;
}

#map-mode {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#map-mode .action-btn {
  flex: 1;
  margin-bottom: 0;
}

.shade-btn {
  background: #7c3aed !important;
}

.shade-btn:hover {
  background: #6d28d9 !important;
}

.shade-btn.active-shade {
  background: #dc2626 !important;
}

.shade-btn.active-shade::after {
  content: " (click to hide)";
}

.action-btn.active-flows {
  background: #dc2626;
}

.action-btn.active-flows::after {
  content: " (click to hide)";
}

/* Filter toggles */
#panel-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #555;
  user-select: none;
}

.filter-toggle input {
  display: none;
}

.filter-slider {
  width: 34px;
  height: 18px;
  background: #ccc;
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.filter-slider::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.filter-toggle input:checked + .filter-slider,
.map-toggle input:checked + .filter-slider {
  background: #2563eb;
}

.filter-toggle input:checked + .filter-slider::after,
.map-toggle input:checked + .filter-slider::after {
  transform: translateX(16px);
}

/* Bar charts */
#chart-origins, #chart-destinations, #chart-age {
  margin-bottom: 20px;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.bar-row:hover .bar-fill {
  opacity: 0.8;
}

.bar-label {
  width: 120px;
  font-size: 12px;
  color: #444;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 18px;
  background: #f0f0f0;
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.bar-fill.inflow {
  background: #2563eb;
}

.bar-fill.outflow {
  background: #dc2626;
}

.bar-value {
  width: 50px;
  font-size: 11px;
  color: #666;
  flex-shrink: 0;
}

/* Population pyramid */
.pyramid-row {
  display: flex;
  align-items: center;
  margin-bottom: 3px;
  height: 24px;
}

.pyramid-label {
  width: 48px;
  font-size: 11px;
  color: #444;
  text-align: center;
  flex-shrink: 0;
}

.pyramid-bar-left {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}

.pyramid-fill-left {
  height: 100%;
  background: #dc2626;
  border-radius: 3px 0 0 3px;
}

.pyramid-bar-right {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  position: relative;
}

.pyramid-fill-right {
  height: 100%;
  background: #2563eb;
  border-radius: 0 3px 3px 0;
}

.pyramid-value-left {
  font-size: 10px;
  color: #888;
  margin-right: 4px;
  flex-shrink: 0;
}

.pyramid-value-right {
  font-size: 10px;
  color: #888;
  margin-left: 4px;
  flex-shrink: 0;
}

/* Attribution */
#attribution {
  position: absolute;
  bottom: 8px;
  left: 12px;
  z-index: 10;
  font-size: 11px;
  color: #666;
  background: rgba(255,255,255,0.85);
  padding: 3px 8px;
  border-radius: 4px;
}

#attribution a {
  color: #2563eb;
  text-decoration: none;
}

#attribution a:hover {
  text-decoration: underline;
}

/* About dialog */
#about-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#about-overlay.about-hidden {
  display: none;
}

#about-dialog {
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 500px;
  width: 90%;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

#about-dialog h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: #111;
}

#about-dialog p,
#about-dialog ul,
#about-dialog li {
  font-size: 14px;
  color: #444;
  line-height: 1.6;
}

#about-dialog p {
  margin-bottom: 10px;
}

#about-dialog ul {
  margin: 4px 0 10px 20px;
}

#about-dialog a {
  color: #2563eb;
  text-decoration: none;
}

#about-dialog a:hover {
  text-decoration: underline;
}

#about-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #888;
  line-height: 1;
}

#about-close:hover {
  color: #333;
}

/* MapLibre popup */
.maplibregl-popup-content {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.popup-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.popup-value {
  color: #555;
  font-size: 12px;
}

/* Responsive */
@media (max-width: 600px) {
  #panel {
    width: 100%;
    transition: transform 0.25s ease, height 0.25s ease, top 0.25s ease;
  }

  #panel.minimized {
    top: 75%;
    height: 25%;
    overflow-y: auto;
  }

  #panel-minimize {
    display: block;
  }

  #search-container {
    width: calc(100% - 24px);
  }

  #view-toggle-container {
    top: 56px;
  }

  .toggle-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}
