{# templates/accounts/register.html #}
{% extends 'base.html' %}
{% block title %}Crear Cuenta{% endblock %}

{% block content %}
<div class="container mx-auto px-4 py-16">
  <div class="max-w-md mx-auto">
    <div class="card">
      <div class="card-h">
        <h1 class="text-2xl font-bold">Crear Cuenta</h1>
        <p class="text-sm mt-1" style="color: var(--muted-foreground);">
          Regístrate para comentar y reaccionar a los artículos
        </p>
      </div>

      <form method="post">
        {% csrf_token %}
        <div class="card-c space-y-4">
          {% if form.non_field_errors %}
            <div class="p-3 rounded-lg border" style="border-color: var(--border); background: rgba(212,24,61,.06);">
              <div class="text-sm" style="color: var(--destructive);">
                {{ form.non_field_errors }}
              </div>
            </div>
          {% endif %}

          {% for field in form %}
            <div class="field">
              <label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
              {{ field }}
              {% if field.help_text %}
                <p class="help">{{ field.help_text }}</p>
              {% endif %}
              {% if field.errors %}
                <p class="text-sm" style="color: var(--destructive);">{{ field.errors|striptags }}</p>
              {% endif %}
            </div>
          {% endfor %}
        </div>

        <div class="card-f flex flex-col gap-4">
          <button type="submit" class="btn btn-primary w-full">Crear Cuenta</button>
          <p class="text-sm text-center" style="color: var(--muted-foreground);">
            ¿Ya tienes cuenta?
            <a href="{% url 'login' %}" class="font-semibold hover:underline" style="color: var(--primary);">
              Inicia sesión aquí
            </a>
          </p>
        </div>

        <script>
          (function(){
            const root = document.currentScript?.closest('form');
            if(!root) return;
            root.querySelectorAll('input[type="text"], input[type="email"], input[type="password"], textarea, select')
              .forEach(el => el.classList.add('input'));
          })();
        </script>
      </form>
    </div>
  </div>
</div>
{% endblock %}