:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg: #0f172a;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-deep: rgba(255, 255, 255, 0.07);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(168, 85, 247, 0.1) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    padding: 0.5rem 1.25rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #818cf8, #c084fc);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 1.25rem;
    max-width: 2000px;
    width: 100%;
    margin: 0 auto;
}

/* --- Login Form --- */
.login-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    padding: 2.5rem;
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    backdrop-filter: blur(10px);
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-card h2 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1.2rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

input,
textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.75rem;
    color: white;
    font-size: 1rem;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    outline: none;
}

.btn-login {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.2s;
}

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

#addPropertyToggleRow {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
    flex-wrap: nowrap;
    /* Always 3 across */
}

@media (max-width: 583px) {
    #addPropertyToggleRow {
        justify-content: space-between;
    }

    #addPropertyToggleRow button {
        padding: 0.5rem 0.2rem !important;
        font-size: 0.7rem !important;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.2;
    }

    #addPropertyToggleRow button:nth-child(2) {
        white-space: normal;
    }

    #addPropertyToggleRow button:not(:nth-child(2)) {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* --- Property List --- */
.property-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    width: 100%;
    display: none;
    /* Hidden by default */
}

@media (min-width: 1200px) {
    .property-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.property-top-overlay {
    display: flex;
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 50;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}

.property-top-overlay>* {
    pointer-events: auto;
}

.property-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    overflow: hidden;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.property-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.05);
}

.property-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    background-color: #1e293b;
}

.property-info {
    padding: 0.5rem;
    flex-grow: 1;
}

.property-price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 0.5rem;
}

.property-price-mobile {
    display: block;
    z-index: 25;
    font-size: 1.0rem;
    font-weight: 800;
    color: var(--success);
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    padding: 5px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    white-space: nowrap;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    margin: 0 auto;
}

.property-address {
    position: absolute;
    top: 138px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    width: auto;
    max-width: 92%;
    margin-top: 0 !important;
}

.address-split-container {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: pointer;
    line-height: 1.5;
    margin-top: 0.8rem;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.property-details:hover {
    color: var(--text-main);
}

.address-split-container {
    display: flex;
    align-items: stretch;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.addr-split-left,
.addr-split-right {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.9rem;
    text-decoration: none;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
}

.addr-split-left {
    flex-grow: 1;
    min-width: 0;
    /* Allow shrinking */
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(99, 102, 241, 0.4);
    /* Glass Indigo */
    overflow: hidden;
}

.addr-split-right {
    flex-shrink: 0;
    /* Prevent squishing */
    background: rgba(16, 185, 129, 0.4);
    /* Glass Emerald */
    padding: 0.5rem 1rem;
}

.addr-split-left:hover {
    color: white;
    font-weight: 800;
    font-size: 0.85rem;
    background: transparent;
}

.addr-split-right:hover {
    color: white;
    font-weight: 800;
    font-size: 0.85rem;
    background: transparent;
}

.addr-icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.2));
}

.addr-text {
    margin-left: 8px;
    white-space: nowrap;
}


.property-address a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}


.property-details {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.2;
    margin-top: 0.0rem;
    white-space: pre-wrap;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-logout:hover {
    color: var(--text-main);
    border-color: var(--text-main);
}

#statusMsg {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* --- Modals & Messenger --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background: var(--bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2.5rem;
    position: relative;
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.5);
}

.modal-close {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.4rem;
    transition: all 0.3s ease;
    user-select: none;
    line-height: 1;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: #ef4444;
    transform: rotate(90deg);
}

.btn-submit {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 1rem;
}

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

/* Scrollbar styling for message history */
#messageHistory::-webkit-scrollbar {
    width: 6px;
}

#messageHistory::-webkit-scrollbar-track {
    background: transparent;
}

#messageHistory::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

#messageHistory::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Mobile Adjustments --- */
@media (max-width: 650px) {
    main {
        padding: 1rem 0.6rem !important;
    }

    .property-info {
        display: none !important;
    }

    .property-info.show {
        display: block !important;
    }

    #addPropertySection {
        padding: 0.8rem !important;
        margin-bottom: 1.2rem !important;
        border-radius: 10px !important;
    }

    #addPropertySection h3 {
        font-size: 0.75rem !important;
        margin-bottom: 0.6rem !important;
        line-height: 1.2 !important;
        color: var(--text-muted) !important;
    }

    #addPropertyForm {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    #addPropertyForm input {
        font-size: 0.7rem !important;
        padding: 0.5rem !important;
        border-radius: 6px !important;
    }

    #addPropertyBtn {
        width: 100% !important;
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
        margin-top: 0 !important;
        height: auto !important;
    }

    .property-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .property-price {
        font-size: 1.1rem !important;
    }

    .property-details {
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
        display: block !important;
        overflow: visible !important;
        font-size: 0.85rem !important;
        margin-top: 0.0rem !important;
        line-height: 1.6 !important;
    }

    #propertyGallery h2 {
        font-size: 1.0rem !important;
        margin-bottom: 0 !important;
    }

    .logo {
        font-size: 1.1rem !important;
    }
}

/* --- Agent Notes --- */
.agent-notes-display {
    padding: 0.5rem 0.6rem;
    background: rgba(99, 102, 241, 0.08);
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.85rem;
    line-height: 1.5;
    color: #a5b4fc;
    display: block;
    animation: fadeIn 0.3s ease;
}

/* --- AI Evaluation Styles --- */
.score-badge {
    position: static;
    z-index: 20;
    width: auto;
    background: var(--primary);
    color: white;
    font-weight: 800;
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.score-badge:hover {
    background: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

#scoreReasoning {
    color: var(--text-muted);
    line-height: 1.5;
    white-space: pre-wrap;
    font-size: 0.95rem;
}