{% extends "base.html" %}

{% block title %}{{ project.name }} - ZOP Kaszubia{% endblock %}

{% block extra_css %}
<style>
    .project-header {
        background: linear-gradient(135deg, {{ project.color or '#059669' }}cc, {{ project.color or '#047857' }});
        color: white;
        padding: var(--spacing-2xl) 0;
        margin-bottom: var(--spacing-xl);
        border-radius: var(--radius-lg);
    }

    .project-header .container {
        max-width: 800px;
    }

    .back-link {
        display: inline-flex;
        align-items: center;
        gap: var(--spacing-xs);
        color: rgba(255,255,255,0.8);
        text-decoration: none;
        margin-bottom: var(--spacing-md);
    }

    .back-link:hover {
        color: white;
    }

    .project-status {
        display: inline-block;
        padding: 4px 12px;
        border-radius: var(--radius);
        font-size: var(--font-size-sm);
        font-weight: 500;
        background: rgba(255,255,255,0.2);
        margin-bottom: var(--spacing-md);
    }

    .project-header h1 {
        font-size: var(--font-size-3xl);
        margin-bottom: var(--spacing-md);
    }

    .project-header p {
        font-size: var(--font-size-lg);
        opacity: 0.9;
        line-height: 1.6;
    }

    .project-meta {
        display: flex;
        gap: var(--spacing-xl);
        margin-top: var(--spacing-xl);
        flex-wrap: wrap;
    }

    .project-meta-item {
        text-align: center;
    }

    .project-meta-value {
        font-size: var(--font-size-xl);
        font-weight: 700;
    }

    .project-meta-label {
        font-size: var(--font-size-sm);
        opacity: 0.8;
    }

    .content-grid {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: var(--spacing-xl);
    }

    .section {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-lg);
        box-shadow: var(--shadow);
        margin-bottom: var(--spacing-lg);
    }

    .section h2 {
        font-size: var(--font-size-lg);
        margin-bottom: var(--spacing-lg);
        padding-bottom: var(--spacing-md);
        border-bottom: 1px solid var(--border);
    }

    .news-list {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .news-item {
        padding: var(--spacing-md);
        background: var(--background);
        border-radius: var(--radius);
        text-decoration: none;
        color: inherit;
        transition: var(--transition);
    }

    .news-item:hover {
        transform: translateX(4px);
    }

    .news-item h4 {
        font-size: var(--font-size-base);
        margin-bottom: var(--spacing-xs);
        line-height: 1.4;
    }

    .news-item-meta {
        font-size: var(--font-size-xs);
        color: var(--text-secondary);
    }

    .resources-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--spacing-md);
    }

    .resource-item {
        text-align: center;
        padding: var(--spacing-md);
        background: var(--background);
        border-radius: var(--radius);
        text-decoration: none;
        color: inherit;
        transition: var(--transition);
    }

    .resource-item:hover {
        background: var(--border);
    }

    .resource-icon {
        width: 40px;
        height: 40px;
        margin: 0 auto var(--spacing-sm);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--primary);
    }

    .resource-item h5 {
        font-size: var(--font-size-sm);
        font-weight: 500;
    }

    .companies-list {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .company-link-item {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        padding: var(--spacing-md);
        background: var(--background);
        border-radius: var(--radius);
        text-decoration: none;
        color: inherit;
    }

    .company-link-item:hover {
        background: var(--border);
    }

    .company-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--primary);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
    }

    .company-info h5 {
        font-size: var(--font-size-sm);
        margin-bottom: 2px;
    }

    .company-info p {
        font-size: var(--font-size-xs);
        color: var(--text-secondary);
    }

    .empty-state {
        text-align: center;
        padding: var(--spacing-lg);
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
    }

    @media (max-width: 768px) {
        .content-grid {
            grid-template-columns: 1fr;
        }

        .project-header {
            padding: var(--spacing-xl) var(--spacing-md);
        }

        .project-meta {
            gap: var(--spacing-lg);
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="project-header">
    <div class="container">
        <a href="{{ url_for('zopk_index') }}" class="back-link">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
            Powrót do ZOP Kaszubia
        </a>

        <span class="project-status">
            {% if project.status == 'planned' %}Planowany{% elif project.status == 'in_progress' %}W realizacji{% else %}{{ project.status }}{% endif %}
        </span>

        <h1>{{ project.name }}</h1>

        {% if project.description %}
        <p>{{ project.description }}</p>
        {% endif %}

        <div class="project-meta">
            {% if project.region %}
            <div class="project-meta-item">
                <div class="project-meta-value">{{ project.region }}</div>
                <div class="project-meta-label">Region</div>
            </div>
            {% endif %}
            {% if project.estimated_investment %}
            <div class="project-meta-item">
                <div class="project-meta-value">{{ "{:,.0f}".format(project.estimated_investment|float).replace(",", " ") }} PLN</div>
                <div class="project-meta-label">Szacowane inwestycje</div>
            </div>
            {% endif %}
            {% if project.estimated_jobs %}
            <div class="project-meta-item">
                <div class="project-meta-value">{{ project.estimated_jobs }}</div>
                <div class="project-meta-label">Szacowane miejsca pracy</div>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<div class="content-grid">
    <div class="main-content">
        <!-- News -->
        <div class="section">
            <h2>Aktualności</h2>
            {% if news_items %}
            <div class="news-list">
                {% for news in news_items %}
                <a href="{{ news.url }}" target="_blank" rel="noopener" class="news-item">
                    <h4>{{ news.title }}</h4>
                    <div class="news-item-meta">
                        {{ news.source_name or news.source_domain }} &bull;
                        {{ news.published_at.strftime('%d.%m.%Y') if news.published_at else '-' }}
                    </div>
                </a>
                {% endfor %}
            </div>
            {% else %}
            <div class="empty-state">
                <p>Brak aktualności o tym projekcie.</p>
            </div>
            {% endif %}
        </div>

        <!-- Resources -->
        {% if resources %}
        <div class="section">
            <h2>Materiały</h2>
            <div class="resources-list">
                {% for resource in resources %}
                <a href="{{ resource.url or '#' }}" target="_blank" rel="noopener" class="resource-item">
                    <div class="resource-icon">
                        {% if resource.resource_type == 'document' %}
                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
                        {% elif resource.resource_type == 'video' %}
                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="23 7 16 12 23 17 23 7"/><rect width="15" height="14" x="1" y="5" rx="2" ry="2"/></svg>
                        {% else %}
                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
                        {% endif %}
                    </div>
                    <h5>{{ resource.title }}</h5>
                </a>
                {% endfor %}
            </div>
        </div>
        {% endif %}
    </div>

    <div class="sidebar">
        <!-- Norda Companies -->
        <div class="section">
            <h2>Firmy Norda Biznes</h2>
            {% if company_links %}
            <div class="companies-list">
                {% for link in company_links %}
                <a href="{{ url_for('company_detail_by_slug', slug=link.company.slug) }}" class="company-link-item">
                    <div class="company-avatar">{{ link.company.name[0].upper() }}</div>
                    <div class="company-info">
                        <h5>{{ link.company.name }}</h5>
                        <p>{{ link.link_type|replace('_', ' ')|capitalize }}</p>
                    </div>
                </a>
                {% endfor %}
            </div>
            {% else %}
            <div class="empty-state">
                <p>Brak powiązanych firm z Norda Biznes.</p>
                <p style="margin-top: var(--spacing-sm);">Firmy mogą zgłosić swoje zainteresowanie projektem.</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
