/* =====================================================================
   TPS PALEMBANG — INTERACTIVE MAP DASHBOARD
   Design language: modern GIS + academic research + public information
   White surfaces, navy/blue accent, restrained radius, minimal motion.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

/* =====================================================================
   1. DESIGN TOKENS
   ===================================================================== */
:root {
    /* --- brand (unchanged from the original app so Home <-> Map stay in sync) --- */
    --accent: #007bff;
    --accent-rgb: 0, 123, 255;
    --accent-strong: #0059c8;
    --accent-contrast: #ffffff;

    /* --- neutrals / surfaces (light) --- */
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-alt: #f0f2f8;
    --fg: #10131a;
    --fg-muted: #5b6472;
    --fg-faint: #8991a0;
    --border: #e1e4ec;
    --border-strong: #c9cedb;
    --panel: rgba(255, 255, 255, 0.86);
    --overlay-scrim: rgba(10, 14, 26, 0.45);

    /* --- navy, reserved for hero-adjacent / high-emphasis chrome --- */
    --navy-900: #0a1128;
    --navy-800: #0f1b3d;
    --navy-700: #162b57;

    /* --- capacity classification (data-driven thresholds, see app.js) --- */
    --cap-low: #2f9e5b;
    --cap-medium: #d6a52a;
    --cap-high: #e2812e;
    --cap-veryhigh: #d5484f;

    /* --- status semantics --- */
    --success: #2f9e5b;
    --warning: #d6a52a;
    --danger: #d5484f;
    --info: var(--accent);

    /* --- typography --- */
    --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
    --fs-2xs: 11px;
    --fs-xs: 12.5px;
    --fs-sm: 13.5px;
    --fs-base: 14.5px;
    --fs-md: 16px;
    --fs-lg: 19px;
    --fs-xl: 24px;

    /* --- spacing scale (4px base) --- */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;

    /* --- radius (restrained, per brief) --- */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    /* --- elevation (single soft layer, no heavy/colored shadows) --- */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);

    /* --- layout metrics --- */
    --topbar-h: 58px;
    --topbar-h-mobile: 102px;
    --sidebar-w: 268px;
    --sidebar-w-collapsed: 0px;
    --panel-w: 320px;

    /* --- motion (restrained; disabled entirely under reduced-motion) --- */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --t-fast: 120ms;
    --t-base: 200ms;

    /* --- z-index scale --- */
    --z-map: 1;
    --z-legend: 400;
    --z-topbar: 900;
    --z-sidebar: 850;
    --z-panel: 820;
    --z-backdrop: 800;
    --z-toast: 1200;
    --z-modal: 1300;
}

