Feature: Navigation and state retention

  Users navigate forward through screens by making selections, and
  backward with Esc. The session remembers previous answers so users
  can review and revise without re-entering everything.

  Rule: Esc navigates back one visible screen at a time

    Scenario: Going back from a command-specific screen
      Given the user is on the first screen of a command flow
      When they press Esc
      Then the preset selection screen is shown
      And their previous preset choice is preserved

    Scenario: Going back from the preset selection
      Given the user is on the preset selection screen
      When they press Esc
      Then the command menu is shown
      And their previous command selection is highlighted

    Scenario: Going back step by step through a multi-screen flow
      Given the user has progressed through several screens
      When they press Esc repeatedly
      Then they step back through each previously-visited screen
      And each screen shows their earlier answer

    Scenario: Esc on the command menu exits the session
      Given the user is on the command menu
      When they press Esc
      Then the session exits without executing restic

  Rule: Screens are skipped when the needed value is already resolved

    Scenario: Command provided on the command line
      Given the user invokes keld with a command argument
      Then the command menu is not shown
      And the session begins at the preset selection

    Scenario: Preset provided on the command line
      Given the user invokes keld with --preset
      Then the preset selection screen is not shown

    Scenario: No presets defined in configuration
      Given the configuration defines no presets
      Then the preset selection screen is not shown

    Scenario: Exactly one preset defined
      Given the configuration defines exactly one preset
      Then that preset is selected automatically
      And the preset selection screen is not shown

    Scenario: All required values already resolved
      Given the command, preset, and all command-specific values are already provided
      Then the session skips directly to the confirmation screen

  Rule: Skipped screens are also skipped during back navigation

    Scenario: Navigating back past a skipped screen
      Given a screen was skipped because its value was already resolved
      When the user navigates back from the screen after it
      Then they land on the screen before the skipped one

  Rule: CLI-provided values are always skipped regardless of navigation

    Scenario: CLI-provided values cannot be reached via back navigation
      Given the user provided a value on the command line
      Then that value's screen is never shown
      And back navigation passes over it in both directions
