:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #687283;
  --line: #e4e8ee;
  --accent: #2563eb;
  --map-bg: #e9edf2;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 6px 24px rgba(20,30,50,.06);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
header {
  flex: 0 0 auto; padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 14px;
  z-index: 5;
}
header h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -.2px; }
header .sub { color: var(--muted); font-size: 12.5px; }
header .sub a { color: var(--accent); text-decoration: none; }
header .sub a:hover { text-decoration: underline; }

#wrap { flex: 1 1 auto; display: flex; min-height: 0; }
#map { flex: 1 1 auto; position: relative; background: var(--map-bg); }
#sidebar {
  flex: 0 0 372px; width: 372px; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto; padding: 16px;
}
.section { margin-bottom: 18px; }
.section h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 8px; font-weight: 650;
}
label.field { display: block; margin-bottom: 8px; }
select, input[type=search] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff; appearance: none;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.metric-desc { color: var(--muted); font-size: 12px; margin: 6px 2px 0; }

/* legend */
.legend { margin-top: 10px; }
.legend .bar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; }
.legend .bar > div { flex: 1; }
.legend .ticks { display: flex; justify-content: space-between; margin-top: 4px; font-size: 10.5px; color: var(--muted); }
.legend .ends { display: flex; justify-content: space-between; font-size: 11px; margin-top: 2px; color: var(--ink); }
.legend .nodata { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.legend .nodata .sw { width: 13px; height: 13px; border-radius: 3px; background: #e9e9e9; border: 1px solid var(--line); }

/* scatter */
#scatterWrap { position: relative; }
#scatter { width: 100%; display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.corr { font-size: 12px; color: var(--muted); margin-top: 6px; }
.corr b { color: var(--ink); }
.scatter-tip {
  position: absolute; pointer-events: none; background: rgba(20,28,40,.92); color: #fff;
  padding: 5px 8px; border-radius: 6px; font-size: 11.5px; white-space: nowrap; transform: translate(-50%, -130%);
  opacity: 0; transition: opacity .08s; z-index: 4;
}

/* condition · range-highlight slider */
.rangeslider { position: relative; height: 24px; margin: 12px 0 4px; }
.rangeslider .rs-track, .rangeslider .rs-fill {
  position: absolute; top: 10px; height: 4px; border-radius: 2px;
}
.rangeslider .rs-track { left: 0; right: 0; background: var(--line); }
.rangeslider .rs-fill { background: var(--accent); left: 0; width: 100%; }
.rangeslider input[type=range] {
  position: absolute; top: 0; left: 0; width: 100%; height: 24px; margin: 0;
  -webkit-appearance: none; appearance: none; background: none; pointer-events: none;
}
.rangeslider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto;
  width: 15px; height: 15px; border-radius: 50%; background: #fff;
  border: 2px solid var(--accent); box-shadow: var(--shadow); cursor: pointer;
}
.rangeslider input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 15px; height: 15px; border-radius: 50%; background: #fff;
  border: 2px solid var(--accent); box-shadow: var(--shadow); cursor: pointer;
}
.rs-vals { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink); }
.cond-note { color: var(--muted); font-size: 11.5px; margin-top: 7px; }
.cond-note .clear { color: var(--accent); cursor: pointer; font-weight: 600; margin-left: 6px; }

/* detail card */
#detail { font-size: 13px; }
#detail .empty { color: var(--muted); font-style: italic; }
#detail .zip { font-size: 16px; font-weight: 650; }
#detail .place { color: var(--muted); margin-bottom: 8px; }
#detail table { width: 100%; border-collapse: collapse; }
#detail td { padding: 3px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
#detail td.k { color: var(--muted); padding-right: 6px; line-height: 1.2; font-size: 12px; }
#detail td.h { width: 80px; padding: 3px 6px; }
#detail td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; white-space: nowrap; }
#detail tr.active td.k, #detail tr.active td.v { color: var(--accent); }
#detail svg.mini { display: block; }
#detail svg.mini .bars rect { fill: #d3dae3; }
#detail tr.active svg.mini .bars rect { fill: #aebfff; }
#detail svg.mini .mk { stroke: var(--accent); stroke-width: 1.3; }
#detail svg.mini .mk-d { fill: var(--accent); }

