{% extends 'rental_app/base_rental.html' %}

{% block title %}Change Username{% endblock %}

{% block content %}

<style>
    /* =========================================================
       RENTAL OWNER CHANGE USERNAME — PREMIUM
    ========================================================= */

    .rental-username-page {
        min-height: 100vh;
        padding: 4rem 0 5rem;
        background:
            radial-gradient(circle at top left, rgba(251, 191, 36, 0.10), transparent 28%),
            radial-gradient(circle at top right, rgba(14, 116, 144, 0.10), transparent 32%),
            linear-gradient(180deg, #f8fafc 0%, #eff6ff 44%, #ffffff 100%);
    }

    .rental-username-hero {
        position: relative;
        overflow: hidden;
        border-radius: 38px;
        padding: 2.5rem 2.35rem;
        margin-bottom: 2rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(251, 191, 36, 0.18), transparent 32%),
            linear-gradient(135deg, #082f49 0%, #0e7490 56%, #0f766e 100%);
        box-shadow: 0 30px 68px rgba(15, 23, 42, 0.20);
    }

    .rental-username-hero::before {
        content: "";
        position: absolute;
        top: -110px;
        right: -85px;
        width: 300px;
        height: 300px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.07);
        pointer-events: none;
    }

    .rental-username-hero::after {
        content: "";
        position: absolute;
        bottom: -150px;
        left: -110px;
        width: 360px;
        height: 360px;
        border-radius: 50%;
        background: rgba(251, 191, 36, 0.08);
        pointer-events: none;
    }

    .rental-username-hero-inner {
        position: relative;
        z-index: 2;
    }

    .rental-username-kicker {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.52rem 1rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.22);
        color: #fef3c7;
        font-size: 0.84rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 1rem;
    }

    .rental-username-hero h1 {
        font-size: clamp(2.1rem, 4vw, 3.35rem);
        font-weight: 950;
        line-height: 1.12;
        letter-spacing: -0.045em;
        margin-bottom: 0.8rem;
    }

    .rental-username-hero p {
        max-width: 820px;
        margin-bottom: 0;
        color: rgba(255, 255, 255, 0.88);
        font-size: 1.03rem;
        line-height: 1.8;
    }

    .rental-username-layout {
        align-items: stretch;
    }

    .rental-username-card,
    .rental-username-side-card {
        height: 100%;
        border-radius: 34px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid rgba(226, 232, 240, 0.95);
        box-shadow: 0 24px 56px rgba(15, 23, 42, 0.10);
        overflow: hidden;
    }

    .rental-username-card-header,
    .rental-username-side-header {
        padding: 1.6rem 1.7rem 1.15rem;
        border-bottom: 1px solid #e2e8f0;
        background:
            radial-gradient(circle at top right, rgba(14, 116, 144, 0.06), transparent 28%),
            linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    }

    .rental-username-card-header h2,
    .rental-username-side-header h3 {
        color: #0f172a;
        font-weight: 950;
        margin-bottom: 0.4rem;
    }

    .rental-username-card-header p,
    .rental-username-side-header p {
        color: #64748b;
        line-height: 1.7;
        margin-bottom: 0;
    }

    .rental-username-card-body,
    .rental-username-side-body {
        padding: 1.7rem;
    }

    .rental-username-field .form-label {
        display: block;
        color: #0f172a;
        font-weight: 850;
        margin-bottom: 0.55rem;
    }

    .rental-username-field input {
        width: 100%;
        border-radius: 16px;
        border: 1px solid #dbe4ee;
        padding: 0.9rem 1rem;
        background: #f8fafc;
        color: #0f172a;
        transition: all 0.22s ease;
    }

    .rental-username-field input:focus {
        outline: none;
        background: #ffffff;
        border-color: #0e7490;
        box-shadow: 0 0 0 0.22rem rgba(14, 116, 144, 0.12);
    }

    .rental-username-error {
        color: #dc2626;
        font-size: 0.88rem;
        margin-top: 0.35rem;
        font-weight: 700;
    }

    .rental-current-box {
        border-radius: 22px;
        background:
            radial-gradient(circle at top right, rgba(251, 191, 36, 0.08), transparent 28%),
            #f8fafc;
        border: 1px solid #e2e8f0;
        padding: 1rem 1.1rem;
        margin-bottom: 1.3rem;
    }

    .rental-current-label {
        color: #64748b;
        font-size: 0.8rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.045em;
        margin-bottom: 0.35rem;
    }

    .rental-current-value {
        color: #0f172a;
        font-size: 1.2rem;
        font-weight: 950;
        word-break: break-word;
    }

    .rental-username-note {
        margin-top: 1.5rem;
        border-radius: 22px;
        padding: 1rem 1.1rem;
        background: #eff6ff;
        border: 1px solid #bfdbfe;
        color: #1d4ed8;
        line-height: 1.72;
    }

    .rental-username-actions {
        margin-top: 1.7rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.85rem;
    }

    .rental-username-actions .btn {
        border-radius: 999px;
        font-weight: 850;
        min-height: 52px;
        padding-left: 1.35rem;
        padding-right: 1.35rem;
    }

    .rental-username-save-btn {
        color: #fff;
        border: none;
        background: linear-gradient(135deg, #0f172a, #0e7490);
    }

    .rental-username-save-btn:hover {
        color: #fff;
        transform: translateY(-1px);
    }

    .rental-username-non-field-error {
        margin-top: 1.4rem;
        border-radius: 20px;
    }

    .rental-tip-list {
        display: grid;
        gap: 0.95rem;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .rental-tip-item {
        display: flex;
        align-items: flex-start;
        gap: 0.75rem;
        color: #475569;
        line-height: 1.68;
    }

    .rental-tip-item i {
        color: #0e7490;
        font-size: 1.05rem;
        margin-top: 0.2rem;
        flex-shrink: 0;
    }

    @media (max-width: 991.98px) {
        .rental-username-page {
            padding-top: 2.8rem;
        }

        .rental-username-hero {
            padding: 2rem 1.45rem;
            border-radius: 30px;
        }

        .rental-username-card-header,
        .rental-username-side-header,
        .rental-username-card-body,
        .rental-username-side-body {
            padding-left: 1.35rem;
            padding-right: 1.35rem;
        }
    }

    @media (max-width: 767.98px) {
        .rental-username-actions {
            flex-direction: column;
            align-items: stretch;
        }

        .rental-username-actions .btn {
            width: 100%;
        }
    }
</style>


<section class="rental-username-page">
    <div class="container">

        <!-- =====================================================
             HERO
        ====================================================== -->
        <div class="rental-username-hero">
            <div class="rental-username-hero-inner">
                <span class="rental-username-kicker">
                    <i class="bi bi-person-gear"></i>
                    Rental Owner Account
                </span>

                <h1>Change Username</h1>

                <p>
                    Update the username used to sign in to your Rent in Sri Lanka account.
                    Choose a clear and memorable username that you can use securely going forward.
                </p>
            </div>
        </div>


        <div class="row g-4 justify-content-center rental-username-layout">

            <!-- MAIN FORM -->
            <div class="col-lg-7">
                <div class="rental-username-card">

                    <div class="rental-username-card-header">
                        <h2>Update Login Username</h2>
                        <p>
                            Your username is part of your account login identity. Changes take effect immediately after saving.
                        </p>
                    </div>

                    <div class="rental-username-card-body">

                        <div class="rental-current-box">
                            <div class="rental-current-label">
                                Current Username
                            </div>

                            <div class="rental-current-value">
                                {{ request.user.username }}
                            </div>
                        </div>

                        <form method="post">
                            {% csrf_token %}

                            {% for field in form %}
                                <div class="rental-username-field mb-3">
                                    <label class="form-label"
                                           for="{{ field.id_for_label }}">
                                        {{ field.label }}
                                    </label>

                                    {{ field }}

                                    {% if field.help_text %}
                                        <div class="form-text">
                                            {{ field.help_text }}
                                        </div>
                                    {% endif %}

                                    {% for error in field.errors %}
                                        <div class="rental-username-error">
                                            {{ error }}
                                        </div>
                                    {% endfor %}
                                </div>
                            {% endfor %}

                            <div class="rental-username-note">
                                After updating your username, continue using the same password unless you separately change it from the password settings page.
                            </div>

                            <div class="rental-username-actions">
                                <button type="submit"
                                        class="btn rental-username-save-btn">
                                    <i class="bi bi-check-circle-fill me-2"></i>
                                    Update Username
                                </button>

                                <a href="{% url 'rental_app:rental_owner_profile_page' %}"
                                   class="btn btn-outline-secondary">
                                    <i class="bi bi-arrow-left-circle me-2"></i>
                                    Cancel
                                </a>
                            </div>

                            {% if form.non_field_errors %}
                                <div class="alert alert-danger rental-username-non-field-error mb-0">
                                    {% for error in form.non_field_errors %}
                                        <div>{{ error }}</div>
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </form>
                    </div>

                </div>
            </div>


            <!-- SIDE INFO -->
            <div class="col-lg-5">
                <div class="rental-username-side-card">

                    <div class="rental-username-side-header">
                        <h3>Username Tips</h3>
                        <p>
                            A few reminders before you update your sign-in identity.
                        </p>
                    </div>

                    <div class="rental-username-side-body">
                        <ul class="rental-tip-list">
                            <li class="rental-tip-item">
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Choose a username you can easily remember for future sign-ins.</span>
                            </li>

                            <li class="rental-tip-item">
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Your username must be unique and cannot already belong to another account.</span>
                            </li>

                            <li class="rental-tip-item">
                                <i class="bi bi-check-circle-fill"></i>
                                <span>This change does not alter your profile name, email address, or owner details.</span>
                            </li>

                            <li class="rental-tip-item">
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Use the separate password page if you also want to update your account security.</span>
                            </li>
                        </ul>
                    </div>

                </div>
            </div>

        </div>

    </div>
</section>

{% endblock %}