        <header class="page-heading"><p class="eyebrow">COMANDO DE FLOTA</p><h1>Flotas</h1><p>Ordena ataques, bloqueos, ayuda humanitaria, rutas comerciales, patrullas aliadas, cartografía, colonización y expediciones.</p></header>
        {% if fleets %}<section class="panel" aria-labelledby="active-fleets-title"><h2 id="active-fleets-title">Movimientos activos</h2><ul class="activity-list">{% for fleet in fleets %}<li><div><strong>{{ MISSIONS[fleet.mission] }} a [{{ fleet.target_galaxy }}:{{ fleet.target_system }}:{{ fleet.target_position }}]</strong><span>{{ 'En ruta' if fleet.status == 'outbound' else 'De regreso' }} desde {{ fleet.origin_name }} · velocidad {{ fleet.speed_percent }} % · combustible {{ fleet.fuel_cost }}</span></div><time class="countdown" data-end="{{ fleet.arrival_at if fleet.status == 'outbound' else fleet.return_at }}">{{ ((fleet.arrival_at if fleet.status == 'outbound' else fleet.return_at)-now)|duration }}</time>{% if fleet.status == 'outbound' %}<form method="post" action="{{ url_for('recall_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="fleet_id" value="{{ fleet.id }}"><button class="button button-danger" type="submit">Retirar {{ MISSIONS[fleet.mission]|lower }} hacia [{{ fleet.target_galaxy }}:{{ fleet.target_system }}:{{ fleet.target_position }}]</button></form>{% endif %}</li>{% endfor %}</ul></section>{% endif %}
        {% if recall_preview %}
        <section id="recall-confirmation" class="panel notice notice-warning" aria-labelledby="recall-confirmation-title" tabindex="-1">
          <p class="eyebrow">REVISIÓN DE RETIRADA</p>
          <h2 id="recall-confirmation-title">Confirmar retirada de {{ recall_preview.mission|lower }}</h2>
          <dl class="definition-list">
            <div><dt>Origen</dt><dd>{{ recall_preview.origin }}</dd></div>
            <div><dt>Destino que se abandona</dt><dd>{{ recall_preview.destination }}</dd></div>
            <div><dt>Llegada prevista anterior</dt><dd>{{ recall_preview.old_arrival_at|datetime }}</dd></div>
            <div><dt>Nuevo regreso estimado</dt><dd>{{ recall_preview.new_return_at|datetime }}</dd></div>
            <div><dt>Combustible ya consumido</dt><dd>{{ recall_preview.fuel_cost }} deuterio; no reembolsable</dd></div>
          </dl>
          <h3>Naves que regresarán</h3>
          <ul>{% for name, amount in recall_preview.ships.items() %}<li>{{ amount }} × {{ name }}</li>{% endfor %}</ul>
          <h3>Carga que regresará</h3>
          {% if recall_preview.cargo %}<ul>{% for resource, amount in recall_preview.cargo.items() %}<li>{{ resource }}: {{ amount }}</li>{% endfor %}</ul>{% else %}<p>Sin carga.</p>{% endif %}
          <p><strong>Consecuencia:</strong> {{ recall_preview.consequence }}</p>
          <form method="post" action="{{ url_for('recall_action') }}" class="stacked-form">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <input type="hidden" name="stage" value="confirm">
            <input type="hidden" name="fleet_id" value="{{ recall_preview.fleet_id }}">
            <label class="check-row"><input type="checkbox" name="confirm" value="1" required> He revisado la misión, las naves, la carga, los tiempos y el combustible no reembolsable</label>
            <button class="button button-danger" type="submit">Confirmar retirada de esta flota</button>
          </form>
        </section>
        {% endif %}
        {% if fleet_repeat %}<p><a class="button" href="{{ url_for('game_view', section='fleet', planet=planet.id, repeat=1, focus='main') }}#new-mission-title">Preparar otra flota con los mismos parámetros</a> La orden vuelve al formulario y debe revisarse y confirmarse de nuevo.</p>{% endif %}
        {% if fleet_preview %}<section id="fleet-confirmation" class="panel notice notice-warning" aria-labelledby="fleet-confirmation-title" tabindex="-1"><p class="eyebrow">REVISIÓN OBLIGATORIA</p><h2 id="fleet-confirmation-title">Confirmar orden exacta</h2><p>{{ fleet_preview.summary }}</p><form method="post" action="{{ url_for('fleet_action') }}" class="stacked-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="stage" value="confirm"><label class="check-row"><input type="checkbox" name="confirm" value="1" required> Confirmo destino, misión, naves, carga, velocidad, duración y combustible</label><button class="button button-primary button-large" type="submit">Enviar esta flota</button></form><p>Si algo no coincide, modifica el formulario inferior y vuelve a calcular; el resumen anterior se sustituirá sin consumir nada.</p></section>{% endif %}
        <section class="panel mission-panel" aria-labelledby="new-mission-title"><div class="panel-heading"><div><p class="eyebrow">NUEVA ORDEN</p><h2 id="new-mission-title">Preparar misión desde {{ planet.name }}</h2></div><span>{{ fleets|length }} / {{ 1 + techs.get('computer_tech',0) }} ranuras</span></div>
          {% if fleet_templates %}<div class="fleet-template-picker" aria-labelledby="fleet-template-picker-title"><h3 id="fleet-template-picker-title">Rellenar desde una plantilla</h3><p>Solo completa el formulario; revisa destino, disponibilidad, carga y consumo antes de enviar.</p><div class="inline-form"><label>Plantilla<select id="fleet-template-select">{% for template in fleet_templates %}<option value="{{ template.id }}" data-ships="{{ template.ships_json|forceescape }}" data-cargo="{{ template.cargo_json|forceescape }}" data-mission="{{ template.mission }}" data-speed="{{ template.preferred_speed }}">{{ template.name }}</option>{% endfor %}</select></label><button class="button" type="button" data-apply-fleet-template>Aplicar plantilla</button><a href="{{ url_for('game_view', section='command') }}#fleet-templates">Gestionar plantillas</a></div></div>{% else %}<p><a href="{{ url_for('game_view', section='command') }}#fleet-templates">Crear plantillas de flota</a> permite preparar composiciones frecuentes sin lanzar nada automáticamente.</p>{% endif %}
          {% set repeat = fleet_repeat if request.args.get('repeat') == '1' else none %}
          {% if ships %}<form method="post" action="{{ url_for('fleet_action') }}" class="mission-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="stage" value="preview">
            <fieldset><legend>1. Selecciona las naves</legend><div class="form-grid">{% for key, definition, owned in ships %}<label>{{ definition.name }} <small>{{ owned }} disponibles</small><input type="number" name="ship_{{ key }}" min="0" max="{{ owned }}" value="{{ [repeat.ships.get(key,0),owned]|min if repeat else 1 if key == 'espionage_probe' and request.args.get('mission') == 'espionage' else 0 }}"></label>{% endfor %}</div></fieldset>
            <fieldset><legend>2. Destino y misión</legend><div class="form-grid coords"><label>Galaxia<input name="galaxy" type="number" min="1" max="{{ config.get('galaxy_count',1) }}" value="{{ repeat.galaxy if repeat else request.args.get('galaxy',planet.galaxy) }}" required></label><label>Sistema<input name="system" type="number" min="1" max="{{ game.galaxy_size }}" value="{{ repeat.system if repeat else request.args.get('system',planet.system) }}" required></label><label>Posición<input name="position" type="number" min="1" max="15" value="{{ repeat.position if repeat else request.args.get('position',planet.position) }}" required></label><label>Misión<select name="mission">{% for key, label in missions.items() %}<option value="{{ key }}" {% if (repeat and repeat.mission == key) or (not repeat and request.args.get('mission') == key) %}selected{% endif %}>{{ label }} — {{ MISSION_DESCRIPTIONS[key] }}</option>{% endfor %}</select></label></div></fieldset>
            <fieldset><legend>3. Velocidad inequívoca</legend><label>Porcentaje de velocidad<select name="speed_percent">{% for speed in range(100,0,-10) %}<option value="{{ speed }}" {% if repeat and repeat.speed_percent == speed %}selected{% endif %}>{{ speed }} % — {{ 'máxima velocidad y mayor consumo' if speed == 100 else 'viaje más lento y menor consumo' }}</option>{% endfor %}</select></label></fieldset>
            <fieldset><legend>4. Carga opcional</legend><p>Ayuda humanitaria y rutas comerciales necesitan carga. El alimento también ocupa capacidad.</p><div class="form-grid"><label>Metal<input name="cargo_metal" type="number" min="0" value="{{ repeat.cargo.get('metal',0) if repeat else 0 }}"></label><label>Cristal<input name="cargo_crystal" type="number" min="0" value="{{ repeat.cargo.get('crystal',0) if repeat else 0 }}"></label><label>Deuterio<input name="cargo_deuterium" type="number" min="0" value="{{ repeat.cargo.get('deuterium',0) if repeat else 0 }}"></label><label>Alimento<input name="cargo_food" type="number" min="0" value="{{ repeat.cargo.get('food',0) if repeat else 0 }}"></label></div></fieldset>
            <button class="button button-primary button-large" type="submit">Calcular y revisar antes de enviar</button>
          </form>{% else %}<p class="empty-state">No hay naves disponibles en este planeta. Constrúyelas en el astillero antes de preparar una misión.</p><a class="button" href="{{ url_for('game_view', section='shipyard') }}">Ir al astillero</a>{% endif %}
        </section>
