:root {
  --bg: #0f1720;
  --panel: #161f2b;
  --panel-2: #1e2937;
  --line: #2a3644;
  --text: #e6edf3;
  --muted: #93a1b0;
  --accent: #ffb020;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#map { position: absolute; inset: 0; background: var(--bg); }

/* ---------- Panel ---------- */
.panel {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  width: 330px; max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform .25s ease, opacity .25s ease;
}
.panel.hidden { transform: translateX(-115%); opacity: 0; pointer-events: none; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1b2635, #161f2b);
}
.panel-head h1 { font-size: 15px; margin: 0; letter-spacing: .2px; font-weight: 700; }
.panel-head h1 span { color: var(--accent); }
.panel-toggle, .panel-show {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; width: 28px; height: 28px; cursor: pointer; font-size: 16px; line-height: 1;
}
.panel-toggle:hover, .panel-show:hover { background: #26374a; }
.panel-show {
  position: absolute; top: 12px; left: 12px; z-index: 5; width: 40px; height: 40px;
  font-size: 18px; display: none; box-shadow: var(--shadow);
}
.panel-body { padding: 12px 14px; overflow-y: auto; }

/* ---------- Search ---------- */
.search { position: relative; margin-bottom: 12px; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 13px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search-results {
  list-style: none; margin: 6px 0 0; padding: 0; max-height: 240px; overflow-y: auto;
  border-radius: 9px; display: none;
}
.search-results.show { display: block; border: 1px solid var(--line); background: var(--panel-2); }
.search-results li { padding: 8px 11px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: #26374a; }
.search-results li small { color: var(--muted); display: block; margin-top: 2px; }

/* ---------- Layer groups ---------- */
.layer-group { margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.layer-row { display: flex; align-items: center; justify-content: space-between; }
.layer-row label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.layer-row input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.count {
  font-size: 11px; color: var(--muted); background: var(--panel-2);
  padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); min-width: 34px; text-align: center;
}
.legend { margin: 8px 0 2px 24px; display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.legend-item.off { opacity: .35; text-decoration: line-through; }
.legend .swatch { width: 13px; height: 13px; border-radius: 3px; flex: none; border: 1px solid rgba(255,255,255,.15); }
.legend .swatch.line { height: 4px; border-radius: 2px; }
.legend .swatch.dot { border-radius: 50%; }

/* ---------- Basemap ---------- */
.basemap { margin: 12px 0 6px; }
.basemap > label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 6px; }
.seg { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; }
.seg button {
  flex: 1; padding: 6px; border: none; background: transparent; color: var(--muted);
  border-radius: 7px; cursor: pointer; font-size: 12px;
}
.seg button.active { background: var(--accent); color: #1a1200; font-weight: 600; }

/* ---------- Footer ---------- */
.panel-foot { margin-top: 10px; font-size: 11px; color: var(--muted); }
.panel-foot #meta { margin-bottom: 6px; }
.attrib a { color: var(--accent); text-decoration: none; }
.attrib a:hover { text-decoration: underline; }

/* ---------- Popup ---------- */
.maplibregl-popup-content {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 0; box-shadow: var(--shadow); overflow: hidden; min-width: 210px;
}
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 2px 8px; }
.pp-head { padding: 10px 12px; font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.pp-tag { font-size: 10px; padding: 2px 7px; border-radius: 5px; color: #fff; font-weight: 600; }
.pp-body { padding: 2px 12px 12px; font-size: 12.5px; }
.pp-body .row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-top: 1px solid var(--line); }
.pp-body .row .k { color: var(--muted); }
.pp-body .row .v { text-align: right; font-weight: 500; }
.pp-body a { color: var(--accent); text-decoration: none; font-size: 11.5px; }

/* ---------- Loading ---------- */
.loading {
  position: absolute; inset: 0; z-index: 20; display: flex; gap: 14px;
  align-items: center; justify-content: center; flex-direction: column;
  background: rgba(15,23,32,.85); color: var(--text); font-size: 14px;
}
.loading.done { display: none; }
.spinner { width: 38px; height: 38px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .panel { width: calc(100% - 24px); max-height: 60%; }
}
