:root {
  --c-points: #d1495b;
  --c-lines: #00798c;
  --c-polygons: #6a994e;
  --c-accent: #1f4e79;
  --c-border: #d6d9de;
  --c-muted: #667085;
  --sidebar: 360px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1d2939;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; }

#sidebar {
  width: var(--sidebar);
  flex: none;
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--c-border);
  background: #fafbfc;
  display: flex;
  flex-direction: column;
}
#map { flex: 1; height: 100%; }

header { padding: 14px 16px 6px; }
h1 { font-size: 18px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--c-muted); }

form { padding: 0 16px; }
fieldset { border: 0; padding: 0; margin: 12px 0 0; }
legend { font-weight: 600; margin-bottom: 4px; }
label { display: block; margin: 3px 0; }
input[type="search"], input:not([type]), select, .tag-row input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
input[type="number"] {
  width: 90px;
  padding: 4px 6px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  font: inherit;
}
.layer { display: flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.swatch.points { background: var(--c-points); border-radius: 50%; }
.swatch.lines { background: var(--c-lines); height: 4px; }
.swatch.polygons { background: color-mix(in srgb, var(--c-polygons) 45%, white); border: 2px solid var(--c-polygons); }

.tag-row { display: grid; grid-template-columns: 1fr 1fr 28px; gap: 4px; margin-bottom: 4px; }
.tag-row .remove { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--c-muted); }
.hint { color: var(--c-muted); font-size: 12px; margin: 4px 0 0; }
code { background: #eef1f5; padding: 0 3px; border-radius: 3px; }

button { font: inherit; cursor: pointer; }
button.link { border: 0; background: none; color: var(--c-accent); padding: 2px 0; }
.actions { display: flex; gap: 8px; margin: 16px 0 8px; }
#submit {
  flex: 1;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  background: var(--c-accent);
  color: #fff;
  font-weight: 600;
}
#submit:disabled { opacity: 0.6; cursor: progress; }
.secondary { padding: 8px 12px; border: 1px solid var(--c-border); border-radius: 6px; background: #fff; }

#results { padding: 0 16px 8px; flex: 1; }
#status { margin: 6px 0; }
#status .count { display: flex; align-items: center; gap: 6px; }
#status .warn { color: #b54708; font-size: 12px; margin-left: 20px; }
#status .error { color: #b42318; }
#result-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--c-border); }
#result-list li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 2px;
  border-bottom: 1px solid #eceef1;
  cursor: pointer;
}
#result-list li:hover { background: #eef4fb; }
#result-list .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#result-list .title.unnamed { color: var(--c-muted); font-style: italic; }
#result-list .kind { color: var(--c-muted); font-size: 12px; white-space: nowrap; }
#result-list .more { color: var(--c-muted); cursor: default; justify-content: center; }

footer { padding: 8px 16px; font-size: 12px; color: var(--c-muted); border-top: 1px solid var(--c-border); }
footer a { color: inherit; }

.maplibregl-popup-content { max-width: 340px; max-height: 360px; overflow-y: auto; font-size: 13px; }
.popup h3 { margin: 0 0 4px; font-size: 14px; }
.popup .meta { color: var(--c-muted); margin-bottom: 6px; }
.popup table { border-collapse: collapse; width: 100%; }
.popup td { border-top: 1px solid #eceef1; padding: 2px 4px; vertical-align: top; word-break: break-word; }
.popup td:first-child { color: var(--c-muted); white-space: nowrap; }

@media (max-width: 720px) {
  body { flex-direction: column-reverse; }
  #sidebar { width: 100%; height: 50%; border-right: 0; border-top: 1px solid var(--c-border); }
  #map { height: 50%; }
}
