/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --green: #34c759;
    --orange: #ff9500;
    --red: #ff3b30;
    --border: #d2d2d7;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Header */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 20px 24px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 2px;
}

.stats-bar {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 1400px;
    margin: 0 auto;
    overflow-x: auto;
}

.stat-item { white-space: nowrap; }
.stat-value { font-weight: 600; color: var(--text); }

/* Layout */
.layout {
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100vh - 100px);
}

/* Sidebar */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px;
    position: sticky;
    top: 100px;
    height: calc(100vh - 100px);
    overflow-y: auto;
}

.sidebar-toggle {
    display: none;
}

.filter-section {
    margin-bottom: 18px;
}

.filter-section label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.filter-section input[type="text"],
.filter-section input[type="number"],
.filter-section select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.filter-section input:focus,
.filter-section select:focus {
    outline: none;
    border-color: var(--accent);
}

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

.range-inputs input { flex: 1; }
.range-inputs span { color: var(--text-secondary); }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-size: 14px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    color: var(--text) !important;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

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

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

/* Main Content */
.main-content {
    flex: 1;
    padding: 20px 24px;
    min-width: 0;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

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

/* Listings Grid */
.listings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

/* Listing Card */
.listing-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.listing-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.card-photo {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--bg);
    display: block;
}

.card-photo-placeholder {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, #e0e0e0 0%, #f0f0f0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.card-body {
    padding: 14px 16px;
}

.card-price {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

.card-address {
    font-size: 14px;
    color: var(--text);
    margin-top: 2px;
    font-weight: 500;
}

.card-city {
    font-size: 13px;
    color: var(--text-secondary);
}

.card-details {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.card-details span { white-space: nowrap; }

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tag-fixer {
    background: #fff3e0;
    color: #e65100;
}

.tag-probate {
    background: #e8f5e9;
    color: #2e7d32;
}

.tag-dom {
    background: #e3f2fd;
    color: #1565c0;
}

.tag-score {
    background: #fce4ec;
    color: #c62828;
}

.tag-deal {
    background: #e8f5e9;
    color: #1b5e20;
    font-weight: 700;
}

/* Deal highlight - green left border on cards */
.listing-card.deal-card {
    border-left: 4px solid var(--green);
}

.deal-banner {
    background: linear-gradient(90deg, #e8f5e9, #c8e6c9);
    color: #1b5e20;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.deal-banner-modal {
    background: linear-gradient(90deg, #e8f5e9, #c8e6c9);
    color: #1b5e20;
    padding: 10px 24px;
    font-size: 15px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Agent info on cards */
.card-agent {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.card-agent a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* Agent contact block in modal */
.agent-contact {
    background: #f0f7ff;
    border: 1px solid #bdd7f1;
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    margin-top: 14px;
}

.agent-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.agent-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.agent-phone {
    display: inline-block;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
}

.agent-phone:hover { text-decoration: underline; }

.agent-email {
    display: inline-block;
    margin-left: 12px;
    margin-top: 4px;
    font-size: 14px;
    color: var(--accent);
    text-decoration: none;
}

.agent-email:hover { text-decoration: underline; }

.agent-office {
    margin-top: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid var(--bg);
    font-size: 12px;
    color: var(--text-secondary);
}

.card-area {
    font-weight: 500;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    padding: 20px 0;
}

.pagination button {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.pagination button:hover:not(:disabled) {
    background: var(--bg);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination button.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.pagination .page-info {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 0 8px;
}

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

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-photos {
    position: relative;
    overflow: hidden;
}

.modal-photos img {
    width: 100%;
    height: 400px;
    object-fit: cover;
    display: block;
}

.photo-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-nav.prev { left: 12px; }
.photo-nav.next { right: 12px; }

.photo-counter {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
}

.modal-details {
    padding: 24px;
}

.modal-price {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
}

.modal-address {
    font-size: 18px;
    margin-top: 4px;
}

.modal-city {
    font-size: 15px;
    color: var(--text-secondary);
}

.modal-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 16px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.spec-item {
    text-align: center;
}

.spec-value {
    font-size: 18px;
    font-weight: 600;
}

.spec-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.modal-description {
    margin-top: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.modal-meta {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.meta-item {
    font-size: 13px;
}

.meta-label {
    color: var(--text-secondary);
}

.meta-value {
    font-weight: 600;
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background 0.2s;
}

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

/* Loading */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text);
    margin-bottom: 8px;
}

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

    .sidebar {
        width: 100%;
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 0;
    }

    .sidebar-toggle {
        display: block;
        width: 100%;
        padding: 14px 20px;
        background: var(--surface);
        border: none;
        border-bottom: 1px solid var(--border);
        font-size: 15px;
        font-weight: 600;
        color: var(--accent);
        cursor: pointer;
        text-align: left;
    }

    .sidebar-content {
        display: none;
        padding: 16px 20px;
    }

    .sidebar.open .sidebar-content {
        display: block;
    }

    .listings-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    .modal-content { max-height: 95vh; }
    .modal-photos img { height: 250px; }
    .modal-details { padding: 16px; }
    .modal-price { font-size: 24px; }
}