[data-theme="dark"] {
    --accent: #4da3ff;
    --accent-rgb: 77, 163, 255;
    --accent-strong: #7fbdff;
    --accent-contrast: #04101f;

    --bg: #0b0e14;
    --surface: #12161f;
    --surface-alt: #171c27;
    --fg: #eef1f6;
    --fg-muted: #a7afbe;
    --fg-faint: #737c8c;
    --border: #262c3a;
    --border-strong: #333a4a;
    --panel: rgba(18, 22, 31, 0.88);
    --overlay-scrim: rgba(0, 0, 0, 0.6);

    --navy-900: #060a18;
    --navy-800: #0a1128;
    --navy-700: #0f1b3d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.55);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* =====================================================================
   2. RESET / BASE
   ===================================================================== */
* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.45;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button, input, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

a { color: inherit; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }

.mono, .tabular {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* =====================================================================
   3. APP SHELL / LAYOUT GRID
   ===================================================================== */
.app-shell {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
    grid-template-rows: var(--topbar-h) 1fr;
    transition: grid-template-columns var(--t-base) var(--ease);
}

.app-shell.sidebar-collapsed {
    grid-template-columns: 0px 1fr var(--panel-w);
}

.app-shell.panel-collapsed {
    grid-template-columns: var(--sidebar-w) 1fr 0px;
}

.app-shell.sidebar-collapsed.panel-collapsed {
    grid-template-columns: 0px 1fr 0px;
}

/* =====================================================================
   4. TOPBAR
   ===================================================================== */
.topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: var(--topbar-h);
    padding: 0 var(--sp-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: var(--z-topbar);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-width: 0;
    flex: 0 0 auto;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--fg-muted);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
    flex: 0 0 auto;
}

.icon-btn:hover {
    background: var(--surface-alt);
    color: var(--fg);
}

.icon-btn.is-active {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
}

.icon-btn svg { width: 19px; height: 19px; }

.brand {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-width: 0;
    text-decoration: none;
}

.brand-logo {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    flex: 0 0 auto;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.brand-title {
    font-size: var(--fs-base);
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-subtitle {
    font-size: var(--fs-2xs);
    color: var(--fg-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-center {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    justify-content: center;
    position: relative;
}

.search-wrap {
    position: relative;
    width: 100%;
    max-width: 460px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--fg-faint);
    pointer-events: none;
}

.tool-search {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--fg);
    font-size: var(--fs-sm);
    transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.tool-search:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
}

.tool-search::placeholder { color: var(--fg-faint); }

.suggest-box {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    max-height: 320px;
    overflow-y: auto;
    z-index: var(--z-topbar);
    padding: 6px;
}
.s-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--fs-sm);
}
.s-item:hover, .s-item.is-active { background: var(--surface-alt); }
.s-item-icon {
    width: 22px; height: 22px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
}
.s-item-icon svg { width: 12px; height: 12px; }
.s-item-icon.type-kelurahan, .s-item-icon.type-kecamatan { background: var(--surface-alt); color: var(--fg-muted); }
.s-item-text { display: flex; flex-direction: column; min-width: 0; }
.s-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-item-meta { font-size: var(--fs-2xs); color: var(--fg-muted); }
.s-item-empty { padding: var(--sp-3); text-align: center; color: var(--fg-muted); font-size: var(--fs-xs); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex: 0 0 auto;
}

.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--fg-muted);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
    white-space: nowrap;
}

.btn-text:hover { background: var(--surface-alt); color: var(--fg); border-color: var(--border-strong); }
.btn-text svg { width: 15px; height: 15px; }

/* theme switch (kept functionally identical, restyled) */
.switch {
    position: relative;
    width: 42px;
    height: 24px;
    display: inline-block;
    flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: var(--border-strong);
    transition: background-color var(--t-base) var(--ease);
    border-radius: var(--radius-pill);
}
.slider::before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; top: 3px;
    background-color: #fff;
    transition: transform var(--t-base) var(--ease);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider::before { transform: translateX(18px); }
input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =====================================================================
   5. SIDEBAR
   ===================================================================== */
.sidebar {
    grid-row: 2;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: var(--z-sidebar);
}

.app-shell.sidebar-collapsed .sidebar { display: none; }

.sidebar-inner {
    width: var(--sidebar-w);
    padding: var(--sp-4) var(--sp-3) var(--sp-8);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
}

.sidebar-section-title {
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fg-faint);
    padding: 0 var(--sp-2);
    margin-bottom: var(--sp-2);
}

.nav-list, .tool-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: 9px var(--sp-2);
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--fg-muted);
    font-size: var(--fs-sm);
    font-weight: 500;
    text-align: left;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; }

.nav-item:hover { background: var(--surface-alt); color: var(--fg); }

.nav-item.active {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
    font-weight: 600;
}

.field-label {
    display: block;
    font-size: var(--fs-2xs);
    font-weight: 600;
    color: var(--fg-muted);
    margin: var(--sp-3) 0 6px;
    padding: 0 var(--sp-2);
}
.field-label:first-child { margin-top: 0; }

.tool-select {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--fg);
    font-size: var(--fs-sm);
}
.tool-select:focus { outline: none; border-color: var(--accent); }

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 var(--sp-2);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--fg-muted);
    font-size: var(--fs-2xs);
    font-weight: 600;
    user-select: none;
    transition: all var(--t-fast) var(--ease);
}

.chip input { position: absolute; opacity: 0; width: 0; height: 0; }

.chip .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.chip:has(input:checked) {
    background: var(--surface);
    border-color: currentColor;
    box-shadow: var(--shadow-sm);
}

