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

{% block title %}Assistants and Local Service Partners | Trusted Local Support in Sri Lanka{% endblock %}

{% block content %}

<style>
    .guest-service-list-page {
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.07), transparent 28%),
            radial-gradient(circle at 88% 18%, rgba(13, 110, 253, 0.09), transparent 30%),
            linear-gradient(180deg, #f8fbff 0%, #ffffff 48%, #eef6ff 100%);
        overflow: hidden;
    }

    /* =========================
       HERO
       ========================= */
    .guest-service-list-hero {
        position: relative;
        padding: 5.7rem 0 8rem;
        background-color: #0d1f2a;
        color: #fff;
        overflow: hidden;
    }

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

    .guest-service-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-service-list-hero .container {
        position: relative;
        z-index: 2;
    }

    .guest-service-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-service-badge i {
        color: #ffc107;
    }

    .guest-service-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-service-list-hero .lead {
        color: rgba(255, 255, 255, 0.88) !important;
        font-size: 1.12rem;
        line-height: 1.85;
        max-width: 850px;
    }

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

    .guest-service-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-service-hero-point i {
        color: #ffc107;
        font-size: 1.2rem;
    }

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

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

    /* =========================
       FILTER PANEL
       ========================= */
    .guest-service-filter-panel {
        padding: 1.7rem;
        margin-top: -5rem;
        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 #dbeafe;
    }

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

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

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

    .guest-service-filter-panel .form-label {
        color: #0f172a;
        font-size: .88rem;
        font-weight: 850 !important;
    }

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

    .guest-service-filter-panel .form-select:focus,
    .guest-service-filter-panel .form-control:focus {
        border-color: #0d6efd;
        box-shadow: 0 0 0 .22rem rgba(13, 110, 253, 0.12);
    }

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

    .guest-service-filter-panel .btn-dark {
        border: none;
        background: linear-gradient(135deg, #0d6efd, #0b3f74);
        box-shadow: 0 16px 30px rgba(13, 110, 253, 0.20);
    }

    .guest-service-filter-panel .btn-dark:hover {
        background: linear-gradient(135deg, #0b5ed7, #082f5f);
    }

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

    .guest-service-filter-panel .btn-outline-secondary:hover {
        background: #0d6efd;
        border-color: #0d6efd;
        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 #dbeafe;
        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(13, 110, 253, 0.10);
        color: #0d6efd;
        font-weight: 850;
        border: 1px solid rgba(13, 110, 253, 0.14);
    }

    /* =========================
       SERVICE CARDS
       ========================= */
    .guest-service-profile-card {
        border-radius: 32px !important;
        border: 1px solid #dbeafe !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-service-profile-card:hover {
        transform: translateY(-8px);
        box-shadow: 0 38px 92px rgba(15, 23, 42, 0.18) !important;
        border-color: rgba(13, 110, 253, 0.30) !important;
    }

    .guest-service-image-wrap {
        position: relative;
        height: 305px;
        overflow: hidden;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.14), transparent 35%),
            radial-gradient(circle at bottom right, rgba(13, 110, 253, 0.18), transparent 35%),
            #eef6ff;
    }

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

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

    .guest-service-placeholder {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #0d6efd;
        font-size: 3rem;
    }

    .guest-service-type-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(13, 110, 253, 0.16);
        color: #0d6efd;
        font-size: .76rem;
        font-weight: 900;
        backdrop-filter: blur(8px);
        box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
    }

    .guest-service-featured-badge {
        position: absolute;
        top: 1rem;
        right: 1rem;
        display: inline-flex;
        align-items: center;
        gap: .35rem;
        padding: .48rem .78rem;
        border-radius: 999px;
        background: rgba(255, 193, 7, 0.94);
        border: 1px solid rgba(255, 193, 7, 0.36);
        color: #422006;
        font-size: .76rem;
        font-weight: 900;
        backdrop-filter: blur(8px);
        box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
    }

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

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

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

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

    .guest-service-meta i {
        color: #0d6efd;
    }

    .guest-service-intro {
        color: #64748b !important;
        line-height: 1.65;
    }

    .guest-service-info-list {
        list-style: none;
        padding: 0;
        margin: 0 0 1.2rem;
    }

    .guest-service-info-list li {
        display: flex;
        align-items: flex-start;
        gap: .55rem;
        color: #64748b;
        font-size: .9rem;
        line-height: 1.5;
        margin-bottom: .5rem;
    }

    .guest-service-info-list i {
        color: #0d6efd;
        margin-top: .12rem;
    }

    .guest-service-info-list strong {
        color: #0f172a;
    }

    .guest-service-profile-card .btn-outline-dark {
        border-radius: 999px;
        border: 2px solid #0d6efd;
        color: #0d6efd;
        font-weight: 850;
        padding: .68rem 1rem;
    }

    .guest-service-profile-card .btn-outline-dark:hover {
        background: #0d6efd;
        border-color: #0d6efd;
        color: #fff;
    }

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

    .guest-empty-services i {
        width: 74px;
        height: 74px;
        border-radius: 26px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #0d6efd, #0b3f74);
        color: #fff;
        font-size: 2rem;
        margin-bottom: 1.2rem;
        box-shadow: 0 20px 38px rgba(13, 110, 253, 0.20);
    }

    /* =========================
       PAGINATION
       ========================= */
    .guest-service-pagination .page-link {
        border-radius: 999px !important;
        border: 1px solid #dbeafe;
        color: #0d6efd;
        font-weight: 850;
        padding: .62rem .9rem;
        min-width: 44px;
        text-align: center;
        box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
        transition: all 0.2s ease;
    }

    .guest-service-pagination .page-link:hover {
        background: rgba(13, 110, 253, 0.08);
        border-color: rgba(13, 110, 253, 0.20);
        color: #0d6efd;
        transform: translateY(-1px);
    }

    .guest-service-pagination .page-item.active .page-link {
        background: linear-gradient(135deg, #0d6efd, #0b3f74);
        border-color: #0d6efd;
        color: #fff;
        box-shadow: 0 14px 28px rgba(13, 110, 253, 0.22);
    }

    .guest-service-pagination .page-item.disabled .page-link {
        border-color: #dbeafe;
        color: #94a3b8;
        background-color: #f8fbff;
    }

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

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

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

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

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

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

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

        .guest-service-image-wrap {
            height: 285px;
        }
    }