/* map tooltip */
.map-tip {
  position: absolute; pointer-events: none; background: rgba(20,28,40,.94); color: #fff;
  padding: 7px 10px; border-radius: 7px; font-size: 12px; max-width: 260px;
  z-index: 10; box-shadow: var(--shadow); opacity: 0; transition: opacity .07s;
}
.map-tip .t-zip { font-weight: 650; }
.map-tip .t-place { opacity: .8; font-size: 11px; margin-bottom: 4px; }
.map-tip .t-tbl { border-collapse: collapse; width: 100%; }
.map-tip .t-tbl td { padding: 1px 0; font-size: 11px; opacity: .85; }
.map-tip .t-tbl td:last-child { text-align: right; padding-left: 14px; font-variant-numeric: tabular-nums; font-weight: 600; opacity: 1; }
.map-tip .t-tbl tr.cur td { color: #ffe27a; opacity: 1; }

/* map controls overlay */
.map-ctrl {
  position: absolute; z-index: 3; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow);
}
#search-box { top: 12px; left: 12px; width: 230px; padding: 0; }
#search-box input { border: none; border-radius: 8px; }
#search-results { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); max-height: 240px; overflow-y: auto; }
#search-results li { padding: 7px 10px; cursor: pointer; font-size: 12.5px; }
#search-results li:hover, #search-results li.sel { background: #eef3ff; }
#search-results li .sm { color: var(--muted); }
#search-results:empty { display: none; }
#reset { top: 12px; left: 252px; padding: 7px 11px; cursor: pointer; font-size: 12.5px; }
#reset:hover { background: #f4f6f9; }

/* Pan / Select tool toggle */
#tool { top: 12px; right: 12px; display: flex; overflow: hidden; }
.tool-btn { display: flex; align-items: center; gap: 5px; border: none; background: var(--panel);
  padding: 7px 10px; font: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.tool-btn + .tool-btn { border-left: 1px solid var(--line); }
.tool-btn.active { background: var(--accent); color: #fff; }
.tool-btn:not(.active):hover { background: #f4f6f9; }
.tool-btn svg { display: block; }
/* crosshair cursor on the MAIN map only while in Select mode (not insets) */
#map.select-mode > .maplibregl-canvas-container .maplibregl-canvas { cursor: crosshair !important; }

/* AK / HI insets */
.map-inset { position: absolute; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; box-shadow: var(--shadow); background: var(--map-bg); z-index: 3; }
#inset-ak { width: 172px; height: 124px; left: 12px; bottom: 14px; }
#inset-hi { width: 128px; height: 86px; left: 192px; bottom: 14px; }
.inset-label { position: absolute; top: 3px; left: 5px; font-size: 10px; font-weight: 650;
  color: #4a5566; background: rgba(255,255,255,.72); padding: 0 4px; border-radius: 4px;
  z-index: 4; pointer-events: none; }

/* selection rectangles */
.boxsel, .brush-rect { position: absolute; background: rgba(37,99,235,.12);
  border: 1.5px solid var(--accent); pointer-events: none; z-index: 6; border-radius: 2px; }

.corr .clear { color: var(--accent); cursor: pointer; margin-left: 8px; font-weight: 600; }
.corr .clear:hover { text-decoration: underline; }
.corr .badge { background: #eef3ff; color: var(--accent); border-radius: 10px; padding: 1px 7px; font-weight: 600; }

#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--map-bg); color: var(--muted); font-size: 13px; z-index: 20; transition: opacity .4s; gap: 10px;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.maplibregl-ctrl-attrib { font-size: 10px; }

@media (max-width: 820px) {
  #wrap { flex-direction: column; }
  #sidebar { flex: 0 0 auto; width: 100%; border-left: none; border-top: 1px solid var(--line); max-height: 46vh; }
  #map { min-height: 54vh; }
}

/* "more about these measures" popup */
header .sub a { cursor: pointer; }
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,22,35,.45); }
.modal-card { position: relative; background: var(--panel); border-radius: 12px;
  box-shadow: 0 12px 48px rgba(15,22,35,.32); max-width: 720px; width: calc(100% - 40px);
  max-height: calc(100vh - 64px); overflow-y: auto; padding: 26px 32px; }
.modal-close { position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 26px;
  line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.modal-close:hover { background: #f0f2f5; color: var(--ink); }
.modal-body { font-size: 14px; line-height: 1.55; color: var(--ink); }
.modal-body h1 { font-size: 20px; margin: 0 0 10px; letter-spacing: -.2px; }
.modal-body h2 { font-size: 15px; margin: 22px 0 6px; }
.modal-body h3 { font-size: 13.5px; margin: 16px 0 4px; }
.modal-body p { margin: 8px 0; }
.modal-body ul { margin: 6px 0; padding-left: 20px; }
.modal-body li { margin: 4px 0; }
.modal-body code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.modal-body blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent);
  background: #f6f8fc; border-radius: 0 6px 6px 0; font-variant-numeric: tabular-nums; }
.modal-body hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.modal-body a { color: var(--accent); }
