/* ==========================================================================
   NusaBlue — Calm, Minimalist Dark-Slate Spatial Design System
   Zero neon clutter, lightweight, crisp typography, generous breathing room.
   ========================================================================== */

:root {
  --bg: #0b1015;
  --surface: rgba(16, 22, 29, 0.92);
  --surface-elevated: rgba(23, 31, 41, 0.85);
  --border: rgba(255, 255, 255, 0.09);
  --border-hover: rgba(255, 255, 255, 0.2);

  --accent: #10b981;
  --accent-muted: rgba(16, 185, 129, 0.14);
  --soil: #38bdf8;

  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
}

.surface {
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-size: 11px; }
.muted { color: var(--text-secondary); }
.accent { color: var(--accent); }
.icon-sm { width: 15px; height: 15px; flex-shrink: 0; }
.icon-xs { width: 13px; height: 13px; flex-shrink: 0; }

/* ==========================================================================
   MINIMAL TOP BAR
   ========================================================================== */
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  height: 50px;
  z-index: 1000;
  border-radius: var(--radius);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.brand-name {
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -0.02em;
}

.brand-divider { color: var(--text-muted); font-size: 13px; }
.brand-sub { color: var(--text-secondary); font-size: 12px; font-weight: 500; }

/* Search & Curated Filter Dropdown */
.search-container {
  position: relative;
  flex: 1;
  max-width: 440px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#region-search {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#region-search::placeholder { color: var(--text-muted); }
#region-search:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.07);
}

.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  border-radius: var(--radius);
  padding: 8px;
  z-index: 1100;
}

.filter-pills {
  display: flex;
  gap: 4px;
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.pill {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.pill.active {
  color: var(--accent);
  background: var(--accent-muted);
  border-color: rgba(16, 185, 129, 0.3);
}

.dropdown-list {
  max-height: 290px;
  overflow-y: auto;
}

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s;
}

.dropdown-item:hover { background: rgba(255, 255, 255, 0.06); }
.di-name { font-weight: 500; font-size: 12.5px; }
.di-sub { font-size: 11px; color: var(--text-muted); }
.di-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 5px;
}

/* Topbar Buttons */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-secondary, .btn-primary, .btn-ghost, .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.btn-secondary:hover, .btn-secondary.active {
  border-color: rgba(16, 185, 129, 0.45);
  background: var(--accent-muted);
  color: #ecfdf5;
}

.btn-primary {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #052e16;
  font-weight: 600;
}

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost {
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.05);
}

.btn-sm { height: 28px; font-size: 11.5px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11px; }

.btn-icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
}

.btn-icon:hover, .btn-icon.active {
  color: var(--text);
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.09);
}

.count-pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--accent-muted);
  color: var(--accent);
  display: inline-grid;
  place-items: center;
}

/* ==========================================================================
   LAYERS & FILTERS POPOVER (Progressive Disclosure)
   ========================================================================== */
.layers-popover {
  position: fixed;
  top: 72px;
  right: 12px;
  width: 316px;
  max-height: calc(100vh - 96px);
  z-index: 1050;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.popover-title {
  font-weight: 600;
  font-size: 13px;
}

.basemap-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}

.basemap-toggle button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
}

.basemap-toggle button.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.popover-body {
  overflow-y: auto;
  padding: 10px 14px 14px;
}

.section-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

.section-label:first-child { margin-top: 2px; }

.layer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5.5px 0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.layer-toggle:last-of-type { border-bottom: none; }
.lt-text { display: flex; flex-direction: column; min-width: 0; }
.lt-name { font-size: 12.5px; font-weight: 500; color: var(--text); }
.lt-desc { font-size: 11px; color: var(--text-muted); }

.layer-toggle input { display: none; }

.toggle-ui {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  flex-shrink: 0;
  transition: background 0.15s;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e2e8f0;
  transition: transform 0.15s;
}

.layer-toggle input:checked + .toggle-ui {
  background: var(--accent);
}

.layer-toggle input:checked + .toggle-ui::after {
  transform: translateX(14px);
  background: #ffffff;
}