</style>

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

    <!-- HERO -->
    <section class="guest-service-list-hero">
        <div class="container">
            <span class="guest-service-badge">
                <i class="bi bi-person-workspace"></i>
                Local Service Partner Directory
            </span>

            <h1 class="fw-bold mb-3">
                Browse Trusted Assistants and Local Service Partners in Sri Lanka
            </h1>

            <p class="lead mb-0">
                Find approved drivers, housekeepers, helpers, translators, caregivers, and local assistants
                who can support your day-to-day life, travel, relocation, and long-stay experience in Sri Lanka.
            </p>

            <div class="row g-3 guest-service-hero-points">
                <div class="col-md-6 col-lg-3">
                    <div class="guest-service-hero-point">
                        <i class="bi bi-patch-check-fill"></i>
                        <span>Reviewed service profiles</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-service-hero-point">
                        <i class="bi bi-grid-1x2-fill"></i>
                        <span>Multiple support categories</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-service-hero-point">
                        <i class="bi bi-translate"></i>
                        <span>Language and local help</span>
                    </div>
                </div>

                <div class="col-md-6 col-lg-3">
                    <div class="guest-service-hero-point">
                        <i class="bi bi-shield-check"></i>
                        <span>More guided support process</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

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

            <!-- FILTER BOX -->
            <div class="guest-premium-panel guest-service-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 Service Search
                            </span>

                            <h5 class="fw-bold mt-3 mb-1">Find the Right Local Support for Your Sri Lanka Lifestyle</h5>

                            <p class="text-muted mb-0">
                                Filter by service type, city, or keyword to discover suitable local service partners.
                            </p>
                        </div>

                        <div class="d-flex flex-wrap gap-2">
                            <button class="btn btn-dark" type="submit">
                                <i class="bi bi-search me-1"></i>
                                Apply Filters
                            </button>

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

                    <div class="row g-3 align-items-end">
                        <div class="col-md-4">
                            <label class="form-label fw-semibold">Service Type</label>
                            <select name="service_type" class="form-select">
                                <option value="">All Service Types</option>
                                {% for value, label in service_type_choices %}
                                    <option value="{{ value }}" {% if selected_service_type == value %}selected{% endif %}>
                                        {{ label }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>

                        <div class="col-md-4">
                            <label class="form-label fw-semibold">City</label>
                            <select name="city" class="form-select">
                                <option value="">All Cities</option>
                                {% for value, label in city_choices %}
                                    <option value="{{ value }}" {% if selected_city == value %}selected{% endif %}>
                                        {{ label }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>

                        <div class="col-md-4">
                            <label class="form-label fw-semibold">Keyword</label>
                            <input type="text"
                                   name="q"
                                   value="{{ search_query }}"
                                   class="form-control"
                                   placeholder="Search by name, skills, language...">
                        </div>

                        <div class="col-12 d-flex flex-wrap gap-2 d-lg-none">
                            <button class="btn btn-dark" type="submit">
                                <i class="bi bi-search me-1"></i>
                                Apply Filters
                            </button>
                            <a href="{% url 'expat_life:public_assistant_list' %}" class="btn btn-outline-secondary">
                                Reset
                            </a>
                        </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 Service Partners</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 service partner 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>

            <!-- CARDS -->
            <div class="row g-4">
                {% for profile in profiles %}
                    <div class="col-md-6 col-lg-4">
                        <div class="card h-100 guest-service-profile-card">
                            <div class="guest-service-image-wrap">
                                {% if profile.profile_photo %}
                                    <img src="{{ profile.profile_photo.url }}"
                                         class="guest-service-image"
                                         alt="{{ profile.full_name }}">
                                {% else %}
                                    <div class="guest-service-placeholder">
                                        <i class="bi bi-person-workspace"></i>
                                    </div>
                                {% endif %}

                                <div class="guest-service-type-badge">
                                    <i class="bi bi-briefcase-fill"></i>
                                    {{ profile.get_service_type_display }}
                                </div>

                                {% if profile.is_featured %}
                                    <div class="guest-service-featured-badge">
                                        <i class="bi bi-star-fill"></i>
                                        Featured
                                    </div>
                                {% endif %}
                            </div>

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

                                <div class="guest-service-meta">
                                    <span>
                                        <i class="bi bi-geo-alt-fill"></i>
                                        {{ profile.city|default:"Location not specified" }}
                                        {% if profile.district %}, {{ profile.district }}{% endif %}
                                    </span>
                                </div>

                                {% if profile.short_intro %}
                                    <p class="guest-service-intro small mb-3">
                                        {{ profile.short_intro|truncatechars:120 }}
                                    </p>
                                {% endif %}

                                <ul class="guest-service-info-list">
                                    {% if profile.languages_spoken %}
                                        <li>
                                            <i class="bi bi-translate"></i>
                                            <span><strong>Languages:</strong> {{ profile.languages_spoken }}</span>
                                        </li>
                                    {% endif %}

                                    {% if profile.experience_summary %}
                                        <li>
                                            <i class="bi bi-award-fill"></i>
                                            <span><strong>Experience:</strong> {{ profile.experience_summary|truncatechars:60 }}</span>
                                        </li>
                                    {% endif %}

                                    {% if profile.education %}
                                        <li>
                                            <i class="bi bi-mortarboard-fill"></i>
                                            <span><strong>Education:</strong> {{ profile.education }}</span>
                                        </li>
                                    {% endif %}
                                </ul>

                                <div class="mt-auto">
                                    <a href="{% url 'expat_life:public_assistant_detail' profile.pk %}" class="btn btn-outline-dark w-100">
                                        View Details
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                {% empty %}
                    <div class="col-12">
                        <div class="guest-empty-services">
                            <i class="bi bi-search"></i>
                            <h5 class="fw-bold mb-2">No service partner profiles found</h5>
                            <p class="text-muted mb-4">
                                Try changing the service type, city, or keyword search to discover more local support profiles.
                            </p>

                            <a href="{% url 'expat_life:public_assistant_list' %}" class="btn btn-dark 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="Assistant list pagination" class="guest-service-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 %}