:root {
  --bg: #f7f3ec;
  --panel: #ffffff;
  --ink: #1f1a14;
  --muted: #6b6257;
  --line: #e6dfd3;
  --accent: #b45309;
  --accent-ink: #ffffff;
  --soft: #fbf5ea;
  --shadow: 0 6px 24px rgba(40, 30, 10, 0.12);
  --radius: 12px;
  --sidebar-w: 400px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14px; }

#app { display: flex; height: 100vh; height: 100dvh; }

#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  position: relative;
  z-index: 1000;
  box-shadow: var(--shadow);
}

#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

.brand {
  display: flex; gap: 12px; align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--soft), var(--panel));
}
.brand-icon { font-size: 30px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.panel { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; position: relative; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }

select, input[type="search"], input[type="text"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  outline: none;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.12); }
select:disabled { color: var(--muted); background: var(--soft); }

.suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  max-height: 260px; overflow: auto;
}
.suggest li { padding: 8px 10px; border-radius: 6px; cursor: pointer; line-height: 1.3; }
.suggest li:hover { background: var(--soft); }
.suggest li small { display: block; color: var(--muted); }

.btn {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--soft); border-color: #d6c9b3; }
.btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.buttons { margin-bottom: 10px; }
.link { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

.radius input[type="range"] { width: 100%; accent-color: var(--accent); }
.radius { margin-bottom: 6px; }

.center-info {
  font-size: 12.5px; color: var(--muted);
  background: var(--soft); border-radius: 8px; padding: 8px 10px;
}
.center-info b { color: var(--ink); }

.filter-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.filter-head span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  font-size: 12.5px; cursor: pointer; user-select: none;
  color: var(--muted);
}
.chip.on { background: var(--chip, var(--accent)); border-color: var(--chip, var(--accent)); color: #fff; }
.chip .n { opacity: 0.8; font-variant-numeric: tabular-nums; }

#results { flex: 1; overflow: auto; }
.status { padding: 12px 18px; color: var(--muted); font-size: 13px; }
.status.loading::before { content: "⏳ "; }
.status.error { color: #b91c1c; }

.list { list-style: none; margin: 0; padding: 0 10px 14px; }
.item {
  display: grid; grid-template-columns: 72px 1fr; gap: 12px;
  padding: 10px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid transparent;
}
.item:hover { background: var(--soft); }
.item.selected { border-color: var(--accent); background: var(--soft); }
.thumb {
  width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
  background: var(--soft); display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex: 0 0 auto;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item .name { font-weight: 700; font-size: 14px; line-height: 1.25; margin-bottom: 3px; }
.item .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--chip, #eee); color: #fff; }
.wiki-badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* Detail panel */
.detail {
  position: absolute; inset: 0; background: var(--panel); z-index: 5;
  display: flex; flex-direction: column; overflow: auto;
}
.detail .back {
  position: sticky; top: 0; z-index: 2;
  text-align: left; border: 0; border-bottom: 1px solid var(--line);
  padding: 12px 18px; background: rgba(255,255,255,0.95); backdrop-filter: blur(6px);
  font: inherit; font-weight: 600; color: var(--accent); cursor: pointer;
}
.hero { position: relative; background: var(--soft); min-height: 200px; }
.hero img { width: 100%; max-height: 280px; object-fit: cover; display: block; }
.hero .placeholder { height: 200px; display: flex; align-items: center; justify-content: center; font-size: 64px; }
.hero .credit { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.hero .credit a { color: #fff; }
.detail-content { padding: 14px 18px 24px; }
.detail h2 { margin: 0 0 6px; font-size: 20px; line-height: 1.2; }
.detail .meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.detail p.extract { line-height: 1.55; margin: 0 0 12px; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 14px; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.actions a { text-decoration: none; }
.gallery h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 0 0 8px; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.gallery-grid a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--soft); }
.gallery-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .empty { color: var(--muted); font-size: 13px; }
.detail p.desc { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.nearby { list-style: none; margin: 0; padding: 0; }
.nearby li { display: grid; grid-template-columns: 56px 1fr; gap: 10px; padding: 6px; border-radius: 10px; cursor: pointer; }
.nearby li:hover { background: var(--soft); }
.nearby .thumb { width: 56px; height: 56px; font-size: 22px; }
.nearby .name { font-weight: 600; font-size: 13.5px; line-height: 1.25; margin-bottom: 2px; }
.nearby .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.item .dist { margin-left: auto; font-variant-numeric: tabular-nums; }
.suggest li.sugg-scope { background: var(--soft); }
.center-info .link { margin-left: 6px; font-size: 12px; }

/* Map extras */
.floating {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 800; box-shadow: var(--shadow);
}
.pick-hint {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 800; background: rgba(31, 26, 20, 0.85); color: #fff;
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
}
#map.picking { cursor: crosshair; }

.pin {
  width: 32px; height: 32px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--pin, var(--accent));
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
}
.pin span { transform: rotate(45deg); font-size: 15px; line-height: 1; }
.pin.selected { outline: 3px solid rgba(180, 83, 9, 0.45); outline-offset: 1px; }
.user-pin {
  width: 18px; height: 18px; border-radius: 50%;
  background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25);
}
.leaflet-popup-content { margin: 10px 12px; font: inherit; font-size: 13px; }
.leaflet-popup-content .name { font-weight: 700; margin-bottom: 2px; }
.leaflet-popup-content .type { color: var(--muted); margin-bottom: 6px; }
.leaflet-popup-content img { width: 100%; max-width: 220px; border-radius: 6px; display: block; margin-bottom: 6px; }
.leaflet-popup-content button { font: inherit; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #sidebar { width: 100%; flex: 0 0 52vh; border-right: 0; border-top: 1px solid var(--line); }
  #map-wrap { flex: 1; }
  .brand p { display: none; }
  .brand { padding: 10px 14px; }
  .panel { padding: 10px 14px; }
}
