=ARRAYFORMULA({SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY("♠"&SORT(UNIQUE(FILTER(A2:A, A2:A<>"")))&
TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
"select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0)),
"♠ ♦"&TRANSPOSE(SORT(UNIQUE(FILTER(B2:B, B2:B<>""))))&"♦"&QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
"select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0), ))
, , 999^99))&"♠ ♦Total:♦"&MMULT(QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
"select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0)*1,
TRANSPOSE(SPLIT(REPT(COUNTUNIQUE(B2:B)&"♦", COUNTUNIQUE(B2:B)), "♦")^0)), , 999^99)),
"♠")), "♦"); "", "Total:", SUM(C2:C)})