:root {
  --ink: #14171c;
  --muted: #5b6470;
  --line: #e2e5ea;
  --accent: #0b5cad;
  --panel: rgba(255, 255, 255, 0.94);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

html, body { margin: 0; height: 100%; background: #000; }
#map { position: absolute; inset: 0; }

/* ---------- side panel ---------- */
#panel {
  position: absolute; top: 12px; left: 12px; z-index: 2;
  width: 320px; max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
#panel-head { display: flex; gap: 10px; align-items: center; padding: 10px 10px 10px 12px; cursor: pointer; user-select: none; }
#panel-head .title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
#panel-head strong { font-size: 15px; }
#panel-head small { color: var(--muted); font-size: 12px; line-height: 1.35; }
/* hide / show button: chevron points up when open (hide), down when hidden (show) */
#toggle {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; padding: 0;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer;
}
#toggle:hover { background: #eef3fa; }
#toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#toggle .chev {
  width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(2px) rotate(-135deg); transition: transform .15s;
}
#panel:not(.open) #toggle .chev { transform: translateY(-2px) rotate(45deg); }
#panel-body { display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
#panel:not(.open) #panel-body { display: none; }

#filter {
  margin: 8px 12px 6px; padding: 7px 10px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
#filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* sort / expand toolbar */
#tools { display: flex; align-items: center; gap: 6px; margin: 0 12px 6px; font-size: 12px; color: var(--muted); }
#tools .spacer { flex: 1; }
#sort { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#sort button {
  padding: 3px 9px; border: 0; background: #fff; color: var(--ink);
  font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
#sort button + button { border-left: 1px solid var(--line); }
#sort button[aria-pressed="true"] { background: #dce8f7; color: var(--accent); font-weight: 600; }
#sort button:focus-visible, #tools .link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#tools .link { padding: 2px 3px; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; }
#tools .link:hover { text-decoration: underline; }

/* city list, grouped by country */
#cities, #cities ul, #unlocated ul { list-style: none; margin: 0; padding: 0; }
#cities, #unlocated ul { padding: 0 6px 6px; overflow-y: auto; }
#cities { flex: 1 1 auto; min-height: 0; }
#cities li.group.collapsed > ul { display: none; }
#cities button.country {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 7px 6px 4px; border: 0; background: #fbfbfc; color: var(--muted);
  font: inherit; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  text-align: left; cursor: pointer;
}
#cities button.country:hover { color: var(--ink); }
#cities button.country:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#cities .chev { display: inline-block; width: 8px; transition: transform .12s; }
#cities .chev::before { content: "▾"; }
#cities li.collapsed .chev { transform: rotate(-90deg); }
#cities .gmeta { margin-left: auto; font-weight: 400; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
#cities li.city > button {
  display: flex; align-items: baseline; gap: 6px; width: 100%;
  padding: 5px 6px 5px 20px; border: 0; border-radius: 5px; background: none;
  font: inherit; font-size: 13px; text-align: left; cursor: pointer; color: inherit;
}
#cities li.city > button:hover, #cities li.city > button:focus-visible { background: #eef3fa; outline: none; }
#cities li.city.active > button { background: #dce8f7; }
#cities .region { color: var(--muted); font-size: 11px; }
#cities .count {
  margin-left: auto; min-width: 22px; padding: 0 6px; border-radius: 9px;
  background: #eceff3; color: var(--muted); font-size: 11px; text-align: center; font-variant-numeric: tabular-nums;
}
#cities .empty { padding: 10px 6px; color: var(--muted); font-size: 13px; }

#unlocated { margin: 0 12px 6px; font-size: 12px; color: var(--muted); }
#unlocated summary { cursor: pointer; padding: 4px 0; }
#unlocated li { padding: 2px 6px; }

footer { padding: 8px 12px 10px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); line-height: 1.5; }
footer a { color: var(--accent); }

/* ---------- popup ---------- */
.city-popup .mapboxgl-popup-content { padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.city-popup .mapboxgl-popup-close-button { font-size: 18px; padding: 2px 7px; }
.popup { max-height: min(60vh, 460px); overflow-y: auto; font-size: 13px; }
.popup section + section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.popup h2 { margin: 0 18px 2px 0; font-size: 16px; }
.popup .sub { margin: 0 0 6px; color: var(--muted); }
.popup .stats { margin: 0 0 6px; font-size: 12px; }
.popup pre {
  margin: 0; padding: 8px; max-height: 240px; overflow: auto;
  background: #f5f7fa; border: 1px solid var(--line); border-radius: 5px;
  font: 12px/1.45 var(--mono); white-space: pre;
}
.popup .geo { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
.popup .warn { color: #a15c00; }

/* ---------- AWS popup sections ---------- */
.popup .eyebrow { margin: 0 0 2px; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.popup .eyebrow.aws { color: #b35c00; }
.popup .eyebrow.lz { color: #5b25d9; }
.popup .eyebrow.wlz { color: #007a7a; }
.popup .note { margin: 4px 0 0; font-size: 12px; line-height: 1.45; }
.popup a { color: var(--accent); }

/* ---------- map layer toggles (side panel) ---------- */
#layers { margin: 10px 12px 2px; padding: 6px 8px 4px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
#layers legend { padding: 0 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
#layers label { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; white-space: nowrap; }
#layers input { margin: 0; accent-color: var(--accent); }
#layers img { width: 22px; height: auto; }
#layers .n { margin-left: auto; padding-left: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* display: flex would override the hidden attribute; a layer without items must disappear */
#layers label[hidden] { display: none; }

/* ---------- snapshot picker (side panel) ---------- */
#history { display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; font-size: 12px; color: var(--muted); }
#history[hidden] { display: none; }
#history span { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
#history select { flex: 1; min-width: 0; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: inherit; font-size: 12px; }
#history select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 2D / 3D control ---------- */
.projection-toggle button { font: 600 11px/29px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #333; }
.projection-toggle button[aria-pressed="true"] { background: #dce8f7; color: var(--accent); }

/* ---------- notice ---------- */
#notice {
  position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: min(460px, calc(100% - 40px)); padding: 16px 18px;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; line-height: 1.5;
}
#notice code { font: 12px var(--mono); background: #f1f3f6; padding: 1px 4px; border-radius: 3px; }

@media (max-width: 640px) {
  #panel { left: 8px; right: 8px; top: 8px; width: auto; max-height: 55%; }
}