.chip[data-cap="low"]:has(input:checked) { color: var(--cap-low); }
.chip[data-cap="medium"]:has(input:checked) { color: var(--cap-medium); }
.chip[data-cap="high"]:has(input:checked) { color: var(--cap-high); }
.chip[data-cap="veryhigh"]:has(input:checked) { color: var(--cap-veryhigh); }

.chip.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.active-filters {
    display: none;
    flex-direction: column;
    gap: 6px;
    margin: var(--sp-2) var(--sp-2) 0;
    padding: var(--sp-2) var(--sp-3);
    background: rgba(var(--accent-rgb), 0.07);
    border: 1px solid rgba(var(--accent-rgb), 0.25);
    border-radius: var(--radius-sm);
    font-size: var(--fs-2xs);
}
.active-filters.visible { display: flex; }
.active-filters-title { font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; font-size: 10px; }
.active-filters-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--fg-muted); }
.clear-filters-btn {
    background: none; border: none; color: var(--accent);
    font-size: var(--fs-2xs); font-weight: 700; padding: 4px 0;
    text-align: left;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 7px var(--sp-2);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    color: var(--fg);
}
.layer-row.is-disabled { color: var(--fg-faint); }

.tool-checkbox, .radio-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    width: 100%;
}
.layer-row.is-disabled .tool-checkbox,
.layer-row.is-disabled .radio-row { cursor: not-allowed; }

.tool-checkbox input, .radio-row input {
    width: 15px; height: 15px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.layer-swatch {
    width: 12px; height: 12px;
    border-radius: 3px;
    flex: 0 0 auto;
}

.unavailable-tag {
    margin-left: auto;
    font-size: 10px;
    color: var(--fg-faint);
    font-style: italic;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: 9px var(--sp-2);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--fg);
    font-size: var(--fs-sm);
    font-weight: 500;
    text-align: left;
    transition: background var(--t-fast) var(--ease);
}
.tool-btn:hover { background: var(--surface-alt); }
.tool-btn svg { width: 16px; height: 16px; color: var(--fg-muted); flex: 0 0 auto; }

.tool-btn.primary {
    background: var(--accent);
    color: var(--accent-contrast);
    justify-content: center;
    font-weight: 600;
    margin-top: 2px;
}
.tool-btn.primary:hover { background: var(--accent-strong); }
.tool-btn.primary svg { color: inherit; }

.draw-btn-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 0 var(--sp-2);
}
.draw-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--fg-muted);
    transition: all var(--t-fast) var(--ease);
}
.draw-btn:hover { border-color: var(--accent); color: var(--accent); }
.draw-btn.is-active { background: rgba(var(--accent-rgb), 0.14); border-color: var(--accent); color: var(--accent); }
.draw-btn svg { width: 15px; height: 15px; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-scrim);
    z-index: var(--z-backdrop);
}

/* =====================================================================
   6. MAP CONTAINER
   ===================================================================== */
.map-container {
    grid-row: 2;
    position: relative;
    overflow: hidden;
    z-index: var(--z-map);
}

#map {
    width: 100%;
    height: 100%;
    background: var(--surface-alt);
}

[data-theme="dark"] .leaflet-tile-pane { filter: none; }

.leaflet-control-zoom { margin-top: var(--sp-3) !important; margin-left: var(--sp-3) !important; }
.leaflet-touch .leaflet-bar { border-color: var(--border) !important; }
.leaflet-bar a {
    background: var(--surface) !important;
    color: var(--fg) !important;
    border-bottom-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--surface-alt) !important; }

/* hide the native Leaflet.draw toolbar UI — actions are triggered from the sidebar Tools section,
   the plugin's edit/handler engine is still used under the hood (see ui.js) */
.leaflet-draw.leaflet-control { display: none !important; }

.leaflet-popup-content-wrapper {
    background: var(--surface);
    color: var(--fg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0;
}
.leaflet-popup-content { margin: 0; width: auto !important; }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-container a.leaflet-popup-close-button {
    color: var(--fg-muted);
    top: 10px; right: 10px;
    width: 22px; height: 22px;
    font-size: 18px;
}
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--fg); }

