        <header class="page-heading"><p class="eyebrow">ECONOMÍA VIVA</p><h1>Agricultura de {{ planet.name }}</h1><p>Asigna población, cultiva alimentos y cosecha manualmente o mediante automatización. La IA administra sus propias granjas con las mismas reglas.</p></header>
        <section class="metric-grid" aria-label="Resumen agrícola">
          <article><span>Alimento almacenado</span><strong>{{ snap.food|number }}</strong><small>reserva planetaria</small></article>
          <article><span>Población</span><strong>{{ snap.population|number }}</strong><small>capacidad laboral</small></article>
          <article><span>Trabajadores agrícolas</span><strong>{{ assigned_workers|number }}</strong><small>máximo {{ (snap.population * 0.3)|int|number }}</small></article>
          <article><span>Parcelas</span><strong>{{ farms|length }} / {{ farm_slots }}</strong><small>amplía el Complejo agrícola</small></article>
        </section>
        {% if farm_rows %}<section aria-labelledby="active-farms-title"><h2 id="active-farms-title" class="section-title">Granjas activas</h2><div class="farm-grid">
          {% for farm in farm_rows %}<article class="farm-card">
            <header><div class="crop-symbol" aria-hidden="true">{{ '%02d'|format(loop.index) }}</div><div><p class="eyebrow">{{ farm.crop.name }}</p><h3>{{ farm.row.name }} <span>Nivel {{ farm.row.level }}</span></h3></div></header>
            <p>{{ farm.crop.description }} <a href="{{ url_for('game_view', section='encyclopedia') }}#wiki-crop-{{ farm.row.crop }}">Consultar cultivo</a></p>
            <dl class="farm-stats"><div><dt>Cosecha lista</dt><dd>{{ farm.row.stored|number }} / {{ farm.capacity|number }}</dd></div><div><dt>Producción</dt><dd>{{ (farm.rate * game.speed)|number }}/h</dd></div><div><dt>Trabajadores</dt><dd>{{ farm.row.workers }}</dd></div><div><dt>Automatizada</dt><dd>{{ 'Sí' if farm.row.automation else 'No' }}</dd></div></dl>
            <div class="button-row"><form method="post" action="{{ url_for('farm_harvest_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="farm_id" value="{{ farm.row.id }}"><button class="button button-primary" type="submit">Cosechar {{ farm.row.stored|int|number }}</button></form><form method="post" action="{{ url_for('farm_upgrade_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="farm_id" value="{{ farm.row.id }}"><button class="button" type="submit">Mejorar a nivel {{ farm.row.level + 1 }}</button></form></div>
            <details><summary>Organizar trabajadores y automatización</summary><form class="inline-form detail-form" method="post" action="{{ url_for('farm_configure_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="farm_id" value="{{ farm.row.id }}"><label>Trabajadores<input type="number" name="workers" min="1" max="500" value="{{ farm.row.workers }}"></label><label class="check-label"><input type="checkbox" name="automation" value="1" {% if farm.row.automation %}checked{% endif %}> Cosecha automática al 75 % <small>Requiere Computación 2 y pierde un 6 %.</small></label><button class="button" type="submit">Guardar organización</button></form></details>
          </article>{% endfor %}
        </div></section>{% else %}<p class="empty-state">Aún no hay granjas. El primer asentamiento agrícola no necesita un Complejo agrícola.</p>{% endif %}
        {% if farms|length < farm_slots %}<section class="panel create-farm" aria-labelledby="create-farm-title"><div><p class="eyebrow">NUEVA PARCELA</p><h2 id="create-farm-title">Establecer una granja</h2><p>Coste base: 1.000 metal, 700 cristal y 250 deuterio. Las parcelas posteriores aumentan de precio.</p></div><form method="post" action="{{ url_for('farm_create_action') }}" class="form-grid"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><label>Nombre<input name="name" maxlength="40" value="Granja orbital {{ farms|length + 1 }}" required></label><label>Cultivo<select name="crop">{% for key, crop in CROPS.items() %}<option value="{{ key }}">{{ crop.name }} — {{ crop.description }}</option>{% endfor %}</select></label><label>Trabajadores iniciales<input name="workers" type="number" min="1" max="500" value="30"></label><button class="button button-primary" type="submit">Fundar granja</button></form></section>{% endif %}
