*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

:root {
    --pin-blue: #2563eb;
    --pin-amber: #d97706;
    --primary: #eb0029;
    --primary-hover: #cc0022;
    --accent: #eb0029;
    --accent-dim: #cc0022;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;

    --bg-base: #f8fafc;
    --bg-card: rgba(255,255,255,0.85);
    --bg-input: rgba(255,255,255,0.95);
    --bg-hover: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --border: rgba(0,0,0,0.1);
    --border-focus: rgba(235,0,41,0.5);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --blur: blur(28px);
    --shadow: 0 8px 32px rgba(0,0,0,0.08);
    --shadow-lg: 0 25px 80px rgba(0,0,0,0.15);

    --font: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#map {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    background: var(--bg-base);
}

.glass {
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* ─── Search Bar ─── */
.header-wrap {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
}

.brand-logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.brand-logo {
    height: 64px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 3px 10px rgba(0,0,0,0.5));
}

@media (max-width: 600px) {
    .brand-logo {
        height: 52px; /* slightly smaller on mobile */
    }
    .header-wrap {
        gap: 8px;
    }
}

.search-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    width: 100%;
    max-width: 540px;
    border-radius: var(--radius-xl);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    min-width: 0;
}
.search-input::placeholder { color: var(--text-muted); }

.search-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: rgba(235,0,41,0.12);
    color: var(--primary);
    border: 1px solid rgba(235,0,41,0.2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    font-family: var(--font);
}
.filter-btn:hover { background: rgba(235,0,41,0.22); }

.filter-count-badge {
    display: none;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.filter-count-badge.visible { display: inline-block; }

/* ─── Chicklet Bar ─── */
.chicklet-bar {
    position: fixed;
    top: 64px;
    left: 12px;
    z-index: 10;
    display: flex;
    gap: 6px;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.chicklet-bar::-webkit-scrollbar { display: none; }

.chicklet {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: var(--font);
}
.chicklet:hover { background: var(--bg-hover); color: var(--text-primary); }
.chicklet.active {
    background: rgba(235,0,41,0.15);
    border-color: rgba(235,0,41,0.3);
    color: var(--accent);
}

/* ─── Legend Bar ─── */
.legend-bar {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    padding: 6px 14px;
    border-radius: var(--radius-full);
}

.legend-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.leg-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.leg-sep {
    width: 1px;
    height: 12px;
    background: var(--border);
}

.leg-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(235,0,41,0.1);
    color: var(--accent);
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: var(--font);
}
.leg-btn:hover { background: rgba(235,0,41,0.2); }

/* ─── Modal Backdrop ─── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }

@media (min-width: 640px) {
    .modal-backdrop { align-items: center; padding: 16px; }
}

.modal-card {
    width: 100%;
    max-width: 440px;
    max-height: 82vh;
    overflow-y: auto;
    background: rgba(28,28,30,0.95);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    padding: 24px;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Sleek Webkit Scrollbar */
.modal-card::-webkit-scrollbar {
    width: 6px;
}
.modal-card::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.02);
    border-radius: 10px;
}
.modal-card::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
}
.modal-card::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.25);
}
@media (min-width: 640px) {
    .modal-card {
        border-radius: var(--radius-xl);
        border-bottom: 1px solid var(--border);
    }
}

@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
}

.modal-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.modal-close-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.modal-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Filter Chips ─── */
.filter-section { margin-bottom: 16px; }

.filter-section-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.fchip {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}
.fchip:hover { border-color: var(--text-muted); color: var(--text-primary); }
.fchip.active {
    background: rgba(235,0,41,0.15);
    border-color: var(--primary);
    color: var(--accent);
}

.rent-range {
    display: flex;
    align-items: center;
    gap: 10px;
}
.rent-dash { color: var(--text-muted); }

.form-input {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
}
.form-input:focus { border-color: var(--border-focus); }
.form-input::placeholder { color: var(--text-muted); }

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    font-family: var(--font);
}

.btn-cancel {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-cancel:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-submit {
    background: var(--primary);
    color: white;
}
.btn-submit:hover { background: var(--primary-hover); }

/* ─── Pin Detail ─── */
.detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.detail-stat {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}

.detail-stat-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.detail-stat-value {
    font-size: 17px;
    font-weight: 700;
}

.detail-stat-value.accent { color: var(--accent); }

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.detail-row:last-of-type { border-bottom: none; }

.detail-label { color: var(--text-muted); }

/* ─── Stats ─── */
.stats-tab-row {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.stats-tab {
    flex: 1;
    padding: 7px 10px;
    border-radius: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}
.stats-tab:hover { color: var(--text-secondary); }
.stats-tab.active { background: var(--bg-hover); color: var(--text-primary); }

.stats-tab-content.active { display: block; }

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.stat-row:last-of-type { border-bottom: none; }

.stat-label { color: var(--text-muted); }
.stat-value { font-weight: 700; }
.stat-value.accent { color: var(--accent); }

/* ─── Leaderboard Rows (stats tabs) ─── */
.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}
.lb-row:hover { background: var(--bg-hover); }

.lb-rank {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    background: var(--bg-input);
    color: var(--text-muted);
    flex-shrink: 0;
}
.lb-rank.r1 { background: rgba(234,179,8,0.15); color: #eab308; }
.lb-rank.r2 { background: rgba(148,163,184,0.15); color: #94a3b8; }
.lb-rank.r3 { background: rgba(180,83,9,0.15); color: #d97706; }

.lb-info { flex: 1; min-width: 0; }
.lb-main { font-size: 13px; font-weight: 600; }
.lb-sub { font-size: 11px; color: var(--text-muted); }

.lb-amount { text-align: right; flex-shrink: 0; }
.lb-perbhk { font-size: 14px; font-weight: 700; color: var(--accent); }
.lb-total { font-size: 11px; color: var(--text-muted); }

/* ─── Loading ─── */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg-base);
    transition: opacity 0.3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ─── Error Toast ─── */
.error-toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: rgba(239,68,68,0.9);
    color: white;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.error-toast.visible { opacity: 1; }

/* ─── City Picker ─── */
.city-picker-card {
    max-width: 480px;
    width: 90%;
    padding: 36px 24px;
    text-align: center;
}
.city-picker-brand {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}
.city-picker-brand span { color: var(--primary); }
.city-picker-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    margin-bottom: 24px;
    line-height: 1.5;
}
.city-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
}
.city-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 12px 10px;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}
.city-pill:hover {
    border-color: var(--primary);
    background: rgba(235,0,41,0.08);
}
.city-pill.active {
    border-color: var(--primary);
    background: rgba(235,0,41,0.15);
}
.city-pill-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.city-pill-count {
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 639px) {
    .header-wrap { top: 10px; left: 10px; right: 10px; }
    .chicklet-bar { top: 58px; left: 10px; right: 10px; }
    .legend-bar { bottom: 10px; }
    .filter-btn-label { display: none; }
    .detail-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
    .search-divider { display: none; }
}