{% extends "base.html" %}

{% block title %}{{ page_title|default:"Log in | Momentum Atlas" }}{% endblock %}
{% block meta_description %}Log in to Momentum Atlas and continue your private daily tracking workflow.{% endblock %}

{% block content %}
<div class="subpage-shell auth-shell">
  <div class="container py-5">
    {% if messages %}
    <div class="message-stack mb-4">
      {% for message in messages %}
      <div class="alert alert-{{ message.tags|default:'info' }} custom-alert mb-0" role="alert">{{ message }}</div>
      {% endfor %}
    </div>
    {% endif %}

    <div class="row justify-content-center">
      <div class="col-lg-6 col-xl-5">
        <div class="glass-panel auth-card">
          <span class="eyebrow">Account access</span>
          <h1>Log in to your dashboard</h1>
          <p>Once logged in, new check-ins belong to your account and only you will see them.</p>

          <form method="post" novalidate>
            {% csrf_token %}
            {% for field in form %}
            <div class="mb-3">
              <label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
              {{ field }}
              {% if field.help_text %}
              <div class="form-hint">{{ field.help_text }}</div>
              {% endif %}
              {% if field.errors %}
              <div class="invalid-feedback d-block">
                {% for error in field.errors %}{{ error }}{% endfor %}
              </div>
              {% endif %}
            </div>
            {% endfor %}
            {% if form.non_field_errors %}
            <div class="invalid-feedback d-block mb-3">
              {% for error in form.non_field_errors %}{{ error }}{% endfor %}
            </div>
            {% endif %}
            {% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %}
            <button type="submit" class="btn btn-accent btn-lg w-100">Log in</button>
          </form>

          <div class="auth-footer">
            <span>New here?</span>
            <a class="text-link" href="{% url 'signup' %}{% if next %}?next={{ next|urlencode }}{% endif %}">Create your free account</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}