/* =====================================================================
   7. TPS MARKERS (custom divIcon)
   ===================================================================== */
.tps-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--t-fast) var(--ease);
}
.tps-marker-dot {
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}
[data-theme="dark"] .tps-marker-dot { border-color: #1a2030; }

.tps-marker:hover { transform: scale(1.18); z-index: 650 !important; }

.tps-marker.is-selected .tps-marker-dot {
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent), 0 2px 6px rgba(15,23,42,.4);
}

.tps-marker.is-deemphasized { opacity: 0.32; }

.user-location-marker { display: flex; align-items: center; justify-content: center; }
.user-location-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(15,23,42,.4);
    animation: user-pulse 2s ease-out infinite;
}
@keyframes user-pulse {
    0% { box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(15,23,42,.4); }
    70% { box-shadow: 0 0 0 10px rgba(var(--accent-rgb), 0), 0 2px 6px rgba(15,23,42,.4); }
    100% { box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0), 0 2px 6px rgba(15,23,42,.4); }
}

/* marker cluster restyle to match the accent palette instead of Leaflet's default green/orange/red */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
    background-clip: padding-box;
}
.marker-cluster-small div { background-color: rgba(var(--accent-rgb), 0.75); }
.marker-cluster-medium div { background-color: rgba(var(--accent-rgb), 0.85); }
.marker-cluster-large div { background-color: var(--navy-700); }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
    background-color: rgba(var(--accent-rgb), 0.28);
}
.marker-cluster div {
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(15,23,42,.3);
}
.marker-cluster span { font-size: 12px; }

/* =====================================================================
   8. LEGEND
   ===================================================================== */
.map-legend {
    position: absolute;
    left: var(--sp-3);
    bottom: var(--sp-3);
    z-index: var(--z-legend);
    background: var(--panel);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--sp-3);
    min-width: 168px;
    font-size: var(--fs-xs);
}
.map-legend-title {
    font-size: var(--fs-2xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
    margin-bottom: var(--sp-2);
}
.map-legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    color: var(--fg-muted);
}
.map-legend-swatch {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
    border: 1.5px solid rgba(255,255,255,.7);
    box-shadow: 0 0 0 1px rgba(15,23,42,.15);
}
.map-legend-gradient {
    height: 10px;
    border-radius: var(--radius-pill);
    margin: 4px 0 6px;
    background: linear-gradient(90deg, #330000, #ff0000, #ff8c00, #ffff00, #ffffff);
}
.map-legend-scale {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--fg-faint);
}

@media (max-width: 860px) {
    .map-legend { left: var(--sp-2); bottom: calc(var(--sp-2) + 84px); }
}

/* =====================================================================
   9. RIGHT PANEL
   ===================================================================== */
.right-panel {
    grid-row: 2;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    z-index: var(--z-panel);
    display: flex;
    flex-direction: column;
}

.app-shell.panel-collapsed .right-panel { display: none; }

.panel-body {
    padding: var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
}

.panel-view { display: none; flex-direction: column; gap: var(--sp-5); }
.panel-view.active { display: flex; }

.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
}
.kpi-card {
    padding: var(--sp-3);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid var(--border);
}
.kpi-label {
    font-size: var(--fs-2xs);
    color: var(--fg-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.kpi-value {
    font-family: var(--font-mono);
    font-size: var(--fs-lg);
    font-weight: 600;
    margin-top: 2px;
    letter-spacing: -0.01em;
}
.kpi-unit { font-size: var(--fs-xs); color: var(--fg-muted); font-weight: 500; margin-left: 3px; }

.panel-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--fs-2xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: var(--sp-6) var(--sp-3);
    color: var(--fg-muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
}
.empty-state svg { width: 26px; height: 26px; color: var(--fg-faint); margin-bottom: 4px; }
.empty-state-title { font-size: var(--fs-sm); font-weight: 600; color: var(--fg); }
.empty-state-desc { font-size: var(--fs-xs); }

/* selected TPS card (mirrors popup content, lives in the Ringkasan panel) */
.selected-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.selected-card-header {
    padding: var(--sp-3);
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
}
.selected-card-name { font-weight: 700; font-size: var(--fs-sm); }
.selected-card-sub { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: 2px; }
.selected-card-body { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); }

.stat-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: var(--fs-sm);
}
.stat-row-label { color: var(--fg-muted); }
.stat-row-value { font-family: var(--font-mono); font-weight: 600; }

