/* --- GRID LAYOUT & LOADING --- */
.mls-grid {
    display: grid;
    /* Columns are handled by Elementor Responsive Controls */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); /* Fallback */
    gap: 20px;
    margin-top: 30px;
    position: relative;
    min-height: 200px;
}

.mls-grid.mls-loading {
    opacity: 0.5;
    pointer-events: none;
}

.mls-grid.mls-loading::before {
    content: "";
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: mls-spin 0.8s linear infinite;
    z-index: 10;
}

.mls-grid.mls-loading::after {
    content: "Searching MLS Listings...";
    position: absolute;
    top: 105px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    font-weight: 500;
    color: #333;
    background: rgba(255,255,255,0.95);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 10;
}

@keyframes mls-spin {
    0% { transform: translateX(-50%) rotate(0deg); }
    100% { transform: translateX(-50%) rotate(360deg); }
}


/* --- VIEW TOGGLES --- */
.mls-view-toggles {
    display: flex;
    gap: 15px; /* Separation between group and map button */
    align-items: center;
}
.mls-layout-toggles, .mls-map-toggle, .mls-fav-toggle {
    display: flex;
    gap: 5px;
}

.view-toggle-btn, .map-toggle-btn {
    background: #fff;
    border: 1px solid #ddd;
    padding: 0; /* Removing padding for centering */
    cursor: pointer;
    border-radius: 4px;
    color: #666;
    transition: all 0.2s;
    font-size: 16px;
    width: 36px;
    height: 36px;
    display: inline-flex; /* Use inline-flex for tight wrapping */
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.view-toggle-btn:hover, .map-toggle-btn:hover {
    background: #f5f5f5;
    color: #333;
}

.view-toggle-btn.active, .map-toggle-btn.active {
    background: #0073aa;
    color: white;
    border-color: #0073aa;
}
#mls-fav-trigger.active {
    background: #e74c3c;
    border-color: #e74c3c;
    color: white;
}

/* --- LIST VIEW STYLES --- */
.mls-grid.mls-list-view {
    grid-template-columns: 1fr !important; /* Force 1 column */
}
.mls-list-view .nine10-listing-card {
    flex-direction: row;
    height: auto;
    min-height: 250px; /* Increased for better aspect ratio */
    align-items: stretch; /* Ensure children stretch to fill height */
}
.mls-list-view .listing-thumb {
    width: 35%;
    height: auto;
    min-height: 100%; /* Force full height of card */
    overflow: hidden;
    position: relative; /* Context for absolute fav button */
}
/* Ensure Image Fills Space */
.mls-list-view .listing-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: absolute; /* Absolute to fill relative parent */
    top: 0;
    left: 0;
}
.mls-list-view .listing-details {
    width: 65%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 20px; /* Add breathing room */
}
.mls-list-view .listing-description {
    display: block !important;
    margin: 10px 0;
    line-height: 1.5;
}
@media (max-width: 768px) {
    .mls-list-view .nine10-listing-card {
        flex-direction: column;
    }
    .mls-list-view .listing-thumb {
        width: 100%;
        height: 250px; /* Fixed height on mobile stack */
        min-height: 250px;
    }
    .mls-list-view .listing-details {
        width: 100%;
    }
}

/* --- MAP --- */
#nine10-mls-map-container {
    width: 100%;
    background: #eee;
    border-radius: 8px;
    border: 1px solid #ddd;
}

/* --- CARD STYLING --- */
.nine10-listing-card {
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}
.nine10-listing-card:hover {
    transform: translateY(-3px);
}
.listing-thumb {
    position: relative;
    height: 250px; /* Default Grid Height */
    background: #f4f4f4;
    overflow: hidden;
    flex-shrink: 0;
}
.listing-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* --- GRID FAV BUTTON (Default: Top Right) --- */
.nine10-listing-card .mls-fav-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    color: #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    z-index: 10;
    min-width: 20px;
    padding: 0;
}
.nine10-listing-card .mls-fav-btn:hover {
    color: #ff6b6b;
}
.nine10-listing-card .mls-fav-btn.active {
    color: #ff0000;
}

/* --- LIST VIEW FAV BUTTON (Override: Top Left) --- */
.mls-list-view .nine10-listing-card .mls-fav-btn {
    right: auto; /* Reset right */
    left: 10px;  /* Set left */
    top: 10px;
}

.listing-details {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    z-index: 1;
}

.mls-ai-reason-text {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
    border-left: 3px solid #6e8efb;
    color: #444;
    font-size: 0.85em;
    padding: 10px 12px;
    margin-bottom: 12px;
    border-radius: 0 6px 6px 0;
    line-height: 1.4;
}
.mls-ai-reason-text i.fa-robot {
    color: #6e8efb;
    margin-right: 4px;
}
.mls-ai-reason-text strong {
    color: #5a6fd6;
    margin-right: 3px;
}

.listing-details h3 {
    margin: 0 0 5px;
    color: #333;
    font-size: 1.2em;
}
.listing-address {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 10px;
    line-height: 1.4;
}
.listing-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.85em;
    color: #888;
    margin-bottom: 15px;
    margin-top: auto;
}
.listing-meta span {
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
}
.view-btn {
    display: block;
    text-align: center;
    background: #333;
    color: #fff;
    padding: 10px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 500;
    transition: background 0.2s;
    margin-top: 10px;
}
.view-btn:hover {
    background: #555;
}

.mls-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
}
.mls-results-count {
    font-weight: bold;
    color: #555;
    font-size: 1.1em;
}
.mls-sort-wrapper label {
    margin-right: 10px;
    color: #666;
}
.mls-sort-wrapper select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
}
.mls-load-more-container {
    text-align: center;
    margin-top: 40px;
    margin-bottom: 20px;
}
#mls-load-more-btn {
    background: #fff;
    color: #0073aa;
    border: 2px solid #0073aa;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
}
#mls-load-more-btn:hover {
    background: #0073aa;
    color: #fff;
}
