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

{% block title %}{{ project.title }} | Studio AI Production{% endblock %}

{% block content %}
<div class="hero-section py-5">
    <div class="container">
        <nav aria-label="breadcrumb" class="mb-4">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{% url 'home' %}" class="text-cyan text-decoration-none">Command Center</a></li>
                <li class="breadcrumb-item active text-muted" aria-current="page">{{ project.title }}</li>
            </ol>
        </nav>
        
        <div class="row align-items-center">
            <div class="col-lg-8">
                <div class="d-flex align-items-center mb-3">
                    <span class="pipeline-badge badge-{{ project.status|lower }} me-2">{{ project.get_status_display }}</span>
                    {% if project.is_ai_generated %}
                    <span class="badge bg-purple text-white rounded-pill px-3 py-2"><i class="bi bi-robot me-1"></i> AI GENERATED</span>
                    {% endif %}
                    <span class="badge bg-dark border border-secondary rounded-pill px-3 py-2 ms-2">{{ project.category }}</span>
                </div>
                <h1 class="display-4 outfit mb-3 text-gradient-neon">{{ project.title }}</h1>
                <p class="lead text-muted">{{ project.description }}</p>
            </div>
            <div class="col-lg-4 text-lg-end">
                <div class="stats-card bg-opacity-10 border-opacity-10">
                    <span class="text-muted small text-uppercase d-block mb-1">Status da Produção</span>
                    <span class="display-6 outfit fw-bold text-cyan">
                        {% with last_step=project.steps.last %}{{ last_step.progress|default:0 }}{% endwith %}%
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

<section class="py-5">
    <div class="container">
        <ul class="nav nav-pills mb-5 justify-content-center" id="prodTab" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active fw-bold px-4" id="pipeline-tab" data-bs-toggle="pill" data-bs-target="#pipeline" type="button" role="tab">PIPELINE CGI</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link fw-bold px-4" id="script-tab" data-bs-toggle="pill" data-bs-target="#script" type="button" role="tab">ROTEIRO & CENAS</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link fw-bold px-4" id="cast-tab" data-bs-toggle="pill" data-bs-target="#cast" type="button" role="tab">PERSONAGENS (REAL)</button>
            </li>
        </ul>

        <div class="tab-content" id="prodTabContent">
            <!-- Pipeline Tab -->
            <div class="tab-pane fade show active" id="pipeline" role="tabpanel">
                <div class="row g-4">
                    {% for step in steps %}
                    <div class="col-md-4 col-lg-3">
                        <div class="project-card p-4 h-100 border-opacity-10">
                            <div class="text-muted small mb-2">ETAPA {{ forloop.counter }}</div>
                            <h4 class="h6 mb-3 outfit">{{ step.get_name_display }}</h4>
                            <div class="d-flex justify-content-between align-items-center mb-2">
                                <span class="small text-muted">Progresso</span>
                                <span class="small text-cyan">{{ step.progress }}%</span>
                            </div>
                            <div class="progress" style="height: 4px;">
                                <div class="progress-bar {% if step.is_completed %}bg-cyan{% endif %}" style="width: {{ step.progress }}%"></div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            </div>

            <!-- Script & Scenes Tab -->
            <div class="tab-pane fade" id="script" role="tabpanel">
                <div class="row justify-content-center">
                    <div class="col-lg-9">
                        {% for scene in scenes %}
                        <div class="scene-item mb-5 p-4 glass-card border-opacity-10 rounded-4">
                            <div class="d-flex align-items-center mb-3">
                                <div class="bg-cyan text-black fw-bold rounded-circle d-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                    {{ scene.number }}
                                </div>
                                <h3 class="h4 outfit mb-0 text-cyan">{{ scene.title }}</h3>
                            </div>
                            <div class="scene-body text-light lead-sm border-start border-cyan border-opacity-25 ps-4 ms-3">
                                {{ scene.description|linebreaks }}
                            </div>
                        </div>
                        {% empty %}
                        <p class="text-center text-muted py-5">Nenhuma cena gerada para este roteiro.</p>
                        {% endfor %}
                    </div>
                </div>
            </div>

            <!-- Cast & Characters Tab -->
            <div class="tab-pane fade" id="cast" role="tabpanel">
                <div class="row g-4">
                    {% for asset in assets %}
                    {% if asset.asset_type == 'CHAR' %}
                    <div class="col-md-6">
                        <div class="project-card p-4 h-100 border-opacity-10 d-flex gap-4">
                            <div class="char-placeholder rounded-4 bg-dark border border-secondary border-opacity-25 d-flex align-items-center justify-content-center" style="width: 120px; height: 160px; min-width: 120px;">
                                <i class="bi bi-person-bounding-box text-muted display-4"></i>
                            </div>
                            <div>
                                <h4 class="outfit text-cyan mb-2">{{ asset.name }}</h4>
                                <span class="badge bg-purple bg-opacity-10 text-purple border border-purple border-opacity-25 mb-3">APARÊNCIA REALISTA</span>
                                <p class="small text-muted mb-0"><strong>Físico:</strong> {{ asset.physical_description }}</p>
                            </div>
                        </div>
                    </div>
                    {% endif %}
                    {% empty %}
                    <p class="text-center text-muted py-5">Nenhum personagem definido no elenco.</p>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>
</section>

<style>
    .nav-pills .nav-link {
        color: rgba(255,255,255,0.5);
        border: 1px solid rgba(255,255,255,0.1);
        margin: 0 5px;
        border-radius: 50px;
    }
    .nav-pills .nav-link.active {
        background-color: #00e5ff;
        color: #000;
        box-shadow: 0 0 15px rgba(0,229,255,0.4);
    }
    .lead-sm {
        font-size: 1.1rem;
        line-height: 1.8;
    }
</style>
{% endblock %}
