:root {
  --bg: #f6f7f5;
  --panel: #ffffff;
  --ink: #1c2321;
  --ink-2: #4c5753;
  --ink-3: #7b8682;
  --line: #e3e7e4;
  --soft: #eef2ef;
  --accent: #0f766e;
  --accent-ink: #0b4f4a;
  --accent-soft: #dcefeb;
  --brand: #0f3d3a;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 6px 20px rgba(16, 24, 22, .10);
  --panel-w: 340px;
  --track: #c9d0cd;
  --chrome: rgba(255, 255, 255, .9);
  --chrome-ink: #37413e;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111615; --panel: #171d1c; --ink: #e7ecea; --ink-2: #b4bfbb; --ink-3: #85918d;
    --line: #29312f; --soft: #1f2725; --accent: #2dd4bf; --accent-ink: #5eead4; --accent-soft: #123a36;
    --brand: #2dd4bf; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
    --track: #3a4441; --chrome: rgba(23, 29, 28, .9); --chrome-ink: #cfd8d5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111615; --panel: #171d1c; --ink: #e7ecea; --ink-2: #b4bfbb; --ink-3: #85918d;
  --line: #29312f; --soft: #1f2725; --accent: #2dd4bf; --accent-ink: #5eead4; --accent-soft: #123a36;
  --brand: #2dd4bf; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
    --track: #3a4441; --chrome: rgba(23, 29, 28, .9); --chrome-ink: #cfd8d5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; display: flex; }

/* ---------- Panel ---------- */
#panel {
  width: var(--panel-w); flex: 0 0 var(--panel-w); height: 100%;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 5;
  transition: margin-left .25s ease, transform .25s ease;
}
.panel-collapsed #panel { margin-left: calc(-1 * var(--panel-w)); }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 14px 12px 16px; }
.brand-mark { color: var(--brand); display: grid; flex: none; }
.brand-text { min-width: 0; flex: 1; }
.brand h1 { font-size: 15.5px; line-height: 1.25; margin: 0; letter-spacing: -.01em; font-weight: 700; }
.brand p { margin: 1px 0 0; color: var(--ink-3); font-size: 12px; }
.icon-btn {
  border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2); flex: none;
}
.icon-btn:hover { background: var(--soft); }

.search-wrap { position: relative; margin: 0 14px 10px; }
.search-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
#search {
  width: 100%; height: 38px; padding: 0 12px 0 34px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--soft); color: var(--ink); font: inherit; outline: none;
}
#search:focus { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-soft); }
#results {
  position: absolute; left: 0; right: 0; top: 42px; z-index: 10; list-style: none; margin: 0; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 320px; overflow: auto;
}
#results li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
#results li:hover, #results li.active { background: var(--accent-soft); }
#results li.empty { color: var(--ink-3); cursor: default; }
#results li.empty:hover { background: none; }
.r-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-type { color: var(--ink-3); font-size: 12px; white-space: nowrap; }

.panel-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 12px; }
.grp { padding: 6px 0 4px; }
.grp + .grp, #layers .grp:first-child { border-top: 1px solid var(--line); }
.grp-title {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); margin: 8px 8px 6px;
}
.bm { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 6px 8px; padding: 3px; background: var(--soft); border-radius: 9px; }
.bm-btn { border: 0; background: transparent; padding: 6px 2px; border-radius: 7px; cursor: pointer; font-size: 12px; color: var(--ink-2); }
.bm-btn[aria-pressed="true"] { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.entry { border-radius: 9px; }
.entry.is-open { background: var(--soft); }
.entry-head { display: flex; align-items: center; }
.entry-toggle { flex: 1; display: flex; align-items: center; gap: 9px; padding: 7px 4px 7px 8px; cursor: pointer; min-width: 0; }
.entry-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 28px; height: 16px; border-radius: 99px; background: var(--track); position: relative; flex: none; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.entry-toggle input:checked + .switch { background: var(--accent); }
.entry-toggle input:checked + .switch::after { transform: translateX(12px); }
.entry-toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.entry-title { flex: 1; min-width: 0; font-weight: 520; color: var(--ink-2); }
.entry.is-on .entry-title { color: var(--ink); }
.entry-more {
  border: 0; background: transparent; width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
  color: var(--ink-3); display: grid; place-items: center; flex: none; margin-right: 2px;
}
.entry-more:hover { background: var(--line); color: var(--ink); }
.entry-more svg { transition: transform .15s; }
.entry-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent-soft); border-top-color: var(--accent); display: none; animation: spin .7s linear infinite; flex: none; }
.entry.is-busy .spin { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.entry-body { padding: 2px 10px 10px 45px; }
.lg-title { font-size: 11.5px; font-weight: 650; color: var(--ink-2); margin: 8px 0 2px; }
.legend { list-style: none; margin: 2px 0 0; padding: 0; }
.legend li { font-size: 12.5px; color: var(--ink-2); }
.legend li > label, .legend li:not(:has(label)) { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.legend li:not(:has(label)) { cursor: default; }
.legend input { margin: 0; accent-color: var(--accent); width: 14px; height: 14px; flex: none; }
.legend input:not(:checked) ~ span:last-child { color: var(--ink-3); text-decoration: line-through; }
.legend input:not(:checked) ~ .sw { opacity: .3; }
.lg-actions { display: flex; gap: 14px; margin-top: 6px; }
.link { border: 0; background: none; padding: 0; color: var(--accent-ink); font-size: 12px; cursor: pointer; }
.link:hover { text-decoration: underline; }
.opacity { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); margin: 4px 0 6px; }
.opacity input { flex: 1; accent-color: var(--accent); min-width: 0; }
.opacity output { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-3); }

