        {% from "components/_tabs.html" import tabs_intro %}
        <header class="page-heading"><p class="eyebrow">FRONTERA DESCONOCIDA</p><h1>Expediciones profundas</h1><p>Diseña misiones científicas con objetivo, especialista, nivel de riesgo, suministros y destino. Cada viaje escribe un diario y puede descubrir artefactos que modifican permanentemente tu imperio.</p></header>
        <div data-tab-scope="expeditions" data-tab-auto>
        {{ tabs_intro('expeditions', 'Apartados de expediciones', 'Accede a misiones, preparación, anomalías, diarios y artefactos sin recorrer toda la pantalla.') }}
        <section class="metric-grid" aria-label="Capacidad expedicionaria">
          <article><span>Exploradores disponibles</span><strong>{{ available_explorers }}</strong><small>en {{ planet.name }}</small></article>
          <article><span>Equipos activos</span><strong>{{ active_expeditions|length }} / {{ expedition_slots }}</strong><small>Astrofísica y Red profunda añaden equipos</small></article>
          <article><span>Artefactos</span><strong>{{ artifacts|length }}</strong><small>bonificaciones permanentes acumulables</small></article>
          <article><span>Anomalías conocidas</span><strong>{{ anomalies|selectattr('discovered_by')|list|length }}</strong><small>destinos cartografiados</small></article>
        </section>
        {% if active_expeditions %}<section class="panel" aria-labelledby="deep-active-title"><div class="panel-heading"><div><p class="eyebrow">EN CURSO</p><h2 id="deep-active-title">Misiones activas</h2></div></div><ul class="activity-list">{% for expedition in active_expeditions %}<li><div><strong>{{ expedition.ship_name }}</strong><span>{{ EXPEDITION_PROFILES[expedition.profile].name }} · {{ SPECIALISTS[expedition.specialist].name }} · riesgo {{ RISK_LEVELS[expedition.risk].name|lower }} · destino [{{ expedition.target_galaxy }}:{{ expedition.target_system }}:{{ expedition.target_position }}]</span></div><time class="countdown" data-end="{{ expedition.completes_at }}">{{ (expedition.completes_at-now)|duration }}</time></li>{% endfor %}</ul></section>{% endif %}
        <section class="panel mission-panel" aria-labelledby="deep-launch-title"><div class="panel-heading"><div><p class="eyebrow">NUEVA MISIÓN</p><h2 id="deep-launch-title">Preparar una expedición</h2></div><span>{{ available_explorers }} exploradores disponibles</span></div>
          {% if available_explorers > 0 and active_expeditions|length < expedition_slots %}<form method="post" action="{{ url_for('deep_expedition_action') }}" class="mission-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><fieldset><legend>1. Identidad y objetivo</legend><div class="form-grid"><label>Nombre de la nave<input name="ship_name" maxlength="40" value="Horizonte Errante" required></label><label>Objetivo<select name="profile">{% for key, profile in EXPEDITION_PROFILES.items() %}<option value="{{ key }}" {% if request.args.get('profile') == key %}selected{% endif %}>{{ profile.name }}</option>{% endfor %}</select></label><label>Especialista<select name="specialist">{% for key, specialist in SPECIALISTS.items() %}<option value="{{ key }}">{{ specialist.name }} — {{ specialist.description }}</option>{% endfor %}</select></label></div></fieldset><fieldset><legend>2. Riesgo y destino</legend><div class="form-grid"><label>Protocolo de riesgo<select name="risk">{% for key, risk in RISK_LEVELS.items() %}<option value="{{ key }}" {% if key == 'balanced' %}selected{% endif %}>{{ risk.name }} — {{ risk.description }}</option>{% endfor %}</select></label><label>Galaxia<input name="galaxy" type="number" min="1" max="{{ config.get('galaxy_count',1) }}" value="{{ request.args.get('galaxy',planet.galaxy) }}" required></label><label>Sistema<input name="system" type="number" min="1" max="{{ game.galaxy_size }}" value="{{ request.args.get('system',planet.system) }}" required></label><label>Posición<input name="position" type="number" min="1" max="15" value="{{ request.args.get('position',1) }}" required></label></div></fieldset><button class="button button-primary button-large" type="submit">Iniciar expedición profunda</button></form>{% else %}<p class="empty-state">Necesitas un Explorador de espacio profundo disponible y una ranura libre. Constrúyelo en el Astillero o amplía Astrofísica y la Red de espacio profundo.</p>{% endif %}
          <details><summary>Comparar objetivos y costes base</summary><div class="table-wrap"><table><caption>Objetivos de expedición y suministros antes de modificadores.</caption><thead><tr><th scope="col">Objetivo</th><th scope="col">Propósito</th><th scope="col">Alimento</th><th scope="col">Deuterio</th></tr></thead><tbody>{% for key, profile in EXPEDITION_PROFILES.items() %}<tr><th scope="row">{{ profile.name }}</th><td>{{ profile.description }}</td><td>{{ profile.food|number }}</td><td>{{ profile.deuterium|number }}</td></tr>{% endfor %}</tbody></table></div></details>
        </section>
        {% set known_anomalies = anomalies|selectattr('discovered_by')|list %}{% if known_anomalies %}<section aria-labelledby="anomaly-destinations-title"><h2 id="anomaly-destinations-title" class="section-title">Anomalías cartografiadas</h2><div class="table-wrap"><table><caption>Destinos especiales revelados por expediciones anteriores.</caption><thead><tr><th scope="col">Nombre</th><th scope="col">Coordenadas</th><th scope="col">Naturaleza</th><th scope="col">Dificultad</th><th scope="col">Acción</th></tr></thead><tbody>{% for anomaly in known_anomalies %}<tr><th scope="row">{{ anomaly.name }}</th><td>[{{ anomaly.galaxy }}:{{ anomaly.system }}:{{ anomaly.position }}]</td><td>{{ anomaly.kind }}</td><td>{{ anomaly.difficulty }} de 5</td><td><a href="{{ url_for('game_view', section='expeditions', galaxy=anomaly.galaxy, system=anomaly.system, position=anomaly.position) }}">Usar como destino</a></td></tr>{% endfor %}</tbody></table></div></section>{% endif %}
        {% set completed_expeditions = expeditions|selectattr('status','equalto','completed')|list %}{% if completed_expeditions %}<section aria-labelledby="deep-log-title"><h2 id="deep-log-title" class="section-title">Diarios de expedición</h2><div class="event-grid">{% for expedition in completed_expeditions %}<article class="event-card"><p class="eyebrow">{{ EXPEDITION_PROFILES[expedition.profile].name }}</p><h3>{{ expedition.ship_name }}</h3><p>{{ expedition.result_summary }}</p><dl class="farm-stats"><div><dt>Especialista</dt><dd>{{ SPECIALISTS[expedition.specialist].name }}</dd></div><div><dt>Nave</dt><dd>{{ 'Regresó' if expedition.explorer_returned else 'Perdida' }}</dd></div></dl><details><summary>Leer diario completo</summary><ol>{% for entry in expedition.log_json|from_json %}<li>{{ entry.text }}</li>{% endfor %}</ol></details></article>{% endfor %}</div></section>{% endif %}
        <section aria-labelledby="artifacts-title"><h2 id="artifacts-title" class="section-title">Colección de artefactos</h2>{% if artifacts %}<div class="artifact-grid">{% for artifact in artifacts %}<article class="artifact-card rarity-{{ artifact.rarity }}"><span class="artifact-rarity">{{ {'common':'Común','rare':'Raro','legendary':'Legendario'}[artifact.rarity] }}</span><h3>{{ artifact.name }}</h3><p>{{ artifact.lore }}</p><strong>+{{ (artifact.effect_value * 100)|round(1) }} % {{ ARTIFACT_EFFECTS[artifact.effect_key]|lower }}</strong></article>{% endfor %}</div>{% else %}<p class="empty-state">Aún no se han recuperado artefactos. Arqueología e Inmersión en el vacío ofrecen las mejores posibilidades.</p>{% endif %}</section>
        </div>
