{% extends 'base.html' %}
{% load static %}

{% block title %}Rapha-Bethel BNPS — School Management{% endblock %}

{% block extra_css %}
<style>
/* Home page — unauthenticated landing */
.home-wrap {
    min-height: calc(100vh - var(--rb-nav-h));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.25rem;
    background: linear-gradient(160deg, #fdf8f3 0%, #f2ebe2 100%);
}
.home-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,.12);
    overflow: hidden;
}
.home-card-header {
    background: linear-gradient(135deg, var(--rb-red-dark), var(--rb-red));
    padding: 2rem 2rem 1.5rem;
    text-align: center;
    position: relative;
}
.home-card-header::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0;
    height: 20px;
    background: #fff;
    border-radius: 16px 16px 0 0;
}
.home-logo {
    width: 88px; height: 132px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,.3));
    margin-bottom: 1rem;
}
.home-school-name {
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}
.home-school-sub {
    color: rgba(255,255,255,.75);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}
.home-card-body { padding: 1.5rem 2rem 2rem; }
.home-card-body h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 0.35rem;
}
.home-card-body p {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 1.5rem;
}
.btn-login {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    transition: all .2s;
    min-height: 50px;
    margin-bottom: 0.75rem;
}
.btn-login-staff {
    background: linear-gradient(135deg, var(--rb-red-dark), var(--rb-red));
    color: #fff;
    border: none;
}
.btn-login-staff:hover { background: linear-gradient(135deg, var(--rb-red), var(--rb-red-light)); color: #fff; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(139,0,0,.3); }
.btn-login-parent {
    background: #fff;
    color: var(--rb-red);
    border: 2px solid var(--rb-red);
}
.btn-login-parent:hover { background: #fff5f5; color: var(--rb-red); transform: translateY(-1px); }
.home-meta {
    text-align: center;
    font-size: 0.75rem;
    color: #bbb;
    margin-top: 1.25rem;
}

/* If authenticated — show a fast-redirect card instead */
.home-auth-wrap {
    text-align: center;
    padding: 3rem 1.25rem;
}
.home-auth-wrap h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.5rem; }
.home-auth-wrap p { color: #888; font-size: 0.9rem; margin-bottom: 1.5rem; }

/* Quick-stat pills (shown when authenticated) */
.quick-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}
.quick-pill {
    background: #fff;
    border: 1px solid #ede8e3;
    border-radius: 20px;
    padding: 0.35rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: #444;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.quick-pill i { color: var(--rb-red); }
</style>
{% endblock %}

{% block content %}
{% if user.is_authenticated %}
<!-- Authenticated: fast-forward to dashboard -->
<div class="home-auth-wrap">
    <picture>
        <source srcset="{% static 'admin/img/logo-nav.webp' %}" type="image/webp">
        <img src="{% static 'admin/img/logo-nav.png' %}" alt="Logo" width="56" height="56" style="border-radius:12px;margin-bottom:1rem;">
    </picture>
    <h1>Welcome back, {{ user.get_full_name|default:user.username }}</h1>
    <p>You're signed in to the Rapha-Bethel School Management System.</p>
    <a href="{% url 'dashboard' %}" class="btn btn-rb-primary btn-lg px-5">
        <i class="fas fa-th-large me-2"></i> Go to Dashboard
    </a>
        <div class="home-meta mt-3">
            <form method="post" action="{% url 'staff:logout' %}" style="margin:0;display:inline">
                {% csrf_token %}
                <button type="submit" style="background:none;border:none;color:#bbb;cursor:pointer;font-size:.75rem;padding:0">Sign out</button>
            </form>
        </div>
</div>

{% else %}
<!-- Unauthenticated: clean login landing -->
<div class="home-wrap">
    <div class="home-card">
        <div class="home-card-header">
            <picture>
                <source srcset="{% static 'admin/img/logo-hero.webp' %}" type="image/webp">
                <img src="{% static 'admin/img/logo-hero.png' %}" alt="Rapha-Bethel BNPS" class="home-logo">
            </picture>
            <p class="home-school-name">Rapha-Bethel BNPS</p>
            <p class="home-school-sub">Bilingual Nursery &amp; Primary School &middot; Douala</p>
        </div>

        <div class="home-card-body">
            <h2>School Management System</h2>
            <p>Sign in to access student records, attendance, finance &amp; more.</p>

            <a href="{% url 'staff:login' %}" class="btn-login btn-login-staff">
                <i class="fas fa-id-badge"></i> Staff &amp; Admin Login
            </a>
            <a href="{% url 'parents:parent_login' %}" class="btn-login btn-login-parent">
                <i class="fas fa-users"></i> Parent Portal
            </a>

            <div class="home-meta">
                Rapha-Bethel BNPS &middot; &copy; {% now "Y" %} Vi-2s-Dk Foundation
            </div>
        </div>
    </div>
</div>
{% endif %}
{% endblock %}