:root {
  --bg: #0d1420;
  --panel: #141c2b;
  --panel-2: #1c2637;
  --border: #263248;
  --text: #e8eef7;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--text); }
#map { position: absolute; inset: 0; background: var(--bg); }

/* ---------------- Topbar ---------------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 62px; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(90deg, rgba(13,20,32,.96), rgba(13,20,32,.80));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: .5px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px rgba(59,130,246,.4);
}
.titles h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px; line-height: 1.1; }
.titles p { margin: 2px 0 0; font-size: 13px; color: var(--accent-2); font-weight: 600; }
#toggle-panel {
  display: none; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}

/* ---------------- Sidebar ---------------- */
#panel {
  position: absolute; top: 74px; left: 12px; bottom: 12px; width: 310px; z-index: 9;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow-y: auto;
  display: flex; flex-direction: column;
}
#panel.hidden { display: none; }
.block { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.block h2 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700;
}
#kecamatan {
  width: 100%; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
}

.lyr { display: flex; align-items: center; gap: 9px; padding: 7px 4px; font-size: 13.5px; cursor: pointer; }
.lyr input { accent-color: var(--accent); width: 15px; height: 15px; }
.sw { width: 15px; height: 15px; border-radius: 4px; flex: none; }
.sw-grad { background: linear-gradient(90deg, #fde68a, #f59e0b, #dc2626); }

.sub { margin: 12px 0 7px; font-size: 12px; color: var(--muted); }
.segmented { display: flex; gap: 5px; background: var(--panel-2); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.segmented button {
  flex: 1; padding: 7px 4px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--muted); border: none; border-radius: 7px; transition: .15s;
}
.segmented button.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(59,130,246,.35); }

/* ---------------- Stats ---------------- */
.stats { display: flex; flex-direction: column; gap: 10px; }
.stat-row { display: flex; gap: 10px; }
.stat-card {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px;
}
.stat-card .num { font-size: 22px; font-weight: 800; color: #fff; line-height: 1; }
.stat-card .num small { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-card .lbl { margin-top: 5px; font-size: 11px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.bar-item { font-size: 12px; }
.bar-head { display: flex; justify-content: space-between; margin-bottom: 3px; color: var(--text); }
.bar-head b { color: var(--muted); font-weight: 600; }
.bar-track { height: 7px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.credit { margin-top: auto; padding: 14px 16px; font-size: 10.5px; color: var(--muted); line-height: 1.5; }

/* ---------------- Legend ---------------- */
#legend {
  position: absolute; bottom: 20px; right: 14px; z-index: 9;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; max-width: 230px; font-size: 12px; box-shadow: var(--shadow);
}
#legend h3 { margin: 0 0 9px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#legend .row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
#legend .box { width: 15px; height: 15px; border-radius: 4px; flex: none; border: 1px solid rgba(255,255,255,.15); }

/* ---------------- Popup ---------------- */
.maplibregl-popup-content {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 0; overflow: hidden; box-shadow: var(--shadow); max-width: 300px;
}
.pop-head { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 10px 14px; font-weight: 700; font-size: 13.5px; }
.pop-body { padding: 10px 14px; }
.pop-body table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.pop-body td { padding: 3px 0; vertical-align: top; }
.pop-body td.k { color: var(--muted); padding-right: 10px; white-space: nowrap; }
.maplibregl-popup-close-button { color: #fff; font-size: 18px; padding: 4px 8px; }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }

.maplibregl-ctrl-attrib { font-size: 10px; }

@media (max-width: 720px) {
  #toggle-panel { display: block; }
  #panel { top: 70px; left: 8px; right: 8px; width: auto; max-height: 66vh; }
  #panel.hidden { display: none; }
  #legend { bottom: 10px; right: 8px; }
  .titles h1 { font-size: 13px; }
}
