Zigzag this string by collapsing duplicates Given a string, your task is to collapse it into a zigzag-like structure as described below. 

Folding into a Zigzag

We'll take the string "Mississippi" as an example:


First, output the longest prefix consisting of unique characters only:

Mis

When you reach the first duplicate character C, ignore it, and output the longest prefix consisting of unique characters of the remaining string (issippi) vertically, below the first occurrence of C:

Mis
  i
  s

Repeat the process, alternating between horizontal and vertical continuation. But now be careful (at step 1) to continue outputting horizontally from latest occurrence of the duplicate character, which is not necessarily the last one, as in this case:

Mis
  i
  sip
-----
Mis
  i
  sip
    i



Rules


The string will only contain printable ASCII characters, but won't contain any kind of whitespace.
You can compete in any programming language and can take input and provide output through any standard method and in any reasonable format1, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.
1 Input: String / List of characters / whatever else your language uses to represent strings. Output: Multiline string, list of strings representing lines or list of lists of characters/length-1 strings, but please include a pretty-print version of your code in your answer, if possible.
Regarding additional spaces, the output may contain:


Leading / trailing newlines
Trailing spaces on each line / at the end
A consistent number of leading spaces on each line

You must begin to output horizontally, you may not start vertically.


Test cases

Inputs:


"Perfect"
"Mississippi"
"Oddities"
"Trivialities"
"Cthulhu"
"PPCG"
"pOpOpOpOpOpOp"
"ABCCCE"
"ABCCCECCEEEEC"
"abcdcebffg"
"abca"
"AAAAAAAA"


Corresponding outputs:


Perf
 c
 t



Mis
  i
  sip
    i



Od
 ies
 t



Triv
  a
  l
  ies
  t



Cthul
  u



P
C
G



pO 
OpO
pOp
 p



ABC
  C
  E



ABC
  CCE
  E EC



abcd
  e
  b
  fg



abc



A
AA
 A
Wolfram Language (Mathematica), 143 bytes

{#}//.{q___,a_,r___,a_,Longest@s___}:&gt;{q}~f@{a,r}~{{s}}//.{q_~f@a_~s_}/;s~FreeQ~f:&gt;(PadLeft@{q~Join~#,##2}&amp;)@@PadRight@Join[{a},s]/. 0-&gt;" "&amp;


Try it online!

Contains 0xF8FF, which corresponds to the \[Transpose] operator.

Phew, it was tough making the result into a string. Getting each branch isn't so tough: #//.{q___,a_,r___,a_,Longest@s___}:&gt;{q,a,{r},{s}}&amp;