<?php
declare(strict_types=1);

require __DIR__ . '/bootstrap.php';
require __DIR__ . '/includes/header.php';
?>

<section class="hero">
    <div class="container hero-grid">
        <div>
            <div class="eyebrow">✦ <?= e((string) t('hero.eyebrow')) ?></div>
            <h1><?= e((string) t('hero.title')) ?></h1>
            <p class="hero-lead"><?= e((string) t('hero.subtitle')) ?></p>
            <div class="hero-actions">
                <a class="btn btn-primary" href="<?= url('overview') ?>"><?= e((string) t('hero.button_primary')) ?> →</a>
                <a class="btn btn-ghost" href="<?= url('contact') ?>"><?= e((string) t('hero.button_secondary')) ?></a>
                <a class="btn btn-ghost" href="<?= url('documents') ?>"><?= e((string) t('hero.button_docs')) ?></a>
            </div>
        </div>
        <aside class="hero-panel">
            <div class="metric-grid">
                <?php foreach ($app['metrics'] as $metric): ?>
                    <div class="metric">
                        <strong><?= e($metric['value']) ?></strong>
                        <span><?= e((string) t('metrics.' . $metric['key'])) ?></span>
                    </div>
                <?php endforeach; ?>
            </div>
        </aside>
    </div>
</section>

