:root {
      --bg-dark: #0d1117;
      --bg-panel: #161b22;
      --bg-card: #21262d;
      --border: #30363d;
      --text-main: #e6edf3;
      --text-muted: #8b949e;
      --accent: #58a6ff;
      --radius: 10px;
    }

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

    body {
      font-family: 'Inter', sans-serif;
      background: var(--bg-dark);
      color: var(--text-main);
      display: flex;
      flex-direction: column;
      height: 100vh;
      overflow: hidden;
    }

    /* ── TOP BAR ── */
    #topbar {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 20px;
      background: linear-gradient(135deg, #008744 0%, #005a2d 100%);
      border-bottom: 1px solid #004d26;
      box-shadow: 0 2px 10px rgba(0,0,0,0.3);
      z-index: 1000;
      flex-shrink: 0;
    }

    #topbar .logo {
      font-size: 18px;
      font-weight: 700;
      letter-spacing: 0.5px;
      color: #ffffff;
      white-space: pre-wrap;
      text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    }

    #topbar .subtitle {
      font-size: 12px;
      color: rgba(255, 255, 255, 0.85);
    }

    #topbar .spacer {
      flex: 1;
    }

    /* stats badges */
    .stat-badge {
      display: flex;
      flex-direction: column;
      align-items: center;
      background: rgba(255, 255, 255, 0.15);
      border: 1px solid rgba(255, 255, 255, 0.3);
      backdrop-filter: blur(4px);
      border-radius: var(--radius);
      padding: 6px 14px;
      min-width: 80px;
      box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    }

    .stat-badge .val {
      font-size: 18px;
      font-weight: 700;
      color: #ffffff;
      line-height: 1;
      text-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }

    .stat-badge .lbl {
      font-size: 10px;
      color: rgba(255, 255, 255, 0.85);
      margin-top: 2px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    /* ── BODY ── */
    #content {
      display: flex;
      flex: 1;
      overflow: hidden;
    }

    /* ── SIDEBAR ── */
    #sidebar {
      width: 300px;
      background: var(--bg-panel);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      flex-shrink: 0;
      transition: width 0.3s;
    }

    #sidebar.collapsed {
      width: 0;
      overflow: hidden;
    }

    #sidebar-header {
      padding: 14px 16px 10px;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.8px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    /* search */
    #search-wrap {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    #search-input {
      width: 100%;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 7px 12px;
      color: var(--text-main);
      font-size: 13px;
      outline: none;
      transition: border-color 0.2s;
    }

    #search-input:focus {
      border-color: var(--accent);
    }

    #search-input::placeholder {
      color: var(--text-muted);
    }

    /* ── LAYER ACCORDION ── */
    #layers {
      flex: 1;
      overflow-y: auto;
      padding: 6px 0 12px;
    }

    #layers::-webkit-scrollbar {
      width: 4px;
    }

    #layers::-webkit-scrollbar-track {
      background: transparent;
    }

    #layers::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 2px;
    }

    /* District header row */
    .district-header {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 9px 14px;
      cursor: pointer;
      border-radius: 7px;
      margin: 2px 8px;
      transition: background 0.15s;
      user-select: none;
    }

    .district-header:hover {
      background: var(--bg-card);
    }

    .layer-checkbox {
      width: 15px;
      height: 15px;
      border-radius: 4px;
      border: 2px solid;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background 0.2s;
    }

    .layer-checkbox.checked::after {
      content: '✓';
      font-size: 10px;
      color: #fff;
      font-weight: 700;
    }

    .layer-dot {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      flex-shrink: 0;
    }

    .district-label {
      flex: 1;
    }

    .district-name {
      font-size: 13px;
      font-weight: 600;
    }

    .district-count {
      font-size: 11px;
      color: var(--text-muted);
    }

    .expand-arrow {
      font-size: 11px;
      color: var(--text-muted);
      transition: transform 0.25s;
      flex-shrink: 0;
    }

    .expand-arrow.open {
      transform: rotate(90deg);
    }

    /* Sub-list container */
    .district-body {
      overflow: hidden;
      max-height: 0;
      transition: max-height 0.3s ease;
    }

    .district-body.open {
      max-height: 2000px;
    }

    /* Individual location row */
    .loc-item {
      display: flex;
      align-items: flex-start;
      gap: 8px;
      padding: 6px 14px 6px 38px;
      cursor: pointer;
      border-radius: 6px;
      margin: 1px 8px;
      transition: background 0.12s;
    }

    .loc-item:hover {
      background: var(--bg-card);
    }

    .loc-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      margin-top: 5px;
      flex-shrink: 0;
    }

    .loc-info {
      flex: 1;
      min-width: 0;
    }

    .loc-name {
      font-size: 12px;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .loc-sub {
      font-size: 10.5px;
      color: var(--text-muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    /* ── MAP ── */
    #map {
      flex: 1;
      background: #1a1a2e;
    }

    /* ── TOGGLE SIDEBAR BUTTON ── */
    #toggle-sidebar {
      position: absolute;
      left: 300px;
      top: 50%;
      transform: translateY(-50%);
      z-index: 1001;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-left: none;
      border-radius: 0 6px 6px 0;
      width: 20px;
      height: 48px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      font-size: 12px;
      transition: left 0.3s, color 0.2s;
    }

    #toggle-sidebar:hover {
      color: var(--text-main);
    }

    /* ── POPUP CUSTOM ── */
    .leaflet-popup-content-wrapper {
      background: var(--bg-card) !important;
      color: var(--text-main) !important;
      border: 1px solid var(--border) !important;
      border-radius: 10px !important;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
      padding: 0 !important;
    }

    .leaflet-popup-tip {
      background: var(--bg-card) !important;
    }

    .leaflet-popup-content {
      margin: 0 !important;
      width: 280px !important;
    }

    .popup-header {
      padding: 12px 14px 8px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .popup-badge {
      font-size: 10px;
      font-weight: 700;
      padding: 2px 8px;
      border-radius: 20px;
      color: #fff;
    }

    .popup-title {
      font-size: 13px;
      font-weight: 600;
      line-height: 1.3;
    }

    .popup-body {
      padding: 10px 14px 12px;
    }

    .popup-row {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      font-size: 12px;
      margin-bottom: 5px;
      gap: 8px;
    }

    .popup-row .pk {
      color: var(--text-muted);
      flex-shrink: 0;
    }

    .popup-row .pv {
      color: var(--text-main);
      text-align: right;
    }

    .popup-coords {
      margin-top: 8px;
      display: grid;
      grid-template-columns: 1fr;
      gap: 6px;
    }

    .coord-box {
      background: rgba(88, 166, 255, 0.08);
      border: 1px solid rgba(88, 166, 255, 0.2);
      border-radius: 6px;
      padding: 5px 8px;
      font-size: 11px;
    }

    .coord-box .cl {
      color: var(--accent);
      font-weight: 600;
      margin-bottom: 2px;
    }

    .coord-box .cv {
      color: var(--text-muted);
      font-family: monospace;
    }

    .coord-box .cv span.lbl {
      display: inline-block;
      width: 35px;
      color: var(--text-main) !important;
      font-weight: bold;
    }

    /* ── LOADING ── */
    #loading {
      position: absolute;
      inset: 0;
      background: var(--bg-dark);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      gap: 16px;
    }

    .spinner {
      width: 48px;
      height: 48px;
      border: 4px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

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

    .loading-text {
      font-size: 14px;
      color: var(--text-muted);
    }

    /* ── BOTTOM STATUS ── */
    #status-bar {
      padding: 5px 16px;
      background: var(--bg-panel);
      border-top: 1px solid var(--border);
      font-size: 11px;
      color: var(--text-muted);
      display: flex;
      gap: 16px;
      flex-shrink: 0;
    }

    /* Legend */
    .map-legend {
      position: absolute;
      bottom: 40px;
      right: 12px;
      background: linear-gradient(135deg, #f0fdf4 0%, #e6f9ed 100%);
      border: none;
      border-radius: var(--radius);
      padding: 12px 14px;
      z-index: 500;
      min-width: 160px;
      overflow: hidden;
      transition: all 0.3s ease;
      box-shadow: 0 4px 12px rgba(0,0,0,0.2);
      color: #064e3b;
    }

    .map-legend.collapsed {
      padding-bottom: 12px;
    }

    .legend-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      cursor: pointer;
    }

    .map-legend h4 {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      color: #047857;
      margin: 0;
      font-weight: 700;
    }

    .legend-toggle {
      font-size: 10px;
      color: #047857;
    }

    .legend-body {
      margin-top: 8px;
      display: flex;
      flex-direction: column;
    }

    .map-legend.collapsed .legend-body {
      display: none;
    }

    .legend-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 5px;
      font-size: 12px;
    }

    .legend-dot-large {
      width: 14px;
      height: 14px;
      border-radius: 50%;
      flex-shrink: 0;
      border: 2px solid rgba(255, 255, 255, 0.3);
    }

    /* Basemap switcher */
    #basemap-switcher {
      position: absolute;
      top: 10px;
      right: 12px;
      z-index: 500;
      display: flex;
      gap: 4px;
    }

    .bm-btn {
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 5px 10px;
      font-size: 11px;
      color: var(--text-muted);
      cursor: pointer;
      transition: all 0.2s;
    }

    .bm-btn:hover,
    .bm-btn.active {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
    }

    /* Pulsing user location marker */
    .user-loc-marker {
      background-color: #3b82f6;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      border: 2px solid white;
      box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4);
      animation: pulse 2s infinite;
    }

    @keyframes pulse {
      0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
      }

      70% {
        box-shadow: 0 0 0 12px rgba(59, 130, 246, 0);
      }

      100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
      }
    }

    /* Leaflet native locate control styling */
    .leaflet-control-locate {
      background-color: var(--bg-panel);
      width: 34px;
      height: 34px;
      border: 2px solid rgba(255, 255, 255, 0.2) !important;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      cursor: pointer;
      box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
      color: var(--text-main);
    }

    .leaflet-control-locate:hover {
      background-color: #2a313c;
    }

    /* ── RESPONSIVE MOBILE ── */
    @media (max-width: 768px) {
      #sidebar {
        display: none !important;
      }

      #toggle-sidebar {
        display: none !important;
      }

      #topbar {
        flex-direction: column;
        align-items: flex-start;
        height: auto;
        padding: 12px;
        gap: 8px;
      }

      #topbar .spacer {
        display: none;
      }

      #status-bar {
        left: 10px;
        bottom: 10px;
        right: 10px;
        justify-content: center;
        border-radius: 8px;
      }

      #basemap-switcher {
        flex-wrap: wrap;
        padding-left: 10px;
      }

      .map-legend {
        bottom: 50px;
        right: 10px;
        padding: 8px 10px;
        min-width: 130px;
      }

      .legend-row {
        font-size: 11px;
        margin-bottom: 4px;
        gap: 6px;
      }

      .legend-dot-large {
        width: 12px;
        height: 12px;
      }
    }