:root {
  --bg: #eef0ec;
  --panel: #fff;
  --ink: #1f2420;
  --muted: #6b746c;
  --line: #d9ddd4;
  --accent: #4a7c59;
  --danger: #b23b3b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.09), 0 6px 20px rgba(0,0,0,.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
h1 { font-size: 18px; margin: 0; white-space: nowrap; }
a { color: var(--accent); }

/* header */
header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50;
}
header.top .spacer { flex: 1; }
header.top nav a { text-decoration: none; padding: 6px 10px; border-radius: 8px; background: var(--bg); }

button.btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
button.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.btn:disabled { opacity: .5; cursor: default; }

.searchbar { position: relative; }
.searchbar.mini { width: 280px; }
.searchbar input {
  width: 100%; padding: 8px 11px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 300px; overflow-y: auto;
}
.suggestions button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 11px; font: inherit; cursor: pointer; border-bottom: 1px solid var(--line);
}
.suggestions button:hover { background: var(--bg); }

main { padding: 22px clamp(18px, 6vw, 130px) 60px; }
.msg { padding: 9px 13px; border-radius: 8px; margin-bottom: 12px; }
.msg.ok { background: #e7f0e8; color: #2f5d3a; }
.msg.err { background: #f6e4e4; color: var(--danger); }

/* preset windows — two per row, side gutters kept */
#windows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}
@media (max-width: 1200px) { #windows { grid-template-columns: 1fr; } }
.win-wrap { position: relative; min-width: 0; }
.win-loading, .mw-fail { padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.mw-fail { color: var(--danger); }

.mw {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.mw-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: #f7f8f5;
}
.mw-title { font-weight: 600; font-size: 15px; }
.mw-app { color: var(--muted); font-size: 12px; }
.mw-scale { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 70px; }
.mw-spacer { flex: 1; }

.mw-main { position: relative; }
.mw-stage { position: relative; min-width: 0; }
.mw-body {
  position: relative; width: 100%;
  aspect-ratio: var(--mw-aspect, 4 / 3);
}
.mw-map { position: absolute; inset: 0; }
/* editor: dock the layer panel beside the map, scrolling inside the map height */
.mw-main.has-panel .mw-stage { margin-right: 320px; }
.mw-cross {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  pointer-events: none; z-index: 6;
}
.mw-cross::before, .mw-cross::after {
  content: ""; position: absolute; background: rgba(0,0,0,.55);
}
.mw-cross::before { left: 10px; top: 0; width: 2px; height: 22px; }
.mw-cross::after { top: 10px; left: 0; height: 2px; width: 22px; }

.mw-loading {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 9;
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px 4px 9px; font-size: 12px; color: var(--muted);
  box-shadow: var(--shadow); pointer-events: none;
}
.mw-loading[hidden] { display: none; }
.mw-spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: mw-spin .8s linear infinite;
}
@keyframes mw-spin { to { transform: rotate(360deg); } }
.mw-loading.done { color: #2f5d3a; border-color: #bcd8bf; background: #eef6ef; }
.mw-loading.done .mw-spin {
  animation: none; border: 0; background: none; position: relative;
}
.mw-loading.done .mw-spin::after {
  content: "✓"; position: absolute; inset: -3px 0 0 -1px; color: #2f5d3a; font-weight: 700; font-size: 14px;
}

.mw-tools {
  position: absolute; left: 10px; top: 10px; z-index: 7; display: flex; flex-direction: column; gap: 4px;
}
.mw-tools button {
  width: 34px; height: 34px; border: 1px solid var(--line); background: rgba(255,255,255,.95);
  border-radius: 8px; font-size: 17px; cursor: pointer; box-shadow: var(--shadow);
}
.mw-tools button:hover { background: #fff; }

/* layer panel: absolutely positioned inside .mw-main so its height is clamped
   to the map area and it scrolls internally (both the main-page overlay and the
   editor's docked column). */
.mw-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 340px; z-index: 8;
  background: #fff; border-left: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain; padding: 8px 6px;
}
.mw-panel:not(.open) {
  background: rgba(255,255,255,.97); box-shadow: -4px 0 14px rgba(0,0,0,.08);
}
.mw-main.has-panel .mw-panel.open { width: 320px; box-shadow: none; }

.mw-basemap {
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 8px;
  margin-bottom: 6px; border-bottom: 1px solid var(--line);
}
.mw-basemap label { font-size: 12px; color: var(--muted); }
.mw-basemap select {
  flex: 1; min-width: 0; font: inherit; padding: 4px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}

.mw-foot {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-top: 1px solid var(--line); background: #f7f8f5;
}
.mw-msg { color: var(--muted); font-size: 12px; }
.mw-msg.err { color: var(--danger); }

/* locked editor map: click-to-place, slider-to-zoom */
.mw-locked .mw-map { cursor: crosshair; }
.mw-hint {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 999px;
  font-size: 11px; color: var(--muted); padding: 2px 10px; pointer-events: none; z-index: 7;
  white-space: nowrap;
}
.mw-zoombar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-top: 1px solid var(--line); background: #eef2ec; font-size: 12px;
}
.mw-zoombar .mw-zoom { flex: 1; max-width: 420px; }
.mw-zoombar .mw-zoomval { font-variant-numeric: tabular-nums; min-width: 74px; }
.mw-zoombar .mw-saved {
  color: #2f5d3a; background: #d9e8db; border-radius: 999px; padding: 1px 8px; font-size: 11px;
}

/* export preview modal */
.exp-preview {
  position: fixed; inset: 0; z-index: 200; background: rgba(20,22,20,.72);
  display: flex; align-items: center; justify-content: center; padding: 30px;
}
.exp-preview img { max-width: 96vw; max-height: 92vh; box-shadow: 0 8px 40px rgba(0,0,0,.5); background: #fff; }
.exp-close {
  position: fixed; top: 16px; right: 20px; width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: #fff; font-size: 17px; cursor: pointer;
}

/* ---- layer tree (xgis2-style) ---- */
.lt { font-size: 13px; line-height: 1.3; }
.lt-row {
  display: flex; align-items: center; gap: 6px; min-height: 28px;
  padding: 2px 4px 2px calc(var(--lt-depth, 0) * 17px + 4px);
  border-radius: 6px;
}
.lt-row:hover { background: #f3f5f1; }
.lt-row.lt-disabled { color: #9aa39a; }
.lt-row.lt-disabled .lt-icons { opacity: .35; }
.lt-row.lt-disabled input { pointer-events: none; }
.lt-kids { }
/* single-choice group: a rail down the options */
.lt-kids.lt-radio {
  margin-left: calc(var(--lt-depth, 0) * 17px + 13px);
  border-left: 2px solid var(--line);
  padding-left: 4px;
}
.lt-kids.lt-radio .lt-row { padding-left: 6px; }
.lt-caret {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  display: flex; padding: 0; width: 16px; height: 16px; align-items: center; justify-content: center;
  flex: none; transition: transform .12s;
}
.lt-caret.open { transform: rotate(90deg); }
.lt-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; flex: 1; min-width: 0; }
.lt-check input { margin: 0; flex: none; }
.lt-check > label, .lt-check { overflow: hidden; text-overflow: ellipsis; }
.lt-icons { display: inline-flex; gap: 3px; flex: none; }
.lt-icon {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
}
.lt-icon:hover { color: var(--ink); border-color: var(--muted); background: var(--bg); }
.lt-badge {
  font-size: 10px; background: #f2e3c8; color: #7a5b17; border-radius: 999px; padding: 1px 7px; flex: none;
}
.lt-pop {
  position: absolute; z-index: 90; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 10px; max-width: 280px; font-size: 12px;
}
.lt-pop input[type=range] { width: 200px; }
.lt-meta { white-space: pre-wrap; }
.lt-attrs { margin-top: 6px; color: var(--muted); }

/* settings page */
.set-wrap { max-width: 1180px; margin: 0 auto; }
.field { margin: 10px 0; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input[type=text], .field input[type=number], .field select {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit;
}
.field.inline { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.preset-row { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.preset-row > summary { cursor: pointer; font-weight: 600; margin-bottom: 4px; }
.preset-row .muted { color: var(--muted); font-weight: 400; font-size: 12px; }

.aspect-btns { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.aspect-btns button {
  border: 0; background: #fff; padding: 7px 12px; font: inherit; cursor: pointer; border-right: 1px solid var(--line);
}
.aspect-btns button:last-child { border-right: 0; }
.aspect-btns button.on { background: var(--accent); color: #fff; }

.ovl { display: block; font-size: 13px; color: var(--ink); margin: 2px 0; }

/* app picker combobox */
.apick { position: relative; display: inline-block; min-width: 240px; }
.apick-in { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.apick-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 70;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 320px; overflow-y: auto;
}
.apick-row {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; padding: 7px 10px; font: inherit; cursor: pointer; border-bottom: 1px solid var(--line);
}
.apick-row:last-child { border-bottom: 0; }
.apick-row:hover, .apick-row.on { background: var(--bg); }
.apick-id { color: var(--muted); font-size: 11px; }
.apick-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.p-window .mw { margin-top: 4px; }
.searchbar .suggestions { top: calc(100% + 4px); }