/* Simbol legenda */
.sw { flex: none; display: inline-block; }
.sw-fill { width: 16px; height: 12px; border-radius: 3px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.sw-line { width: 16px; height: var(--h, 3px); border-radius: 2px; background: var(--c); }
.sw-circle { width: 11px; height: 11px; margin: 0 2.5px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(0,0,0,.15); }

.note { margin: 10px 8px 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); }
.note p { margin: 0 0 6px; }

/* ---------- Peta ---------- */
#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }
#panel-toggle {
  position: absolute; top: 10px; left: 10px; z-index: 3; display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px 0 10px; border-radius: 9px; border: 0; cursor: pointer;
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; font-size: 13px;
}
#panel-toggle:hover { color: var(--accent-ink); }
#app:not(.panel-collapsed) #panel-toggle { display: none; }
.statusbar {
  position: absolute; left: 10px; bottom: 10px; z-index: 2; display: flex; gap: 10px;
  background: var(--chrome); color: var(--chrome-ink); backdrop-filter: blur(4px);
  font-size: 11.5px; padding: 3px 9px; border-radius: 6px; font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0,0,0,.12); pointer-events: none;
}
#toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6;
  background: #2b2f2e; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow);
}

.maplibregl-ctrl-group { border-radius: 9px !important; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button { width: 34px; height: 34px; }
.maplibregl-ctrl-group button svg { display: block; margin: auto; color: var(--ink); }
.maplibregl-ctrl-scale { border-color: var(--chrome-ink); color: var(--chrome-ink); background: var(--chrome); font-size: 11px; }

/* Ikon tema: tampilkan bulan di mode terang, matahari di mode gelap */
#theme-toggle .ico-sun, [data-theme="dark"] #theme-toggle .ico-moon { display: none; }
[data-theme="dark"] #theme-toggle .ico-sun { display: block; }

/* Kontrol peta di mode gelap */
[data-theme="dark"] .maplibregl-ctrl-group { background: var(--panel); }
[data-theme="dark"] .maplibregl-ctrl-group button + button { border-top-color: var(--line); }
[data-theme="dark"] .maplibregl-ctrl button:not(:disabled):hover { background-color: var(--soft); }
[data-theme="dark"] .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1) hue-rotate(180deg) brightness(1.1); }
[data-theme="dark"] .maplibregl-ctrl-attrib,
[data-theme="dark"] .maplibregl-ctrl-attrib.maplibregl-compact { background: var(--chrome); color: var(--chrome-ink); }
[data-theme="dark"] .maplibregl-ctrl-attrib a { color: var(--ink-2); }
[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }
[data-theme="dark"] .maplibregl-popup-close-button:hover { background: var(--soft); }
[data-theme="dark"] .sw-circle { box-shadow: 0 0 0 1.5px var(--panel), 0 0 0 2.5px rgba(255,255,255,.2); }

/* Popup */
.info-pop .maplibregl-popup-content { padding: 0; border-radius: 11px; box-shadow: var(--shadow); background: var(--panel); color: var(--ink); }
.info-pop.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel); }
.info-pop.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel); }
.info-pop.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--panel); }
.info-pop.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--panel); }
.info-pop .maplibregl-popup-close-button { font-size: 18px; width: 28px; height: 28px; right: 3px; top: 3px; border-radius: 7px; color: var(--ink-3); }
.pop { max-height: 46vh; overflow: auto; }
.pop-card { padding: 11px 14px 12px; }
.pop-card + .pop-card { border-top: 1px solid var(--line); }
.pop-layer { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding-right: 22px; }
.pop-title { font-size: 14.5px; font-weight: 680; margin: 4px 0 6px; line-height: 1.3; }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 12.5px; }
.pop dt { color: var(--ink-3); white-space: nowrap; }
.pop dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --panel-w: min(88vw, 360px); }
  #panel {
    position: absolute; top: 0; left: 0; bottom: 0; transform: translateX(-102%);
    box-shadow: var(--shadow); margin-left: 0 !important;
  }
  .panel-open #panel { transform: none; }
  #app:not(.panel-open) #panel-toggle { display: flex; }
  #app.panel-open #panel-toggle { display: none; }
  .statusbar #coord { display: none; }
  .brand { padding-top: max(16px, env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
