{% extends 'expat_life/base.html' %}
{% load static %}

{% block title %}Browse Sri Lankan Dating Partners | Guest Relationship Introductions{% endblock %}

{% block content %}

<style>
    .guest-partner-list-page {
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.08), transparent 28%),
            radial-gradient(circle at 90% 16%, rgba(194, 24, 91, 0.08), transparent 30%),
            linear-gradient(180deg, #fff7fb 0%, #ffffff 46%, #fff1f6 100%);
        overflow: hidden;
    }

    /* =========================
       HERO
       ========================= */
    .guest-partner-list-hero {
        position: relative;
        padding: 5.7rem 0 4.7rem;
        background-color: #2a0d1f;
        overflow: hidden;
        color: #fff;
    }

    .guest-partner-list-hero::before {
        content: "";
        position: absolute;
        inset: 0;
        background:
            linear-gradient(
                90deg,
                rgba(36, 9, 27, 0.94) 0%,
                rgba(36, 9, 27, 0.82) 42%,
                rgba(36, 9, 27, 0.58) 72%,
                rgba(36, 9, 27, 0.42) 100%
            ),
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.18), transparent 28%),
            radial-gradient(circle at bottom right, rgba(194, 24, 91, 0.22), transparent 35%),
            url("{% static 'expat_life/images/dating_partners_hero.webp' %}") center center / cover no-repeat;
        transform: scale(1.02);
        z-index: 0;
    }

    .guest-partner-list-hero::after {
        content: "";
        position: absolute;
        right: -150px;
        bottom: -180px;
        width: 520px;
        height: 520px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.08);
        pointer-events: none;
        z-index: 1;
    }

    .guest-partner-list-hero .container {
        position: relative;
        z-index: 2;
    }

    .guest-partner-badge {
        display: inline-flex;
        align-items: center;
        gap: .5rem;
        background: rgba(255, 193, 7, 0.18);
        color: #ffc107;
        border: 1px solid rgba(255, 193, 7, 0.36);
        padding: .55rem 1rem;
        border-radius: 999px;
        font-weight: 850;
        font-size: .82rem;
        letter-spacing: .055em;
        text-transform: uppercase;
        margin-bottom: 1rem;
        backdrop-filter: blur(8px);
    }

    .guest-partner-badge i {
        color: #ffd166;
    }

    .guest-partner-list-hero h1 {
        color: #fff;
        font-size: clamp(2.45rem, 4.5vw, 4.4rem);
        font-weight: 950;
        line-height: 1.04;
        letter-spacing: -0.055em;
        max-width: 900px;
    }

    .guest-partner-list-hero .lead {
        color: rgba(255, 255, 255, 0.88) !important;
        font-size: 1.12rem;
        line-height: 1.85;
        max-width: 820px;
    }

    .guest-partner-hero-points {
        margin-top: 1.8rem;
    }

    .guest-partner-hero-point {
        height: 100%;
        display: flex;
        align-items: center;
        gap: .75rem;
        padding: .95rem 1rem;
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.11);
        border: 1px solid rgba(255, 255, 255, 0.16);
        color: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(8px);
        line-height: 1.5;
        font-weight: 650;
    }

    .guest-partner-hero-point i {
        color: #ffc107;
        font-size: 1.2rem;
    }

    /* =========================
       MAIN
       ========================= */
    .guest-partner-main {
        position: relative;
        padding: 4rem 0 5rem;
    }

    .guest-premium-panel {
        border-radius: 32px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid #f1dce7;
        box-shadow: 0 24px 62px rgba(15, 23, 42, 0.09);
    }

    /* =========================
       FILTER PANEL
       ========================= */
    .guest-partner-filter-panel {
        padding: 1.7rem;
        margin-top: -6rem;
        position: relative;
        z-index: 5;
    }

    .guest-filter-title-row {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 1rem;
        align-items: flex-start;
        padding-bottom: 1rem;
        margin-bottom: 1.25rem;
        border-bottom: 1px solid #f1dce7;
    }

    .guest-section-kicker {
        display: inline-flex;
        align-items: center;
        gap: .45rem;
        background: rgba(194, 24, 91, 0.10);
        color: #c2185b !important;
        border: 1px solid rgba(194, 24, 91, 0.16);
        font-size: .78rem;
        font-weight: 900 !important;
        text-transform: uppercase;
        letter-spacing: .08em;
        padding: .45rem .85rem;
        border-radius: 999px;
    }

    .guest-partner-filter-panel h5,
    .guest-results-heading h5 {
        color: #0f172a;
        font-weight: 950;
        letter-spacing: -0.02em;
    }

    .guest-partner-filter-panel p,
    .guest-results-heading p {
        color: #64748b !important;
        line-height: 1.7;
    }

    .guest-partner-filter-panel .form-select,
    .guest-partner-filter-panel .form-control {
        min-height: 50px;
        border-radius: 16px;
        border: 1px solid #e5c8d8;
        background-color: #ffffff;
        color: #0f172a;
        box-shadow: none;
        font-weight: 650;
    }

    .guest-partner-filter-panel .form-select:focus,
    .guest-partner-filter-panel .form-control:focus {
        border-color: #c2185b;
        box-shadow: 0 0 0 .22rem rgba(194, 24, 91, 0.12);
    }

    .guest-partner-filter-panel .btn {
        border-radius: 999px;
        font-weight: 850;
        padding: .78rem 1.15rem;
    }

    .guest-partner-filter-panel .btn-primary {
        border: none;
        background: linear-gradient(135deg, #c2185b, #7c3aed);
        box-shadow: 0 16px 30px rgba(194, 24, 91, 0.20);
    }

    .guest-partner-filter-panel .btn-primary:hover {
        background: linear-gradient(135deg, #db2777, #8b5cf6);
    }

    .guest-partner-filter-panel .btn-outline-secondary {
        border: 2px solid #c2185b;
        color: #c2185b;
        background: transparent;
    }

    .guest-partner-filter-panel .btn-outline-secondary:hover {
        background: #c2185b;
        border-color: #c2185b;
        color: #fff;
    }

    /* =========================
       RESULTS SUMMARY
       ========================= */
    .guest-results-heading {
        padding: 1.35rem 1.5rem;
        border-radius: 26px;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.08), transparent 30%),
            #ffffff;
        border: 1px solid #f1dce7;
        box-shadow: 0 18px 42px rgba(15, 23, 42, 0.06);
    }

    .guest-page-pill {
        display: inline-flex;
        align-items: center;
        gap: .45rem;
        padding: .55rem .9rem;
        border-radius: 999px;
        background: rgba(194, 24, 91, 0.10);
        color: #c2185b;
        font-weight: 850;
        border: 1px solid rgba(194, 24, 91, 0.14);
    }

    /* =========================
       PROFILE CARDS
       ========================= */
    .guest-partner-profile-card {
        border-radius: 32px !important;
        border: 1px solid #f1dce7 !important;
        box-shadow: 0 26px 68px rgba(15, 23, 42, 0.11) !important;
        overflow: hidden;
        transition: all .28s ease;
        background: rgba(255, 255, 255, 0.98);
    }

    .guest-partner-profile-card:hover {
        transform: translateY(-8px);
        box-shadow: 0 38px 92px rgba(15, 23, 42, 0.18) !important;
        border-color: rgba(194, 24, 91, 0.28) !important;
    }

    .guest-partner-image-wrap {
        position: relative;
        height: 315px;
        overflow: hidden;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.14), transparent 35%),
            radial-gradient(circle at bottom right, rgba(194, 24, 91, 0.18), transparent 35%),
            #fff1f6;
    }

    .guest-partner-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition: transform .35s ease;
    }

    .guest-partner-profile-card:hover .guest-partner-image {
        transform: scale(1.045);
    }

    .guest-partner-card-badge {
        position: absolute;
        top: 1rem;
        left: 1rem;
        display: inline-flex;
        align-items: center;
        gap: .35rem;
        padding: .48rem .78rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.94);
        border: 1px solid rgba(194, 24, 91, 0.16);
        color: #c2185b;
        font-size: .76rem;
        font-weight: 900;
        backdrop-filter: blur(8px);
        box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
    }

    .guest-partner-card-body {
        padding: 1.45rem;
    }

    .guest-partner-card-body h5 {
        color: #0f172a;
        font-weight: 950;
        letter-spacing: -0.02em;
    }

    .guest-partner-meta {
        display: flex;
        flex-wrap: wrap;
        gap: .45rem;
        margin-bottom: .9rem;
    }

    .guest-partner-meta span {
        display: inline-flex;
        align-items: center;
        gap: .35rem;
        padding: .42rem .68rem;
        border-radius: 999px;
        background: #fff1f6;
        border: 1px solid #f1dce7;
        color: #64748b;
        font-size: .84rem;
        font-weight: 750;
    }

    .guest-partner-meta i {
        color: #c2185b;
    }

    .guest-partner-goal {
        padding: .9rem;
        border-radius: 18px;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.10), transparent 30%),
            #fff7fb;
        border: 1px solid #f1dce7;
        color: #475569;
        line-height: 1.55;
    }

    .guest-partner-goal strong {
        color: #0f172a;
    }

    .guest-partner-profile-card .btn-outline-primary {
        border-radius: 999px;
        border: 2px solid #c2185b;
        color: #c2185b;
        font-weight: 850;
        padding: .68rem 1rem;
    }

    .guest-partner-profile-card .btn-outline-primary:hover {
        background: #c2185b;
        border-color: #c2185b;
        color: #fff;
    }

    .guest-empty-profiles {
        border-radius: 32px;
        padding: 3rem 1.5rem;
        background: #ffffff;
        border: 1px solid #f1dce7;
        box-shadow: 0 24px 60px rgba(15, 23, 42, 0.09);
        text-align: center;
    }

    .guest-empty-profiles i {
        width: 74px;
        height: 74px;
        border-radius: 26px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #c2185b, #7c3aed);
        color: #fff;
        font-size: 2rem;
        margin-bottom: 1.2rem;
        box-shadow: 0 20px 38px rgba(194, 24, 91, 0.20);
    }

    /* =========================
       PAGINATION
       ========================= */
    .guest-partner-pagination .page-link {
        border-radius: 999px !important;
        border: 1px solid #f1dce7;
        color: #c2185b;
        font-weight: 850;
        padding: .62rem .9rem;
        box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
    }

    .guest-partner-pagination .page-link:hover {
        background: rgba(194, 24, 91, 0.08);
        border-color: rgba(194, 24, 91, 0.20);
        color: #c2185b;
    }

    .guest-partner-pagination .page-item.active .page-link {
        background: linear-gradient(135deg, #c2185b, #7c3aed);
        border-color: #c2185b;
        color: #fff;
        box-shadow: 0 14px 28px rgba(194, 24, 91, 0.22);
    }

    @media (max-width: 991.98px) {
        .guest-partner-list-hero {
            padding: 4.5rem 0 8rem;
        }

        .guest-partner-filter-panel {
            margin-top: -5rem;
        }

        .guest-premium-panel {
            border-radius: 28px;
        }
    }

    @media (max-width: 575.98px) {
        .guest-partner-list-hero {
            padding: 3.5rem 0 7rem;
        }

        .guest-partner-list-hero h1 {
            font-size: 2.35rem;
        }

        .guest-partner-filter-panel,
        .guest-results-heading {
            padding: 1.2rem;
        }

        .guest-partner-profile-card,
        .guest-premium-panel,
        .guest-empty-profiles {
            border-radius: 24px !important;
        }

        .guest-partner-image-wrap {
            height: 295px;
        }
    }
</style>

<div class="guest-partner-list-page">

    <!-- HERO -->
    <section class="guest-partner-list-hero">
        <div class="container">
            <span class="guest-partner-badge">
                <i class="bi bi-heart-fill"></i>
                Browse Local Partner Profiles
            </span>

            <h1 class="fw-bold mb-3">
                Discover Approved Sri Lankan Dating and Marriage Partner Profiles
            </h1>

            <p class="lead mb-0">
                Explore local Sri Lankan candidates interested in sincere relationships, companionship,
                long-term commitment, and marriage-oriented introductions through a more respectful Guest platform.
            </p>

            <div class="row g-3 guest-partner-hero-points">
                <div class="col-md-6 col-lg-3">
                    <div class="guest-partner-hero-point">
                        <i class="bi bi-person-check-fill"></i>
                        <span>Approved public profiles</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-partner-hero-point">
                        <i class="bi bi-shield-lock-fill"></i>
                        <span>Protected contact process</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-partner-hero-point">
                        <i class="bi bi-chat-heart-fill"></i>
                        <span>Respectful introductions</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-partner-hero-point">
                        <i class="bi bi-heart-arrow"></i>
                        <span>Serious relationship focus</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- MAIN -->
    <section class="guest-partner-main">
        <div class="container">

            <!-- FILTER BOX -->
            <div class="guest-premium-panel guest-partner-filter-panel mb-4">
                <form method="get">
                    <div class="guest-filter-title-row">
                        <div>
                            <span class="guest-section-kicker">
                                <i class="bi bi-sliders"></i>
                                Smart Profile Search
                            </span>

                            <h5 class="fw-bold mt-3 mb-1">Find Profiles That Match Your Relationship Intention</h5>

                            <p class="text-muted mb-0">
                                Filter by gender, relationship goal, and city to explore suitable local profiles.
                            </p>
                        </div>

                        <div class="d-flex flex-wrap gap-2">
                            <button class="btn btn-primary" type="submit">
                                <i class="bi bi-search me-1"></i>
                                Filter Profiles
                            </button>

                            <a href="{% url 'expat_life:public_partner_list' %}" class="btn btn-outline-secondary">
                                Reset Filters
                            </a>
                        </div>
                    </div>

                    <div class="row g-3 align-items-end">
                        <div class="col-md-3">
                            <select name="gender" class="form-select">
                                <option value="">All Genders</option>
                                <option value="male" {% if selected_gender == 'male' %}selected{% endif %}>Male</option>
                                <option value="female" {% if selected_gender == 'female' %}selected{% endif %}>Female</option>
                                <option value="other" {% if selected_gender == 'other' %}selected{% endif %}>Other</option>
                            </select>
                        </div>

                        <div class="col-md-4">
                            <select name="goal" class="form-select">
                                <option value="">All Relationship Goals</option>
                                <option value="marriage" {% if selected_goal == 'marriage' %}selected{% endif %}>Marriage</option>
                                <option value="long_term" {% if selected_goal == 'long_term' %}selected{% endif %}>Long Term Relationship</option>
                                <option value="friendship_first" {% if selected_goal == 'friendship_first' %}selected{% endif %}>Friendship First</option>
                            </select>
                        </div>

                        <div class="col-md-3">
                            <input
                                type="text"
                                name="city"
                                class="form-control"
                                placeholder="Search by city"
                                value="{{ selected_city }}"
                            >
                        </div>

                        <div class="col-md-2 d-grid d-lg-none">
                            <button class="btn btn-primary" type="submit">
                                Filter
                            </button>
                        </div>
                    </div>
                </form>
            </div>

            <!-- SUMMARY -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="guest-results-heading d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3">
                        <div>
                            <h5 class="fw-bold mb-1">Available Profiles</h5>

                            {% if total_results > 0 %}
                                <p class="text-muted mb-0">
                                    Showing {{ page_obj.start_index }}–{{ page_obj.end_index }} of {{ total_results }} profile{{ total_results|pluralize }}
                                </p>
                            {% else %}
                                <p class="text-muted mb-0">No profiles found for the selected filters.</p>
                            {% endif %}
                        </div>

                        {% if page_obj.paginator.num_pages > 1 %}
                            <div class="guest-page-pill">
                                <i class="bi bi-layers"></i>
                                Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- PROFILES -->
            <div class="row g-4">
                {% for profile in profiles %}
                    <div class="col-md-6 col-lg-4">
                        <div class="card h-100 guest-partner-profile-card">
                            <div class="guest-partner-image-wrap">
                                {% if profile.profile_photo %}
                                    <img src="{{ profile.profile_photo.url }}"
                                         class="guest-partner-image"
                                         alt="{{ profile.full_name }}">
                                {% else %}
                                    <img src="{% static 'expat_life/images/default-profile.jpg' %}"
                                         class="guest-partner-image"
                                         alt="Profile">
                                {% endif %}

                                <div class="guest-partner-card-badge">
                                    <i class="bi bi-patch-check-fill"></i>
                                    Approved Profile
                                </div>
                            </div>

                            <div class="guest-partner-card-body d-flex flex-column">
                                <h5 class="fw-bold mb-2">
                                    {{ profile.display_name|default:profile.full_name }}
                                </h5>

                                <div class="guest-partner-meta">
                                    <span>
                                        <i class="bi bi-calendar-heart"></i>
                                        {{ profile.age }} years
                                    </span>

                                    {% if profile.city %}
                                        <span>
                                            <i class="bi bi-geo-alt-fill"></i>
                                            {{ profile.city }}
                                        </span>
                                    {% endif %}
                                </div>

                                <div class="guest-partner-goal mb-3">
                                    <strong>Relationship Goal:</strong>
                                    {{ profile.get_relationship_goal_display }}
                                </div>

                                <div class="mt-auto">
                                    <a href="{% url 'expat_life:public_partner_detail' profile.pk %}" class="btn btn-outline-primary w-100">
                                        View Full Profile
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                {% empty %}
                    <div class="col-12">
                        <div class="guest-empty-profiles">
                            <i class="bi bi-search-heart-fill"></i>
                            <h5 class="fw-bold mb-2">No profiles found</h5>
                            <p class="text-muted mb-4">
                                Try changing the gender, relationship goal, or city filter to discover more local partner profiles.
                            </p>

                            <a href="{% url 'expat_life:public_partner_list' %}" class="btn btn-primary rounded-pill px-4">
                                Reset Filters
                            </a>
                        </div>
                    </div>
                {% endfor %}
            </div>

            <!-- PAGINATION -->
            {% if page_obj.paginator.num_pages > 1 %}
                <div class="row mt-5">
                    <div class="col-12">
                        <nav aria-label="Partner profile pagination" class="guest-partner-pagination">
                            <ul class="pagination justify-content-center flex-wrap gap-2">

                                {% if page_obj.has_previous %}
                                    <li class="page-item">
                                        <a class="page-link px-3"
                                           href="?{% if query_string %}{{ query_string }}&{% endif %}page=1">
                                            First
                                        </a>
                                    </li>

                                    <li class="page-item">
                                        <a class="page-link px-3"
                                           href="?{% if query_string %}{{ query_string }}&{% endif %}page={{ page_obj.previous_page_number }}">
                                            Previous
                                        </a>
                                    </li>
                                {% endif %}

                                {% for num in page_obj.paginator.page_range %}
                                    {% if num == page_obj.number %}
                                        <li class="page-item active">
                                            <span class="page-link px-3">{{ num }}</span>
                                        </li>
                                    {% elif num >= page_obj.number|add:'-2' and num <= page_obj.number|add:'2' %}
                                        <li class="page-item">
                                            <a class="page-link px-3"
                                               href="?{% if query_string %}{{ query_string }}&{% endif %}page={{ num }}">
                                                {{ num }}
                                            </a>
                                        </li>
                                    {% endif %}
                                {% endfor %}

                                {% if page_obj.has_next %}
                                    <li class="page-item">
                                        <a class="page-link px-3"
                                           href="?{% if query_string %}{{ query_string }}&{% endif %}page={{ page_obj.next_page_number }}">
                                            Next
                                        </a>
                                    </li>

                                    <li class="page-item">
                                        <a class="page-link px-3"
                                           href="?{% if query_string %}{{ query_string }}&{% endif %}page={{ page_obj.paginator.num_pages }}">
                                            Last
                                        </a>
                                    </li>
                                {% endif %}

                            </ul>
                        </nav>
                    </div>
                </div>
            {% endif %}

        </div>
    </section>

</div>

{% endblock %}