:root {
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);

  --series-1: #3987e5; /* blue */
  --series-2: #199e70; /* teal */

  /* Sequential scale for the district-price choropleth: one hue (blue, same
     family as --series-1), light->dark mapped to low->high price so the
     ramp reads as magnitude, not identity. */
  --scale-low: #1e3a5c;
  --scale-high: #5fa8f5;
  --scale-no-data: var(--gridline);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  animation: page-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

a {
  color: var(--series-1);
}

.topbar h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  width: fit-content;
  cursor: pointer;
  transition: color 150ms ease;
}

.topbar h1:hover {
  color: var(--series-1);
}

.topbar h1:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 4px;
}

.subtitle {
  color: var(--text-secondary);
  margin: 0 0 28px;
  max-width: 70ch;
}

#refresh-countdown {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 24px;
}

.search-wrap {
  position: relative;
  flex: 1 1 320px;
}

#search {
  width: 100%;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 34px 9px 12px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

#search:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: color 150ms ease, background-color 150ms ease;
}

.search-clear:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

@keyframes suggestions-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  max-height: 340px;
  overflow-y: auto;
}

.suggestions:not([hidden]) {
  animation: suggestions-in 140ms ease-out both;
}

.suggestions .group-label {
  padding: 6px 8px 4px;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.suggestions li.option {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 120ms ease;
}

.suggestions li.option .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestions li.option .meta {
  flex: none;
  color: var(--text-muted);
  font-size: 11px;
}

.suggestions li.option:hover,
.suggestions li.option.active {
  background: rgba(57, 135, 229, 0.14);
}

.filter-select {
  flex: none;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 10px;
  transition: border-color 150ms ease;
  /* Fixed rather than content-sized: a <select>'s intrinsic width follows
     its widest <option>, and the real district/type lists (populated after
     the first fetch) are wider than the "All ..." placeholder — without
     this the whole filters row visibly reflows right after load. */
  min-width: 205px;
}

.filter-select:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.result-note {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: auto;
  /* Reserved so the filters row doesn't reflow/wrap differently once this
     goes from empty (pre-load) to populated ("Showing first N matches") —
     otherwise the row visibly changes shape right after the page loads. */
  min-width: 190px;
  text-align: right;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

@keyframes value-in {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 1;
  }
}

.stat-value.flash {
  animation: value-in 300ms ease-out;
}

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

.stats.is-loading .stat-value {
  display: inline-block;
  min-width: 70px;
  min-height: 1em;
  color: transparent;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface) 25%, rgba(255, 255, 255, 0.09) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

.stats,
.charts-grid,
.table-card {
  transition: opacity 200ms ease;
}

.view-loading .stats:not(.is-loading),
.view-loading .charts-grid,
.view-loading .table-card {
  opacity: 0.5;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
}

.chart-card h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 14px;
}

.chart-card canvas {
  max-height: 260px;
}

.map-card {
  margin-bottom: 24px;
}

.map-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.map-card-head h2 {
  margin: 0;
}

.map-wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
}

#map-svg {
  display: block;
  width: 100%;
  height: auto;
}

.district-path {
  stroke: var(--page);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: filter 120ms ease, stroke-width 120ms ease;
}

.district-path:hover,
.district-path:focus-visible {
  filter: brightness(1.25);
  stroke: var(--text-primary);
  stroke-width: 2.5;
  outline: none;
}

.district-path.no-data {
  cursor: default;
}

.map-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: #0d0d0d;
  border: 1px solid var(--baseline);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: nowrap;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, calc(-100% - 10px));
}

.map-tooltip .tooltip-title {
  font-weight: 600;
}

.map-tooltip .tooltip-meta {
  color: var(--text-muted);
}

.map-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.map-legend-value {
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.map-legend-bar {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--scale-low), var(--scale-high));
}

.map-note,
.map-source {
  text-align: center;
  margin: 10px 0 0;
}

.map-note button {
  background: none;
  border: none;
  padding: 0;
  color: var(--series-1);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.table-card h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.table-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.table-hint {
  color: var(--text-muted);
  font-size: 11px;
}

.address-detail {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

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

.address-detail:not([hidden]) {
  animation: suggestions-in 180ms ease-out both;
}

#address-detail-meta {
  color: var(--text-secondary);
}

.map-link {
  flex: none;
  color: var(--series-1);
  white-space: nowrap;
}

td.address-cell {
  cursor: pointer;
  transition: color 120ms ease;
}

td.address-cell:hover {
  color: var(--series-1);
  text-decoration: underline;
}

td.notes-cell {
  white-space: normal;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.note-size {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.badge {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

tbody tr {
  transition: background-color 120ms ease;
  animation: row-in 240ms ease-out both;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.page-footer {
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 12px;
}

@media (max-width: 640px) {
  .page {
    padding: 20px 14px 48px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  /* CSS Grid tracks don't shrink below their minmax floor the way flex items
     wrap — at 340px minimum, three chart cards would force horizontal page
     overflow on any phone narrower than ~380px. One column below 640px. */
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-card canvas {
    max-height: 220px;
  }

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

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-select {
    width: 100%;
  }

  .result-note {
    margin-left: 0;
    min-width: 0;
    text-align: left;
  }

  .checkbox {
    white-space: normal;
  }

  .address-detail {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}
