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

:root {
    --sidebar-width: 320px;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-muted: #64748b;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    color: var(--text-color);
}

#app {
    display: flex;
    height: 100%;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

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

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Filters */
.filters {
    padding: 20px;
    flex: 1;
}

.filters h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group > label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

.filter-group > label span {
    font-weight: 600;
    color: var(--primary-color);
    margin-left: 4px;
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-inputs input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
}

.range-inputs span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

input[type="range"] {
    width: 100%;
    margin: 8px 0;
}

select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    background: white;
}

/* Buttons */
.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Overlays section */
.overlays {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.overlays h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

/* Results Info */
.results-info {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--bg-color);
}

#results-count {
    font-weight: 600;
    color: var(--primary-color);
}

/* Map Container */
#map-container {
    flex: 1;
    position: relative;
}

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

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
    font-size: 0.875rem;
    color: var(--text-muted);
}

#loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Map Popup */
.maplibregl-popup-content {
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-width: 280px;
}

.popup-content h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.popup-content .price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.popup-content .details {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.popup-content .view-btn {
    display: inline-block;
    padding: 6px 12px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-color);
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#property-detail {
    padding: 24px;
}

#property-detail h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

#property-detail .price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 16px;
}

#property-detail .property-meta {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

#property-detail .property-images {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
}

#property-detail .property-images img {
    height: 120px;
    border-radius: 8px;
    object-fit: cover;
}

#property-detail .description {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-color);
    margin-bottom: 16px;
}

#property-detail .view-listing {
    display: inline-block;
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
}

/* Multiple sources display */
#property-detail .property-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

#property-detail .sources-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

#property-detail .source-link {
    display: inline-block;
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}

#property-detail .source-link:hover {
    background: #2a6a3a;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
        max-height: 50vh;
        order: 2;
    }

    #map-container {
        height: 50vh;
        order: 1;
    }
}
