:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #5b626d;
  --border: #e5e7eb;
  --panel-bg: rgba(255, 255, 255, 0.97);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  --accent: #2c7fb8;
  --good: #2ca25f;
  --mid: #d98200;
  --bad: #d7301f;
  --focus: #1d4ed8;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  overflow: hidden;
}

#map { position: absolute; inset: 0; }

/* Visible keyboard focus everywhere. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---- Layer panel ---- */
.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  width: 280px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  /* Slightly translucent so the map shows through; blur keeps text legible. */
  background: rgba(255, 255, 255, 0.8);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px 14px 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.panel.collapsed { width: auto; }
.panel.collapsed .panel__hint,
.panel.collapsed .search,
.panel.collapsed .panel__actions,
.panel.collapsed #layer-list { display: none; }

.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h1 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.panel__collapse {
  border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.panel__collapse:hover { background: rgba(0,0,0,0.06); }
.panel__hint { font-size: 12px; color: var(--muted); margin: 10px 0 10px; line-height: 1.4; }

/* ---- Search ---- */
.search { position: relative; display: flex; gap: 6px; margin: 10px 0 8px; }
.search input[type="search"] {
  flex: 1; min-width: 0; font-size: 13px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--fg);
}
.search button {
  border: 1px solid var(--border); background: #fff; border-radius: 7px; cursor: pointer;
  font-size: 14px; padding: 0 9px; line-height: 1;
}
.search button:hover { background: #f3f4f6; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 7;
  margin: 0; padding: 4px; list-style: none; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 240px; overflow-y: auto;
}
.search-result { padding: 7px 9px; font-size: 12.5px; border-radius: 6px; cursor: pointer; line-height: 1.3; }
.search-result:hover, .search-result.active { background: #eaf2fb; }

/* ---- Action buttons ---- */
.panel__actions { display: flex; gap: 8px; margin-bottom: 6px; }
.btn {
  flex: 1; font-size: 12.5px; padding: 7px 8px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; border-radius: 7px; color: var(--fg);
}
.btn:hover { background: #f3f4f6; }
.btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ok { background: var(--good); color: #fff; border-color: var(--good); }

.layer-group { margin-bottom: 10px; }
.layer-group__title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin: 8px 0 4px; font-weight: 600;
  display: flex; align-items: center; cursor: pointer; user-select: none;
  list-style: none; /* Firefox: drop the default disclosure triangle */
}
.layer-group__title::-webkit-details-marker { display: none; } /* WebKit */
.layer-group__title:hover { color: var(--fg); }
/* Chevron on the right: points down when open, right when collapsed. */
.layer-group__title::after {
  content: "›"; margin-left: auto; font-size: 15px; line-height: 1;
  transform: rotate(90deg); transition: transform 0.15s ease;
}
.layer-group:not([open]) > .layer-group__title::after { transform: rotate(0deg); }
.layer-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; margin: 0 -6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.layer-row:hover { background: rgba(0, 0, 0, 0.06); }
.layer-row input { cursor: pointer; width: 15px; height: 15px; flex: 0 0 auto; }
.layer-row .swatch { width: 13px; height: 13px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,0.12); }
.layer-row .swatch--line { height: 4px; }

/* One-click "Hide all" toolbar above the layer list */
.layer-tools { display: flex; justify-content: flex-end; margin: 2px 0 4px; }
.linkbtn { border: none; background: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.linkbtn:hover { background: rgba(44,127,184,0.12); text-decoration: underline; }

/* Row-hover explanation tooltip */
.help-tip {
  position: fixed; z-index: 30; max-width: 260px;
  background: #1f2937; color: #f3f4f6; font-size: 12px; line-height: 1.45;
  padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow); pointer-events: none;
}
.help-tip .help-src { margin-top: 6px; color: #9ca3af; font-style: italic; }
.help-tip[hidden] { display: none; }

/* ---- Scorecard ---- */
.scorecard {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 6;
  width: 320px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  backdrop-filter: blur(4px);
}
.scorecard--empty { display: none; }
.scorecard__close {
  position: absolute; top: 6px; right: 8px; border: none; background: none;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
  padding: 4px 8px; border-radius: 6px;
}
.scorecard__close:hover { background: rgba(0,0,0,0.06); }
.scorecard h2 { font-size: 14px; margin: 0 0 2px; padding-right: 20px; }
.scorecard .coords { font-size: 11px; color: var(--muted); margin: 0 0 8px; }
.score-explain { font-size: 11.5px; color: var(--muted); line-height: 1.45; margin: 0 0 10px; }

.score-ring { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.score-ring .num { font-size: 34px; font-weight: 800; line-height: 1; }
.score-ring .label { font-size: 12px; color: var(--muted); }

.metric { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--border); font-size: 13px; }
.metric:first-of-type { border-top: none; }
.metric .m-name { display: flex; align-items: center; gap: 6px; color: var(--fg); flex: 1; }
.metric .m-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.metric .m-bar { width: 46px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; flex: 0 0 auto; }
.metric .m-bar > i { display: block; height: 100%; }
.metric--muted .m-name, .metric--muted .m-val { color: var(--muted); font-weight: 500; }

/* Compare layout */
.cmp-head { display: flex; gap: 8px; font-size: 11.5px; font-weight: 600; margin: 2px 0 6px; }
.cmp-col { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-a { color: var(--bad); }
.cmp-b { color: var(--focus); }
.cmp-scores { display: flex; gap: 8px; margin-bottom: 8px; }
.cmp-scores .score-ring { flex: 1; margin: 0; }
.cmp-scores .score-ring .num { font-size: 28px; }
.metric--cmp { display: grid; grid-template-columns: 1.4fr 1fr 1fr; align-items: center; }
.metric--cmp .m-name { font-size: 12px; }
.metric--cmp .m-val { font-size: 12px; text-align: right; font-weight: 500; }
.metric--cmp .m-win { font-weight: 800; }
.metric--hdr { font-size: 11px; color: var(--muted); }
.metric--hdr .m-val { text-align: right; font-weight: 700; }

.weights { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.weights summary { font-size: 12px; color: var(--muted); cursor: pointer; }
.weights .w-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 0; }
.weights .w-row label { flex: 1; }
.weights input[type="range"] { width: 90px; }

/* ---- Legend ---- */
.legend {
  position: absolute; bottom: 16px; left: 12px; z-index: 5;
  background: var(--panel-bg); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 11px; max-width: 220px;
}
.legend:empty { display: none; }
.legend > div + div { margin-top: 8px; }
.legend .legend-title { font-weight: 600; margin-bottom: 4px; }
.legend .legend-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.legend .legend-row i { width: 14px; height: 10px; border-radius: 2px; flex: 0 0 auto; }

/* ---- Loading + error states ---- */
.loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 8;
  background: var(--panel-bg); border-radius: 8px; box-shadow: var(--shadow);
  padding: 12px 18px; font-size: 13px; color: var(--muted);
}
.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 9;
  background: #7a1d1d; color: #fff; border-radius: 8px; box-shadow: var(--shadow);
  padding: 9px 14px; font-size: 12.5px; max-width: 80%; line-height: 1.4;
}
.banner[hidden], .loading[hidden] { display: none; }

/* ---- Building dossier page (building.html) ---- */
body.dossier-page { overflow: auto; height: auto; background: #f5f6f8; }
.dossier-wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
.topnav { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 14px; }
.topnav a { color: var(--accent); text-decoration: none; }
.topnav a:hover { text-decoration: underline; }
.topnav span { color: var(--muted); font-weight: 600; }

.bsearch { display: flex; gap: 8px; }
.bsearch input[type="search"] {
  flex: 1; min-width: 0; font-size: 16px; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--fg);
}
.bsearch button {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 9px;
  cursor: pointer; font-size: 15px; font-weight: 600; padding: 0 18px;
}
.bsearch button:hover { background: #24699a; }

.status { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }
.status--error { color: var(--bad); }

.bmap { height: 300px; border-radius: 12px; overflow: hidden; margin: 14px 0 4px; box-shadow: var(--shadow); }
.bmap[hidden] { display: none; }

.dossier { margin-top: 8px; }
.intro { font-size: 14px; color: var(--muted); line-height: 1.55; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.intro a { color: var(--accent); }

.dossier-head { margin: 18px 2px 6px; }
.dossier-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
.dossier-head .sub { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11.5px; font-weight: 600; color: #7a1d1d; background: #fdeaea; border: 1px solid #f6c9c9; border-radius: 999px; padding: 3px 10px; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin: 12px 0; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card .muted { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }
.card .src { font-size: 11px; color: var(--muted); font-style: italic; margin: 12px 0 0; line-height: 1.45; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin: 0; }
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.fact dd { font-size: 14.5px; margin: 0; color: var(--fg); word-break: break-word; }
.fact dd a { color: var(--accent); }

/* Circled "i" info affordance + the popover card it opens (zoning term explanations). */
.infobtn { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 6px; padding: 0; font: italic 700 11px/1 Georgia, "Times New Roman", serif; color: var(--accent); background: #eaf2f8; border: 1px solid #cfe0ee; border-radius: 50%; cursor: pointer; vertical-align: middle; }
.infobtn:hover, .infobtn:focus-visible { background: var(--accent); color: #fff; outline: none; }
.infopop { position: absolute; z-index: 1000; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14); padding: 12px 14px; font-size: 13px; line-height: 1.5; color: var(--fg); max-width: 90vw; }
.infopop-title { font-weight: 700; font-size: 12.5px; margin-bottom: 6px; }
.infopop-lead { margin: 0 0 8px; }
.infopop p { margin: 0 0 8px; }
.infopop p:last-of-type { margin-bottom: 0; }
.infopop code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.infopop-tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin: 0 0 8px; }
.infopop-tbl th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); border-bottom: 1px solid var(--border); padding: 3px 8px 3px 0; }
.infopop-tbl td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.infopop-tbl tr:last-child td { border-bottom: none; }
.infopop-src { display: inline-block; margin-top: 2px; font-size: 12px; font-weight: 600; color: var(--accent); }

.tablewrap { overflow-x: auto; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); border-bottom: 1px solid var(--border); padding: 6px 8px 6px 0; }
.card td { padding: 7px 8px 7px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.card tr:last-child td { border-bottom: none; }

.explore { margin: 18px 0 8px; }
.bigbtn { display: block; text-align: center; background: var(--accent); color: #fff; text-decoration: none; font-weight: 600; font-size: 14px; padding: 14px 16px; border-radius: 12px; }
.bigbtn:hover { background: #24699a; }
.foot { font-size: 11.5px; color: var(--muted); line-height: 1.55; margin: 18px 2px 0; }

@media (max-width: 560px) {
  .facts { grid-template-columns: 1fr; }
  .dossier-head h1 { font-size: 20px; }
}

/* ---- Mobile ---- */
@media (max-width: 640px) {
  /* Panel: top, capped so it never swallows the screen; scrolls internally. */
  .panel { width: calc(100% - 24px); max-height: 44%; }
  /* Scorecard: bottom sheet; leaves a gap below the panel (44% + 50% + margins). */
  .scorecard { width: calc(100% - 24px); top: auto; bottom: 12px; right: 12px; left: 12px; max-height: 50%; }
  /* Keep the legend (so choropleths stay interpretable) but only when the panel
     is collapsed — otherwise the full-width panel would sit on top of it. */
  .legend { bottom: auto; top: 12px; right: 12px; left: auto; max-width: 132px; font-size: 10px; opacity: 0.96; }
  .panel:not(.collapsed) ~ .legend { display: none; }
}
