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

:root {
    --bg-primary: #0B0E11;
    --bg-card: #141921;
    --bg-card-hover: #1A2030;
    --bg-input: #0F1218;
    --gold: #C8A84E;
    --gold-light: #E8CC6A;
    --gold-dim: rgba(200, 168, 78, 0.15);
    --green: #3D9970;
    --green-dim: rgba(61, 153, 112, 0.12);
    --green-text: #5AC28E;
    --red: #E74C3C;
    --red-dim: rgba(231, 76, 60, 0.12);
    --text-primary: #E8E6E3;
    --text-secondary: #8B95A5;
    --text-muted: #5A6577;
    --border: rgba(200, 168, 78, 0.08);
    --border-input: rgba(200, 168, 78, 0.12);
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-family: 'Space Grotesk', sans-serif;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        linear-gradient(rgba(200, 168, 78, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(200, 168, 78, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px 60px;
    position: relative;
    z-index: 1;
}

/* ─── Nav ─── */
nav {
    padding: 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--gold-dim);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--gold-light);
}

/* ─── Buttons ─── */
.btn-primary {
    background: var(--gold);
    color: var(--bg-primary);
    padding: 12px 28px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: 'DM Sans', sans-serif;
}

.btn-primary:hover {
    background: var(--gold-light);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-lg {
    padding: 16px 36px;
    font-size: 16px;
    width: 100%;
    justify-content: center;
    margin-top: 24px;
}

.btn-secondary {
    background: transparent;
    color: var(--gold);
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    border: 1px solid var(--gold-dim);
    transition: all 0.2s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'DM Sans', sans-serif;
}

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

.btn-sm {
    padding: 8px 14px;
    font-size: 12px;
}

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

.btn-green:hover {
    background: #4aad80;
}

/* ─── Page Header ─── */
.page-header {
    padding: 40px 0 32px;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* ─── Form ─── */
.search-form {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
}

.form-section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: -12px;
    margin-bottom: 20px;
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
    margin-top: 12px;
}

label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

.required {
    color: var(--gold);
}

.optional {
    color: var(--text-muted);
    font-weight: 400;
}

input, select, textarea {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    transition: border-color 0.2s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

select {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238B95A5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.input-prefix {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.input-prefix:focus-within {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

.input-prefix span {
    padding: 12px 0 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
}

.input-prefix input {
    border: none;
    background: transparent;
    flex: 1;
    padding-left: 6px;
}

.input-prefix input:focus {
    box-shadow: none;
}

/* ─── Spinner ─── */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: var(--bg-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

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

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

.btn-loading {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ─── Error Banner ─── */
.error-banner {
    background: var(--red-dim);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 12px;
    padding: 16px 20px;
    color: #F5A8A0;
    margin-top: 20px;
    font-size: 14px;
}

/* ─── Loading State ─── */
.loading-state {
    text-align: center;
    padding: 120px 0;
}

.loading-state h2 {
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 500;
}

/* ─── Results ─── */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 40px 0 32px;
    gap: 20px;
}

.results-header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}

.results-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

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

/* ─── Listing Card ─── */
.listing-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
}

.listing-card:hover {
    border-color: rgba(200, 168, 78, 0.2);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
}

.listing-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 12px;
}

.listing-price {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--gold);
}

.listing-price span {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 400;
}

.match-badge {
    background: var(--green-dim);
    color: var(--green-text);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.listing-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}

.listing-address {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 14px;
}

.listing-details {
    display: flex;
    gap: 16px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}

.listing-detail {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.listing-detail strong {
    color: var(--text-primary);
    font-weight: 600;
}

.listing-desc {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
    flex: 1;
}

.listing-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.tag {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 500;
}

.tag-green {
    background: var(--green-dim);
    color: var(--green-text);
}

.tag-gold {
    background: var(--gold-dim);
    color: var(--gold);
}

.tag-neutral {
    background: rgba(139, 149, 165, 0.1);
    color: var(--text-secondary);
}

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

.listing-actions .btn-primary {
    flex: 1;
    justify-content: center;
    padding: 10px;
    font-size: 13px;
}

.listing-actions .btn-secondary {
    padding: 10px 14px;
}

/* ─── Modal ─── */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 28px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

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

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

.modal-body p {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 12px;
}

#letter-content {
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-primary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.tone-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tone-selector label {
    font-size: 12px;
    color: var(--text-muted);
}

.tone-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}

.tone-btn:hover {
    border-color: var(--gold-dim);
    color: var(--text-primary);
}

.tone-btn.active {
    background: var(--gold-dim);
    border-color: var(--gold);
    color: var(--gold);
}

.letter-buttons {
    display: flex;
    gap: 8px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .listings-grid {
        grid-template-columns: 1fr;
    }
    .results-header {
        flex-direction: column;
    }
    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .tone-selector {
        justify-content: center;
    }
    .letter-buttons {
        justify-content: center;
    }
}
