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

{% block title %}{{ category.name }} - Blog ECOLUX BTP{% endblock %}

{% block content %}
<!-- Category Header -->
<section class="category-header">
    <div class="container">
        <div class="category-header-content">
            <div class="category-breadcrumb">
                <a href="{% url 'app:home' %}">Accueil</a>
                <span>/</span>
                <a href="{% url 'app:blog_list' %}">Blog</a>
                <span>/</span>
                <span>{{ category.name }}</span>
            </div>
            
            <div class="category-info">
                <div class="category-badge" style="background-color: {{ category.color }};">
                    {{ category.name }}
                </div>
                <h1>{{ category.name }}</h1>
                {% if category.description %}
                <p>{{ category.description }}</p>
                {% endif %}
                <div class="category-stats">
                    <span>{{ posts.paginator.count }} article{{ posts.paginator.count|pluralize }}</span>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Articles -->
<section class="category-content">
    <div class="container">
        <div class="articles-grid">
            {% for post in posts %}
            <article class="article-card">
                {% if post.featured_image %}
                <div class="article-image">
                    <img src="{{ post.featured_image.url }}" alt="{{ post.title }}">
                </div>
                {% endif %}
                
                <div class="article-content">
                    <div class="article-meta">
                        <span class="article-date">{{ post.published_at|date:"d F Y" }}</span>
                        <span class="article-reading-time">{{ post.reading_time }} min de lecture</span>
                    </div>
                    
                    <h2 class="article-title">
                        <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
                    </h2>
                    
                    <p class="article-excerpt">{{ post.excerpt }}</p>
                    
                    <div class="article-footer">
                        <div class="article-author">
                            <span>Par {{ post.author.first_name }} {{ post.author.last_name }}</span>
                        </div>
                        <a href="{{ post.get_absolute_url }}" class="read-more">
                            Lire la suite →
                        </a>
                    </div>
                </div>
            </article>
            {% empty %}
            <div class="no-articles">
                <div class="no-articles-icon">
                    <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1">
                        <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"></path>
                    </svg>
                </div>
                <h3>Aucun article dans cette catégorie</h3>
                <p>Il n'y a pas encore d'articles publiés dans cette catégorie.</p>
                <a href="{% url 'app:blog_list' %}" class="btn-primary">Voir tous les articles</a>
            </div>
            {% endfor %}
        </div>

        <!-- Pagination -->
        {% if posts.has_other_pages %}
        <div class="pagination-wrapper">
            <div class="pagination">
                {% if posts.has_previous %}
                <a href="?page=1" class="page-link">Premier</a>
                <a href="?page={{ posts.previous_page_number }}" class="page-link">Précédent</a>
                {% endif %}

                <span class="page-info">
                    Page {{ posts.number }} sur {{ posts.paginator.num_pages }}
                </span>

                {% if posts.has_next %}
                <a href="?page={{ posts.next_page_number }}" class="page-link">Suivant</a>
                <a href="?page={{ posts.paginator.num_pages }}" class="page-link">Dernier</a>
                {% endif %}
            </div>
        </div>
        {% endif %}
    </div>
</section>

<style>
/* Category Styles */
.category-header {
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--secondary)));
    color: white;
    padding: 6rem 0 4rem;
}

.category-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    opacity: 0.9;
}

.category-breadcrumb a {
    color: white;
    text-decoration: none;
}

.category-breadcrumb span {
    opacity: 0.6;
}

.category-info {
    text-align: center;
}

.category-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    color: white;
    margin-bottom: 1rem;
}

.category-info h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.category-info p {
    font-size: 1.25rem;
    opacity: 0.9;
    margin-bottom: 1rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.category-stats {
    font-size: 1rem;
    opacity: 0.8;
}

.category-content {
    padding: 4rem 0;
}

.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
}

.article-card {
    background: hsl(var(--card));
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.article-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
}

.article-image {
    height: 200px;
    overflow: hidden;
}

.article-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-content {
    padding: 1.5rem;
}

.article-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: hsl(var(--foreground) / 0.6);
}

.article-title {
    margin-bottom: 1rem;
}

.article-title a {
    text-decoration: none;
    color: hsl(var(--foreground));
    font-weight: 600;
    font-size: 1.25rem;
}

.article-title a:hover {
    color: hsl(var(--primary));
}

.article-excerpt {
    color: hsl(var(--foreground) / 0.8);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.article-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.article-author {
    font-size: 0.9rem;
    color: hsl(var(--foreground) / 0.6);
}

.read-more {
    color: hsl(var(--primary));
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
}

.read-more:hover {
    text-decoration: underline;
}

.no-articles {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
}

.no-articles-icon {
    margin-bottom: 1.5rem;
    color: hsl(var(--foreground) / 0.3);
}

.no-articles h3 {
    margin-bottom: 1rem;
    color: hsl(var(--foreground));
}

.no-articles p {
    color: hsl(var(--foreground) / 0.6);
    margin-bottom: 2rem;
}

.pagination-wrapper {
    margin-top: 3rem;
    display: flex;
    justify-content: center;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-link {
    padding: 0.5rem 1rem;
    border: 2px solid hsl(var(--border));
    border-radius: 0.5rem;
    text-decoration: none;
    color: hsl(var(--foreground));
    transition: var(--transition);
}

.page-link:hover {
    background: hsl(var(--primary));
    border-color: hsl(var(--primary));
    color: white;
}

.page-info {
    padding: 0.5rem 1rem;
    color: hsl(var(--foreground) / 0.6);
}

/* Responsive */
@media (max-width: 768px) {
    .articles-grid {
        grid-template-columns: 1fr;
    }
    
    .category-info h1 {
        font-size: 2rem;
    }
    
    .category-info p {
        font-size: 1rem;
    }
    
    .article-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}
</style>
{% endblock %}
