{% extends 'affiliates_app/base_affiliate.html' %}
{% load static %}

{% block title %}Affiliate Partner Sign In | Partner with Ensolanka{% endblock %}


{% block content %}
<style>
    .affiliate-login-hero {
        position: relative;
        min-height: 100vh;
        padding: 6rem 0;
        background:
            radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 34%),
            radial-gradient(circle at bottom right, rgba(250, 204, 21, 0.14), transparent 32%),
            linear-gradient(135deg, #052e25 0%, #0f766e 55%, #064e3b 100%);
        color: #fff;
        overflow: hidden;
    }

    .affiliate-login-hero h1 {
        color: #fff;
    }

    .affiliate-login-hero .lead {
        color: rgba(255, 255, 255, 0.86) !important;
    }

    .affiliate-login-hero .login-info-item {
        color: rgba(255, 255, 255, 0.92);
    }

    .affiliate-login-hero .login-note-box {
        background: rgba(255, 251, 235, 0.14);
        border-left-color: #fde68a;
        color: rgba(255, 255, 255, 0.92);
    }
    .section-mini-title {
        display: inline-block;
        background: rgba(15, 118, 110, 0.12);
        color: #fde68a;
        font-weight: 700;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        padding: 6px 14px;
        border-radius: 40px;
        margin-bottom: 16px;
    }
    .login-info-list {
        margin: 24px 0 20px;
    }
    .login-info-item {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 14px;
        font-size: 1rem;
    }
    .login-info-item i {
        color: #2c7a4d;
        font-size: 1.2rem;
    }
    .login-note-box {
        background: #ecfdf5;
        border-left: 4px solid #0f766e;
        padding: 16px 20px;
        border-radius: 16px;
        display: flex;
        gap: 12px;
        align-items: flex-start;
    }
    .login-note-box i {
        color: #0f766e;
        font-size: 1.3rem;
        margin-top: 2px;
    }
    .login-form-card {
        background: #fff;
        border-radius: 32px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
        overflow: hidden;
        transition: 0.2s;
    }
    .login-form-header {
        background: linear-gradient(135deg, #052e25 0%, #0f766e 100%);
        padding: 28px 32px;
        color: white;
        text-align: center;
    }
    .login-form-header h3 {
        margin: 0;
        font-weight: 800;
    }
    .login-form-header p {
        opacity: 0.9;
        font-size: 0.9rem;
        margin-top: 8px;
    }
    .login-form-body {
        padding: 32px;
    }
    .forgot-password-link {
        color: #0f766e;
        text-decoration: none;
        font-weight: 600;
        font-size: 0.85rem;
    }
    .forgot-password-link:hover {
        text-decoration: underline;
    }
    .btn-affiliate-login {
        background-color: #2c7a4d;
        border: none;
        padding: 12px;
        font-weight: 700;
        border-radius: 48px;
        font-size: 1rem;
    }
    .btn-affiliate-login:hover {
        background-color: #1f5a38;
    }
    .btn-outline-affiliate {
        border: 2px solid #0f766e;
        color: #0f766e;
        font-weight: 600;
        border-radius: 48px;
        padding: 10px;
    }
    .btn-outline-affiliate:hover {
        background-color: #0f766e;
        color: white;
    }
    .login-form-footer {
        border-top: 1px solid #e9ecef;
        padding-top: 24px;
        margin-top: 8px;
    }
    @media (max-width: 768px) {
        .login-form-body {
            padding: 24px;
        }
        .login-form-header {
            padding: 22px 20px;
        }
    }
</style>

<section class="affiliate-login-hero py-5">
    <div class="container">
        <div class="row align-items-center g-5 justify-content-center">
            <!-- Left column: messaging and benefits -->
            <div class="col-lg-5">
                <span class="section-mini-title">Affiliate Access</span>
                <h1 class="fw-bold mb-3">Affiliate Partner Sign In</h1>
                <p class="lead text-muted mb-4">
                    Sign in to access your affiliate dashboard, track referrals, and request payouts.
                </p>

                <div class="login-info-list">
                    <div class="login-info-item">
                        <i class="bi bi-link-45deg"></i>
                        <span>Get your unique affiliate link & QR code</span>
                    </div>
                    <div class="login-info-item">
                        <i class="bi bi-graph-up"></i>
                        <span>Track referred guests & commission earnings</span>
                    </div>
                    <div class="login-info-item">
                        <i class="bi bi-wallet2"></i>
                        <span>Request payouts from your available balance</span>
                    </div>
                    <div class="login-info-item">
                        <i class="bi bi-file-earmark-pdf"></i>
                        <span>Download marketing materials (PDFs, videos, QR cards)</span>
                    </div>
                </div>

                <div class="login-note-box mt-4">
                    <i class="bi bi-info-circle-fill"></i>
                    <div>
                        <strong>Only for registered Affiliate Partners</strong><br>
                        This login area is exclusively for affiliate partners who have already signed up and been approved.  
                        If you haven’t registered yet, please use the signup link below.
                    </div>
                </div>
            </div>

            <!-- Right column: login form -->
            <div class="col-lg-5">
                <div class="login-form-card shadow-lg">
                    <div class="login-form-header">
                        <h3 class="fw-bold mb-2">Affiliate Sign In</h3>
                        <p class="mb-0">
                            Enter your username or email and password.
                        </p>
                    </div>

                    <form method="post" action="{% url 'affiliates_app:affiliate_login' %}" class="login-form-body">
                        {% csrf_token %}

                        {% if messages %}
                            {% for message in messages %}
                                <div class="alert alert-{{ message.tags|default:'info' }} mb-3">
                                    {{ message }}
                                </div>
                            {% endfor %}
                        {% endif %}

                        {% if form.errors %}
                        <div class="alert alert-danger mb-3">
                            Invalid username or password. Please try again.
                        </div>
                        {% endif %}

                        <div class="mb-3">
                            <label for="id_username" class="form-label fw-semibold">Username</label>
                            <input
                                type="text"
                                name="username"
                                autofocus
                                required
                                id="id_username"
                                class="form-control form-control-lg"
                                autocomplete="username"
                                value="{{ form.username.value|default_if_none:'' }}"
                                placeholder=""
                            >
                        </div>

                        <div class="mb-3">
                            <label for="id_password" class="form-label fw-semibold">Password</label>
                            <input
                                type="password"
                                name="password"
                                required
                                id="id_password"
                                class="form-control form-control-lg"
                                autocomplete="current-password"
                                placeholder=""
                            >
                        </div>

                        <div class="d-flex justify-content-end mb-4">
                            <a href="{% url 'affiliates_app:affiliate_password_reset' %}" class="forgot-password-link">
                                <i class="bi bi-key-fill me-1"></i>
                                Forgot your password?
                            </a>
                        </div>

                        {% if next %}
                        <input type="hidden" name="next" value="{{ next }}">
                        {% endif %}

                        <button type="submit" class="btn btn-success btn-affiliate-login w-100">
                            <i class="bi bi-box-arrow-in-right me-2"></i>Sign In as Affiliate
                        </button>
                    </form>

                    <div class="login-form-footer text-center px-4 pb-4">
                        <p class="small text-muted mb-3">
                            Not an affiliate partner yet?
                        </p>
                        <a href="{% url 'affiliates_app:affiliate_register' %}" class="btn btn-outline-affiliate w-100">
                            <i class="bi bi-person-plus me-2"></i>Become an Affiliate Partner
                        </a>
                        <div class="mt-3">
                            <a href="{% url 'affiliates_app:home_affiliates' %}" class="text-muted small">
                                ← Back to Affiliate Program Home
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}