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

{% block title %}{{ post.title }} - Blog ECOLUX BTP{% endblock %}

{% block meta_description %}{{ post.meta_description|default:post.excerpt }}{% endblock %}

{% block content %}
<!-- Article Header -->
<article class="blog-article">
    <header class="article-header">
        <div class="container">
            <div class="article-breadcrumb">
                <a href="{% url 'app:home' %}">Accueil</a>
                <span>/</span>
                <a href="{% url 'app:blog_list' %}">Blog</a>
                {% if post.category %}
                <span>/</span>
                <a href="{{ post.category.get_absolute_url }}">{{ post.category.name }}</a>
                {% endif %}
                <span>/</span>
                <span>{{ post.title }}</span>
            </div>
            
            <div class="article-meta">
                {% if post.category %}
                <span class="article-category" style="background-color: {{ post.category.color }};">
                    {{ post.category.name }}
                </span>
                {% endif %}
                <div class="article-info">
                    <span class="article-date">{{ post.published_at|date:"d F Y" }}</span>
                    <span class="article-reading-time">{{ post.reading_time }} min de lecture</span>
                    <span class="article-views">{{ post.views_count }} vue{{ post.views_count|pluralize }}</span>
                </div>
            </div>
            
            <h1 class="article-title">{{ post.title }}</h1>
            
            <div class="article-author">
                <div class="author-info">
                    <div class="author-details">
                        <span class="author-name">{{ post.author.first_name }} {{ post.author.last_name }}</span>
                        <span class="author-role">Expert ECOLUX BTP</span>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Featured Image -->
    {% if post.featured_image %}
    <div class="article-featured-image">
        <div class="container">
            <img src="{{ post.featured_image.url }}" alt="{{ post.title }}">
        </div>
    </div>
    {% endif %}

    <!-- Article Content -->
    <div class="article-content">
        <div class="container">
            <div class="article-layout">
                <main class="article-main">
                    <div class="article-body">
                        {{ post.content|safe }}
                    </div>

                    <!-- Tags -->
                    {% if post.get_tags_list %}
                    <div class="article-tags">
                        <h4>Tags</h4>
                        <div class="tags-list">
                            {% for tag in post.get_tags_list %}
                            <span class="tag">{{ tag }}</span>
                            {% endfor %}
                        </div>
                    </div>
                    {% endif %}

                    <!-- Social Share -->
                    <div class="article-share">
                        <h4>Partager cet article</h4>
                        <div class="share-buttons">
                            <a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}" 
                               target="_blank" class="share-btn facebook">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
                                </svg>
                                Facebook
                            </a>
                            <a href="https://twitter.com/intent/tweet?url={{ request.build_absolute_uri }}&text={{ post.title }}" 
                               target="_blank" class="share-btn twitter">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/>
                                </svg>
                                Twitter
                            </a>
                            <a href="https://www.linkedin.com/sharing/share-offsite/?url={{ request.build_absolute_uri }}" 
                               target="_blank" class="share-btn linkedin">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
                                </svg>
                                LinkedIn
                            </a>
                            <a href="https://wa.me/?text={{ post.title }} - {{ request.build_absolute_uri }}" 
                               target="_blank" class="share-btn whatsapp">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/>
                                </svg>
                                WhatsApp
                            </a>
                        </div>
                    </div>
                </main>

                <!-- Sidebar -->
                <aside class="article-sidebar">
                    <!-- Author Info -->
                    <div class="sidebar-widget author-widget">
                        <h4>À propos de l'auteur</h4>
                        <div class="author-card">
                            <div class="author-content">
                                <h5>{{ post.author.first_name }} {{ post.author.last_name }}</h5>
                                <p>Expert en construction et membre de l'équipe ECOLUX BTP avec plus de 15 ans d'expérience dans le secteur.</p>
                            </div>
                        </div>
                    </div>

                    <!-- Contact CTA -->
                    <div class="sidebar-widget contact-cta">
                        <h4>Besoin d'aide ?</h4>
                        <p>Nos experts sont là pour vous accompagner dans votre projet de construction.</p>
                        <a href="#contact" class="btn-primary">Contactez-nous</a>
                    </div>
                </aside>
            </div>
        </div>
    </div>
</article>

<!-- Related Articles -->
{% if related_posts %}
<section class="related-articles">
    <div class="container">
        <h2>Articles similaires</h2>
        <div class="related-grid">
            {% for related_post in related_posts %}
            <article class="related-card">
                {% if related_post.featured_image %}
                <div class="related-image">
                    <img src="{{ related_post.featured_image.url }}" alt="{{ related_post.title }}">
                </div>
                {% endif %}
                <div class="related-content">
                    <span class="related-date">{{ related_post.published_at|date:"d M Y" }}</span>
                    <h3><a href="{{ related_post.get_absolute_url }}">{{ related_post.title }}</a></h3>
                    <p>{{ related_post.excerpt|truncatewords:15 }}</p>
                </div>
            </article>
            {% endfor %}
        </div>
    </div>
</section>
{% endif %}

