:root {
  --ink: #1a1a1a;
  --paper: #fafaf7;
  --rule: #d8d8d2;
  --dim: #6b6b66;
  --accent: #0a4f8e;
  --saver: #2c7fb8;
  --neutral: #f5f5f0;
  --payer: #d7301f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  flex-wrap: wrap;
}

.title h1 {
  font-size: 1rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.title p {
  font-size: 0.75rem;
  margin: 0;
  color: var(--dim);
}

#paint-toggle, #layer-toggles {
  display: flex;
  gap: 0.6rem;
  font-size: 0.82rem;
  border-left: 1px solid var(--rule);
  padding-left: 1rem;
}

#paint-toggle label, #layer-toggles label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  user-select: none;
}

#nbhd-select {
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: white;
  max-width: 18rem;
}

#about-btn {
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  background: white;
  border: 1px solid var(--rule);
  border-radius: 3px;
  cursor: pointer;
}
#about-btn:hover { background: #f0f0eb; }

#aggregate {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--dim);
  text-align: right;
  line-height: 1.35;
  min-width: 13rem;
}

#aggregate b { color: var(--ink); font-weight: 600; }

main {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  overflow: hidden;
}

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

/* ---------- legend ---------- */
#legend {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  background: rgba(250, 250, 247, 0.96);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  color: var(--ink);
  z-index: 5;
  min-width: 14rem;
  max-width: 16rem;
}
.legend-title {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.legend-bar {
  height: 0.55rem;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    #08306b 0%, #2171b5 25%, #9ecae1 45%, #f5f5f0 50%, #fbb4b9 55%, #cb181d 80%, #67000d 100%
  );
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}
.legend-foot {
  margin-top: 0.4rem;
  color: var(--dim);
  font-size: 0.7rem;
}
.legend-swatches {
  list-style: none;
  margin: 0; padding: 0;
}
.legend-swatches li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.12rem 0;
}
.sw {
  display: inline-block;
  width: 0.85rem; height: 0.85rem;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.1);
}

/* ---------- side panel ---------- */
#sidepanel {
  width: 22rem;
  border-left: 1px solid var(--rule);
  background: var(--paper);
  overflow-y: auto;
  padding: 1rem 1.25rem 2rem;
  font-size: 0.85rem;
  position: relative;
}
#sidepanel[hidden] { display: none; }

#close-side {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: 0;
  font-size: 1.4rem;
  color: var(--dim);
  cursor: pointer;
  line-height: 1;
}

#sidepanel h2 { font-size: 1rem; margin: 0 0 0.5rem; }

#sidepanel .row {
  display: flex;
  justify-content: space-between;
  padding: 0.18rem 0;
  border-bottom: 1px dotted var(--rule);
}

#sidepanel .row .k { color: var(--dim); }
#sidepanel .row .v { font-variant-numeric: tabular-nums; }

#sidepanel .delta-saver { color: var(--saver); font-weight: 600; }
#sidepanel .delta-payer { color: var(--payer); font-weight: 600; }

#sidepanel .hcad-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--accent);
}

/* ---------- about modal ---------- */
#about-modal {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.5rem 1.75rem;
  max-width: 36rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
}
#about-modal::backdrop { background: rgba(0,0,0,0.35); }
#about-modal h2 { margin-top: 0; }
#about-modal code {
  background: #efefe9;
  padding: 0 0.25rem;
  border-radius: 2px;
  font-size: 0.85em;
}
#about-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: 0;
  font-size: 1.5rem;
  color: var(--dim);
  cursor: pointer;
}
.dim { color: var(--dim); }
.small { font-size: 0.8rem; }

/* ---------- footer ---------- */
#footer {
  padding: 0.4rem 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.75rem;
  color: var(--dim);
  display: flex;
  gap: 0.6rem;
}
#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* MapLibre overrides — keep popups subtle */
.maplibregl-popup-content {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}
