{% load i18n %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{% trans "Set New Password - PX360" %}</title>

    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">

    <style>
        :root {
            --primary: #0086d2;
            --primary-dark: #005d93;
            --bg-gradient-start: #667eea;
            --bg-gradient-end: #764ba2;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .reset-container {
            width: 100%;
            max-width: 420px;
            padding: 1.5rem;
        }

        .reset-card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
            overflow: hidden;
        }

        .reset-header {
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
            color: white;
            padding: 2rem 1.5rem;
            text-align: center;
        }

        .reset-header h3 {
            margin-bottom: 0.5rem;
            font-weight: 700;
        }

        .reset-header p {
            margin-bottom: 0;
            opacity: 0.9;
            font-size: 0.9rem;
        }

        .reset-body {
            padding: 2rem 1.5rem;
        }

        .form-control {
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 0.75rem 1rem;
            font-size: 0.95rem;
        }

        .form-control:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 0.2rem rgba(0, 134, 210, 0.15);
        }

        .btn-reset {
            background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
            border: none;
            color: white;
            font-weight: 600;
            padding: 0.75rem;
            border-radius: 8px;
            transition: all 0.3s ease;
        }

        .btn-reset:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 134, 210, 0.3);
            color: white;
        }

        .input-group-text {
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 8px 0 0 8px;
        }

        .input-group .form-control {
            border-radius: 0 8px 8px 0;
            border-left: none;
        }

        .input-group .form-control:focus {
            border-left: none;
        }

        .reset-footer {
            padding: 1rem 1.5rem;
            background: #f8f9fa;
            text-align: center;
            font-size: 0.85rem;
            color: #6c757d;
        }

        .reset-footer a {
            color: var(--primary);
            text-decoration: none;
        }

        .reset-footer a:hover {
            text-decoration: underline;
        }

        .alert {
            border-radius: 8px;
            border: none;
        }

        .helptext {
            font-size: 0.8rem;
            color: #6c757d;
            margin-top: 0.25rem;
        }

        /* Responsive */
        @media (max-width: 576px) {
            .reset-container {
                padding: 1rem;
            }

            .reset-header {
                padding: 1.5rem 1rem;
            }

            .reset-body {
                padding: 1.5rem 1rem;
            }
        }
    </style>
</head>
<body>
    <div class="reset-container">
        <div class="reset-card">
            <!-- Header -->
            <div class="reset-header">
                <div class="mb-3">
                    <i class="bi bi-shield-lock" style="font-size: 2.5rem;"></i>
                </div>
                <h3>{% trans "Set New Password" %}</h3>
                <p>{% trans "Enter your new password below" %}</p>
            </div>

            <!-- Body -->
            <div class="reset-body">
                <!-- Messages -->
                {% if messages %}
                    {% for message in messages %}
                        <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                            {{ message }}
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                    {% endfor %}
                {% endif %}

                {% if validlink %}
                    <!-- Password Reset Confirm Form -->
                    <form method="post">
                        {% csrf_token %}

                        <!-- New Password -->
                        <div class="mb-3">
                            <label for="id_new_password1" class="form-label fw-semibold">
                                <i class="bi bi-lock me-1"></i> {% trans "New Password" %}
                            </label>
                            <input type="password" 
                                   class="form-control" 
                                   id="id_new_password1" 
                                   name="new_password1" 
                                   required 
                                   autofocus>
                            {% if form.new_password1.errors %}
                                <div class="text-danger mt-1 small">
                                    {{ form.new_password1.errors }}
                                </div>
                            {% endif %}
                            {% if form.new_password1.help_text %}
                                <div class="helptext">{{ form.new_password1.help_text }}</div>
                            {% endif %}
                        </div>

                        <!-- Confirm Password -->
                        <div class="mb-4">
                            <label for="id_new_password2" class="form-label fw-semibold">
                                <i class="bi bi-lock-fill me-1"></i> {% trans "Confirm Password" %}
                            </label>
                            <input type="password" 
                                   class="form-control" 
                                   id="id_new_password2" 
                                   name="new_password2" 
                                   required>
                            {% if form.new_password2.errors %}
                                <div class="text-danger mt-1 small">
                                    {{ form.new_password2.errors }}
                                </div>
                            {% endif %}
                        </div>

                        <!-- Submit Button -->
                        <button type="submit" class="btn btn-reset w-100">
                            <i class="bi bi-check-circle me-2"></i> {% trans "Set New Password" %}
                        </button>
                    </form>
                {% else %}
                    <!-- Invalid Link -->
                    <div class="alert alert-danger" role="alert">
                        <i class="bi bi-exclamation-triangle me-2"></i>
                        {% trans "The password reset link was invalid, possibly because it has already been used or has expired." %}
                    </div>
                    <a href="{% url 'accounts:password_reset' %}" class="btn btn-reset w-100">
                        <i class="bi bi-arrow-repeat me-2"></i> {% trans "Request New Reset Link" %}
                    </a>
                {% endif %}
            </div>

            <!-- Footer -->
            <div class="reset-footer">
                <p class="mb-2">
                    <a href="{% url 'accounts:login' %}">
                        <i class="bi bi-arrow-left me-1"></i> {% trans "Back to Login" %}
                    </a>
                </p>
                <p class="mb-0">
                    {% trans "Secure password reset powered by" %} <strong>PX360</strong>
                </p>
            </div>
        </div>
    </div>

    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

    <!-- Auto-dismiss alerts after 5 seconds -->
    <script>
        setTimeout(function() {
            const alerts = document.querySelectorAll('.alert:not(.alert-danger)');
            alerts.forEach(alert => {
                const bsAlert = new bootstrap.Alert(alert);
                bsAlert.close();
            });
        }, 5000);
    </script>
</body>
</html>
