{% extends 'expat_life/base.html' %}
{% load static %}
{% block title %}My Interested Properties{% endblock %}

{% block content %}

<style>
    /* =========================================================
       INTERESTED PROPERTIES - PREMIUM LIVE IN SRI LANKA THEME
    ========================================================= */

    :root {
        --lis-deep: #07131c;
        --lis-navy: #0b2638;
        --lis-blue: #0d6efd;
        --lis-blue-dark: #0b3d91;
        --lis-teal: #0f766e;
        --lis-teal-bright: #20c997;
        --lis-gold: #ffc107;
        --lis-gold-light: #ffd45f;
        --lis-soft-blue: #f5f9ff;
        --lis-sand: #fff8ed;
        --lis-white: #ffffff;
        --lis-text: #102033;
        --lis-muted: #64748b;
        --lis-border: rgba(15, 42, 64, 0.10);
        --lis-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
        --lis-shadow-strong: 0 28px 70px rgba(15, 23, 42, 0.16);
    }

    .interested-properties-section {
        position: relative;
        overflow: hidden;
        min-height: 88vh;
        padding: 90px 0;
        background:
            radial-gradient(circle at 10% 12%, rgba(255, 193, 7, 0.13), transparent 28%),
            radial-gradient(circle at 88% 14%, rgba(13, 110, 253, 0.10), transparent 30%),
            radial-gradient(circle at 82% 86%, rgba(15, 118, 110, 0.12), transparent 32%),
            linear-gradient(180deg, #f5f9ff 0%, #ffffff 100%);
    }

    .interested-properties-section::before {
        content: "";
        position: absolute;
        width: 430px;
        height: 430px;
        right: -210px;
        top: -210px;
        border-radius: 50%;
        background: rgba(255, 193, 7, 0.11);
        pointer-events: none;
    }

    .interested-properties-section::after {
        content: "";
        position: absolute;
        width: 360px;
        height: 360px;
        left: -170px;
        bottom: -180px;
        border-radius: 50%;
        background: rgba(13, 110, 253, 0.07);
        pointer-events: none;
    }

    .interested-properties-wrap {
        position: relative;
        z-index: 2;
    }

    .interested-properties-hero {
        position: relative;
        overflow: hidden;
        border-radius: 36px;
        padding: 2.4rem 2.3rem;
        margin-bottom: 2.2rem;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.18), transparent 34%),
            radial-gradient(circle at bottom left, rgba(32, 201, 151, 0.18), transparent 34%),
            linear-gradient(135deg, #061b2a 0%, #0b3d91 52%, #0f766e 100%);
        color: #ffffff;
        box-shadow: 0 30px 70px rgba(15, 23, 42, 0.20);
    }

    .interested-properties-hero::before {
        content: "";
        position: absolute;
        top: -95px;
        right: -70px;
        width: 280px;
        height: 280px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.08);
        pointer-events: none;
    }

    .interested-properties-hero::after {
        content: "";
        position: absolute;
        bottom: -130px;
        left: -80px;
        width: 340px;
        height: 340px;
        border-radius: 50%;
        background: rgba(255, 193, 7, 0.10);
        pointer-events: none;
    }

    .interested-properties-hero > * {
        position: relative;
        z-index: 2;
    }

    .section-mini-title,
    .interested-properties-mini-title {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        padding: 7px 15px;
        border-radius: 999px;
        background: rgba(15, 118, 110, 0.09);
        border: 1px solid rgba(15, 118, 110, 0.14);
        color: var(--lis-teal);
        font-size: 0.78rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.075em;
        margin-bottom: 14px;
    }

    .section-mini-title::before,
    .interested-properties-mini-title::before {
        content: "";
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--lis-gold);
        box-shadow: 0 0 0 5px rgba(255, 193, 7, 0.14);
    }

    .interested-properties-hero .section-mini-title,
    .interested-properties-hero .interested-properties-mini-title {
        background: rgba(255, 193, 7, 0.14);
        border: 1px solid rgba(255, 193, 7, 0.28);
        color: #ffd36b;
        backdrop-filter: blur(10px);
    }

    .interested-properties-hero .section-mini-title::before,
    .interested-properties-hero .interested-properties-mini-title::before {
        background: #ffffff;
        box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.12);
    }

    .interested-properties-hero h1 {
        color: #ffffff;
        font-weight: 950;
        letter-spacing: -0.045em;
        line-height: 1.07;
        font-size: clamp(2.15rem, 4vw, 3.35rem);
        margin-bottom: 0.75rem;
    }

    .interested-properties-hero p {
        max-width: 760px;
        color: rgba(255, 255, 255, 0.86) !important;
        line-height: 1.78;
        font-size: 1.04rem;
        margin-bottom: 0;
    }

    .interested-properties-hero .btn {
        border-radius: 999px;
        font-weight: 850;
        padding: 0.82rem 1.35rem;
        transition: all 0.22s ease;
    }

    .interested-properties-hero .btn-outline-dark {
        background: rgba(255, 255, 255, 0.10);
        color: #ffffff;
        border: 1px solid rgba(255, 255, 255, 0.42);
        backdrop-filter: blur(10px);
    }

    .interested-properties-hero .btn-outline-dark:hover {
        background: #ffffff;
        color: var(--lis-deep);
        border-color: #ffffff;
        transform: translateY(-2px);
    }

    .final-selected-panel {
        position: relative;
        overflow: hidden;
        border: 1px solid rgba(15, 118, 110, 0.18);
        border-radius: 28px;
        padding: 1.35rem 1.45rem;
        background:
            radial-gradient(circle at 92% 10%, rgba(255, 193, 7, 0.12), transparent 32%),
            linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
        box-shadow: var(--lis-shadow);
        margin-bottom: 2rem;
    }

    .final-selected-panel::before {
        content: "";
        position: absolute;
        inset: 0 0 auto 0;
        height: 5px;
        background: linear-gradient(90deg, var(--lis-gold), var(--lis-teal), var(--lis-blue));
    }

    .final-selected-panel > * {
        position: relative;
        z-index: 2;
    }

    .final-selected-panel h5 {
        color: var(--lis-text);
        font-weight: 950;
        letter-spacing: -0.02em;
    }

    .final-selected-panel p {
        color: var(--lis-muted);
        line-height: 1.65;
    }

    .final-selected-panel strong {
        color: var(--lis-teal);
    }

    .property-interest-card {
        position: relative;
        overflow: hidden;
        height: 100%;
        border: 1px solid rgba(15, 42, 64, 0.08);
        border-radius: 30px;
        background:
            radial-gradient(circle at 92% 10%, rgba(255, 193, 7, 0.10), transparent 32%),
            linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
        box-shadow: var(--lis-shadow);
        transition: all 0.24s ease;
    }

    .property-interest-card::before {
        content: "";
        position: absolute;
        inset: 0 0 auto 0;
        height: 4px;
        background: linear-gradient(90deg, var(--lis-gold), var(--lis-teal), var(--lis-blue));
        opacity: 0;
        transition: opacity 0.24s ease;
        z-index: 3;
    }

    .property-interest-card:hover {
        transform: translateY(-6px);
        border-color: rgba(15, 118, 110, 0.18);
        box-shadow: var(--lis-shadow-strong);
    }

    .property-interest-card:hover::before {
        opacity: 1;
    }

    .property-image-wrap {
        position: relative;
        overflow: hidden;
        height: 250px;
        background: #07131c;
    }

    .property-interest-image {
        width: 100%;
        height: 250px;
        object-fit: cover;
        transition: transform 0.35s ease, filter 0.35s ease;
    }

    .property-interest-card:hover .property-interest-image {
        transform: scale(1.04);
        filter: saturate(1.05) contrast(1.03);
    }

    .property-image-wrap::after {
        content: "";
        position: absolute;
        inset: 0;
        background:
            linear-gradient(180deg, transparent 46%, rgba(7, 19, 28, 0.72) 100%),
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.16), transparent 34%);
        pointer-events: none;
    }

    .property-placeholder {
        height: 250px;
        display: flex;
        align-items: center;
        justify-content: center;
        background:
            radial-gradient(circle at center, rgba(255, 193, 7, 0.14), transparent 36%),
            linear-gradient(135deg, #ecfdf5, #e9f2ff);
        color: var(--lis-teal);
    }

    .property-placeholder i {
        font-size: 3rem;
    }

    .property-status-badge {
        position: absolute;
        top: 16px;
        right: 16px;
        z-index: 4;
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.42rem 0.78rem;
        border-radius: 999px;
        background: linear-gradient(135deg, var(--lis-gold-light), var(--lis-gold));
        color: #231707;
        font-size: 0.78rem;
        font-weight: 900;
        border: none;
        box-shadow: 0 14px 28px rgba(255, 193, 7, 0.24);
    }

    .property-status-badge::before {
        content: "\F3ED";
        font-family: "bootstrap-icons";
        font-size: 0.85rem;
    }

    .property-interest-body {
        padding: 1.45rem;
        display: flex;
        flex-direction: column;
        min-height: 360px;
    }

    .property-title-row {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.8rem;
        margin-bottom: 0.85rem;
    }

    .property-interest-title {
        color: var(--lis-text);
        font-weight: 950;
        letter-spacing: -0.02em;
        line-height: 1.25;
        margin-bottom: 0;
    }

    .property-location {
        color: var(--lis-muted) !important;
        line-height: 1.55;
        margin-bottom: 1rem;
    }

    .property-meta-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.8rem;
        margin-bottom: 1rem;
    }

    .property-meta-box {
        padding: 0.9rem 0.95rem;
        border-radius: 18px;
        background:
            radial-gradient(circle at 92% 10%, rgba(13, 110, 253, 0.055), transparent 30%),
            linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
        border: 1px solid rgba(15, 42, 64, 0.08);
        box-shadow: 0 10px 22px rgba(15, 23, 42, 0.035);
    }

    .property-meta-label {
        display: block;
        color: var(--lis-muted);
        font-size: 0.72rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        margin-bottom: 0.25rem;
    }

    .property-meta-value {
        color: var(--lis-text);
        font-weight: 850;
        line-height: 1.45;
        word-break: break-word;
    }

    .property-rent-box {
        background:
            radial-gradient(circle at 92% 12%, rgba(255, 193, 7, 0.18), transparent 34%),
            linear-gradient(135deg, var(--lis-deep) 0%, var(--lis-blue-dark) 54%, var(--lis-teal) 100%);
        border: none;
        color: #ffffff;
    }

    .property-rent-box .property-meta-label {
        color: rgba(255, 255, 255, 0.72);
    }

    .property-rent-box .property-meta-value {
        color: #ffd36b;
        font-weight: 950;
        font-size: 1.1rem;
    }

    .property-notes-box {
        border-radius: 20px;
        padding: 1rem;
        margin-bottom: 1rem;
        background:
            radial-gradient(circle at 92% 10%, rgba(255, 193, 7, 0.13), transparent 32%),
            linear-gradient(135deg, #fff8ed 0%, #ffffff 100%);
        border: 1px solid rgba(255, 193, 7, 0.22);
        color: #475569;
        line-height: 1.65;
    }

    .property-notes-box strong {
        color: var(--lis-text);
        font-weight: 900;
    }

    .property-actions {
        margin-top: auto;
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .property-actions .btn {
        border-radius: 999px;
        padding: 0.76rem 1.15rem;
        font-weight: 850;
        letter-spacing: 0.01em;
        transition: all 0.22s ease;
    }

    .property-actions .btn-outline-primary {
        background: #ffffff;
        color: var(--lis-blue);
        border: 1px solid rgba(13, 110, 253, 0.32);
        box-shadow: 0 12px 24px rgba(15, 23, 42, 0.05);
    }

    .property-actions .btn-outline-primary:hover {
        background: linear-gradient(135deg, var(--lis-deep), var(--lis-blue));
        border-color: transparent;
        color: #ffffff;
        transform: translateY(-2px);
    }

    .property-actions .btn-dark {
        background: linear-gradient(135deg, var(--lis-deep), var(--lis-blue));
        border: none;
        color: #ffffff;
        box-shadow: 0 16px 32px rgba(13, 110, 253, 0.20);
    }

    .property-actions .btn-dark:hover {
        background: linear-gradient(135deg, var(--lis-deep), var(--lis-teal));
        color: #ffffff;
        transform: translateY(-2px);
        box-shadow: 0 20px 38px rgba(15, 118, 110, 0.24);
    }

    .property-actions .btn-success,
    .property-actions button.btn-success:disabled {
        background: rgba(15, 118, 110, 0.10);
        border: 1px solid rgba(15, 118, 110, 0.16);
        color: var(--lis-teal);
        opacity: 1;
        box-shadow: none;
    }

    .interested-properties-empty-card {
        position: relative;
        overflow: hidden;
        border: 1px solid rgba(15, 42, 64, 0.08);
        border-radius: 34px;
        background:
            radial-gradient(circle at 92% 8%, rgba(255, 193, 7, 0.14), transparent 32%),
            linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
        box-shadow: var(--lis-shadow-strong);
    }

    .interested-properties-empty-card::before {
        content: "";
        position: absolute;
        inset: 0 0 auto 0;
        height: 6px;
        background: linear-gradient(90deg, var(--lis-gold), var(--lis-teal), var(--lis-blue));
        z-index: 2;
    }

    .interested-properties-empty-card .card-body {
        position: relative;
        z-index: 3;
        padding: 3.2rem 1.8rem;
    }

    .empty-property-icon {
        width: 92px;
        height: 92px;
        margin: 0 auto 1.2rem;
        border-radius: 30px;
        background:
            radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.75), transparent 28%),
            linear-gradient(135deg, var(--lis-gold-light), var(--lis-gold));
        color: var(--lis-deep);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 2.65rem;
        box-shadow:
            0 18px 38px rgba(255, 193, 7, 0.28),
            0 0 0 10px rgba(255, 193, 7, 0.10);
    }

    .interested-properties-empty-card h4 {
        color: var(--lis-text);
        font-weight: 950;
        letter-spacing: -0.025em;
    }

    .interested-properties-empty-card p {
        color: var(--lis-muted) !important;
        line-height: 1.75;
        max-width: 620px;
        margin-left: auto;
        margin-right: auto;
    }

    .interested-properties-empty-card .btn-warning {
        border-radius: 999px;
        padding: 0.82rem 1.45rem;
        font-weight: 850;
        background: linear-gradient(135deg, var(--lis-gold-light), var(--lis-gold));
        border: none;
        color: #231707;
        box-shadow: 0 16px 32px rgba(255, 193, 7, 0.24);
    }

    .interested-properties-empty-card .btn-warning:hover {
        background: linear-gradient(135deg, #ffe08a, var(--lis-gold));
        color: #231707;
        transform: translateY(-2px);
    }

    @media (max-width: 767.98px) {
        .interested-properties-section {
            padding: 60px 0;
            min-height: auto;
        }

        .interested-properties-hero {
            border-radius: 30px;
            padding: 2.1rem 1.35rem;
        }

        .interested-properties-hero h1 {
            font-size: 2.1rem;
        }

        .property-interest-card {
            border-radius: 26px;
        }

        .property-image-wrap,
        .property-interest-image,
        .property-placeholder {
            height: 230px;
        }

        .property-interest-body {
            min-height: auto;
        }

        .property-title-row {
            flex-direction: column;
        }

        .property-meta-grid {
            grid-template-columns: 1fr;
        }

        .property-actions {
            flex-direction: column;
        }

        .property-actions .btn,
        .property-actions form,
        .property-actions form button {
            width: 100%;
        }
    }

    @media (max-width: 420px) {
        .interested-properties-hero {
            border-radius: 26px;
        }

        .property-image-wrap,
        .property-interest-image,
        .property-placeholder {
            height: 215px;
        }

        .interested-properties-empty-card {
            border-radius: 28px;
        }
    }
</style>

<section class="interested-properties-section">
    <div class="container interested-properties-wrap">

        <div class="interested-properties-hero">
            <div class="d-flex flex-column flex-lg-row justify-content-between align-items-lg-center gap-3">
                <div>
                    <span class="interested-properties-mini-title">My Stay</span>
                    <h1>Interested Properties</h1>
                    <p>
                        Review the rental properties you are interested in and select your final property when ready.
                    </p>
                </div>

                <div>
                    <a href="{% url 'expat_life:foreigner_dashboard' %}" class="btn btn-outline-dark">
                        <i class="bi bi-arrow-left-circle me-2"></i>
                        Back to Dashboard
                    </a>
                </div>
            </div>
        </div>

        {% if lead.final_rental_property %}
        <div class="final-selected-panel">
            <h5 class="mb-2">
                <i class="bi bi-check-circle-fill me-2"></i>
                Final Selected Property
            </h5>
            <p class="mb-1">
                <strong>{{ lead.final_rental_property.title }}</strong>
            </p>
            <p class="mb-0">
                This property is currently saved as your final rental selection.
            </p>
        </div>
        {% endif %}

        <div class="row g-4">
            {% for interest in interests %}
            <div class="col-lg-6">
                <div class="property-interest-card">
                    {% with listing=interest.listing %}

                        <div class="property-image-wrap">
                            {% if listing.images.first %}
                                <img src="{{ listing.images.first.image.url }}"
                                     class="property-interest-image"
                                     alt="{{ listing.title }}">
                            {% else %}
                                <div class="property-placeholder">
                                    <i class="bi bi-house-heart-fill"></i>
                                </div>
                            {% endif %}

                            <span class="property-status-badge">
                                {{ interest.get_status_display }}
                            </span>
                        </div>

                        <div class="property-interest-body">
                            <div class="property-title-row">
                                <h5 class="property-interest-title">{{ listing.title }}</h5>
                            </div>

                            <p class="property-location">
                                <i class="bi bi-geo-alt me-1"></i>
                                {{ listing.city }}{% if listing.district %}, {{ listing.district }}{% endif %}
                            </p>

                            <div class="property-meta-grid">
                                <div class="property-meta-box">
                                    <span class="property-meta-label">Property Type</span>
                                    <div class="property-meta-value">
                                        {{ listing.get_property_type_display }}
                                    </div>
                                </div>

                                <div class="property-meta-box property-rent-box">
                                    <span class="property-meta-label">Monthly Rent</span>
                                    <div class="property-meta-value">
                                        ${{ listing.monthly_rent_usd|default:"0.00" }}
                                    </div>
                                </div>

                                <div class="property-meta-box">
                                    <span class="property-meta-label">Visibility</span>
                                    <div class="property-meta-value">
                                        {{ listing.get_listing_visibility_display }}
                                    </div>
                                </div>
                            </div>

                            {% if interest.notes %}
                            <div class="property-notes-box">
                                <strong>Your Notes:</strong>
                                <div>{{ interest.notes }}</div>
                            </div>
                            {% endif %}

                            <div class="property-actions">
                                <a href="{% url 'expat_life:rental_detail' listing.slug %}" class="btn btn-outline-primary">
                                    <i class="bi bi-eye me-2"></i>
                                    View Details
                                </a>

                                {% if lead.final_rental_property and lead.final_rental_property.id == listing.id %}
                                    <button class="btn btn-success" disabled>
                                        <i class="bi bi-check-circle me-2"></i>
                                        Final Property Selected
                                    </button>
                                {% else %}
                                    <form method="post" action="{% url 'expat_life:select_final_rental_property' interest.id %}">
                                        {% csrf_token %}
                                        <button type="submit" class="btn btn-dark">
                                            <i class="bi bi-house-check me-2"></i>
                                            Select Final Property
                                        </button>
                                    </form>
                                {% endif %}
                            </div>
                        </div>

                    {% endwith %}
                </div>
            </div>
            {% empty %}
            <div class="col-12">
                <div class="interested-properties-empty-card">
                    <div class="card-body text-center">
                        <div class="empty-property-icon">
                            <i class="bi bi-house-heart"></i>
                        </div>

                        <h4>No Interested Properties Yet</h4>

                        <p class="mb-4">
                            You have not marked any rental properties as interested yet.
                            Browse available rentals and save the ones you would like to review later.
                        </p>

                        <a href="{% url 'expat_life:public_rental_list' %}" class="btn btn-warning">
                            <i class="bi bi-search me-2"></i>
                            Browse Rental Properties
                        </a>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>

    </div>
</section>

{% endblock %}