<section id="overview" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('overview.title')) ?></h2>
            <div class="accent-line"></div>
        </div>
        <div class="overview-text">
            <?php foreach ((array) t('overview.paragraphs') as $paragraph): ?>
                <p><?= e((string) $paragraph) ?></p>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="admissions" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('admissions.title')) ?></h2>
            <p><?= e((string) t('admissions.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-2" style="margin-bottom:2rem">
            <article class="card">
                <h3><?= e((string) t('admissions.facts_title')) ?></h3>
                <ul class="fact-list">
                    <li><strong><?= e((string) t('admissions.fact_duration')) ?>:</strong> <?= (int) $programFacts['duration_months'] ?> <?= $lang === 'es' ? 'meses' : 'months' ?></li>
                    <li><strong><?= e((string) t('admissions.fact_modality')) ?>:</strong> <?= e($programFacts['modality'][$lang]) ?></li>
                    <li><strong><?= e((string) t('admissions.fact_tuition')) ?>:</strong> <?= e($programFacts['tuition'][$lang]) ?></li>
                    <li><strong><?= e((string) t('admissions.fact_start')) ?>:</strong> <?= e($programFacts['start_dates'][$lang]) ?></li>
                </ul>
            </article>
            <article class="card">
                <h3><?= e((string) t('admissions.requirements_title')) ?></h3>
                <ul class="fact-list">
                    <?php foreach ($requirements as $req): ?>
                        <li><?= e($req[$lang]) ?></li>
                    <?php endforeach; ?>
                </ul>
            </article>
        </div>
        <h3 style="text-align:center;font-family:'Cormorant Garamond',serif;margin-bottom:1.5rem"><?= e((string) t('admissions.process_title')) ?></h3>
        <div class="grid-4 steps-grid">
            <?php foreach ($admissionsSteps as $step): ?>
                <article class="card step-card">
                    <span class="number-badge"><?= (int) $step['step'] ?></span>
                    <h3 style="font-family:inherit;font-size:1rem"><?= e($step['title_' . $lang]) ?></h3>
                    <p style="margin:0;color:var(--muted);font-size:.88rem"><?= e($step['text_' . $lang]) ?></p>
                </article>
            <?php endforeach; ?>
        </div>
        <h3 style="text-align:center;font-family:'Cormorant Garamond',serif;margin:2.5rem 0 1.5rem"><?= e((string) t('admissions.timeline_title')) ?></h3>
        <div class="timeline">
            <?php foreach ($timeline as $phase): ?>
                <article class="timeline-item card">
                    <span class="timeline-phase"><?= e($phase['phase_' . $lang]) ?></span>
                    <span class="timeline-months"><?= e($phase['months_' . $lang]) ?></span>
                    <p><?= e($phase['desc_' . $lang]) ?></p>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="about" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('about.title')) ?></h2>
            <p><?= e((string) t('about.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-2">
            <article class="card">
                <div class="icon-box">☆</div>
                <h3><?= e((string) t('about.mission_title')) ?></h3>
                <p><?= e((string) t('about.mission_text')) ?></p>
            </article>
            <article class="card">
                <div class="icon-box" style="background:rgba(61,214,232,.12);color:var(--cyan)">◉</div>
                <h3><?= e((string) t('about.vision_title')) ?></h3>
                <p><?= e((string) t('about.vision_text')) ?></p>
            </article>
        </div>
    </div>
</section>

<section id="values" class="reveal">
    <div class="container">
        <h2 style="text-align:center;font-family:'Cormorant Garamond',serif;font-size:1.75rem;margin:0 0 1.5rem">
            <?= e((string) t('values_title')) ?>
        </h2>
        <div class="values-row">
            <?php foreach ($values as $value): ?>
                <span class="pill"><?= e($value[$lang]) ?></span>
            <?php endforeach; ?>
        </div>
        <div class="grid-3">
            <?php
            $cardKeys = ['international', 'bilingual', 'madrid'];
            $icons = ['◎', '▣', '⌖'];
            foreach ($cardKeys as $i => $key):
            ?>
                <article class="card" style="text-align:center">
                    <div class="icon-box" style="margin-inline:auto"><?= $icons[$i] ?></div>
                    <h3><?= e((string) t("cards.{$key}_title")) ?></h3>
                    <p><?= e((string) t("cards.{$key}_text")) ?></p>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="outcomes" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('outcomes.title')) ?></h2>
            <p><?= e((string) t('outcomes.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-3">
            <?php foreach ($outcomes as $index => $outcome): ?>
                <article class="card outcome-card">
                    <span class="number-badge"><?= $index + 1 ?></span>
                    <div>
                        <h3 style="font-family:inherit;font-size:1rem;margin:0 0 .5rem"><?= e($outcome[$lang . '_title']) ?></h3>
                        <p style="margin:0;color:var(--muted);font-size:.9rem"><?= e($outcome[$lang . '_text']) ?></p>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="core" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('core.title')) ?></h2>
            <p><?= e((string) t('core.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-3">
            <?php foreach ($coreCourses as $course): ?>
                <article class="card course-card">
                    <span class="course-code"><?= e($course['code']) ?></span>
                    <div>
                        <h3><?= e($course[$lang]) ?></h3>
                        <small><?= e((string) t('core.badge')) ?></small>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="tracks" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('tracks.title')) ?></h2>
            <p><?= e((string) t('tracks.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-3">
            <?php foreach ($tracks as $track): ?>
                <article class="card course-card track <?= e($trackClass($track['category'])) ?>">
                    <span class="course-code"><?= e($track['code']) ?></span>
                    <div>
                        <h3><?= e($track[$lang]) ?></h3>
                        <small><?= e($track['category']) ?></small>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="capstone" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('capstone.title')) ?></h2>
            <p><?= e((string) t('capstone.text')) ?></p>
            <div class="accent-line"></div>
        </div>
        <article class="card" style="max-width:52rem;margin:0 auto;text-align:center">
            <div class="icon-box" style="margin-inline:auto;background:rgba(74,222,128,.12);color:var(--green)">✓</div>
            <h3><?= e((string) t('capstone.card_title')) ?></h3>
            <p><?= e((string) t('capstone.card_tags')) ?></p>
        </article>
    </div>
</section>

<section id="documents" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('documents.title')) ?></h2>
            <p><?= e((string) t('documents.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="doc-filters">
            <button type="button" class="filter-btn active" data-filter="all"><?= e((string) t('documents.filter_all')) ?></button>
            <?php foreach ($docCategories as $category): ?>
                <button type="button" class="filter-btn" data-filter="<?= e($category) ?>"><?= e($category) ?></button>
            <?php endforeach; ?>
        </div>
        <div class="grid-3" id="documentGrid">
            <?php foreach ($documents as $doc): ?>
                <article class="card doc-card" data-category="<?= e($doc['category']) ?>">
                    <div style="display:flex;gap:1rem;min-width:0;align-items:center">
                        <div class="icon-box" style="margin:0;background:rgba(61,214,232,.1);color:var(--cyan)">▤</div>
                        <div style="min-width:0">
                            <div class="doc-title"><?= e($doc['title']) ?></div>
                            <div style="color:var(--muted);font-size:.8rem;margin-top:.35rem"><?= e($doc['type']) ?></div>
                        </div>
                    </div>
                    <a class="download-link" href="<?= downloadUrl((string) $doc['id']) ?>" title="<?= e((string) t('documents.download')) ?>">⇩</a>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="madrid" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('madrid.title')) ?></h2>
            <p><?= e((string) t('madrid.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="grid-2">
            <article class="card">
                <div class="icon-box">⌖</div>
                <h3><?= e((string) t('madrid.card1_title')) ?></h3>
                <p><?= e((string) t('madrid.card1_text')) ?></p>
            </article>
            <article class="card">
                <div class="icon-box" style="background:rgba(251,146,60,.12);color:var(--danger)">✺</div>
                <h3><?= e((string) t('madrid.card2_title')) ?></h3>
                <p><?= e((string) t('madrid.card2_text')) ?></p>
            </article>
        </div>
    </div>
</section>

<section id="team" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('team.title')) ?></h2>
            <p><?= e((string) t('team.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="team-grid">
            <?php foreach ($leadership as $member): ?>
                <article class="card team-card <?= e($member['accent']) ?>">
                    <div class="avatar"><?= e(substr($member['name'], 0, 1)) ?></div>
                    <h3 style="font-size:1rem;margin:0"><?= e($member['name']) ?></h3>
                    <div class="role"><?= e($member['role_' . $lang]) ?></div>
                    <p class="bio"><?= e($member['bio_' . $lang]) ?></p>
                    <a class="team-email" href="mailto:<?= e($member['email']) ?>"><?= e((string) t('team.email')) ?> →</a>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="faq" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('faq.title')) ?></h2>
            <p><?= e((string) t('faq.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="faq-list">
            <?php foreach ($faq as $i => $item): ?>
                <article class="card faq-item">
                    <button type="button" class="faq-q" aria-expanded="false" data-faq="<?= $i ?>">
                        <?= e($item['q_' . $lang]) ?>
                        <span class="faq-icon">+</span>
                    </button>
                    <div class="faq-a" hidden>
                        <p><?= e($item['a_' . $lang]) ?></p>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section id="contact" class="reveal">
    <div class="container">
        <div class="section-head">
            <h2><?= e((string) t('contact.title')) ?></h2>
            <p><?= e((string) t('contact.subtitle')) ?></p>
            <div class="accent-line"></div>
        </div>
        <div class="contact-grid">
            <div class="contact-list">
                <article class="card contact-item">
                    <span class="ci-icon">@</span>
                    <div>
                        <strong><?= e((string) t('contact.email_label')) ?></strong>
                        <a href="mailto:<?= e($contact['email']) ?>"><?= e($contact['email']) ?></a>
                    </div>
                </article>
                <article class="card contact-item">
                    <span class="ci-icon">☎</span>
                    <div>
                        <strong><?= e((string) t('contact.phone_label')) ?></strong>
                        <a href="tel:<?= e(preg_replace('/\s+/', '', $contact['phone'])) ?>"><?= e($contact['phone']) ?></a>
                    </div>
                </article>
                <article class="card contact-item">
                    <span class="ci-icon">W</span>
                    <div>
                        <strong><?= e((string) t('contact.whatsapp_label')) ?></strong>
                        <a href="https://wa.me/<?= e(preg_replace('/\D/', '', $contact['whatsapp'])) ?>" target="_blank" rel="noopener"><?= e($contact['whatsapp']) ?></a>
                    </div>
                </article>
                <article class="card contact-item">
                    <span class="ci-icon">⌖</span>
                    <div>
                        <strong><?= e((string) t('contact.address_label')) ?></strong>
                        <p style="margin:0 0 .5rem"><?= e($contact['address'][$lang]) ?></p>
                        <a href="<?= e($contact['map_url']) ?>" target="_blank" rel="noopener"><?= e((string) t('contact.map_link')) ?> →</a>
                    </div>
                </article>
                <article class="card contact-item">
                    <span class="ci-icon">◷</span>
                    <div>
                        <strong><?= e((string) t('contact.hours_label')) ?></strong>
                        <?= e($contact['hours'][$lang]) ?>
                    </div>
                </article>
                <div class="social-row">
                    <?php foreach ($contact['social'] as $social): ?>
                        <a class="social-btn" href="<?= e($social['url']) ?>" target="_blank" rel="noopener" title="<?= e($social['label']) ?>"><?= e($social['icon']) ?></a>
                    <?php endforeach; ?>
                </div>
            </div>

            <article class="card contact-form">
                <h3 style="margin-top:0"><?= e((string) t('contact.form_title')) ?></h3>
                <?php if ($formSent): ?>
                    <div class="form-success"><?= e((string) t('contact.form_success')) ?></div>
                <?php elseif ($formResult !== null && !$formResult['ok']): ?>
                    <div class="form-error"><?= e(formErrorMessage($formResult, $lang)) ?></div>
                <?php endif; ?>
                <form id="contactForm" method="post" action="<?= url('contact') ?>" novalidate>
                    <input type="hidden" name="contact_form" value="1">
                    <label for="name"><?= e((string) t('contact.form_name')) ?></label>
                    <input type="text" id="name" name="name" required autocomplete="name">

                    <label for="email"><?= e((string) t('contact.form_email')) ?></label>
                    <input type="email" id="email" name="email" required autocomplete="email">

                    <label for="interest"><?= e((string) t('contact.form_interest')) ?></label>
                    <select id="interest" name="interest">
                        <?php foreach ((array) t('contact.interests') as $interest): ?>
                            <option value="<?= e((string) $interest) ?>"><?= e((string) $interest) ?></option>
                        <?php endforeach; ?>
                    </select>

                    <label for="message"><?= e((string) t('contact.form_message')) ?></label>
                    <textarea id="message" name="message" rows="4" required></textarea>

                    <button type="submit" class="btn btn-primary" style="width:100%"><?= e((string) t('contact.form_submit')) ?></button>
                    <p class="form-note"><?= e((string) t('contact.form_note')) ?></p>
                </form>
            </article>
        </div>
    </div>
</section>

<?php require __DIR__ . '/includes/footer.php'; ?>
