<aside id="primary-navigation" class="sidebar" tabindex="-1" aria-label="Navegación y planeta activo" aria-keyshortcuts="{{ shortcut_map.navigation }}" data-binding-action="navigation">
  <section id="planet-controls" tabindex="-1" aria-label="Planeta activo" aria-keyshortcuts="{{ shortcut_map.planet }}" data-binding-action="planet">
    <form class="planet-switcher" method="get" action="{{ url_for('game_view', section=section) }}">
      <input type="hidden" name="focus" value="main">
      <label for="planet-select">Planeta activo</label>
      <select id="planet-select" name="planet">{% for own_planet in planets %}<option value="{{ own_planet.id }}" {% if own_planet.id == planet.id %}selected{% endif %}>{{ own_planet.alias or own_planet.name }} [{{ own_planet.galaxy }}:{{ own_planet.system }}:{{ own_planet.position }}]{% if own_planet.group_key and own_planet.group_key != 'sin_grupo' %} · {{ PLANET_GROUPS[own_planet.group_key] }}{% endif %}</option>{% endfor %}</select>
      <button class="button button-secondary" type="submit">Cambiar planeta</button>
    </form>
    {% if planets|length > 1 %}
      <nav class="planet-stepper" aria-label="Recorrer planetas">
        <a class="button button-secondary" href="{{ url_for('game_view', section=section, planet=previous_planet.id, focus='main') }}" rel="prev">Planeta anterior: {{ previous_planet.alias or previous_planet.name }}</a>
        <a class="button button-secondary" href="{{ url_for('game_view', section=section, planet=next_planet.id, focus='main') }}" rel="next">Planeta siguiente: {{ next_planet.alias or next_planet.name }}</a>
      </nav>
    {% endif %}
  </section>
  {% macro navigation_link(key, label, number) -%}
  <a href="{{ url_for('game_view', section=key, planet=planet.id) }}" {% if shortcut_map.get(key) %}aria-keyshortcuts="{{ shortcut_map[key] }}" data-binding-action="{{ key }}"{% endif %} {% if key == 'manual' %}data-open-manual target="_blank" rel="noopener" aria-description="Se abre en una pestaña nueva"{% endif %} {% if section == key %}aria-current="page"{% endif %}>
    <span aria-hidden="true">{{ number }}</span>{{ label }}
    {% if key == 'messages' and unread %}<b class="badge"><span class="sr-only">, </span>{{ unread }}<span class="sr-only"> sin leer</span></b>{% endif %}
    {% if key == 'operations' and pending_events %}<b class="badge"><span class="sr-only">, </span>{{ pending_events }}<span class="sr-only"> {{ 'decisión pendiente' if pending_events == 1 else 'decisiones pendientes' }}</span></b>{% endif %}
  </a>
  {%- endmacro %}
  {% set navigation_groups = [
    ('command', 'Mando', [
      ('overview','Resumen','01'), ('help','Ayuda y primeros pasos','02'), ('manual','Manual completo','03'), ('command','Centro estratégico','04'), ('encyclopedia','Enciclopedia','05')
    ]),
    ('economy', 'Economía y colonias', [
      ('economy','Economía','06'), ('agriculture','Agricultura','09'), ('commerce','Comercio','10'), ('market','Mercado galáctico','11'), ('logistics','Red logística','32'), ('empire','Panel imperial','29')
    ]),
    ('science', 'Ciencia e industria', [
      ('research','Investigación','07'), ('shipyard','Astillero','08'), ('designs','Diseñador de naves','24'), ('museum','Museo de artefactos','31')
    ]),
    ('fleet', 'Flotas y exploración', [
      ('frontier','Frontera','12'), ('expeditions','Expediciones','13'), ('galaxy','Galaxia','14'), ('fleet','Flotas','15'), ('invasions','Invasiones','25'), ('orbital','Guerra orbital','34')
    ]),
    ('relations', 'Relaciones y sociedad', [
      ('diplomacy','Diplomacia','16'), ('governance','Gobernadores','17'), ('society','Política interna','21'), ('senate','Senado galáctico','22'), ('intelligence','Espionaje','23')
    ]),
    ('history', 'Historia y comunidad', [
      ('operations','Operaciones','18'), ('messages','Informes','19'), ('timeline','Historia del universo','20'), ('encounters','Encuentros y crisis','26'), ('scenarios','Escenarios y mods','27'), ('planning','Planificación y calendario','28'), ('statistics','Estadísticas imperiales','30'), ('seasons','Temporadas locales','33')
    ]),
    ('system', 'Sistema', [
      ('settings','Configuración','35'), ('about','Acerca de','36')
    ])
  ] %}
  <nav aria-label="Navegación principal, modo normal" data-navigation-classic {% if interface_preferences.navigation_mode == 'tabs' %}hidden{% endif %}>
    <ul>{% for group_key, group_label, items in navigation_groups %}{% for key, label, number in items %}<li>{{ navigation_link(key, label, number) }}</li>{% endfor %}{% endfor %}</ul>
  </nav>
  <nav aria-label="Navegación principal agrupada" data-navigation-grouped {% if interface_preferences.navigation_mode != 'tabs' %}hidden{% endif %}>
    {% for group_key, group_label, items in navigation_groups %}
    <details data-navigation-group="{{ group_key }}" {% if section in items|map(attribute=0)|list %}open{% endif %}>
      <summary>{{ group_label }}</summary>
      <ul>{% for key, label, number in items %}<li>{{ navigation_link(key, label, number) }}</li>{% endfor %}</ul>
    </details>
    {% endfor %}
  </nav>
  {% if ONLINE_MODE %}
  <nav aria-label="Cuenta del servidor">
    <ul>
      <li><a href="{{ url_for('online_dashboard') }}"><span aria-hidden="true">C1</span>Mis universos</a></li>
      <li><a href="{{ url_for('online_reports') }}"><span aria-hidden="true">C2</span>Reportar al equipo</a></li>
      <li><a href="{{ url_for('online_store') }}"><span aria-hidden="true">C3</span>Tienda del universo</a></li>
      <li><a href="{{ url_for('online_privacy') }}"><span aria-hidden="true">C4</span>Cuenta y privacidad</a></li>
    </ul>
  </nav>
  {% endif %}
  <div class="commander-card"><span>Comandante</span><strong>{{ empire.commander }}</strong><small>{{ empire.name }} · {{ DOCTRINES[empire.doctrine] }}</small></div>
</aside>
