{% extends 'base.html' %}

{% block title %}Sign up — AgentForms{% endblock %}

{% block head_extra %}
<style nonce="{{ csp_nonce }}">
    main {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 40px 24px;
    }
    .login-card {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 40px;
        width: 100%;
        max-width: 420px;
        box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    }
    .login-card h1 {
        font-size: 24px;
        font-weight: 700;
        margin-bottom: 8px;
        text-align: center;
        color: var(--text);
        letter-spacing: -0.02em;
    }
    .login-card .subtitle {
        color: var(--text-muted);
        text-align: center;
        margin-bottom: 24px;
        font-size: 14px;
    }
    .login-card .card-header {
        text-align: center;
        margin-bottom: 24px;
    }
    .login-card .card-header .logo {
        font-size: 28px;
        font-weight: 700;
        color: var(--text);
        letter-spacing: -0.02em;
    }
    .login-card .card-header .logo span {
        color: var(--accent);
    }
    .login-card input {
        margin: 8px 0;
        width: 100%;
        padding: 12px 14px;
        border: 1.5px solid #ddd;
        border-radius: 6px;
        font-size: 16px;
        line-height: 1.4;
        background: #fafafa;
        transition: border-color 0.15s, box-shadow 0.15s;
        min-height: 48px;
        box-sizing: border-box;
    }
    .login-card input:focus {
        outline: none;
        border-color: #4F46E5;
        background: #fff;
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }
    .login-card .btn {
        width: 100%;
        margin-top: 12px;
        padding: 12px;
    }
    .error {
        background: #fef2f2;
        border: 1px solid #fecaca;
        color: #991b1b;
        padding: 10px 14px;
        border-radius: 6px;
        margin-bottom: 16px;
        font-size: 13px;
    }
    .error ul {
        margin: 4px 0 0 16px;
    }
    .pw-hint {
        font-size: 12px;
        color: var(--text-dim);
        margin-top: -4px;
    }
    .checkbox-group {
        margin: 20px 0;
    }
    .checkbox-group label {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        cursor: pointer;
        padding: 12px;
        border-radius: 8px;
        border: 1px solid var(--border);
        font-size: 13px;
    }
    .checkbox-group input[type="checkbox"] {
        width: 18px;
        height: 18px;
        margin: 0;
        cursor: pointer;
        accent-color: var(--accent);
    }
    .checkbox-group .cb-title {
        font-weight: 600;
        color: var(--text);
    }
    .checkbox-group .cb-desc {
        font-size: 11px;
        color: var(--text-dim);
        margin-top: 2px;
    }
    .auth-footer {
        text-align: center;
        font-size: 13px;
        margin-top: 16px;
        color: var(--text-muted);
    }
    .auth-footer a {
        color: var(--accent);
        font-weight: 500;
    }
    @media (max-width: 480px) {
        .login-card {
            padding: 24px;
            border-radius: 8px;
        }
        .login-card h1 {
            font-size: 20px;
        }
    }
</style>
{% endblock %}

{% block content %}
<main>
    <div class="login-card">
        <div class="card-header">
            <div class="logo">Agent<span>Forms</span></div>
        </div>
        <h1>Create account</h1>
        <p class="subtitle">Start managing your form submissions</p>

        {% if errors %}
        <div class="error">
            <ul>
            {% for e in errors %}<li>{{ e }}</li>{% endfor %}
            </ul>
        </div>
        {% endif %}

        <form method="POST" action="{{ url_for('auth.register') }}">
            <input type="hidden" name="csrf_token" value="{{ csrf_token }}"/>
            <input type="text" name="name" placeholder="Name (optional)" value="{{ name or '' }}" aria-label="Your name">
            <input type="email" name="email" placeholder="Email" required value="{{ email or '' }}" autofocus aria-label="Email address">
            <input type="password" name="password" placeholder="Password" required minlength="8" aria-label="Password">
            <div class="pw-hint">At least 8 characters</div>

            <div class="checkbox-group">
                <label>
                    <input type="checkbox" id="magic-login-enabled" checked>
                    <div>
                        <div class="cb-title">Enable passwordless login</div>
                        <div class="cb-desc">Log in with magic links sent to your email — no password needed</div>
                    </div>
                </label>
            </div>

            <div style="margin:16px 0;">
                <input type="text" name="referral_code" placeholder="Referral code (optional)" value="{{ referral_code or '' }}">
            </div>

            <button type="submit" class="btn">Create Account</button>
        </form>
        <p class="auth-footer">Already have an account? <a href="{{ url_for('auth.login') }}">Sign in</a></p>
    </div>
</main>
{% endblock %}