<style>
/* Article Styles */
.blog-article {
    margin-top: 80px; /* Compensation pour le header fixe */
}

.article-header {
    background: hsl(var(--card));
    padding: 2rem 0;
    border-bottom: 1px solid hsl(var(--border));
}

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

.article-breadcrumb a {
    color: hsl(var(--primary));
    text-decoration: none;
}

.article-breadcrumb span {
    color: hsl(var(--foreground) / 0.4);
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.article-category {
    padding: 0.25rem 0.75rem;
    border-radius: 50px;
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
}

.article-info {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: hsl(var(--foreground) / 0.6);
    flex-wrap: wrap;
}

.article-title {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1.5rem;
    color: hsl(var(--foreground));
}

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

.author-details {
    display: flex;
    flex-direction: column;
}

.author-name {
    font-weight: 600;
    color: hsl(var(--foreground));
}

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

.article-featured-image {
    margin-bottom: 3rem;
}

.article-featured-image img {
    width: 100%;
    height: 400px;
    object-fit: cover;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.article-content {
    padding: 2rem 0;
}

.article-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 3rem;
}

.article-body {
    font-size: 1.1rem;
    line-height: 1.8;
    color: hsl(var(--foreground));
    margin-bottom: 3rem;
}

.article-body h2,
.article-body h3,
.article-body h4 {
    margin: 2rem 0 1rem;
    color: hsl(var(--foreground));
}

.article-body h2 {
    font-size: 1.75rem;
    font-weight: 600;
}

.article-body h3 {
    font-size: 1.5rem;
    font-weight: 600;
}

.article-body h4 {
    font-size: 1.25rem;
    font-weight: 600;
}

.article-body p {
    margin-bottom: 1.5rem;
}

.article-body ul,
.article-body ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.article-body li {
    margin-bottom: 0.5rem;
}

.article-body blockquote {
    border-left: 4px solid hsl(var(--primary));
    padding: 1rem 2rem;
    margin: 2rem 0;
    background: hsl(var(--muted));
    border-radius: 0.5rem;
    font-style: italic;
}

.article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
}

.article-tags {
    margin-bottom: 2rem;
}

.article-tags h4 {
    margin-bottom: 1rem;
    color: hsl(var(--foreground));
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    padding: 0.25rem 0.75rem;
    background: hsl(var(--muted));
    border-radius: 50px;
    font-size: 0.8rem;
    color: hsl(var(--foreground));
}

.article-share {
    border-top: 1px solid hsl(var(--border));
    padding-top: 2rem;
}

.article-share h4 {
    margin-bottom: 1rem;
    color: hsl(var(--foreground));
}

.share-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.share-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: white;
    font-size: 0.9rem;
    transition: var(--transition);
}

.share-btn.facebook {
    background: #1877F2;
}

.share-btn.twitter {
    background: #1DA1F2;
}

.share-btn.linkedin {
    background: #0A66C2;
}

.share-btn.whatsapp {
    background: #25D366;
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Sidebar */
.article-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.sidebar-widget {
    background: hsl(var(--card));
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.sidebar-widget h4 {
    margin-bottom: 1rem;
    color: hsl(var(--foreground));
    font-size: 1.25rem;
}

.author-widget {
    text-align: center;
}

.author-card h5 {
    margin-bottom: 0.5rem;
    color: hsl(var(--foreground));
    font-weight: 600;
}

.author-card p {
    font-size: 0.9rem;
    color: hsl(var(--foreground) / 0.8);
    line-height: 1.5;
}

.contact-cta {
    text-align: center;
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--secondary)));
    color: white;
}

.contact-cta h4 {
    color: white;
}

.contact-cta p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* Related Articles */
.related-articles {
    background: hsl(var(--muted));
    padding: 4rem 0;
}

.related-articles h2 {
    text-align: center;
    margin-bottom: 3rem;
    font-size: 2rem;
    color: hsl(var(--foreground));
}

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

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

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

.related-image {
    height: 150px;
    overflow: hidden;
}

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

.related-content {
    padding: 1.5rem;
}

.related-date {
    font-size: 0.8rem;
    color: hsl(var(--foreground) / 0.6);
    margin-bottom: 0.5rem;
    display: block;
}

.related-content h3 {
    margin-bottom: 0.5rem;
}

.related-content h3 a {
    text-decoration: none;
    color: hsl(var(--foreground));
    font-size: 1.1rem;
    font-weight: 600;
}

.related-content h3 a:hover {
    color: hsl(var(--primary));
}

.related-content p {
    font-size: 0.9rem;
    color: hsl(var(--foreground) / 0.8);
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 768px) {
    .article-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .article-title {
        font-size: 2rem;
    }
    
    .article-featured-image img {
        height: 250px;
    }
    
    .article-body {
        font-size: 1rem;
    }
    
    .share-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .related-grid {
        grid-template-columns: 1fr;
    }
    
    .article-meta {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .article-info {
        flex-direction: column;
        gap: 0.5rem;
    }
}
</style>
{% endblock %}