.legend-box {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.legend-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.legend-bar {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, #0284c7 0%, #10b981 55%, #f59e0b 100%);
}

/* ==========================================================================
   DRAW BAR
   ========================================================================== */
.draw-bar {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1020;
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.draw-status {
  font-size: 12px;
  color: var(--text);
}

.draw-actions {
  display: flex;
  gap: 6px;
}

/* ==========================================================================
   CLEAN RIGHT SUMMARY PANEL
   ========================================================================== */
.summary-panel {
  position: fixed;
  top: 72px;
  right: 12px;
  bottom: 12px;
  width: 364px;
  z-index: 990;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.22s ease, opacity 0.2s ease;
}

.summary-panel.collapsed {
  transform: translateX(390px);
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-muted);
  color: var(--accent);
}

.province-label {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.panel-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.panel-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 5px;
  line-height: 1.48;
}

.custom-aoi-bar {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.custom-aoi-actions { display: flex; gap: 5px; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 18px;
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  color: var(--text-secondary);
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 3-Column KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.kpi-cell {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 9px;
}

.kpi-label {
  font-size: 10.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.kpi-val {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Cards */
.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}

.pool-track {
  display: flex;
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  gap: 2px;
  margin-bottom: 9px;
}

.pool-agb { background: var(--accent); transition: width 0.4s ease; }
.pool-soc { background: var(--soil); transition: width 0.4s ease; }

.pool-stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot.agb { background: var(--accent); }
.dot.soc { background: var(--soil); }

.footnote {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Chart Switch */
.mini-switch {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  padding: 2px;
}

.mini-switch button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
}

.mini-switch button.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.chart-box {
  position: relative;
  height: 145px;
  width: 100%;
}

/* Custom Land Cover List */
.lc-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.lc-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

/* Clean Collapsible Accordions */
.accordion {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.accordion summary::-webkit-details-marker { display: none; }
.accordion[open] .chev { transform: rotate(180deg); }
.chev { color: var(--text-muted); transition: transform 0.15s; }

.accordion-body {
  padding: 0 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 11.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-row .mono {
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-row:last-child { border-bottom: none; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.s2-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.s2-item {
  padding: 8px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

.s2-item-top {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.s2-actions { display: flex; gap: 5px; }

.muted-p {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-msg {
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
}

.code-box {
  background: #0a0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #cbd5e1;
  overflow-x: auto;
}

.accuracy-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.48;
}

.accuracy-list strong { color: var(--text); }

/* Toast */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  padding: 8px 14px;
  border-radius: 99px;
  font-size: 12px;
  color: var(--text);
}

/* ==========================================================================
   CLEAN LEAFLET CONTROLS, POPUPS & MARKERS
   ========================================================================== */
.leaflet-container {
  background: var(--bg) !important;
  font-family: var(--font-sans) !important;
}

.leaflet-bottom.leaflet-left {
  bottom: 14px !important;
  left: 14px !important;
}

.leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: 9px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}

.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom-color: var(--border) !important;
}

.leaflet-bar a:hover {
  background: rgba(255, 255, 255, 0.1) !important;
}

.leaflet-control-scale-line {
  background: var(--surface) !important;
  border-color: var(--border-hover) !important;
  color: var(--text-secondary) !important;
  font-family: var(--font-mono) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution { display: none !important; }

.leaflet-popup-content-wrapper {
  background: rgba(16, 22, 29, 0.96) !important;
  border: 1px solid var(--border-hover);
  border-radius: 10px !important;
  color: var(--text) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-popup-tip { background: rgba(16, 22, 29, 0.96) !important; }
.leaflet-popup-content { margin: 10px 12px !important; min-width: 210px; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

.popup-title { font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
.popup-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-muted);
  color: var(--accent);
  margin-bottom: 7px;
}
.popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  font-size: 11px;
}
.popup-k { color: var(--text-secondary); }
.popup-v { font-family: var(--font-mono); text-align: right; color: var(--text); }

/* Restrained IoT Dot Marker (No loud pulsing rings) */
.iot-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #f59e0b;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; }

@media (max-width: 900px) {
  .brand-divider, .brand-sub { display: none; }
  .summary-panel { width: calc(100vw - 24px); top: auto; height: 48vh; }
}