.nearby-list { display: flex; flex-direction: column; gap: 2px; }
.nearby-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    padding: 7px var(--sp-2);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    color: var(--fg);
    background: transparent;
    border: none;
    text-align: left;
    width: 100%;
}
.nearby-item:hover { background: var(--surface-alt); }
.nearby-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nearby-item-dist { font-family: var(--font-mono); color: var(--fg-muted); flex: 0 0 auto; }

.card-actions { display: flex; gap: var(--sp-2); }
.card-actions .tool-btn { justify-content: center; border: 1px solid var(--border); }

/* =====================================================================
   10. DATA TABLE PANEL
   ===================================================================== */
.data-table-search {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    font-size: var(--fs-sm);
}

.data-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.data-table th {
    position: sticky; top: 0;
    background: var(--surface-alt);
    text-align: left;
    padding: 8px var(--sp-2);
    font-weight: 700;
    color: var(--fg-muted);
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.data-table th:hover { color: var(--fg); }
.data-table th .sort-arrow { margin-left: 4px; opacity: .5; font-size: 10px; }
.data-table td {
    padding: 7px var(--sp-2);
    border-bottom: 1px solid var(--border);
}
.data-table tbody tr { cursor: pointer; transition: background var(--t-fast) var(--ease); }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { font-family: var(--font-mono); text-align: right; }
.data-table-count { font-size: var(--fs-2xs); color: var(--fg-muted); }

/* =====================================================================
   11. STATISTICS PANEL
   ===================================================================== */
.stat-block { display: flex; flex-direction: column; gap: var(--sp-2); }
.stat-block-title { font-size: var(--fs-xs); font-weight: 700; color: var(--fg); }
.chart-frame { position: relative; height: 190px; }
.chart-frame.donut { height: 170px; }

.top-tps-list { display: flex; flex-direction: column; gap: 4px; }
.top-tps-item {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: 7px var(--sp-2);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    border: none; background: transparent; width: 100%; text-align: left;
}
.top-tps-item:hover { background: var(--surface-alt); }
.top-tps-rank {
    font-family: var(--font-mono); font-weight: 700; color: var(--fg-faint);
    width: 16px; flex: 0 0 auto;
}
.top-tps-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-tps-cap { font-family: var(--font-mono); font-weight: 600; color: var(--accent); flex: 0 0 auto; }

/* =====================================================================
   12. AREA ANALYSIS CARD
   ===================================================================== */
.area-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.area-card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-3);
    background: var(--navy-800);
    color: #fff;
}
.area-card-title { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.area-card-close { background: none; border: none; color: rgba(255,255,255,.7); width: 24px; height: 24px; }
.area-card-close:hover { color: #fff; }
.area-kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.area-kpi {
    background: var(--surface);
    padding: var(--sp-3);
}
.area-kpi-label { font-size: 10px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
.area-kpi-value { font-family: var(--font-mono); font-size: var(--fs-md); font-weight: 700; margin-top: 2px; }
.area-card-footer { padding: var(--sp-3); border-top: 1px solid var(--border); display: flex; gap: var(--sp-2); }

/* =====================================================================
   13. TOASTS / BANNERS
   ===================================================================== */
.toast-stack {
    position: absolute;
    top: var(--sp-3);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(420px, calc(100vw - 32px));
    align-items: center;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    width: 100%;
    padding: 11px var(--sp-3);
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-sm);
    animation: toast-in var(--t-base) var(--ease);
}
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-info { border-left: 3px solid var(--accent); }
.toast-icon { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--accent); }
.toast-msg { flex: 1 1 auto; color: var(--fg); }
.toast-close { background: none; border: none; color: var(--fg-faint); width: 20px; height: 20px; flex: 0 0 auto; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   13b. MAP LOADING / EMPTY DATA STATE
   ===================================================================== */
.map-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: var(--z-legend);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition: opacity var(--t-base) var(--ease);
}
.map-loading-overlay.hidden { opacity: 0; pointer-events: none; }
.map-loading-box { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.map-spinner {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.map-loading-text { font-size: var(--fs-xs); color: var(--fg-muted); }

/* =====================================================================
   14. INFO MODAL
   ===================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-scrim);
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
}
.modal-backdrop.open { display: flex; }

.modal-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: min(420px, 100%);
    max-height: 84vh;
    overflow-y: auto;
}
.modal-card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-4);
    background: linear-gradient(160deg, var(--navy-800), var(--navy-700));
    color: #fff;
}
.modal-card-header h2 { margin: 0; font-size: var(--fs-md); font-weight: 700; }
.modal-card-header p { margin: 3px 0 0; font-size: var(--fs-xs); color: rgba(255,255,255,.75); }
.modal-close {
    background: rgba(255,255,255,.12); border: none; color: #fff;
    width: 28px; height: 28px; border-radius: var(--radius-sm); flex: 0 0 auto;
}
.modal-close:hover { background: rgba(255,255,255,.22); }
.modal-card-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); font-size: var(--fs-sm); }
.modal-research-group { display: flex; flex-direction: column; gap: 4px; }
.modal-research-title { font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--fg-faint); }
.modal-research-item { color: var(--fg); }
.modal-card-body .data-note { font-size: var(--fs-xs); color: var(--fg-muted); border-top: 1px solid var(--border); padding-top: var(--sp-3); }

/* =====================================================================
   15. MOBILE / RESPONSIVE
   ===================================================================== */
.mobile-summary-strip { display: none; }
.sheet-handle { display: none; }

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr;
    }

    .brand-subtitle { display: none; }

    .topbar {
        height: auto;
        min-height: var(--topbar-h);
        flex-wrap: wrap;
        padding: 8px var(--sp-3);
        row-gap: 8px;
    }
    .topbar-center {
        order: 3;
        flex: 1 1 100%;
    }
    .search-wrap { max-width: none; }
    #fullscreenBtn { display: none; }

    .sidebar {
        position: fixed;
        top: var(--topbar-h-mobile);
        bottom: 0;
        left: 0;
        width: min(300px, 84vw);
        transform: translateX(-100%);
        transition: transform var(--t-base) var(--ease);
        box-shadow: var(--shadow-lg);
        display: block !important;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-inner { width: 100%; }

    .sidebar-backdrop.open { display: block; }

    .map-container { grid-column: 1; grid-row: 2; }

    .right-panel {
        display: flex !important;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        top: auto;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(15,23,42,.18);
        max-height: 76px;
        overflow: hidden;
        transition: max-height var(--t-base) var(--ease);
    }
    .right-panel.sheet-expanded {
        max-height: 78vh;
        overflow-y: auto;
    }

    .sheet-handle {
        display: flex;
        justify-content: center;
        padding: 10px 0 4px;
        flex: 0 0 auto;
        background: var(--surface);
        border-radius: 16px 16px 0 0;
    }
    .sheet-handle-bar { width: 36px; height: 4px; border-radius: var(--radius-pill); background: var(--border-strong); }

    .mobile-summary-strip {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--sp-4);
        padding: 4px 0 12px;
        font-size: var(--fs-xs);
        color: var(--fg-muted);
        flex: 0 0 auto;
        background: var(--surface);
    }
    .mobile-summary-strip strong { color: var(--fg); font-family: var(--font-mono); }

    .panel-body { padding: 0 var(--sp-4) var(--sp-4); overflow-y: auto; }

    .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
    .btn-text span.label-text { display: none; }
    .btn-text { padding: 0; width: 36px; justify-content: center; }

    .draw-btn-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 460px) {
    .brand-title { font-size: var(--fs-sm); }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* safe-area support for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
    .right-panel { padding-bottom: env(safe-area-inset-bottom); }
    @media (max-width: 860px) {
        .sidebar { padding-bottom: env(safe-area-inset-bottom); }
    }
}
