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

:root {
    --primary: #1a56db;
    --primary-dark: #1e40af;
    --primary-light: #eff6ff;
    --bg: #f1f5f9;
    --sidebar-bg: #ffffff;
    --text: #0f172a;
    --text-mid: #475569;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --green: #16a34a;
    --yellow: #ca8a04;
    --red: #dc2626;
    --sidebar-width: 340px;
    --radius: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ========== Navbar ========== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 100%);
    color: white;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-icon {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.nav-brand h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
}
.nav-brand span { font-weight: 300; opacity: 0.7; }

.nav-center { display: flex; gap: 4px; }
.nav-tab {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-tab.active, .nav-tab:hover {
    color: white;
    background: rgba(255,255,255,0.15);
}

.nav-right { display: flex; align-items: center; }
.nav-tagline {
    font-size: 12px;
    opacity: 0.5;
    font-weight: 300;
    letter-spacing: 0.5px;
}

/* ========== Layout ========== */
.app-container {
    display: flex;
    height: calc(100vh - 60px);
    position: relative;
}

/* ========== Sidebar ========== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform 0.3s;
    z-index: 500;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.sidebar-toggle {
    display: none;
    position: absolute;
    right: -44px;
    top: 12px;
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0 10px 10px 0;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 501;
    box-shadow: var(--shadow-md);
}

.sidebar-content { padding: 0; }

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-section h2 i {
    color: var(--primary);
    font-size: 13px;
}

.hint {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 14px;
}

/* ========== Filters ========== */
.filter-group {
    margin-bottom: 14px;
}
.filter-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-mid);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.range-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}
.range-sep {
    color: var(--text-light);
    font-size: 12px;
}

input[type="number"], select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #f8fafc;
    transition: all 0.2s;
}
input[type="number"]:focus, select:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

/* ========== Preferences ========== */
.pref-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding: 4px 0;
}
.pref-item .pref-icon {
    width: 24px;
    text-align: center;
    font-size: 13px;
}
.pref-item .pref-label {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    min-width: 70px;
    color: var(--text-mid);
}
.pref-item input[type="range"] {
    flex: 2;
    accent-color: var(--primary);
    height: 4px;
}
.pref-item .pref-value {
    width: 26px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    border-radius: 4px;
    padding: 2px 0;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    justify-content: center;
}
.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(26,86,219,0.3);
}
.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(26,86,219,0.4);
    transform: translateY(-1px);
}

.btn-score {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
    box-shadow: 0 2px 4px rgba(22,163,74,0.3);
    margin-top: 8px;
}
.btn-score:hover {
    box-shadow: 0 4px 8px rgba(22,163,74,0.4);
    transform: translateY(-1px);
}

.btn-preset {
    padding: 7px 12px;
    font-size: 11px;
    font-weight: 600;
    width: auto;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-mid);
}
.btn-preset:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}
.btn-preset i { font-size: 10px; }

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

/* ========== Legend ========== */
.sidebar-footer {
    padding: 16px 20px;
}
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-light);
}
.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }
.dot.blue { background: var(--primary); }

/* ========== Main Content ========== */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view { display: none; height: 100%; }
.view.active { display: block; }

#map { height: 100%; width: 100%; }

.map-stats {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.97);
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 400;
    backdrop-filter: blur(8px);
    color: var(--text-mid);
}
.map-stats i { color: var(--primary); }

/* ========== List View ========== */
.list-container {
    padding: 24px;
    overflow-y: auto;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    align-content: start;
    background: var(--bg);
}

.property-card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 18px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.property-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: #cbd5e1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 8px;
}
.card-price {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
}
.card-score {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 16px;
    color: white;
}
.score-high { background: var(--green); }
.score-mid { background: var(--yellow); }
.score-low { background: var(--red); }

