:root {
      --primary: #6366f1;
      --primary-hover: #4f46e5;
      --primary-glow: rgba(99, 102, 241, 0.35);
      --secondary: #0ea5e9;
      --success: #10b981;
      --accent: #f43f5e;
      --bg: #060c1a;
      --surface: rgba(15, 23, 42, 0.8);
      --card: rgba(22, 33, 55, 0.75);
      --border: rgba(255, 255, 255, 0.08);
      --border-hover: rgba(255, 255, 255, 0.18);
      --text: #f1f5f9;
      --text-muted: #64748b;
      --text-light: #94a3b8;
      --radius: 16px;
    }

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

    html,
    body {
      height: 100%;
      overflow: hidden;
    }

    body {
      font-family: 'Plus Jakarta Sans', sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    /* ── Background ───────────────────────────────────── */
    body::before {
      content: '';
      position: fixed;
      inset: 0;
      background:
        radial-gradient(ellipse 80% 60% at 10% -10%, rgba(99, 102, 241, 0.18) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 90% 110%, rgba(14, 165, 233, 0.15) 0%, transparent 60%);
      pointer-events: none;
      z-index: 0;
    }

    /* ── Topbar ───────────────────────────────────────── */
    .topbar {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 64px;
      background: rgba(6, 12, 26, 0.9);
      backdrop-filter: blur(20px);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      z-index: 1000;
      gap: 20px;
    }

    .topbar-logo {
      display: flex;
      align-items: center;
      gap: 10px;
      text-decoration: none;
      flex-shrink: 0;
    }

    .logo-icon {
      width: 34px;
      height: 34px;
      background: linear-gradient(135deg, var(--primary), var(--secondary));
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
    }

    .logo-text {
      font-weight: 800;
      font-size: 1.1rem;
    }

    .topbar-title {
      font-weight: 700;
      font-size: 0.95rem;
      color: var(--text-light);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .topbar-title span {
      font-size: 18px;
    }

    .topbar-actions {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .status-pill {
      display: flex;
      align-items: center;
      gap: 8px;
      background: rgba(99, 102, 241, 0.1);
      border: 1px solid rgba(99, 102, 241, 0.2);
      border-radius: 9999px;
      padding: 6px 14px;
      font-size: 0.78rem;
      font-weight: 700;
      color: #818cf8;
    }

    .status-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #818cf8;
      animation: pulse-dot 2s infinite;
    }

    @keyframes pulse-dot {

      0%,
      100% {
        opacity: 1;
        transform: scale(1);
      }

      50% {
        opacity: 0.4;
        transform: scale(1.5);
      }
    }

    .btn-back {
      display: flex;
      align-items: center;
      gap: 8px;
      background: var(--card);
      border: 1px solid var(--border);
      color: var(--text-light);
      padding: 8px 16px;
      border-radius: 10px;
      font-size: 0.82rem;
      font-weight: 600;
      text-decoration: none;
      transition: all 0.2s;
    }

    .btn-back:hover {
      background: rgba(99, 102, 241, 0.12);
      border-color: rgba(99, 102, 241, 0.3);
      color: var(--text);
    }

    /* ── Layout ───────────────────────────────────────── */
    .layout {
      position: fixed;
      top: 64px;
      left: 0;
      right: 0;
      bottom: 0;
      display: flex;
    }

    /* ── Sidebar ──────────────────────────────────────── */
    .sidebar {
      width: 340px;
      flex-shrink: 0;
      background: rgba(6, 12, 26, 0.92);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      backdrop-filter: blur(20px);
      transition: width 0.3s ease;
      z-index: 10;
    }

    .sidebar.collapsed {
      width: 0;
    }

    .sidebar-header {
      padding: 20px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .sidebar-header h2 {
      font-size: 1rem;
      font-weight: 700;
      margin-bottom: 4px;
    }

    .sidebar-header p {
      font-size: 0.78rem;
      color: var(--text-muted);
    }

    #pin-list {
      overflow-y: auto;
      flex: 1;
      padding: 12px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    #pin-list::-webkit-scrollbar {
      width: 4px;
    }

    #pin-list::-webkit-scrollbar-track {
      background: transparent;
    }

    #pin-list::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 2px;
    }

    .pin-item {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 14px 16px;
      cursor: pointer;
      transition: all 0.2s ease;
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .pin-item:hover {
      border-color: rgba(99, 102, 241, 0.4);
      background: rgba(99, 102, 241, 0.08);
      transform: translateX(3px);
    }

    .pin-icon {
      width: 36px;
      height: 36px;
      border-radius: 10px;
      background: rgba(99, 102, 241, 0.15);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      flex-shrink: 0;
    }

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

    .pin-address {
      font-size: 0.88rem;
      font-weight: 700;
      color: var(--text);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .pin-status {
      font-size: 0.72rem;
      color: var(--text-muted);
      margin-top: 2px;
    }

    .pin-status.ok {
      color: var(--success);
    }

    .pin-status.loading {
      color: #fbbf24;
    }

    .pin-status.error {
      color: var(--accent);
    }

    /* ── Sidebar collapse toggle ──────────────────────── */
    .sidebar-toggle {
      position: absolute;
      left: 340px;
      top: 50%;
      transform: translateY(-50%);
      width: 22px;
      height: 52px;
      background: rgba(6, 12, 26, 0.92);
      border: 1px solid var(--border);
      border-left: none;
      border-radius: 0 10px 10px 0;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      font-size: 12px;
      transition: all 0.3s ease;
      z-index: 11;
    }

    .sidebar-toggle:hover {
      color: var(--text);
      background: rgba(99, 102, 241, 0.15);
    }

    .sidebar.collapsed+.sidebar-toggle {
      left: 0;
      border-radius: 0 10px 10px 0;
    }

    /* ── Map ──────────────────────────────────────────── */
    #map {
      flex: 1;
      position: relative;
      z-index: 1;
    }

    /* ── Progress bar ─────────────────────────────────── */
    #progress-bar-wrap {
      position: absolute;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(6, 12, 26, 0.9);
      backdrop-filter: blur(16px);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 12px 24px;
      z-index: 500;
      display: flex;
      align-items: center;
      gap: 16px;
      font-size: 0.82rem;
      min-width: 260px;
    }

    .progress-label {
      color: var(--text-light);
      font-weight: 600;
    }

    .progress-value {
      color: #818cf8;
      font-weight: 800;
    }

    .progress-track {
      flex: 1;
      height: 6px;
      background: rgba(255, 255, 255, 0.06);
      border-radius: 9999px;
      overflow: hidden;
    }

    .progress-fill {
      height: 100%;
      background: linear-gradient(to right, var(--primary), var(--secondary));
      border-radius: 9999px;
      transition: width 0.4s ease;
      width: 0%;
    }

    /* ── Leaflet popup override ───────────────────────── */
    .leaflet-popup-content-wrapper {
      background: rgba(15, 23, 42, 0.97) !important;
      border: 1px solid rgba(99, 102, 241, 0.3) !important;
      border-radius: 16px !important;
      backdrop-filter: blur(20px) !important;
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6) !important;
      padding: 0 !important;
      overflow: hidden !important;
    }

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

    .leaflet-popup-tip {
      background: rgba(99, 102, 241, 0.4) !important;
    }

    .leaflet-popup-close-button {
      color: #94a3b8 !important;
      font-size: 18px !important;
      right: 8px !important;
      top: 8px !important;
    }

    .popup-inner {
      padding: 18px 20px;
      min-width: 220px;
    }

    .popup-title {
      font-size: 0.75rem;
      font-weight: 700;
      color: #818cf8;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      margin-bottom: 8px;
    }

    .popup-address {
      font-size: 1rem;
      font-weight: 800;
      color: #f1f5f9;
      margin-bottom: 14px;
      line-height: 1.3;
    }

    .popup-btn {
      display: block;
      text-align: center;
      background: linear-gradient(135deg, var(--primary), var(--secondary));
      color: #fff;
      text-decoration: none;
      padding: 10px 16px;
      border-radius: 10px;
      font-size: 0.82rem;
      font-weight: 700;
      transition: all 0.2s;
      letter-spacing: 0.01em;
    }

    .popup-btn:hover {
      filter: brightness(1.15);
      transform: translateY(-1px);
    }

    /* ── Custom pin marker ────────────────────────────── */
    .custom-marker {
      position: relative;
    }

    /* ── Cluster marker ──────────────────────────────────── */
    .cluster-marker {
      position: relative;
      cursor: pointer;
    }

    .cluster-badge {
      position: absolute;
      top: -6px;
      right: -8px;
      background: linear-gradient(135deg, #f43f5e, #e11d48);
      color: #fff;
      font-size: 10px;
      font-weight: 800;
      font-family: 'Plus Jakarta Sans', sans-serif;
      min-width: 18px;
      height: 18px;
      border-radius: 9999px;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px solid #060c1a;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
      line-height: 1;
      padding: 0 3px;
    }

    /* ── Cluster list popup ──────────────────────────────── */
    .cluster-list-popup {
      min-width: 240px;
      padding: 8px;
    }

    .cluster-list-title {
      font-size: 0.7rem;
      font-weight: 700;
      color: #818cf8;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      margin-bottom: 8px;
      padding: 0 4px;
    }

    .cluster-list-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 10px;
      border-radius: 10px;
      cursor: pointer;
      transition: background 0.15s;
      border: 1px solid transparent;
    }

    .cluster-list-item:hover {
      background: rgba(99, 102, 241, 0.12);
      border-color: rgba(99, 102, 241, 0.25);
    }

    .cluster-list-icon {
      font-size: 16px;
      flex-shrink: 0;
    }

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

    .cluster-list-addr {
      font-size: 0.84rem;
      font-weight: 700;
      color: #f1f5f9;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .cluster-list-sub {
      font-size: 0.7rem;
      color: #64748b;
      margin-top: 1px;
    }

    .cluster-list-arrow {
      font-size: 12px;
      color: #818cf8;
      flex-shrink: 0;
    }

    /* ── Empty state ──────────────────────────────────── */
    #empty-state {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      color: var(--text-muted);
      font-size: 0.9rem;
      display: none;
      pointer-events: none;
      z-index: 500;
    }

    /* ── Responsive — 768px ────────────────────────────────────── */
    @media (max-width: 768px) {
      .topbar {
        padding: 0 14px;
        gap: 8px;
      }

      .topbar-title {
        display: none;
      }

      .topbar-actions {
        gap: 8px;
      }

      /* Sidebar overlays the map on mobile (starts collapsed via JS) */
      .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        width: 300px;
        /* visible when not collapsed */
      }

      /* Toggle sits at left:0 when collapsed, JS moves it to 300px when open */
      .sidebar-toggle {
        left: 0;
        border-left: 1px solid var(--border);
        border-radius: 0 10px 10px 0;
      }

      #progress-bar-wrap {
        left: 12px;
        right: 12px;
        transform: none;
        bottom: 14px;
        min-width: unset;
        width: auto;
      }
    }

    /* ── Responsive — 480px ───────────────────────────────── */
    @media (max-width: 480px) {
      .logo-text {
        display: none;
      }

      .logo-icon {
        width: 30px;
        height: 30px;
        font-size: 14px;
      }

      .topbar .btn-back {
        font-size: 0;
        padding: 8px 10px;
      }

      .topbar .btn-back::before {
        content: '←';
        font-size: 14px;
      }

      .status-pill {
        padding: 5px 10px;
        font-size: 0.72rem;
        gap: 6px;
      }

      #progress-bar-wrap {
        flex-wrap: wrap;
        padding: 10px 16px;
        gap: 8px;
      }

      .progress-label {
        font-size: 0.76rem;
      }

      .progress-value {
        font-size: 0.76rem;
      }
    }

    /* ── Theme Toggle Button ────────────────────────────── */
    #theme-toggle {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 34px;
      height: 34px;
      border-radius: 9px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid var(--border);
      cursor: pointer;
      font-size: 15px;
      transition: all 0.2s;
      flex-shrink: 0;
    }

    #theme-toggle:hover {
      background: rgba(99, 102, 241, 0.1);
      border-color: rgba(99, 102, 241, 0.3);
    }

    /* ── Light Theme ─────────────────────────────────────── */
    [data-theme="light"] {
      --bg: #f0f4fb;
      --surface: rgba(255, 255, 255, 0.95);
      --card: #ffffff;
      --border: rgba(0, 0, 0, 0.08);
      --border-hover: rgba(0, 0, 0, 0.15);
      --text: #0f172a;
      --text-muted: #64748b;
      --text-light: #475569;
    }

    [data-theme="light"] body {
      background: var(--bg) !important;
      color: var(--text) !important;
    }

    [data-theme="light"] body::before {
      background: radial-gradient(ellipse 80% 60% at 10% -10%, rgba(99, 102, 241, 0.08) 0%, transparent 60%), radial-gradient(ellipse 60% 50% at 90% 110%, rgba(14, 165, 233, 0.06) 0%, transparent 60%) !important;
    }

    [data-theme="light"] body::after {
      background-image: radial-gradient(circle, rgba(0, 0, 0, 0.04) 1px, transparent 1px) !important;
    }

    [data-theme="light"] .topbar {
      background: rgba(255, 255, 255, 0.92) !important;
      border-bottom-color: rgba(0, 0, 0, 0.08) !important;
    }

    [data-theme="light"] .sidebar {
      background: rgba(255, 255, 255, 0.95) !important;
      border-right-color: rgba(0, 0, 0, 0.08) !important;
      box-shadow: 10px 0 30px rgba(0, 0, 0, 0.03) !important;
    }

    [data-theme="light"] .sidebar-header {
      border-bottom-color: rgba(0, 0, 0, 0.08) !important;
    }

    [data-theme="light"] .search-box {
      background: #f1f5f9 !important;
      border-color: rgba(0, 0, 0, 0.1) !important;
      color: #0f172a !important;
    }

    [data-theme="light"] .search-box:focus {
      background: #fff !important;
      border-color: rgba(99, 102, 241, 0.5) !important;
      box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1) !important;
    }

    [data-theme="light"] .pin-item {
      background: #f8fafc !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      color: #0f172a !important;
    }

    [data-theme="light"] .pin-item:hover {
      background: #f1f5f9 !important;
      border-color: rgba(99, 102, 241, 0.3) !important;
    }

    [data-theme="light"] .pin-name {
      color: #1e293b !important;
    }

    [data-theme="light"] .pin-addr {
      color: #64748b !important;
    }

    [data-theme="light"] .pin-actions button {
      background: rgba(0, 0, 0, 0.05) !important;
      color: #475569 !important;
    }

    [data-theme="light"] .pin-actions button:hover {
      background: rgba(0, 0, 0, 0.1) !important;
      color: #0f172a !important;
    }

    [data-theme="light"] .sidebar-toggle {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      color: #0f172a !important;
      box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1) !important;
    }

    [data-theme="light"] .leaflet-popup-content-wrapper {
      background: #fff !important;
      border-color: rgba(99, 102, 241, 0.2) !important;
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15) !important;
    }

    [data-theme="light"] .leaflet-popup-tip {
      background: #fff !important;
    }

    [data-theme="light"] .popup-address {
      color: #0f172a !important;
    }

    [data-theme="light"] .popup-title {
      color: #4f46e5 !important;
    }

    [data-theme="light"] #theme-toggle {
      background: #f1f5f9 !important;
      border-color: rgba(0, 0, 0, 0.09) !important;
      color: #0f172a !important;
    }

    [data-theme="light"] #theme-toggle:hover {
      background: rgba(99, 102, 241, 0.08) !important;
    }

    [data-theme="light"] .btn-back {
      background: #f1f5f9 !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      color: #0f172a !important;
    }

    [data-theme="light"] .btn-back:hover {
      background: #e2e8f0 !important;
    }
  


    .logo-imob {
      color: #eee;
    }

    [data-theme="light"] .logo-imob {
      color: #1e293b !important;
    }

    [data-theme="light"] .logo-text span:last-child {
      color: #4f46e5 !important;
    }

    [data-theme="light"] body {
      background: #f0f4fb !important;
    }

    [data-theme="light"] body::before {
      background: radial-gradient(ellipse 80% 60% at 10% -10%, rgba(99, 102, 241, 0.07) 0%, transparent 60%), radial-gradient(ellipse 60% 50% at 90% 110%, rgba(14, 165, 233, 0.05) 0%, transparent 60%) !important;
    }

    [data-theme="light"] .topbar {
      background: rgba(255, 255, 255, 0.94) !important;
      border-bottom-color: rgba(0, 0, 0, 0.07) !important;
    }

    [data-theme="light"] .topbar-title {
      color: #0f172a !important;
    }

    [data-theme="light"] .btn-back {
      background: #f1f5f9 !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      color: #475569 !important;
    }

    [data-theme="light"] .btn-back:hover {
      background: #e2e8f0 !important;
      color: #0f172a !important;
    }

    [data-theme="light"] .status-pill {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      color: #475569 !important;
    }

    [data-theme="light"] .status-dot {
      background: #10b981 !important;
    }

    [data-theme="light"] .sidebar {
      background: rgba(255, 255, 255, 0.97) !important;
      border-right-color: rgba(0, 0, 0, 0.07) !important;
    }

    [data-theme="light"] .sidebar-header {
      background: rgba(255, 255, 255, 0.97) !important;
      border-bottom-color: rgba(0, 0, 0, 0.07) !important;
    }

    [data-theme="light"] .sidebar-title {
      color: #0f172a !important;
    }

    [data-theme="light"] .sidebar-count {
      color: #64748b !important;
    }

    [data-theme="light"] .sidebar-toggle {
      background: rgba(255, 255, 255, 0.97) !important;
      border-color: rgba(0, 0, 0, 0.07) !important;
      color: #475569 !important;
    }

    [data-theme="light"] .pin-item {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(0, 0, 0, 0.06) !important;
    }

    [data-theme="light"] .pin-item:hover {
      background: rgba(240, 244, 251, 0.9) !important;
    }

    [data-theme="light"] .pin-addr {
      color: #0f172a !important;
    }

    [data-theme="light"] .pin-meta {
      color: #64748b !important;
    }

    [data-theme="light"] #pin-list::-webkit-scrollbar-thumb {
      background: rgba(0, 0, 0, 0.1) !important;
    }

    [data-theme="light"] #progress-bar-wrap {
      background: rgba(255, 255, 255, 0.97) !important;
      border-color: rgba(0, 0, 0, 0.07) !important;
    }

    [data-theme="light"] .progress-track {
      background: rgba(0, 0, 0, 0.07) !important;
    }

    [data-theme="light"] .progress-label {
      color: #475569 !important;
    }

    [data-theme="light"] .progress-value {
      color: #0f172a !important;
    }

    [data-theme="light"] .leaflet-popup-content-wrapper {
      background: #fff !important;
      color: #0f172a !important;
      border-color: rgba(99, 102, 241, 0.15) !important;
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12) !important;
    }

    [data-theme="light"] .leaflet-popup-tip {
      background: #fff !important;
    }

    [data-theme="light"] .popup-address {
      color: #0f172a !important;
    }

    [data-theme="light"] .popup-meta {
      color: #475569 !important;
    }

    [data-theme="light"] .popup-btn {
      background: rgba(99, 102, 241, 0.08) !important;
      border-color: rgba(99, 102, 241, 0.2) !important;
      color: #4f46e5 !important;
    }

    [data-theme="light"] .cluster-list-item {
      border-bottom-color: rgba(0, 0, 0, 0.05) !important;
    }

    [data-theme="light"] .cluster-list-item:hover {
      background: rgba(99, 102, 241, 0.05) !important;
    }

    [data-theme="light"] .cluster-list-addr {
      color: #0f172a !important;
    }

    [data-theme="light"] .cluster-list-meta {
      color: #64748b !important;
    }

    [data-theme="light"] #theme-toggle {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(0, 0, 0, 0.08) !important;
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1) !important;
    }

    [data-theme="light"] #theme-toggle:hover {
      background: #fff !important;
      box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15) !important;
      border-color: rgba(99, 102, 241, 0.3) !important;
    }