:root {
    --primary-color: #2563eb;
    --secondary-color: #1e40af;
    --bg-color: #f3f4f6;
    --sidebar-bg: #ffffff;
    --text-color: #1f2937;
    --border-color: #e5e7eb;
    --accent-color: #f59e0b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 400px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #fff;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 600;
}

.subtitle {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

/* Filters */
.filters {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    background: #f9fafb;
    max-height: 40vh;
    /* Prevent filters from taking too much space */
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #374151;
}

.help-text {
    font-size: 0.7rem;
    color: #6b7280;
    margin-top: 2px;
}

/* Controls */
.slider-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="range"] {
    flex: 1;
}

#distanceValue {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--primary-color);
    min-width: 3rem;
    text-align: right;
}

.control-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.input-wrapper span {
    font-size: 0.8rem;
    color: #4b5563;
}

input[type="number"],
select {
    width: 100%;
    padding: 0.3rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.8rem;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.checkbox-wrapper label {
    margin-bottom: 0;
    font-weight: 400;
}

/* Custom Dropdowns */
.custom-dropdown {
    position: relative;
    width: 100%;
}

.dd-button {
    width: 100%;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
    font-size: 0.85rem;
    color: #374151;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dd-button::after {
    content: '▾';
    margin-left: 8px;
    color: #9ca3af;
}

.dd-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 0.5rem;
    margin-top: 4px;
}

.dd-content.show {
    display: block;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px 0;
    font-size: 0.85rem;
}

.checkbox-item:hover {
    background-color: #f3f4f6;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
}

.checkbox-item label {
    cursor: pointer;
    flex: 1;
}

button#updateBtn {
    width: 100%;
    padding: 0.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.2s;
}

button#updateBtn:hover {
    background: var(--secondary-color);
}

/* Results */
.results-summary {
    padding: 0.5rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: #6b7280;
}

.results-summary strong {
    color: var(--text-color);
}

.results-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f3f4f6;
}

/* Pair Card - Enhanced */
.pair-card {
    position: relative;
    /* Context for absolute positioning */
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.pair-card.active {
    border-color: var(--primary-color);
    background-color: #f0f7ff;
    box-shadow: 0 0 0 2px var(--primary-color) inset;
    /* Force outline */
}

.share-icon-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.share-icon-btn:hover {
    background-color: #f3f4f6;
    color: var(--primary-color);
}

.share-icon-btn.copied {
    color: #10b981;
    /* Green */
    background-color: #d1fae5;
}

.pair-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-right: 30px;
    /* Space for share button */
}

.pair-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.pair-distance {
    font-size: 0.8rem;
    color: #059669;
    background: #ecfdf5;
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 600;
}

.houses-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.house-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.house-main {
    flex: 1;
    min-width: 0;
    /* Text truncation support */
}

.house-link {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.house-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.house-loc {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 2px;
}

.house-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: 8px;
    max-width: 45%;
}

.badge-sm {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e5e7eb;
    color: #4b5563;
    white-space: nowrap;
}

.badge-sm.highlight {
    background: #dbeafe;
    color: #1e40af;
    font-weight: 500;
}

.pair-connector {
    height: 0;
    border-top: 1px dashed #e5e7eb;
    margin: 2px 0;
}

/* Map */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.loading {
    text-align: center;
    color: #6b7280;
    padding: 2rem;
}

/* Map Tooltips */
.leaflet-tooltip.custom-tooltip {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.leaflet-tooltip-top:before {
    display: none;
    /* Hide default arrow to style our own if needed, or keep simple */
}

.map-card {
    background: white;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    width: 220px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    pointer-events: auto;
    /* Ensure clicks work */
}

.map-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    align-items: center;
}

.map-card-price {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
}

.map-card-beds {
    background: #f3f4f6;
    color: #4b5563;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.map-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-card-address {
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 8px;
}

.map-card-link {
    display: block;
    text-align: center;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    padding: 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.2s;
}

.map-card-link:hover {
    background: var(--secondary-color);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        /* Fix for mobile address bar */
        height: 100dvh;
        overflow: hidden;
    }

    .app-container {
        flex-direction: column;
        height: 100%;
        overflow: hidden;
    }

    .sidebar {
        width: 100%;
        height: 60%;
        /* List gets 60% */
        order: 2;
        border-right: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.1);
        z-index: 20;
    }

    .map-container {
        width: 100%;
        height: 40%;
        /* Map gets 40% */
        order: 1;
        z-index: 10;
    }

    /* Header upgrades */
    header {
        padding: 0.75rem 1rem;
    }

    .header-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .subtitle.desktop-only {
        display: none;
    }

    /* Collapsible filters */
    .filters {
        display: none;
        /* Hidden by default on mobile */
        padding: 1rem;
        background: #f8f9fa;
        border-bottom: 1px solid #ddd;
        max-height: 50vh;
        /* Don't take whole screen */
    }

    .filters.show {
        display: block;
        animation: slideDown 0.2s ease-out;
    }

    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    .btn-toggle {
        background: #eff6ff;
        color: var(--primary-color);
        border: 1px solid rgba(37, 99, 235, 0.2);
        padding: 4px 10px;
        border-radius: 6px;
        font-size: 0.85rem;
        font-weight: 600;
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }

    .desktop-only {
        display: block;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}