:root {
  --bg: #0B0F14;
  --panel: #141A20;
  --cream: #F7F4EE;
  --muted: #9AA3AD;
  --sage: #3D6B5A;
  --sage2: #8FBFA9;
  --line: #1e262e;
  --radius: 12px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; width: 100%;
  background: var(--bg); color: var(--cream);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  overflow: hidden;
}
html.embed, html.embed body { height: 100%; }

a { color: var(--sage2); text-decoration: none; }
a:hover { color: var(--cream); }

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

header.app-bar, .app-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11,15,20,.96);
}
.app-bar img.wordmark { height: 32px; width: auto; display: block; }
.app-bar .sub {
  color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
}
.app-bar nav { margin-left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.app-bar nav a { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.app-bar nav a:hover { color: var(--cream); }

.open-full { display: none; }
html.embed .open-full {
  display: inline-flex; align-items: center; gap: .35rem;
  position: fixed; top: 8px; right: 8px; z-index: 4000;
  background: var(--sage); color: var(--cream); text-decoration: none;
  font-size: .72rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  padding: .55rem .85rem; border-radius: 999px;
  border: 1px solid rgba(143,191,169,.35);
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
html.embed .app-bar { padding-right: 9.5rem; }
html.embed .app-bar img.wordmark { height: 22px; }
html.embed .app-bar .sub { display: none; }

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 0; min-height: 0;
}

.sql-panel {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}
.sql-panel .panel-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.sql-panel .panel-head h1 {
  margin: 0 0 4px;
  font-family: Syne, sans-serif;
  font-size: 1.15rem; font-weight: 700; letter-spacing: -.015em;
}
.sql-panel .panel-head p {
  margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.45;
}
.sql-panel .panel-head .cue {
  margin: 8px 0 0;
  color: var(--sage2);
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 9px;
  border-left: 2px solid var(--sage);
  background: rgba(61,107,90,.12);
  border-radius: 0 8px 8px 0;
}

.canned {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  max-height: 42%;
  overflow: auto;
}
.canned label {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.canned button {
  appearance: none; text-align: left; cursor: pointer;
  background: var(--bg); color: var(--cream);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px;
  font: 500 12.5px/1.35 "IBM Plex Sans", sans-serif;
  transition: border-color .15s, background .15s;
}
.canned button:hover { border-color: rgba(143,191,169,.45); }
.canned button.active {
  border-color: var(--sage);
  background: rgba(61,107,90,.22);
}
.canned button .qname { display: block; font-weight: 600; color: var(--cream); }
.canned button .qhint {
  display: block; margin-top: 2px;
  font-size: 10.5px; color: var(--muted); font-weight: 400;
  font-family: var(--mono);
}
.canned button .qverb {
  display: inline-block; margin-top: 5px;
  font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sage2); font-weight: 600;
}

.answer-card {
  margin: 10px 14px 0;
  padding: 10px 12px;
  border: 1px solid rgba(143,191,169,.35);
  border-radius: 10px;
  background: rgba(61,107,90,.16);
  flex: 0 0 auto;
}
.answer-card[hidden] { display: none !important; }
.answer-kicker {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--sage2); margin-bottom: 4px; font-weight: 600;
}
.answer-text {
  font-family: Syne, sans-serif;
  font-size: 15px; font-weight: 700; line-height: 1.35;
  color: var(--cream);
}
.answer-meta {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11px; color: var(--muted);
}

.editor-wrap {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  padding: 12px 14px 0;
}
.lbl-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.editor-wrap .lbl {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.lbl-soft { letter-spacing: .04em; text-transform: none; color: #6b737c; font-size: 10px; }
.btn-ghost {
  appearance: none; cursor: pointer;
  background: transparent; color: var(--sage2);
  border: 1px solid rgba(143,191,169,.3);
  border-radius: 6px;
  padding: 3px 9px;
  font: 600 10.5px/1 "IBM Plex Sans", sans-serif;
  letter-spacing: .04em;
}
.btn-ghost:hover { background: rgba(61,107,90,.2); color: var(--cream); }
#sql-editor {
  flex: 1; min-height: 110px; width: 100%; resize: none;
  background: #0a0e12; color: #d7e0d8;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 12px;
  font: 400 12px/1.5 var(--mono);
  outline: none;
  tab-size: 2;
}
#sql-editor:focus { border-color: rgba(143,191,169,.5); }

.actions {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 12px;
  flex: 0 0 auto;
}
.btn-run {
  appearance: none; cursor: pointer;
  background: var(--sage); color: var(--cream);
  border: 1px solid rgba(143,191,169,.35);
  border-radius: 8px;
  padding: 10px 16px;
  font: 600 13px/1 "IBM Plex Sans", sans-serif;
  letter-spacing: .03em;
}
.btn-run:hover { background: #4a7d6a; }
.btn-run:disabled { opacity: .55; cursor: wait; }
.status {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
}

.results {
  border-top: 1px solid var(--line);
  max-height: 30%;
  min-height: 120px;
  display: flex; flex-direction: column;
  background: #10161c;
  flex: 0 0 auto;
}
.results .rhead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 14px 2px;
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.results .rhead strong {
  color: var(--sage2); font-weight: 500; letter-spacing: 0; text-transform: none;
  font-family: var(--mono); font-size: 12px;
}
.results-hint {
  margin: 0 14px 4px;
  font-size: 10.5px; color: var(--sage2);
}
.results .table-wrap { overflow: auto; flex: 1; padding: 0 8px 10px; }
table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
th, td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
th {
  color: var(--muted); font-weight: 500; font-size: 10px;
  letter-spacing: .06em; text-transform: uppercase;
  position: sticky; top: 0; background: #10161c;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11.5px; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: rgba(61,107,90,.18); }
tbody tr.is-pinned { background: rgba(61,107,90,.32); outline: 1px solid rgba(143,191,169,.35); }

.map-side {
  position: relative; min-height: 0; background: #0d1218;
}
.map-side.basemap-imagery #map { background: #1a1a1a; }
#map { position: absolute; inset: 0; background: #0d1218; cursor: crosshair; }

.map-overlay {
  position: absolute; z-index: 500; left: 12px; top: 12px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(340px, calc(100% - 200px));
  pointer-events: none;
}
.map-chip {
  background: rgba(11,15,20,.86); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
  pointer-events: none;
}
.map-chip h2 {
  margin: 0; font-family: Syne, sans-serif; font-size: 15px; font-weight: 700;
}
.map-chip span { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.map-chip .overlay-hint {
  margin-top: 6px; color: var(--sage2); font-size: 10.5px; letter-spacing: .02em;
}

.satellite-chip {
  align-self: flex-start;
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(143,191,169,.55);
  border-radius: 999px;
  background: rgba(11,15,20,.9);
  color: var(--cream);
  cursor: pointer;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 7px 11px;
  box-shadow: 0 4px 14px rgba(0,0,0,.24);
}
.satellite-chip span { color: var(--sage2); margin-right: 4px; }
.satellite-chip:hover,
.satellite-chip.is-active {
  background: var(--sage);
  border-color: var(--sage2);
}
.satellite-chip:focus-visible {
  outline: 2px solid var(--sage2);
  outline-offset: 2px;
}

.detail-panel {
  pointer-events: auto;
  background: rgba(11,15,20,.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.4);
  max-width: 300px;
  max-height: min(380px, 50vh);
  overflow: auto;
}
.detail-panel[hidden] { display: none !important; }
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  margin-bottom: 8px;
}
.detail-head h3 {
  margin: 0;
  font-family: Syne, sans-serif; font-size: 15px; font-weight: 700;
}
.detail-geoid {
  display: block; margin-top: 3px;
  font-family: var(--mono);
  font-size: 10px; letter-spacing: .04em; color: var(--muted);
}
.detail-close {
  appearance: none; border: 0;
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(158,167,177,.12);
  color: var(--cream); cursor: pointer;
  font-size: 18px; line-height: 1;
  flex-shrink: 0;
}
.detail-close:hover { background: rgba(158,167,177,.22); }
.detail-cue {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--sage2); margin-bottom: 8px;
}
.detail-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(30,38,46,.9);
  font-size: 12px;
}
.detail-row:last-child { border-bottom: 0; }
.detail-row .lbl { color: var(--muted); }
.detail-row .val {
  font-family: var(--mono);
  font-weight: 500; color: var(--cream); text-align: right;
}

.layers-box {
  position: absolute; z-index: 500; right: 14px; top: 14px;
  pointer-events: auto;
  background: rgba(11,15,20,.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 176px;
  max-width: 220px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.layers-toggle {
  appearance: none; border: 0; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  background: transparent; color: var(--cream);
  cursor: pointer;
  font-family: "IBM Plex Sans", sans-serif;
  padding: 8px 11px 7px;
}
.layers-toggle-lbl {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); font-weight: 500;
}
.layers-toggle-chev {
  font-size: 10px; color: var(--muted); transition: transform .18s ease;
}
.layers-box.is-collapsed .layers-toggle-chev { transform: rotate(-90deg); }
.layers-box.is-collapsed .layers-body { display: none; }
.layers-body {
  padding: 0 10px 9px;
  border-top: 1px solid rgba(30,38,46,.85);
}
.layers-sec { margin-top: 8px; }
.layers-sec:first-child { margin-top: 7px; }
.layers-sec-lbl {
  font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--sage2); margin-bottom: 4px; font-weight: 500;
}
.layers-opt {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--cream);
  margin: 3px 0; cursor: pointer; line-height: 1.25;
  user-select: none;
}
.layers-opt input {
  accent-color: var(--sage2);
  width: 13px; height: 13px; margin: 0; flex-shrink: 0;
  cursor: pointer;
}

footer.page-foot {
  border-top: 1px solid var(--line);
  padding: 8px 18px;
  color: var(--muted); font-size: 10.5px; line-height: 1.4;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
footer.page-foot b { color: var(--cream); font-weight: 500; }
footer.page-foot a { color: var(--sage2); }
footer.page-foot a:hover { color: var(--cream); }

.leaflet-container { background: #0d1218; font-family: "IBM Plex Sans", system-ui, sans-serif; }
.leaflet-control-zoom a {
  background: var(--panel) !important; color: var(--cream) !important;
  border-color: var(--line) !important;
}
.leaflet-control-attribution {
  background: rgba(11,15,20,.82) !important; color: var(--muted) !important; font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--sage2) !important; }
.leaflet-tooltip {
  background: var(--panel); color: var(--cream); border: 1px solid var(--line);
  border-radius: 6px; box-shadow: none; font-size: 12px;
}
.leaflet-tooltip-top:before { border-top-color: var(--panel); }

@media (max-width: 900px) {
  html, body { overflow: auto; height: auto; }
  #app { height: auto; min-height: 100vh; grid-template-rows: auto auto auto; }
  .workspace { grid-template-columns: 1fr; }
  .sql-panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .canned { max-height: none; }
  .editor-wrap { min-height: 140px; }
  #sql-editor { min-height: 140px; flex: none; height: 160px; }
  .map-side { height: 55vh; min-height: 360px; position: relative; }
  .results { max-height: 220px; }
  .layers-box { top: auto; bottom: 52px; right: 10px; min-width: 152px; }
  .map-overlay { max-width: min(280px, calc(100% - 24px)); }
  .detail-panel { max-width: min(280px, 90%); max-height: 42vh; }
  .satellite-chip { font-size: 10.5px; padding: 6px 10px; }
}
html.embed footer.page-foot { display: none; }
html.embed .layers-box { top: 10px; right: 10px; max-width: 200px; }
html.embed .detail-panel { max-width: min(280px, calc(100% - 24px)); }

.app-bar img.wordmark { height: 32px; width: auto; display: block; }
footer.page-foot { border-top: 1px solid var(--line); padding: 8px 18px; color: var(--muted); font-size: 10.5px; line-height: 1.4; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
footer.page-foot b { color: var(--cream); font-weight: 500; }
footer.page-foot a { color: var(--sage2); }
footer.page-foot a:hover { color: var(--cream); }
.detail-rows { margin-top: 2px; }
.canned button .qverb {
  display: inline-block; margin-top: 5px;
  font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sage2); font-weight: 600;
}
.layers-box.is-collapsed .layers-toggle-chev { transform: rotate(-90deg); }
.layers-box.is-collapsed .layers-body { display: none; }
.satellite-chip.is-active { background: var(--sage); border-color: var(--sage2); }
.map-side.basemap-imagery #map { background: #1a1a1a; }
tbody tr.is-pinned { background: rgba(61,107,90,.32); outline: 1px solid rgba(143,191,169,.35); }
.detail-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 7px 0; border-bottom: 1px solid rgba(30,38,46,.9); font-size: 12px;
}
.detail-row:last-child { border-bottom: 0; }
.detail-row .lbl { color: var(--muted); }
.detail-row .val { font-family: var(--mono); font-weight: 500; color: var(--cream); text-align: right; }
html.embed footer.page-foot { display: none; }
