/* CSS Variables */
:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --rent: #8b5cf6;
    --sale: #10b981;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-sidebar: #e2e8f0;
    --text-sidebar-muted: #94a3b8;

    --border-color: #e2e8f0;
    --border-radius: 8px;
    --border-radius-sm: 4px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    --sidebar-width: 320px;
    --transition: all 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* App Layout */
.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

.sidebar-content {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-sidebar-muted);
    margin-bottom: 6px;
}

/* Unified Input Styling */
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: white;
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 40px;
    transition: var(--transition);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-group input::placeholder {
    color: rgba(255,255,255,0.35);
    font-weight: 400;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Custom Select Arrow */
.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' opacity='0.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}

.form-group select option {
    background: #1e293b;
    color: white;
    padding: 12px;
}

/* Hide number input spinners */
.form-group input[type="number"]::-webkit-outer-spin-button,
.form-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-group input[type="number"] {
    -moz-appearance: textfield;
}

/* Detected Info Badge */
.detected-info {
    margin-bottom: 8px;
}

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(255,255,255,0.1);
    color: var(--text-sidebar-muted);
}

.badge.sale {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.badge.rent {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 12px 0;
}

/* Section Title */
.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    margin-bottom: 12px;
}

/* Property Type Grid */
.property-type-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.chip-checkbox {
    display: block;
    cursor: pointer;
}

.chip-checkbox input {
    display: none;
}

.chip-checkbox span {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    transition: var(--transition);
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.chip-checkbox input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.chip-checkbox:hover span {
    border-color: rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.08);
}

.chip-checkbox input:checked + span:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* Form Row */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.form-row .form-group {
    margin-bottom: 0;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.input-row input,
.input-row select {
    min-width: 0;
}

/* Input with prefix/suffix */
.input-with-prefix,
.input-with-suffix {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-prefix input,
.input-with-suffix input {
    width: 100%;
}

.input-with-prefix input {
    padding-left: 28px !important;
}

.input-with-suffix input {
    padding-right: 32px !important;
}

.prefix, .suffix {
    position: absolute;
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
    pointer-events: none;
    font-weight: 500;
}

.prefix {
    left: 12px;
}

.suffix {
    right: 12px;
}

/* Mortgage Section */
.mortgage-section {
    transition: var(--transition);
}

.mortgage-section.hidden {
    display: none;
}

/* Search Button */
.search-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: auto;
}

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

.search-btn:disabled {
    background: rgba(255,255,255,0.1);
    color: var(--text-sidebar-muted);
    cursor: not-allowed;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Results Header */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 16px;
}

.results-title h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.results-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

.results-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

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

.icon-btn svg {
    flex-shrink: 0;
}

/* Table Container */
.table-container {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    display: none;
}

.table-container.visible {
    display: block;
}

#results-table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
}

#results-table th {
    background: var(--bg-secondary);
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border-color);
}

#results-table th:hover {
    background: var(--border-color);
}

#results-table th .sort-indicator {
    margin-left: 4px;
    opacity: 0.3;
}

#results-table th.sorted-asc .sort-indicator::after,
#results-table th.sorted-desc .sort-indicator::after {
    opacity: 1;
}

#results-table th.sorted-asc .sort-indicator::after {
    content: ' ▲';
}

#results-table th.sorted-desc .sort-indicator::after {
    content: ' ▼';
}

#results-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#results-table tbody tr {
    cursor: pointer;
    transition: var(--transition);
}

#results-table tbody tr:hover {
    background: var(--primary-light);
}

#results-table td.price {
    font-weight: 600;
    color: var(--text-primary);
}

#results-table td.mortgage {
    color: var(--warning);
    font-weight: 500;
}

#results-table td.address {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px;
    color: var(--text-muted);
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    margin-bottom: 24px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
}

/* Loading State */
.loading-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

.loading-state.hidden {
    display: none;
}

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

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

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.visible {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: translateY(-20px);
    transition: var(--transition);
}

.modal.visible .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.columns-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.columns-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.columns-list label:hover {
    background: var(--bg-secondary);
}

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

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

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

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

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

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .main-content {
        margin-left: 280px;
    }
}

@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        position: relative;
        width: 100%;
        max-height: none;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .results-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .table-container {
        margin: 0 -16px;
        border-radius: 0;
    }

    .columns-list {
        grid-template-columns: 1fr;
    }
}
