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

{% block title %}Payment Successful | Live in Sri Lanka{% endblock %}

{% block content %}

<style>
    .payment-success-hero {
        position: relative;
        min-height: 520px;
        background-color: #0e1a22;
        overflow: hidden;
    }

    .payment-success-bg {
        position: absolute;
        inset: 0;
        background:
            url("{% static 'expat_life/images/foreigner_payment_success.webp' %}")
            center center / cover no-repeat;
        transform: scale(1.04);
        z-index: 0;
    }

    .payment-success-overlay {
        position: absolute;
        inset: 0;
        background:
            linear-gradient(
                90deg,
                rgba(7, 19, 28, 0.88) 0%,
                rgba(7, 19, 28, 0.72) 42%,
                rgba(7, 19, 28, 0.50) 70%,
                rgba(7, 19, 28, 0.38) 100%
            ),
            radial-gradient(
                circle at 75% 20%,
                rgba(255, 193, 7, 0.20),
                transparent 32%
            ),
            linear-gradient(
                180deg,
                rgba(0, 0, 0, 0.15) 0%,
                rgba(0, 0, 0, 0.35) 100%
            );
        z-index: 1;
    }

    .payment-success-content {
        position: relative;
        z-index: 2;
        padding: 90px 0 120px;
    }

    .payment-success-badge {
        display: inline-flex;
        align-items: center;
        gap: .45rem;
        padding: .45rem .9rem;
        border-radius: 999px;
        background: rgba(255, 193, 7, 0.16);
        color: #ffc107;
        border: 1px solid rgba(255, 193, 7, 0.35);
        font-size: .78rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .08em;
        backdrop-filter: blur(10px);
    }

    .payment-success-title {
        color: #fff;
        font-weight: 800;
        letter-spacing: -.04em;
    }

    .payment-success-subtitle {
        color: rgba(255, 255, 255, 0.82);
        max-width: 700px;
        line-height: 1.65;
    }

    .payment-success-icon {
        width: 92px;
        height: 92px;
        border-radius: 28px;
        background: linear-gradient(135deg, #ffc107, #ffda6a);
        color: #0e1a22;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 3rem;
        box-shadow: 0 22px 55px rgba(255, 193, 7, 0.30);
    }

    .payment-success-main {
        margin-top: -82px;
        position: relative;
        z-index: 4;
        padding-bottom: 70px;
    }

    .payment-premium-card {
        background: #fff;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 30px;
        box-shadow: 0 24px 70px rgba(15, 23, 42, 0.13);
        overflow: hidden;
    }

    .payment-card-header {
        padding: 1.4rem 1.6rem;
        background:
            linear-gradient(135deg, #ffffff, #fffaf0),
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.18), transparent 35%);
        border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    }

    .payment-card-header h4 {
        margin: 0;
        font-weight: 800;
        color: #0e1a22;
    }

    .payment-card-header p {
        margin: .25rem 0 0;
        color: #64748b;
        font-size: .92rem;
    }

    .payment-summary-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }

    .payment-summary-box {
        padding: 1rem;
        border-radius: 20px;
        background: #f8fafc;
        border: 1px solid #e5e7eb;
    }

    .payment-summary-box .label {
        display: block;
        color: #64748b;
        font-size: .76rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .06em;
        margin-bottom: .35rem;
    }

    .payment-summary-box .value {
        color: #0f172a;
        font-weight: 800;
        font-size: 1rem;
    }

    .payment-amount-highlight {
        background: linear-gradient(135deg, #0e1a22, #1e293b);
        color: #fff;
        border: none;
        position: relative;
        overflow: hidden;
    }

    .payment-amount-highlight::after {
        content: "";
        position: absolute;
        width: 140px;
        height: 140px;
        border-radius: 50%;
        background: rgba(255, 193, 7, 0.22);
        right: -55px;
        top: -55px;
    }

    .payment-amount-highlight .label,
    .payment-amount-highlight .value {
        color: #fff;
        position: relative;
        z-index: 2;
    }

    .payment-amount-highlight .value {
        color: #ffc107;
        font-size: 1.35rem;
    }

    .payment-items-list {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .payment-item-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: 1rem 0;
        border-bottom: 1px solid #e5e7eb;
    }

    .payment-item-row:last-child {
        border-bottom: 0;
        padding-bottom: 0;
    }

    .payment-item-icon {
        width: 42px;
        height: 42px;
        border-radius: 15px;
        background: rgba(25, 135, 84, 0.10);
        color: #198754;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .payment-item-title {
        font-weight: 800;
        color: #0f172a;
        margin-bottom: .12rem;
    }

    .payment-item-note {
        color: #64748b;
        font-size: .84rem;
    }

    .payment-next-step-card {
        border-radius: 24px;
        padding: 1.4rem;
        background:
            linear-gradient(135deg, #fff7ed, #ffffff);
        border: 1px solid rgba(255, 193, 7, 0.25);
    }

    .payment-next-step-card h5 {
        color: #0e1a22;
        font-weight: 800;
    }

    .payment-next-step-card p {
        color: #64748b;
        line-height: 1.6;
    }

    .payment-trust-note {
        border-radius: 20px;
        background: rgba(14, 26, 34, 0.04);
        border: 1px solid rgba(14, 26, 34, 0.08);
        padding: 1rem;
        color: #475569;
        font-size: .92rem;
    }

    .payment-trust-note i {
        color: #ffc107;
    }

    .payment-actions .btn-warning {
        background: #ffc107;
        border-color: #ffc107;
        color: #0e1a22;
        font-weight: 800;
    }

    .payment-actions .btn-dark {
        background: #0e1a22;
        border-color: #0e1a22;
        font-weight: 800;
    }

    @media (max-width: 767.98px) {
        .payment-success-content {
            padding: 70px 0 105px;
        }

        .payment-summary-grid {
            grid-template-columns: 1fr;
        }

        .payment-item-row {
            align-items: flex-start;
        }
    }
    
    @media (max-width: 575.98px) {
        .payment-success-content,
        .payment-cancel-content,
        .payment-failed-content {
            padding-left: 1.15rem;
            padding-right: 1.15rem;
        }

        .payment-success-title,
        .payment-cancel-title,
        .payment-failed-title {
            font-size: 2.15rem;
            line-height: 1.12;
        }

        .payment-success-subtitle,
        .payment-cancel-subtitle,
        .payment-failed-subtitle {
            font-size: 1rem;
            line-height: 1.55;
        }

        .payment-success-badge,
        .payment-cancel-badge,
        .payment-failed-badge {
            max-width: 100%;
            white-space: normal;
            line-height: 1.35;
        }

        .payment-success-icon,
        .payment-cancel-icon,
        .payment-failed-icon {
            width: 76px;
            height: 76px;
            border-radius: 22px;
            font-size: 2.35rem;
        }

        .payment-premium-card {
            border-radius: 24px;
        }

        .payment-card-header,
        .payment-premium-card .p-4,
        .payment-premium-card .p-md-5 {
            padding-left: 1.15rem !important;
            padding-right: 1.15rem !important;
        }
    }
</style>

<section class="payment-success-hero">
    <div class="payment-success-bg"></div>
    <div class="payment-success-overlay"></div>

    <div class="container payment-success-content">
        <div class="row align-items-center">
            <div class="col-lg-8 text-white">
                <span class="payment-success-badge mb-4">
                    <i class="bi bi-shield-check"></i>
                    Secure Payment Completed
                </span>

                <h1 class="display-4 payment-success-title mb-3">
                    Payment Successful
                </h1>

                <p class="lead payment-success-subtitle mb-0">
                    Thank you. Your payment has been recorded successfully, and your Guest account
                    has been updated based on the selected payment items.
                </p>
            </div>

            <div class="col-lg-4 text-lg-end mt-4 mt-lg-0">
                <div class="payment-success-icon">
                    <i class="bi bi-check-circle-fill"></i>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="payment-success-main">
    <div class="container">
        <div class="payment-premium-card mx-auto" style="max-width:1050px;">

            <div class="payment-card-header">
                <div class="d-flex flex-column flex-md-row justify-content-between gap-3">
                    <div>
                        <h4>Payment Confirmation</h4>
                        <p>
                            Transaction reference and paid item summary for your Live in Sri Lanka Guest account.
                        </p>
                    </div>

                    <div class="text-md-end">
                        <span class="badge rounded-pill text-bg-success px-3 py-2">
                            {{ payment_transaction.get_status_display }}
                        </span>
                    </div>
                </div>
            </div>

            <div class="p-4 p-md-5">

                <div class="payment-summary-grid mb-4">

                    <div class="payment-summary-box">
                        <span class="label">Transaction No</span>
                        <span class="value">#{{ payment_transaction.id }}</span>
                    </div>

                    <div class="payment-summary-box">
                        <span class="label">Payment Method</span>
                        <span class="value">
                            {{ payment_transaction.get_payment_method_display }}
                        </span>
                    </div>

                    <div class="payment-summary-box payment-amount-highlight">
                        <span class="label">Total Selected Amount</span>
                        <span class="value">
                            ${{ payment_transaction.total_amount_usd }}
                        </span>
                    </div>

                    <div class="payment-summary-box">
                        <span class="label">Gateway Paid</span>
                        <span class="value">
                            ${{ payment_transaction.gateway_amount_usd }}
                        </span>
                    </div>

                    <div class="payment-summary-box">
                        <span class="label">Wallet Used</span>
                        <span class="value">
                            ${{ payment_transaction.wallet_deduction_usd }}
                        </span>
                    </div>

                    <div class="payment-summary-box">
                        <span class="label">Gateway Reference</span>
                        <span class="value">
                            {% if payment_transaction.gateway_transaction_id %}
                                {{ payment_transaction.gateway_transaction_id }}
                            {% elif payment_transaction.gateway_session_id %}
                                {{ payment_transaction.gateway_session_id }}
                            {% else %}
                                Internal wallet payment
                            {% endif %}
                        </span>
                    </div>

                </div>

                <div class="row g-4">
                    <div class="col-lg-7">
                        <div class="border rounded-4 p-4 h-100">
                            <div class="d-flex align-items-center justify-content-between mb-3">
                                <div>
                                    <h5 class="fw-bold mb-1">Paid Items</h5>
                                    <p class="text-muted small mb-0">
                                        These items were included in this payment transaction.
                                    </p>
                                </div>
                                <i class="bi bi-receipt-cutoff fs-3 text-warning"></i>
                            </div>

                            <ul class="payment-items-list">
                                {% for item in payment_transaction.items.all %}
                                    <li class="payment-item-row">
                                        <div class="d-flex align-items-start gap-3">
                                            <div class="payment-item-icon">
                                                <i class="bi bi-check2-circle"></i>
                                            </div>

                                            <div>
                                                <div class="payment-item-title">
                                                    {{ item.payable_item.title }}
                                                </div>
                                                <div class="payment-item-note">
                                                    Successfully processed
                                                </div>
                                            </div>
                                        </div>

                                        <strong>${{ item.amount_usd }}</strong>
                                    </li>
                                {% empty %}
                                    <li class="text-muted">
                                        No payment items found.
                                    </li>
                                {% endfor %}
                            </ul>
                        </div>
                    </div>

                    <div class="col-lg-5">
                        <div class="payment-next-step-card mb-4">
                            <h5 class="mb-2">
                                <i class="bi bi-compass-fill me-2 text-warning"></i>
                                What happens next?
                            </h5>

                            <p class="mb-0">
                                Your Guest account will now reflect the payment result. Depending on the item paid,
                                your next steps may include viewing private listings, continuing arrangements,
                                or checking your updated payment center.
                            </p>
                        </div>

                        <div class="payment-trust-note mb-4">
                            <i class="bi bi-lock-fill me-2"></i>
                            Your transaction has been recorded securely. A payment confirmation email may also be
                            sent to your registered email address.
                        </div>

                        <div class="payment-actions d-grid gap-3">
                            <a href="{% url 'expat_life:foreigner_payment_center' %}"
                               class="btn btn-warning btn-lg rounded-pill px-4">
                                <i class="bi bi-credit-card me-2"></i>
                                Back to Payment Center
                            </a>

                            <a href="{% url 'expat_life:foreigner_dashboard' %}"
                               class="btn btn-dark btn-lg rounded-pill px-4">
                                <i class="bi bi-speedometer2 me-2"></i>
                                Go to Guest Dashboard
                            </a>

                            <a href="{% url 'expat_life:contact_page' %}"
                               class="btn btn-outline-dark btn-lg rounded-pill px-4 fw-bold">
                                <i class="bi bi-headset me-2"></i>
                                Contact Support
                            </a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</section>

{% endblock %}