{% extends "base.html" %}

{% block content %}
<div class="home">
    {# Hero Section #}
    <header class="hero">
        <div class="hero-content">
            <h1 class="hero-title">{{ page.title | default(site.config.title) }}</h1>
            {% if page.metadata.get('description', '') %}
            <p class="hero-description">{{ page.metadata.get('description', '') }}</p>
            {% endif %}

            {% if page.metadata.get('cta_buttons') %}
            <div class="hero-cta">
                {% for button in page.metadata.get('cta_buttons') %}
                <a href="{{ button.url }}" class="btn btn-{{ button.style | default('primary') }}">
                    {{ button.text }}
                </a>
                {% endfor %}
            </div>
            {% endif %}
        </div>
    </header>

    {# Feature Highlights #}
    {% if page.metadata.get('features') %}
    <section class="features">
        <div class="features-grid">
            {% for feature in page.metadata.get('features') %}
            <div class="feature-card">
                {% if feature.icon %}
                <div class="feature-icon">{{ feature.icon }}</div>
                {% endif %}
                <h3 class="feature-title">{{ feature.title }}</h3>
                <p class="feature-description">{{ feature.description }}</p>
                {% if feature.link %}
                <a href="{{ feature.link.url }}" class="feature-link">
                    {{ feature.link.text | default('Learn more') }} →
                </a>
                {% endif %}
            </div>
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {# Main Content #}
    <div class="home-content prose">
        {{ content | safe }}
    </div>

    {# Quick Links Section #}
    {% if page.metadata.get('quick_links') %}
    <section class="quick-links">
        <h2>Quick Links</h2>
        <div class="quick-links-grid">
            {% for link in page.metadata.get('quick_links') %}
            <a href="{{ link.url }}" class="quick-link-card">
                {% if link.icon %}
                <div class="quick-link-icon">{{ link.icon }}</div>
                {% endif %}
                <h3>{{ link.title }}</h3>
                {% if link.description %}
                <p>{{ link.description }}</p>
                {% endif %}
            </a>
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {# Statistics/Metrics Section #}
    {% if page.metadata.get('stats') %}
    <section class="stats">
        <div class="stats-grid">
            {% for stat in page.metadata.get('stats') %}
            <div class="stat-card">
                <div class="stat-value">{{ stat.value }}</div>
                <div class="stat-label">{{ stat.label }}</div>
            </div>
            {% endfor %}
        </div>
    </section>
    {% endif %}

    {# Recent Posts/Updates (if this is a blog-style home) #}
    {% if page.metadata.get('show_recent_posts') %}
    {% set recent = pages | where('section', 'blog') | sort_by('date', reverse=true) | first(3) %}
    {% if recent %}
    <section class="recent-posts">
        <h2>Recent Updates</h2>
        <div class="posts-grid">
            {% for post in recent %}
            <article class="post-card">
                <h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
                {% if post.date %}
                <time datetime="{{ post.date | date_iso }}">{{ post.date | dateformat('%B %d, %Y') }}</time>
                {% endif %}
                {% if post.metadata.get('description') %}
                <p>{{ post.metadata.get('description') }}</p>
                {% endif %}
                <a href="{{ post.url }}" class="read-more">Read more →</a>
            </article>
            {% endfor %}
        </div>
    </section>
    {% endif %}
    {% endif %}
</div>

<style>
/* Hero Section */
.hero {
    text-align: center;
    padding: 4rem 2rem;
    background: linear-gradient(135deg, var(--color-primary-light, #f0f9ff) 0%, var(--color-secondary-light, #fef3c7) 100%);
    border-radius: 1rem;
    margin-bottom: 3rem;
}

.hero-title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    line-height: 1.2;
    color: var(--color-text-primary, #1a1a1a);
}

.hero-description {
    font-size: 1.25rem;
    color: var(--color-text-secondary, #666);
    max-width: 42rem;
    margin: 0 auto 2rem;
    line-height: 1.6;
}

.hero-cta {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--color-primary, #3b82f6);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-dark, #2563eb);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--color-primary, #3b82f6);
    border: 2px solid var(--color-primary, #3b82f6);
}

.btn-secondary:hover {
    background: var(--color-primary-light, #eff6ff);
    transform: translateY(-2px);
}

/* Features Grid */
.features {
    margin: 3rem 0;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.feature-card {
    padding: 2rem;
    background: white;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 0.75rem;
    transition: all 0.2s;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    border-color: var(--color-primary, #3b82f6);
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.feature-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--color-text-primary, #1a1a1a);
}

.feature-description {
    color: var(--color-text-secondary, #666);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.feature-link {
    color: var(--color-primary, #3b82f6);
    text-decoration: none;
    font-weight: 600;
}

.feature-link:hover {
    text-decoration: underline;
}

/* Main Content */
.home-content {
    max-width: 65rem;
    margin: 3rem auto;
}

/* Quick Links */
.quick-links {
    margin: 3rem 0;
}

.quick-links h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 2rem;
}

.quick-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.quick-link-card {
    display: block;
    padding: 1.5rem;
    background: var(--color-bg-secondary, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 0.5rem;
    text-decoration: none;
    transition: all 0.2s;
}

.quick-link-card:hover {
    background: white;
    border-color: var(--color-primary, #3b82f6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.quick-link-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.quick-link-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text-primary, #1a1a1a);
}

.quick-link-card p {
    color: var(--color-text-secondary, #666);
    font-size: 0.875rem;
    margin: 0;
}

/* Statistics */
.stats {
    margin: 3rem 0;
    padding: 3rem 2rem;
    background: var(--color-bg-secondary, #f9fafb);
    border-radius: 1rem;
}

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

.stat-card {
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--color-primary, #3b82f6);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 1rem;
    color: var(--color-text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Recent Posts */
.recent-posts {
    margin: 3rem 0;
}

.recent-posts h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
}

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

.post-card {
    padding: 1.5rem;
    background: white;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.post-card:hover {
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.post-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
}

.post-card h3 a {
    color: var(--color-text-primary, #1a1a1a);
    text-decoration: none;
}

.post-card h3 a:hover {
    color: var(--color-primary, #3b82f6);
}

.post-card time {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-secondary, #666);
    margin-bottom: 0.75rem;
}

.post-card p {
    color: var(--color-text-secondary, #666);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.read-more {
    color: var(--color-primary, #3b82f6);
    text-decoration: none;
    font-weight: 600;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }

    .hero-description {
        font-size: 1rem;
    }

    .features-grid,
    .quick-links-grid,
    .posts-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
</style>
{% endblock %}