.card-address {
    font-size: 14px;
    color: var(--text);
    font-weight: 500;
    margin-bottom: 6px;
}
.card-details {
    font-size: 13px;
    color: var(--text-mid);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.card-details span {
    display: flex;
    align-items: center;
    gap: 3px;
}
.card-community {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 8px;
}

/* ========== Detail Panel ========== */
.detail-panel {
    position: absolute;
    right: 0;
    top: 0;
    width: 440px;
    height: 100%;
    background: white;
    box-shadow: -8px 0 24px rgba(0,0,0,0.1);
    overflow-y: auto;
    z-index: 600;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 28px;
}
.detail-panel.open { transform: translateX(0); }
.detail-panel::-webkit-scrollbar { width: 4px; }
.detail-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: #f1f5f9;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-mid);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}
.close-btn:hover { background: #e2e8f0; color: var(--text); }

.detail-price {
    font-size: 32px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}
.detail-address {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text-mid);
}

.detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.stat-item {
    background: #f8fafc;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
}
.stat-label {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.stat-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 2px;
    color: var(--text);
}

.detail-links {
    margin: 16px 0;
    display: flex;
    gap: 8px;
}
.detail-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
}
.detail-links a:first-child {
    background: var(--primary);
    color: white;
}
.detail-links a:first-child:hover { background: var(--primary-dark); }
.detail-links a:last-child {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: white;
}
.detail-links a:last-child:hover { opacity: 0.9; }

/* ========== Score Breakdown ========== */
.score-breakdown {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.score-breakdown h3 {
    font-size: 15px;
    margin-bottom: 14px;
    font-weight: 700;
}
.score-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 12px;
}
.score-bar-bg {
    flex: 1;
    height: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    overflow: hidden;
}
.score-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.score-bar.high { background: var(--green); }
.score-bar.mid { background: var(--yellow); }
.score-bar.low { background: var(--red); }

.score-row .distance {
    font-size: 10px;
    color: var(--text-light);
    width: 55px;
    text-align: right;
    font-weight: 500;
}

/* ========== History Chart ========== */
.history-chart {
    margin-top: 20px;
    padding: 18px;
    background: #f8fafc;
    border-radius: var(--radius);
    border: 1px solid #f1f5f9;
}
.history-chart h3 {
    font-size: 13px;
    margin-bottom: 12px;
    font-weight: 700;
    color: var(--text-mid);
}
.history-bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    height: 100px;
    padding-bottom: 24px;
}
.history-bar {
    flex: 1;
    background: linear-gradient(180deg, var(--primary) 0%, #3b82f6 100%);
    border-radius: 4px 4px 0 0;
    position: relative;
    min-height: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.history-bar:last-child { opacity: 1; }
.history-bar:hover { opacity: 1; }
.history-bar .bar-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-light);
    white-space: nowrap;
    font-weight: 600;
}
.history-bar .bar-value {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-mid);
}

/* ========== Leaflet Popup ========== */
.leaflet-popup-content {
    margin: 10px 14px;
    min-width: 200px;
    font-family: 'Inter', sans-serif;
}
.popup-price {
    font-weight: 800;
    font-size: 18px;
    color: var(--text);
}
.popup-address {
    font-size: 13px;
    margin: 4px 0;
    color: var(--text-mid);
    font-weight: 500;
}
.popup-details {
    font-size: 12px;
    color: var(--text-light);
}
.popup-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
}
.popup-link:hover { text-decoration: underline; }

/* ========== Compare Bar ========== */
.compare-bar {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.97);
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    backdrop-filter: blur(8px);
}
.compare-items { display: flex; gap: 6px; flex-wrap: wrap; }
.compare-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
}
.compare-chip i {
    cursor: pointer;
    font-size: 9px;
    opacity: 0.6;
}
.compare-chip i:hover { opacity: 1; }

/* ========== Facility Toggles ========== */
.facility-toggles {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.97);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 400;
    min-width: 160px;
    backdrop-filter: blur(8px);
    overflow: hidden;
}
.facility-toggle-header {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-mid);
    border-bottom: 1px solid var(--border);
}
.facility-toggle-header i:last-child {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.2s;
}
.facility-toggles.expanded .facility-toggle-header i:last-child {
    transform: rotate(180deg);
}
.facility-toggle-list {
    display: none;
    padding: 8px;
}
.facility-toggles.expanded .facility-toggle-list {
    display: block;
}
.facility-toggle-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}
.facility-toggle-item:hover { background: #f1f5f9; }
.facility-toggle-item input { accent-color: var(--primary); }

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 500;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .detail-panel { width: 100%; }
    .nav-tagline { display: none; }
    .nav-brand h1 { font-size: 20px; }
}
